+window.Devices = class Devices {
+ constructor(geotab, filter, date) {
+ this.groupSearch = filter;
+ setGroupSearch(filter) {
+ this.groupSearch = filter;
+ return this.Devices[i];
+ getDeviceById(DeviceID) {
+ for(var i = 0; i < this.Devices.length; i++) {
+ if(DeviceID.toString() == this.Devices[i].id)
+ return this.Devices[i];
+ return this.Devices[i].logRecords;
+ getLogRecordsById(DeviceID) {
+ for(var i = 0; i < this.Devices.length; i++) {
+ if(DeviceID.toString() == this.Devices[i].id)
+ return this.Devices[i].logRecords;
+ return this.geotab.call("Get", {typeName: "Group"});
+ window.changeLoadingMessage("Groups")
+ if (this.geoGroups !== undefined && this.geoGroups.length > 0) {
+ for (var i = 0; i < this.geoGroups.length; i++) {
+ if (this.geoGroups[i].name === undefined) {
+ this.groupCache[this.geoGroups[i].id] = this.geoGroups[i].id;
+ this.groupCache[this.geoGroups[i].id] = this.geoGroups[i].name;
+ return this.groupCache[id];
+ window.changeLoadingMessage("Devices")
+ return this.geotab.call("Get", {
+ groups: this.groupSearch,
+ fromDate: this.date.start.toISOString()
+ .then(Devices => this.Devices = Devices)
+ .then(groups => this.geoGroups = groups)
+ .then(this.buildGroupCache)
+ .then(this.pullRouteProgression)
+ .then(this.pullLogRecords)
+ .then(function(logRecords) {
+ for(var i = 0; i < logRecords.length; i++) {
+ if(logRecords[i].length > 0)
+ _this.Devices[i].logRecords = _this.filter(logRecords[i], logRecords[i][0].device.id);
+ window.changeLoadingMessage("LogRecords")
+ var calls = this.Devices.map(device => ({
+ fromDate: this.date.start.toISOString(),
+ toDate: this.date.end.toISOString(),
+ deviceSearch: {id: device.id}
+ return this.geotab.multiPromise("Get", calls);
+ var device = this.getDeviceById(vId);
+ device.selected = false;
+ groups.forEach(function(value) {
+ tmpGroups.push(value.id);
+ if(value.children.length > 0)
+ tmpGroups.concat(self.getGroups(value.children));
+ getGroupNames(groups) {
+ groups.forEach(function(value) {
+ tmpGroups.push(self.getGroupNameById(value.id));
+ if(value.children.length > 0)
+ tmpGroups.concat(self.getGroups(value.children));
+ this.exportKML(); return;
+ csvContent = "data:text/csv;charset=utf-8,",
+ dateString = this.date.getFullYear() + "-" + (this.date.getMonth() + 1) + "-" + this.date.getDate();
+ data.push(["Device", "Latitude", "Longitude","Date"]);
+ var devices = this.getDevices();
+ devices.forEach((device, deviceId) => {
+ device.logRecords.forEach((logRecord, key) => {
+ new Date(this.date).toISOString()
+ data.forEach(function(infoArray, index){
+ var dataString = infoArray.join(",");
+ csvContent += index < data.length ? dataString+ "\n" : dataString;
+ var encodedUri = encodeURI(csvContent);
+ var link = document.createElement("a");
+ link.setAttribute("href", encodedUri);
+ link.setAttribute("download", "LatReport"+dateString+".csv");
+ var devices = this.getDevices();
+ var xw = new XMLWriter('UTF-8');
+ xw.formatting = 'indented';
+ xw.writeStartDocument( );
+ xw.writeStartElement( 'kml' );
+ xw.writeAttributeString( "xmlns", "http://www.opengis.net/kml/2.2" );
+ xw.writeStartElement('Document');
+ devices.forEach((device, deviceId) => {
+ if(device.logRecords && device.logRecords.length > 0 && device.selected) {
+ xw.writeStartElement('Placemark');
+ xw.writeStartElement('name');
+ xw.writeCDATA( device.name );
+ xw.writeStartElement('Style');
+ xw.writeStartElement('LineStyle');
+ xw.writeElementString('color', '7fffffff');
+ /*xw.writeElementString('width', '4');*/
+ xw.writeStartElement('description');
+ xw.writeStartElement('LineString');
+ xw.writeElementString('extrude', '1');
+ xw.writeElementString('altitudeMode', 'relativeToGround');
+ xw.writeStartElement( "coordinates" );
+ device.logRecords.forEach((logRecord, key) => {
+ xw.writeString( logRecord.longitude + "," + logRecord.latitude + ",0" );
+ var kmlData = new Blob([xml], { type: 'text/kml' });
+ var kmlURL = URL.createObjectURL(kmlData);
+ var element = document.createElement('a');
+ element.setAttribute('download', 'logrecords.kml');
+ element.style.display = 'none';
+ document.body.appendChild(element);
+ document.body.removeChild(element);
+ getFromDate(DeviceID) {
+ var device = this.getDeviceById(DeviceID);
+ date = new Date(this.date).setHours(0);