Free javascript Hosting


staffs.js

Uploaded on Feb 06 2022 23:16 by parag.cste

var SERVER = "http://127.0.0.1:3000"
var $AVATAR_PANEL = $("#nav-item-avatar-panel");
var $SIDEBAR_TOGGLE = $("#sidebarToggleTop");
var $SIDEBAR_NAV = $("#sidebar-navigation-panel");
var $LOGGEDINUSERNAME = $("#loggedin-user-name");
var $ELEM_SIGNIN = $("#elem-signin");
var $ELEM_DASH = $("#elem-dash");
var $ELEM_TRIPS = $("#elem-trips");
var $MARKUP_C_ITEM = $("#markup-coachlist-item");
var $MARKUP_TICKET_LI = $("#markup-ticket-li");
var $PILLS_ONGOING = $("#pills-ongoing");
var $PILLS_UPCOMING = $("#pills-upcoming");
var $PILLS_COMPLETED = $("#pills-completed");
var ELEM_BTN_PASSENGER_DETAILS = ".btn_passenger_details";
var SPINNER = '<div class="spinner-grow text-info" role="status"><span class="sr-only">Loading...</span></div>';
var $ALERT_SIGNIN = $("#alert-signin");
var $NAV_TRIPS = $("#nav-trips");
var $NAV_DASH = $("#nav-dash");
var CACHE_NAME = "curStaff";

/* Get loggedin stafff info from cache */
var CUR_STAFF = localStorage.getItem(CACHE_NAME) == null ? null : localStorage.getItem(CACHE_NAME);
console.log(CUR_STAFF);

if(CUR_STAFF == null || CUR_STAFF == 'null') {
showLoggedoutUI();
} else {
showLoggedinUI();
}

$(document).on('click', '#btn-signin', async function (e) {
let mobile = $("#form-signin .mobile").val();
let pwd = $("#form-signin .password").val();

let res = await axios.post(SERVER + '/staffs/signin', {
mobile: mobile,
pwd: pwd
});

if(res.data.status == true) {
localStorage.setItem(CACHE_NAME, JSON.stringify(res.data));
CUR_STAFF = JSON.stringify(res.data);
showLoggedinUI();
$ALERT_SIGNIN.addClass("d-none");
} else {
$ALERT_SIGNIN.removeClass("d-none");
}
$("#form-signin .password").val("");
});

$(document).on('click', '#btn-logout', function (e) {
localStorage.setItem(CACHE_NAME, null);
$("#logoutModal").modal('hide');
showLoggedoutUI();
Notify("<i class='fa fa-check'></i>", "You have been logged out", "info");
});

$NAV_DASH.click(async function() {
$ELEM_DASH.removeClass('d-none');
$ELEM_TRIPS.addClass('d-none');
$ELEM_DASH.find(".card-body").find(".row").hide();
$ELEM_DASH.find(".card-body").append(SPINNER);
let res = await axios.post(SERVER + '/staffs/getStaffDashData', {
id: JSON.parse(CUR_STAFF).id
});
// console.log(res.data.data[0].total_trx);
$ELEM_DASH.find("#lifetime-completed-trips").html(res.data.lifetime_completed_trips[0].lifetime_completed_trips);
$ELEM_DASH.find("#lifetime-trip-earnings").html(res.data.lifetime_trip_earnings[0].lifetime_trip_earnings);
$ELEM_DASH.find("#lifetime-trip-due").html(res.data.lifetime_trip_due[0].lifetime_trip_due);
$ELEM_DASH.find(".card-body").find(".row").show();
$ELEM_DASH.find(".card-body").find(".spinner-grow").remove();
});

$NAV_TRIPS.click(async function() {
$ELEM_DASH.addClass('d-none');
$ELEM_TRIPS.removeClass('d-none');
$PILLS_UPCOMING.html(SPINNER);
$PILLS_ONGOING.html(SPINNER);
$PILLS_COMPLETED.html(SPINNER);

let res = await axios.post(SERVER + '/staffs/getCoachesByStaffID', {
id: JSON.parse(CUR_STAFF).id
});

$PILLS_UPCOMING.empty();
$PILLS_ONGOING.empty();
$PILLS_COMPLETED.empty();

if(res.data.status == true) {
let coaches = res.data.coaches;
// console.log(coaches);
_.each(coaches, function (coach) {
populateCoachListMarkup(coach);
});

if($PILLS_COMPLETED.find(".coachlist-item").length <= 0 ) {$PILLS_COMPLETED.html("<div class='alert alert-danger'>No Upcoming Coach Found</div>")}

} else {

}
});

$(document).on('click', ELEM_BTN_PASSENGER_DETAILS, async function (e) {
let cuid = $(this).closest(".coachlist-item").attr("data-coach-unique-id");
let $C_MARKUP = $(this).closest(".coachlist-item");
let $TICKET_INFO = $C_MARKUP.find(".ticket-info");
$TICKET_INFO.removeClass('d-none');
$TICKET_INFO.find('.list-group').empty();
$TICKET_INFO.find(".list-group").html(SPINNER);
let res = await axios.post(SERVER + '/staffs/getPassengerDetailsByCoachUniqueID', {
coach_unique_id: cuid
});

if(res.data.status == true) {
let tickets = res.data.tickets;
// console.log(tickets.length)
if(tickets.length >=1) {

let ordered_s_counters = _.groupBy(tickets, 'start_counter_id');
_.each(ordered_s_counters, function (counters) {
let $TICKET_ITEM = $MARKUP_TICKET_LI.find(".list-group-item").clone();
$TICKET_ITEM.find(".counter-name").html(counters[0].start_counter_name);
_.each(counters, function (counter) {
let customer_gender = counter.customer_gender == 'M' ? 'Male' : 'Female';
let h = `<div class="row mt-2 border pt-1 pb-1">
<div class="col-md-6 col-12">
<div class="col-md-12 p-0">
<span class="badge badge-light">${counter.seats}</span>
</div>
<div class="col-md-12 p-0">
<div class="col-12 p-0">Start: <span>${counter.start_counter_name}</span></div>
<div class="col-12 p-0">End: <span>${counter.end_counter_name}</span></div>
</div>
</div>
<div class="col-md-6 col-12 p-0">
<div class="col-12">Name: <span class="">${counter.customer_name}</span></div>
<div class="col-12">Gender: <span class="">${customer_gender}</span></div>
<div class="col-12">Mobile: <span class=""><a href="tel:${counter.customer_mobile}">${counter.customer_mobile}</a></span></div>
</div>
</div>`;
$TICKET_ITEM.find(".ticket-details").append(h);
});
$TICKET_INFO.find(".list-group").find(".spinner-grow").remove();
$TICKET_INFO.find(".list-group").append($TICKET_ITEM);
});
} else {
$TICKET_INFO.find(".list-group").addClass("d-none");
$C_MARKUP.find(".msg-tickets").removeClass("d-none").html(`<div class="alert alert-danger">No Tickets!!</div>`);
}
} else {
$TICKET_INFO.find(".list-group").addClass("d-none");
$C_MARKUP.find(".msg-tickets").removeClass("d-none").html(`<div class="alert alert-danger">Can not connect to server!!</div>`);
}
});

$NAV_DASH.click(function() {
$ELEM_TRIPS.addClass('d-none');
$ELEM_DASH.removeClass('d-none');
});

function populateCoachListMarkup(coach) {
let is_ac = coach.is_ac == 1 ? 'AC' : 'Non AC';
let departure_time = moment(coach.departure_time, 'hh:mm:ss').format('hh:mm A')
let markup = $MARKUP_C_ITEM.find(".coachlist-item").clone();
markup.removeClass("d-none");
markup.attr("data-coach-unique-id", coach.unique_id);
markup.find(".coach-info .departure_time").html(departure_time);
markup.find(".coach-info .departure_date").html(coach.departure_date);
markup.find(".coach-info .s_counter").html(coach.s_counter);
markup.find(".coach-info .e_counter").html(coach.e_counter);
markup.find(".coach-info .is_ac").html(is_ac);
markup.find(".coach-info .coach_code").html(coach.code);
markup.find(".coach-info .bus_no").html(coach.license_plate_no);
markup.find(".coach-info .supervisor_name").html(coach.supervisor);
markup.find(".coach-info .supervisor_mob").html(coach.supervisor_mobile);
markup.find(".coach-info .driver_name").html(coach.driver);
markup.find(".coach-info .driver_mob").html(coach.driver_mobile);
markup.find(".coach-info .helper_name").html(coach.helper);
markup.find(".coach-info .helper_mob").html(coach.helper_mobile);
if(coach.status == 1) { // upcoming coach
$PILLS_UPCOMING.append(markup);
} else if (coach.status == 2) {
$PILLS_ONGOING.append(markup);
} else if (coach.status == 3) {
$PILLS_COMPLETED.append(markup);
}

}

function showLoggedinUI() {
$ELEM_SIGNIN.addClass('d-none');
$SIDEBAR_TOGGLE.removeClass('d-none');
$AVATAR_PANEL.removeClass('d-none');
$SIDEBAR_NAV.removeClass('d-none');
$ELEM_DASH.removeClass('d-none');
$LOGGEDINUSERNAME.html(JSON.parse(CUR_STAFF).name);

$NAV_DASH.click();
}

function showLoggedoutUI() {
$ELEM_SIGNIN.removeClass('d-none');
$SIDEBAR_TOGGLE.addClass('d-none');
$AVATAR_PANEL.addClass('d-none');
$SIDEBAR_NAV.addClass('d-none');
$ELEM_DASH.addClass('d-none');
$ELEM_TRIPS.addClass('d-none');
}

$(document).ready(function() {
$NAV_DASH.click();
});

Back to list