123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- // 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 url = '/TankDetails/';
- 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';
- let mqttoptions = {
- clientId: 'mqttjs_' + (Math.random() * 1000000).toString(),
- timeout: 5000,
- useSSL: false
- };
- let mqttclient = mqtt.connect(mqttUrl, mqttoptions);
- mqttclient.on('connect',
- function (res) {
- mqttclient.subscribe('/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTanksAsync_reply',
- function (err) {
- if (err) {
- console.log(err);
- }
- });
- mqttclient.subscribe('/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankReadingAsync_reply',
- function (err) {
- if (err) {
- console.log(err);
- }
- });
- mqttclient.subscribe('/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankAlarmAsync_reply',
- function (err) {
- if (err) {
- console.log(err);
- }
- });
- mqttclient.subscribe('/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankInventoryAsync_reply',
- function (err) {
- if (err) {
- console.log(err);
- }
- });
- mqttclient.subscribe('/sys/VeederRoot_ATG_Console_Tcp/VeederRoot_ATG_Console.Handler/thing/service/GetTankDeliveryAsync_reply',
- function (err) {
- if (err) {
- console.log(err);
- }
- });
- });
- mqttclient.on('error',
- function (err) {
- console.log(err);
- mqttclient.end();
- });
- mqttclient.on('message',
- function (topic, message) {
- let jsonObj = JSON.parse(message.toString())
- if (jsonObj) {
- OnReply(topic, jsonObj);
- } else {
- console.log(topic, message.toString());
- }
- });
- function Publish1(path) {
- mqttclient.publish(path, '[]');
- }
- function Publish2(value, path) {
- 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() {
- RenderDiv(url + defaultFnav, containerDiv, url + 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(currentId, fnav) {
- RenderDiv(url + currentId, containerDiv, url + defaultPageDic[currentId], contentDiv);
- ToggleClass(currentId, fnav);
- }
- function RenderIndexContainer(currentId, fnav, index) {
- RenderDiv(url + currentId, containerDiv, '/TankDetails/TankDeviceDetails?index=' + index, contentDiv);
- ToggleClass(currentId, fnav);
- }
- function RenderContent(currentId, rnav) {
- RenderDiv(url + 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);
- }
- })
- }
|