123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
- // for details on configuring this project to bundle and minify static web assets.
- // Write your JavaScript code.
- let httpUrl = 'http://127.0.0.1:6688';
- //let mqttUrl = 'ws://localhost:8384/mqtt';
- //let basicUrl = 'http://localhost:8384';
- var href = window.location.href;
- var path = window.location.pathname;
- let basicUrl = href.slice(0, href.indexOf(path));
- //"ws://localhost:8384/mqtt"
- let mqttUrl = "ws:" + basicUrl.slice(basicUrl.indexOf("//")) + "/mqtt";
- let apis = new Map();
- let containerDiv = 'tankcontainer';
- let contentDiv = 'content';
- let defaultFnav = 'TankOverviewFnav';
- let defaultPageDic = new Array();
- defaultPageDic['TankOverviewFnav'] = 'TankDevicesOverview';
- defaultPageDic['TankDetailFnav'] = 'TankDeviceDetails?index=0';
- defaultPageDic['AlarmHistoryFnav'] = 'AlarmHistory';
- defaultPageDic['FuelInventoryFnav'] = 'FuelInventoryList';
- defaultPageDic['SensorDataFnav'] = 'SensorDataDetails';
- defaultPageDic['ListTabFnav'] = 'ListTabPage';
- defaultPageDic['ChartInquiryFnav'] = 'ChartInquiryPage';
- defaultPageDic['NozzlesFnav'] = 'Nozzles';
- let mqttoptions = {
- clientId: 'mqttjs_' + (Math.random() * 1000000).toString(),
- timeout: 5000,
- useSSL: false
- };
- let mqttclient = mqtt.connect(mqttUrl, mqttoptions);
- mqttclient.on('connect',
- function (res) {
- subscribeEvents();
- });
- mqttclient.on('error',
- function (err) {
- console.log(err);
- mqttclient.end();
- });
- mqttclient.on('message',
- function (topic, message) {
- let jsonObj = JSON.parse(message.toString())
- console.log("mqtt client on message:" + typeof (OnReply));
- if (jsonObj && typeof (OnReply) === "function") {
- OnReply(apis, topic, jsonObj);
- } else {
- console.log(topic, message.toString());
- }
- });
- function subscribeEvents() {
- if (!mqttclient.connected || apis.size === 0) {
- console.log("subscribeEvents: mqttclient is not connected or haven't got APIS");
- return;
- }
- mqttclient.subscribe(apis.has("GetTanksAsync_Reply") ? apis.get("GetTanksAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTanksAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetTanksAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetTankReadingAsync_Reply") ? apis.get("GetTankReadingAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankReadingAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetTankReadingAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetTankAlarmAsync_Reply") ? apis.get("GetTankAlarmAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankAlarmAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetTankAlarmAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetTankInventoryAsync_Reply") ? apis.get("GetTankInventoryAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankInventoryAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetTankInventoryAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetTankDeliveryAsync_Reply") ? apis.get("GetTankDeliveryAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankDeliveryAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetTankDeliveryAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetPressureAsync_Reply") ? apis.get("GetPressureAsync_Reply") : '/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetPressureAsync_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetPressureAsync_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetVRBoardNozzleTrxFlowDatas_Reply") ? apis.get("GetVRBoardNozzleTrxFlowDatas_Reply") : '/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetVRBoardNozzleTrxFlowDatas_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetVRBoardNozzleTrxFlowDatas_Reply successfully");
- };
- });
- mqttclient.subscribe(apis.has("GetVaporRecoveryConfig_Reply") ? apis.get("GetVaporRecoveryConfig_Reply") : '/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetVaporRecoveryConfig_Reply',
- function (err) {
- if (!err) {
- console.log("Subscribe GetVaporRecoveryConfig_Reply successfully");
- };
- });
- }
- function Publish1(path, apiname) {
- path = apis.has(apiname) ? apis.get(apiname) : (path + apiname)
- mqttclient.publish(path, '[]');
- }
- function Publish2(value, path, apiname) {
- path = apis.has(apiname) ? apis.get(apiname) : (path + apiname)
- mqttclient.publish(path, value);
- }
- function Publish(name, value, path) {
- let parameters = '{"Parameters": [{"Name": "';
- parameters += name;
- parameters += '", "Value": "';
- parameters += value.replace(new RegExp('"', 'gm'), '\\"') + '"}]}';
- //console.log(parameters);
- mqttclient.publish(path, parameters);
- }
- function OnloadIndex(controller, defaultPage = 'TankOverviewFnav') {
- defaultFnav = defaultPage;
- RenderDiv(controller + defaultFnav, containerDiv, controller + defaultPageDic[defaultFnav], contentDiv);
- }
- function RenderDiv(containerUrl, containerDiv, contentUrl, contentDiv) {
- $.ajax({
- url: containerUrl,
- success: function (result) {
- $('#' + containerDiv).html(result);
- if (contentUrl) {
- RenderDiv(contentUrl, contentDiv, null, null);
- }
- },
- error: function (msg) {
- console.log(msg);
- }
- })
- }
- function RenderContainer(ontroller, currentId, fnav) {
- RenderDiv(ontroller + currentId, containerDiv, ontroller + defaultPageDic[currentId], contentDiv);
- ToggleClass(currentId, fnav);
- }
- function RenderIndexContainer(ontroller, currentId, fnav, index) {
- RenderDiv(ontroller + currentId, containerDiv, ontroller + 'TankDeviceDetails?index=' + index, contentDiv);
- ToggleClass(currentId, fnav);
- }
- function RenderContent(ontroller, currentId, rnav) {
- RenderDiv(ontroller + currentId, contentDiv, null, null);
- ToggleClass(currentId, rnav);
- }
- function ToggleClass(currentId, array) {
- for (let i = 0; i < array.length; i++) {
- let classNames = array[i].className;
- let classImage = classNames.split(' ')[0] + '-image';
- let id = array[i].id;
- if (classNames.length > 1) {
- $('#' + id).removeClass(classImage);
- }
- if (currentId == id) {
- $('#' + id).addClass(classImage);
- }
- }
- }
- function InvokeHttpGet(apiUrl, callback) {
- $.ajax({
- url: httpUrl + apiUrl,
- contentType: 'application/json',
- success: function (res) {
- callback(res);
- },
- error: function (msg) {
- console.log(msg)
- }
- })
- }
- function InvokeHttpPost(apiUrl, reqdata, callback) {
- $.ajax({
- url: httpUrl + apiUrl,
- contentType: 'application/json',
- data: JSON.stringify(reqdata),
- type: 'post',
- success: function (res) {
- callback(res);
- },
- error: function (msg) {
- console.log(msg);
- }
- })
- }
- function ShowMeAPIS(parameter, callBack) {
- var serviceUrl = basicUrl + "/u/?apitype=service&an=ShowMeApi&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
- $.ajax({
- url: serviceUrl,
- datatype: "application/json",
- type: 'post',
- contentType: "application/json;charset=utf-8;",
- data: JSON.stringify(parameter),
- beforeSend: function () {
- },
- success: function (data) {
- console.log(data);
- data.forEach(function (d) {
- if (d.Path === null) return;
- if (apis.has(d.ApiName)) {
- apis.delete(d.ApiName);
- }
- apis.set(d.ApiName, d.Path.slice(d.Path.length - 1) === "+" ? d.Path.slice(0, d.Path.length - 1) : d.Path);
- });
- subscribeEvents();
- if (callBack !== null) callBack();
- },
- error: function (err) {
- console.log(err);
- if (callBack !== null) callBack();
- }
- });
- }
- function GetDataByAPIS(apiName, parameter, method, callBack) {
- if (apis.size === 0 || !apis.has(apiName)) return;
- $.ajax({
- url: basicUrl + apis.get(apiName),
- datatype: "application/json",
- type: method,
- contentType: "application/json;charset=utf-8;",
- data: JSON.stringify(parameter),
- beforeSend: function () {
- },
- success: function (data) {
- console.log(data);
- if (callBack !== null) callBack(data);
- },
- error: function (err) {
- console.log(err);
- if (callBack !== null) callBack(err);
- }
- });
- }
|