From 54179bd03faeef3e2bd16eac6d7d662f685cc74a Mon Sep 17 00:00:00 2001 From: Jakub Hazik Date: Thu, 28 Dec 2023 14:17:08 +0100 Subject: [PATCH 1/6] Add USA hazmats STR-6404 --- mygeotab-sygic-page/src/app/scripts/main.js | 47 ++++++-- sygic-geotab-utils/src/utils.js | 120 ++++++++++++++++++-- 2 files changed, 149 insertions(+), 18 deletions(-) diff --git a/mygeotab-sygic-page/src/app/scripts/main.js b/mygeotab-sygic-page/src/app/scripts/main.js index 44dc977..fb7ff70 100644 --- a/mygeotab-sygic-page/src/app/scripts/main.js +++ b/mygeotab-sygic-page/src/app/scripts/main.js @@ -43,14 +43,28 @@ geotab.addin.mygeotabSygicPage = function (api, state) { @@ -94,11 +108,21 @@ geotab.addin.mygeotabSygicPage = function (api, state) { dimensionDetailsString = 'Dimensions unset'; } + let dimensionsTemplateObject = Object.keys(viewModel).map(key => { + if (key !== 'hazmat') { + return { + value: viewModel[key].value, + key: key, + label: viewModel[key].label, + }; + } + return null; + }).filter(Boolean); - let dimensionsTemplateObject = Object.keys(viewModel).map(key => ({ - value: viewModel[key].value, - key: key, - label: viewModel[key].label + let hazmatTemplateObject = Object.keys(viewModel.hazmat.value).map(key => ({ + value: viewModel.hazmat.value[key].value, + key: key, + label: viewModel.hazmat.value[key].label })); let vehicle_groups_string = device.groups.map((c) => c.name).join(', '); @@ -107,6 +131,7 @@ geotab.addin.mygeotabSygicPage = function (api, state) { vehicle_dimensions_string: dimensionDetailsString, vehicle_groups_string: vehicle_groups_string, vehicle_dimensions: dimensionsTemplateObject, + vehicle_hazmat: hazmatTemplateObject, user: user, apply_changes: state.translate('Apply Changes'), }); diff --git a/sygic-geotab-utils/src/utils.js b/sygic-geotab-utils/src/utils.js index 15b8197..723fb1e 100644 --- a/sygic-geotab-utils/src/utils.js +++ b/sygic-geotab-utils/src/utils.js @@ -147,24 +147,101 @@ export function ApiWrapper(api) { }; } +export class HazmatModel { + constructor({ general, h_class}) { + this.general = general; + this.h_class = h_class; // Possible values: 1,2,3,4,5,6,7,8,9,I , values can be combined, e.g. h_class='124' + } + static getEmpty() { + return new HazmatModel({general: false, h_class:""}); + } + + static getFromStringInputs({general, h_class}) { + if (general === undefined) + { + general = false; + } + if (h_class === undefined) + { + h_class = ''; + } + return new HazmatModel({general: general, h_class: h_class}); + } + + getViewModel(state) { + return { + general: { + value: this.general, + label: `${state.translate('General Hazmat')}`, + }, + class1: { + value: this.h_class.indexOf('1') > -1, + label: `${state.translate('Explosive')} (Class 1)`, + }, + class2: { + value: this.h_class.indexOf('2') > -1, + label: `${state.translate('Flammable gas')} (Class 2)`, + }, + class3: { + value: this.h_class.indexOf('3') > -1, + label: `${state.translate('Flammable liquid')} (Class 3)`, + }, + class4: { + value: this.h_class.indexOf('4') > -1, + label: `${state.translate('Flammable solid')} (Class 4)`, + }, + class5: { + value: this.h_class.indexOf('5') > -1, + label: `${state.translate('Oxidizer')} (Class 5)`, + }, + class6: { + value: this.h_class.indexOf('6') > -1, + label: `${state.translate('Poison')} (Class 6)`, + }, + class7: { + value: this.h_class.indexOf('7') > -1, + label: `${state.translate('Radioactive material')} (Class 7)`, + }, + class8: { + value: this.h_class.indexOf('8') > -1, + label: `${state.translate('Corrosive material')} (Class 8)`, + }, + class9: { + value: this.h_class.indexOf('9') > -1, + label: `${state.translate('Miscellaneous')} (Class 9)`, + }, + classI: { + value: this.h_class.indexOf('I') > -1, + label: `${state.translate('Poison inhalation')} (Class I)`, + }, + } + } + +} // class + export class DimensionsModel { - constructor({ width, height, total_weight, axle_weight, total_length }) { + constructor({ width, height, total_weight, axle_weight, total_length, hazmat}) { this.width = width; this.height = height; this.total_length = total_length; this.axle_weight = axle_weight; this.total_weight = total_weight; + if (hazmat === undefined) { + this.hazmat = HazmatModel.getEmpty(); + } else { + this.hazmat = hazmat; + } } static getEmpty() { - return new DimensionsModel({ undefined, undefined, undefined, undefined, undefined }); + return new DimensionsModel({ undefined, undefined, undefined, undefined, undefined, undefined }); } static getEmptyViewModel(isMetric, state) { return new DimensionsModel.getEmpty().getViewModelWithUnits(isMetric, state) } - static getFromStringInputs({ width, height, total_weight, axle_weight, total_length }, isMetric = true) { + static getFromStringInputs({ width, height, total_weight, axle_weight, total_length, hazmat }, isMetric = true) { width = Number.parseFloat(width); height = Number.parseFloat(height); total_weight = Number.parseFloat(total_weight); @@ -178,7 +255,13 @@ export class DimensionsModel { total_length = Dimensions.convertDimensionToMetric(total_length); } - const data = { width, height, total_weight, axle_weight, total_length }; + if (hazmat !== undefined) { + hazmat = HazmatModel.getFromStringInputs(hazmat); + } else { + hazmat = HazmatModel.getEmpty(); + } + + const data = { width, height, total_weight, axle_weight, total_length, hazmat }; return new DimensionsModel(data); } @@ -228,6 +311,9 @@ export class DimensionsModel { total_weight: { value: roundTo2Decimals(total_weight), label: isMetric ? `${state.translate('Total weight')} (kg)` : `${state.translate('Total weight')} (lb)` + }, + hazmat : { + value: this.hazmat.getViewModel(state), } } } @@ -262,12 +348,25 @@ export let Dimensions = { getInputValues: (parentElement) => { let dimensionsModel = DimensionsModel.getEmpty(); for (const key in dimensionsModel) { - if (dimensionsModel.hasOwnProperty(key) && key !== 'isMetric') { + if (dimensionsModel.hasOwnProperty(key) && key !== 'isMetric' && key !== 'hazmat') { dimensionsModel[key] = parentElement.querySelector( - `input[name=sygic-truck-${key}]` + `input[name=sygic-truck-dimensions-${key}]` ).value; } } + + const hazmat_general = parentElement.querySelector('input[name=sygic-truck-hazmat-general]').checked; + let hazmat_classes = ""; + for (const h_class of "123456789I") { + const checked = parentElement.querySelector(`input[name=sygic-truck-hazmat-class${h_class}]`).checked; + if (checked) { + hazmat_classes += h_class; + } + } + + dimensionsModel.hazmat.general = hazmat_general; + dimensionsModel.hazmat.h_class = hazmat_classes; + return dimensionsModel; }, }; @@ -358,8 +457,15 @@ export function createSygicTruckAttrUrl(dimensions) { valueArray.push(`hei=${dimensions.height}`); } + valueArray.push(`general=${dimensions.hazmat.general * 1}`); + if (dimensions.hazmat.h_class.length > 0) { + valueArray.push(`hClass=${dimensions.hazmat.h_class}`); + } else { + valueArray.push(`hClass=0`); + } + if (valueArray.length > 0) { return `truckSettings|${valueArray.join('&')}&rou=tru`; } return ''; -} \ No newline at end of file +} From fde7b4b5151e8174c1a0055053c07db3b8f3e9da Mon Sep 17 00:00:00 2001 From: Jakub Hazik Date: Fri, 29 Dec 2023 13:55:38 +0100 Subject: [PATCH 2/6] Add hazmats for EU STR-6404 --- .../src/app/scripts/main.js | 7 +- mygeotab-sygic-page/src/app/scripts/main.js | 29 +++++-- sygic-geotab-utils/src/utils.js | 82 +++++++++++++------ 3 files changed, 83 insertions(+), 35 deletions(-) diff --git a/geotabdrive-sygic-addin/src/app/scripts/main.js b/geotabdrive-sygic-addin/src/app/scripts/main.js index 7d715fd..1e546c6 100644 --- a/geotabdrive-sygic-addin/src/app/scripts/main.js +++ b/geotabdrive-sygic-addin/src/app/scripts/main.js @@ -122,9 +122,9 @@ geotab.addin.sygic = function (api, state) { <% if (obj.hasOwnProperty(key)) { %> <% let dimension_label = obj[key].label; %> <% let value = obj[key].value; %> -