301 lines
11 KiB
JavaScript
301 lines
11 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GoData-ECom Express
|
|
+ Filename : HistoryTracking.js
|
|
+ Module Name : Tracking
|
|
+ Purpose : For history tracking of users in outside field using GPS locator.
|
|
+ Coded By : Jitendra Tiwari & Pankaj Khandal
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
* For live monitoring and history tracking of users in outside field using GPS locator.
|
|
* @module TrackingModule
|
|
*/
|
|
|
|
// Global variables
|
|
var ccplMap = null, markerImagePath = "../../Scripts/map_api/icons/red_blank.png", markerTransImgPath = "../../Scripts/map_api/icons/red_blink.gif", defaultLat = 26.912285124827, defaultLng = 75.7873203125;
|
|
var SecurityToken, utcMinutes, UserId;
|
|
|
|
|
|
/*================================================Map Function=============================================*/
|
|
/**
|
|
* Load google map on page.
|
|
* @method initMap
|
|
* @for HistoryTracking
|
|
*/
|
|
function initMap() {
|
|
var mapOptions = { mapPro: 'googleMap', mapDiv: document.getElementById("divMapContainer"), zoom: 12, centerLatitude: 26.912285124827, centerLongitude: 75.7873203125, mapType: 'ROADMAP' }
|
|
ccplMap = new vtsMap(mapOptions);
|
|
}
|
|
|
|
/**
|
|
* Function used to set map location to center.
|
|
* @method setMapLocation
|
|
* @param {String} lat Latitude
|
|
* @param {String} lng Longitude
|
|
* @for HistoryTracking
|
|
*/
|
|
function setMapLocation(lat, lng) { if (ccplMap) { ccplMap.moveMap(lat, lng); } }
|
|
|
|
/**
|
|
* Function used to remove all existing path from map.
|
|
* @method removeAllPath
|
|
* @for HistoryTracking
|
|
*/
|
|
function removeAllPath() { if (ccplMap) { ccplMap.removeAllUnitPath(); } }
|
|
|
|
/**
|
|
* Function used to draw path on map.
|
|
* @method setMapPath
|
|
* @param {Object} jsonObject Required json object for drawing path on map.
|
|
* @for HistoryTracking
|
|
*/
|
|
function setMapPath(jsonObject) {
|
|
//console.log(jsonObject);
|
|
if (ccplMap) {
|
|
ccplMap.drawMultipleUnitPath(jsonObject);
|
|
}
|
|
}
|
|
|
|
//function infoOpen(currObj) {
|
|
// var currRow = $(currObj);
|
|
// if (ccplMap && currObj) {
|
|
// currRow.parent().find('.activeRow').removeClass('activeRow');
|
|
// currRow.addClass('activeRow');
|
|
// var jsonObj = { latitude: currRow.attr('lat'), longitude: currRow.attr('lng'), recordTime: currRow.attr('time'), distance: currRow.attr('dist') };
|
|
// ccplMap.infoOpen(jsonObj);
|
|
// }
|
|
//}
|
|
|
|
/*===================================================End=====================================================*/
|
|
|
|
/*===============================================Device RESTful API===================================*/
|
|
/**
|
|
* Creating a Model for showing data on Live Tracking page. (Dynamic UI)
|
|
* @class HistoryTracking
|
|
* @constructor
|
|
*/
|
|
function HistoryTrackingModel() {
|
|
'use strict';
|
|
var self = this;
|
|
self.chosenEmployee = ko.observable();
|
|
//ViewModel
|
|
self.ServiceEngineerContactNumber = ko.observable();
|
|
self.ServiceEngineerId = ko.observable();
|
|
self.ServiceEngineerName = ko.observable();
|
|
self.VanRegistrationNumber = ko.observable();
|
|
self.IsConnected = ko.observable();
|
|
self.VanId = ko.observable();
|
|
self.VanCity = ko.observable();
|
|
self.ServiceEngineerImeiNumber = ko.observable();
|
|
self.RegionId = ko.observable();
|
|
self.OrganizationName = ko.observable();
|
|
self.RegionName = ko.observable();
|
|
self.employees = ko.observableArray([]);
|
|
//self.securityToken = ko.observable();
|
|
|
|
|
|
/**
|
|
* Getting all the employees list and populating the html on page.
|
|
* @method getAllEmployees
|
|
* @for HistoryTracking
|
|
*/
|
|
self.getAllEmployees = function () {
|
|
//console.log("1");
|
|
SecurityToken = securityToken;
|
|
utcMinutes = UtcMinutes;
|
|
UserId = userId;
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
//url: "http://192.168.1.97:666/Api/Tracking?Tracking=tt",
|
|
url: WCFRESTURL.GetUsersListWithCurrentTrackingData,
|
|
data: { Token: SecurityToken, UtcMinute: utcMinutes, UserId: UserId, DealerNameParam: 'All', VanCityParam: 'All', VanStateParam: 'All' },
|
|
dataType: "json",
|
|
success: function (data) {
|
|
// console.log(data);
|
|
if (data.status == 1) {
|
|
var finalEmployeeList = ko.utils.arrayFilter(data.ListUsers, function (item) {
|
|
return item.ServiceEngineerId != null;
|
|
});
|
|
self.employees(finalEmployeeList);
|
|
$("#tableDevices tbody tr td:first").trigger('click');
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
alert(textStatus);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function used to show device detail on page.
|
|
* @method showDeviceDetail
|
|
* @param {Object} employee Chosen device object.
|
|
* @for HistoryTracking
|
|
*/
|
|
self.showEmployeeDetail = function (employee) {
|
|
self.chosenEmployee(employee).ServiceEngineerId(employee.ServiceEngineerId).ServiceEngineerName(employee.ServiceEngineerName).VanCity(employee.VanCity).ServiceEngineerContactNumber(employee.ServiceEngineerContactNumber).VanRegistrationNumber(employee.VanRegistrationNumber).VanId(employee.VanId).ServiceEngineerImeiNumber(employee.ServiceEngineerImeiNumber).OrganizationName(employee.OrganizationName);
|
|
//.EmployeeAddress(employee.EmployeeAddress).EmailId(employee.EmailId);
|
|
var date = $("#txtDate").val();
|
|
var startTime = $("#txtStartTime").val();
|
|
var endTime = $("#txtEndTime").val();
|
|
|
|
var splitDate = date.split(" ");
|
|
var year = splitDate[2];
|
|
var month = splitDate[1];
|
|
var day = splitDate[0];
|
|
|
|
var dateTo = $("#txtDateTo").val();
|
|
var splitDateTo = dateTo.split(" ");
|
|
var yearTo = splitDateTo[2];
|
|
var monthTo = splitDateTo[1];
|
|
var dayTo = splitDateTo[0];
|
|
|
|
var FromDate, EndDate;
|
|
FromDate = day + "-" + month + "-" + year + " " + startTime;
|
|
EndDate = dayTo + "-" + monthTo + "-" + yearTo + " " + endTime;
|
|
//console.log(FromDate, EndDate);
|
|
removeAllPath();
|
|
var currtime = getCurrentTime();
|
|
//console.log(FromDate, EndDate);
|
|
$.ajax({
|
|
type: "POST",
|
|
url: WCFRESTURL.GetTrackingHistoryUserWise,
|
|
data: { Token: SecurityToken, UtcMinute: utcMinutes, DeviceAlias: employee.ServiceEngineerDeviceAlias, FromDate: FromDate, ToDate: EndDate },
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
if (data) {
|
|
for (var count = 0; count < data.length; count++) {
|
|
//data.color = "";
|
|
data[count].destinationImage = "../../Scripts/map_api/icons/red_d.png";
|
|
data[count].imgCircle = "../../Scripts/map_api/icons/red_circle.png";
|
|
data[count].sourceImage = "../../Scripts/map_api/icons/red_s.png";
|
|
}
|
|
|
|
// console.log(data);
|
|
setMapPath(data);
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log("error");
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function used to show device history on map.
|
|
* @method showEmployeeHistory
|
|
* @for HistoryTracking
|
|
*/
|
|
self.showEmployeeHistory = function () {
|
|
var devId = $(".activeListTr").attr('id');
|
|
var date = $("#txtDate").val();
|
|
var startTime = $("#txtStartTime").val();
|
|
var endTime = $("#txtEndTime").val();
|
|
|
|
var splitDate = date.split(" ");
|
|
var year = splitDate[2];
|
|
var month = splitDate[1];
|
|
var day = splitDate[0];
|
|
|
|
var dateTo = $("#txtDateTo").val();
|
|
var splitDateTo = dateTo.split(" ");
|
|
var yearTo = splitDateTo[2];
|
|
var monthTo = splitDateTo[1];
|
|
var dayTo = splitDateTo[0];
|
|
|
|
var FromDate, EndDate;
|
|
FromDate = day + "-" + month + "-" + year + " " + startTime;
|
|
EndDate = dayTo + "-" + monthTo + "-" + yearTo + " " + endTime;
|
|
//console.log(FromDate, EndDate);
|
|
|
|
removeAllPath();
|
|
var currtime = getCurrentTime();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: WCFRESTURL.GetTrackingHistoryUserWise,
|
|
data: { Token: SecurityToken, UtcMinute: utcMinutes, DeviceAlias: self.chosenEmployee().ServiceEngineerDeviceAlias, FromDate: FromDate, ToDate: EndDate },
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
//console.log(data);
|
|
if (data) {
|
|
var dataLength = data.length;
|
|
for (var count = 0; count < dataLength; count++) {
|
|
//data[count].color = $.getJSON("/Tracking/GetPathColorCode/", { index: dataLength }, function (data) { if (data.success) { data.result; } });
|
|
data[count].destinationImage = "../../Scripts/map_api/icons/red_d.png";
|
|
data[count].imgCircle = "../../Scripts/map_api/icons/red_circle.png";
|
|
data[count].sourceImage = "../../Scripts/map_api/icons/red_s.png";
|
|
}
|
|
|
|
//console.log(data);
|
|
setMapPath(data);
|
|
}
|
|
},
|
|
error: function (data) {
|
|
console.log("error");
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
// Load all devices.
|
|
self.getAllEmployees();
|
|
}
|
|
/*=====================================================End============================================*/
|
|
|
|
/*============================================Device Searching=========================================*/
|
|
/**
|
|
* Function used to trigger row click event.
|
|
* @method initSearch
|
|
* @param {String} keyCode Input key code.
|
|
* @param {String} sValue text to be search.
|
|
* @for HistoryTracking
|
|
*/
|
|
function initSearch(keyCode, sValue) {
|
|
var $rows = $('#tableDevices tbody tr');
|
|
var jThis;
|
|
if (keyCode != 8 && keyCode != 46) {
|
|
$rows.each(function () {
|
|
jThis = $(this);
|
|
if (jThis.is(':visible')) {
|
|
var oLabel = jThis.find('label').text();
|
|
if (oLabel.length > 0) {
|
|
if (oLabel.toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
|
|
jThis.show();
|
|
} else {
|
|
jThis.hide();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$rows.each(function () {
|
|
jThis = $(this);
|
|
var oLabel = jThis.find('label').text();
|
|
if (oLabel.length > 0) {
|
|
if (oLabel.toLowerCase().indexOf(sValue.toLowerCase()) >= 0) {
|
|
jThis.show();
|
|
} else {
|
|
jThis.hide();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
/**
|
|
* Bind textbox keyup event for searching.
|
|
* @event keyup
|
|
* @for HistoryTracking
|
|
*/
|
|
$('#txtSearch').keyup(function (event) {
|
|
var sValue = $.trim($(this).val());
|
|
initSearch(event.keyCode, sValue);
|
|
}).keydown(function () { }).focus(function () { $(this).select(); });
|
|
/*=================================================End=================================================*/ |