diff --git a/Backend/App_Data/bajaJsList.ods b/Backend/App_Data/bajaJsList.ods index 445e2df..7ec7655 100644 Binary files a/Backend/App_Data/bajaJsList.ods and b/Backend/App_Data/bajaJsList.ods differ diff --git a/Frontend/_dashboard.html b/Frontend/_dashboard.html index b521f52..6f97a67 100644 --- a/Frontend/_dashboard.html +++ b/Frontend/_dashboard.html @@ -9,8 +9,8 @@

- 21.5k - users signed up + 560 + 今日用電量 kWH

@@ -20,8 +20,8 @@

- $10,203 - Visual Index Figure + 6560 + 昨日用電量

@@ -69,8 +69,8 @@

- - 103.72 - Offset Balance Ratio + 9,218 + 即時功率

@@ -80,8 +80,8 @@

- +40% - Product level increase + 8,846 + 即時契約容量占比 kWH

@@ -146,62 +146,12 @@
-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
+
+
+
+
@@ -213,7 +163,7 @@
-
+ +
+ 異常數量
18
+ + 賦歸數量
28
+
+
+ 已確認異常
8
+ + 未確認異常
6
@@ -237,16 +197,26 @@
-
-
-
- 3/10 -
-
- -

14,134

-
-
+ +
+ 已完成
6
+ + 未完成
8
+
+
+ 未派工
5
+ + 派工中
9
@@ -327,8 +297,11 @@ [700, 1] ]; - $(document).ready(function () { + var tarElePath = ''; + $(document).ready(function () { + getSubList(); + getFirstEletric(); /* init datatables */ $('#dt-basic-example').dataTable( { @@ -713,4 +686,80 @@ $("#js-page-content").load("_sysMonAll.html", loadCallback); } + function getSubList() { + let url = baseApiUrl + "/api/Device/GetMainSub"; + let sendData = { + building_tag: pageAct.buiTag, + }; + objSendData.Data = sendData; + ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { + if (!res || res.code != "0000" || !res.data) { + + } else { + let strHtml = ``; + $.each(res.data.history_Main_Systems, (index, mainSysObj) => { + $.each(mainSysObj.history_Sub_systems, (index2, subSysObj) => { + strHtml += `
+ + +
`; + }) + }) + $("#sysSubBtnList").html(strHtml); + getAlarmSub(); + + } + }, null, "POST").send(); + } + + function getFirstEletric() { + let url = baseApiUrl + "/api/Device/GetDeviceList"; + let sendData = { + sub_system_tag: "E4", + building_tag: pageAct.buiTag, + }; + objSendData.Data = sendData; + ytAjax = new YourTeam.Ajax(url, objSendData, function (res) { + if (!res || res.code != "0000" || !res.data) { + + } else { + + $.each(res.data, (index, floObj) => { + $.each(floObj.device_list, (index2, devObj) => { + tarElePath = devObj.device_number; + }) + }) + + getElectricBaja(); + } + }, null, "POST").send(); + } + + function getElectricBaja() { + let devPath = tarElePath.split("_").slice(0, 8).join("_"); + + let today = displayDate(new Date, "date").replaceAll("/", "-") + "T00:00:00"; + let tomorrow = displayDate(new Date(new Date(today).getTime() + (24 * 60 * 60 * 1000)), "date").replaceAll("/", "-") + "T00:00:00"; + + getElectricMeterDayDataByBaja(devPath + "_KWH", "Mitsubishi_Sup", today, tomorrow, (data) => { + console.log(data) + }) + } + + function getAlarmSub() { + + + //$(".dev-group").each((idx, ele) => { + // let path = $(ele).data("id"); + // let start = (new Date()).getTime(); + // console.log("path enter baja:", path); + // getOneSystemStateByBaja(path, (data) => { + // let end = (new Date()).getTime(); + // console.log("執行時間 :" + (end - start) / 1000 + " 秒","path : " + path, "輸出結果 :"+ data) + + + // }) + //}) + + } \ No newline at end of file diff --git a/Frontend/_historyData.html b/Frontend/_historyData.html index 12243f7..f89f042 100644 --- a/Frontend/_historyData.html +++ b/Frontend/_historyData.html @@ -232,7 +232,8 @@ t.fnClearTable(); if (res.data.length > 0) t.fnAddData(res.data); - } + } + $(loadEle).Loading("close"); } function setValue(deviceNumber, deviceName, deviceItem, elem) { diff --git a/Frontend/_sysElevator.html b/Frontend/_sysElevator.html index 18b42c0..47c96d5 100644 --- a/Frontend/_sysElevator.html +++ b/Frontend/_sysElevator.html @@ -3,9 +3,11 @@ background-color: #fff; min-height: 520px; } + .elevator-table-wrapper { - padding:0.8rem; + padding: 0.8rem; } + table.elevator-build { /*border: 1px double #000;*/ } @@ -45,16 +47,16 @@
-
+
- -
@@ -86,49 +88,9 @@
-
+
-
-
- -
號機別 : 1
- -
-

10F

- -

狀態 : 運行中

- -
-
-
-
-
- -
號機別 : 2
- -
-

5F

- -

- 狀態 : 維修 -

- -
-
-
-
-
- -
號機別 : 3
- -
-

3F

- -

狀態 : 運行中

- -
-
-
+
@@ -520,7 +482,7 @@
- +
@@ -893,14 +855,16 @@
+ + + + + + - - - + + \ No newline at end of file diff --git a/Frontend/img/u106.png b/Frontend/img/u106.png new file mode 100644 index 0000000..970c405 Binary files /dev/null and b/Frontend/img/u106.png differ diff --git a/Frontend/img/u110.png b/Frontend/img/u110.png new file mode 100644 index 0000000..cfb0eda Binary files /dev/null and b/Frontend/img/u110.png differ diff --git a/Frontend/img/u40.png b/Frontend/img/u40.png new file mode 100644 index 0000000..7afcb72 Binary files /dev/null and b/Frontend/img/u40.png differ diff --git a/Frontend/img/u43.png b/Frontend/img/u43.png new file mode 100644 index 0000000..1b67530 Binary files /dev/null and b/Frontend/img/u43.png differ diff --git a/Frontend/index.html b/Frontend/index.html index 5ce1a8d..7f6ab0b 100644 --- a/Frontend/index.html +++ b/Frontend/index.html @@ -33,10 +33,12 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li + + @@ -1415,8 +1417,8 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li SmartAdmin WebApp + + -->
@@ -1465,10 +1467,10 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
首頁 + + + +
-->
-
運維管理
@@ -1516,11 +1518,6 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
-
-
天氣
- - -
@@ -1529,65 +1526,21 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li Dr. Codex Lantern + Me + -->
+
+
+ +
@@ -2078,433 +2031,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
- + - + @@ -2537,6 +2064,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li + + - + diff --git a/Frontend/js/forge/forgemodel.js b/Frontend/js/forge/forgemodel.js index 1af2339..a88c444 100644 --- a/Frontend/js/forge/forgemodel.js +++ b/Frontend/js/forge/forgemodel.js @@ -49,7 +49,7 @@ var elevatorSpeed; // sensorVals[i] = Math.random(); // } -function launchViewer(urn, eleOption ,callback) { +function launchViewer(urn, callback) { var options = { env: 'AutodeskProduction', getAccessToken: getForgeToken @@ -60,13 +60,11 @@ function launchViewer(urn, eleOption ,callback) { //viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('forgeViewer')); viewer.start(); var documentId = 'urn:' + urn; - - Autodesk.Viewing.Document.load(documentId, function (doc) { - onDocumentLoadSuccess(doc, eleOption); - }, onDocumentLoadFailure); + + Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure); $("#forgeViewer").on("autodesk:loaded", function () { - callback ? callback() : ""; + callback ? callback(viewer) : ""; }) @@ -139,7 +137,7 @@ class elevator3D { this.init(); } - setTreeFrag = function () { + setTreeFrag = function (callback) { let tree = this.viewer.model.getData().instanceTree; let nodeId = this.nodeId; //tree.enumNodeChildren(nodeId, (node) => { @@ -155,34 +153,44 @@ class elevator3D { // }); //}) - tree.enumNodeFragments(nodeId, (frag) => { - let fragProxy = this.viewer.impl.getFragmentProxy(this.viewer.model, frag); - this.fragProxy = fragProxy; - this.fragProxys.push({ nodeId: nodeId, frag: fragProxy }); + if (nodeId) { + let childCnt = tree.getChildCount(nodeId); + let curIdx = 1; + this.fragProxys.filter(x => x.nodeId == nodeId).forEach((x) => { + let idx = this.fragProxys.indexOf(x); + this.fragProxys.splice(idx,1); + }) + tree.enumNodeFragments(nodeId, (frag) => { + let fragProxy = this.viewer.impl.getFragmentProxy(this.viewer.model, frag); - this.fragProxy.getAnimTransform(); - let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + this.fragProxys.push({ nodeId: nodeId, fragId: frag, frag: fragProxy }); - this.fragProxy.position = fragPosition; + fragProxy.getAnimTransform(); + let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 - this.fragProxy.updateAnimTransform(); - },true); + fragProxy.position = fragPosition; + fragProxy.updateAnimTransform(); + if (childCnt == curIdx) { + this.initCallback ? this.initCallback() : ""; + callback ? callback() : ""; + } + curIdx++; + }, true); + } this.viewer.impl.sceneUpdated(true); - if (typeof $(this.ele)[0]._elevator3D == "undefined") { + if (typeof $(this.ele)[0]._elevator3D == "undefined") { $(this.ele)[0]._elevator3D = []; } $(this.ele)[0]._elevator3D.push({ nodeId: nodeId, obj: this }); - this.initCallback ? this.initCallback() : ""; - } - init = function () { - this.setTreeFrag(); + init = function (callback = null) { + this.setTreeFrag(callback); } setElevatorFloor = function (floor) { - this.targetFloorZ = this.floorHeight.filter(x => x.floor == floor)[0].height; + this.targetFloorZ = this.floorHeight.filter(x => x.floor == floor)[0]?.height ?? 0; } setElevatorSpeed = function (speed) { //0.01 ~ 1 @@ -195,12 +203,15 @@ class elevator3D { let nodeId = this.nodeId; let fragProxyZ = 0; let movStatus = this.movStatus; // 0=no 1=up 2=down + let fragProxy = this.fragProxys.filter(x => x.nodeId == nodeId)[0]?.frag; + if (!fragProxy) { + return; + } - - if (this.fragProxy.position.z > this.targetFloorZ) { + if (fragProxy.position.z > this.targetFloorZ) { movStatus = 2 } - else if (this.fragProxy.position.z < this.targetFloorZ) { + else if (fragProxy.position.z < this.targetFloorZ) { movStatus = 1 } @@ -209,20 +220,20 @@ class elevator3D { } tree.enumNodeFragments(nodeId, (frag) => { - this.fragProxy = this.viewer.impl.getFragmentProxy(this.viewer.model, frag); - this.fragProxy.getAnimTransform(); + let fragProxy = this.viewer.impl.getFragmentProxy(this.viewer.model, frag); + fragProxy.getAnimTransform(); //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 if (movStatus == 2) { - this.fragProxy.position.z -= this.speed; + fragProxy.position.z -= this.speed; } else if (movStatus == 1) { - this.fragProxy.position.z += this.speed; + fragProxy.position.z += this.speed; } - fragProxyZ = this.fragProxy.position.z; - this.fragProxy.updateAnimTransform() + fragProxyZ = fragProxy.position.z; + fragProxy.updateAnimTransform() - },true); + }, true); this.viewer.impl.sceneUpdated(true); let movElevator = $(this.ele)[0]._elevator3D.filter(x => x.nodeId == this.nodeId)[0]?.obj.movElevator.bind(this); @@ -252,7 +263,7 @@ class elevator3D { } } -function onDocumentLoadSuccess(doc,eleOption) { +function onDocumentLoadSuccess(doc, eleOption) { var viewables = doc.getRoot().getDefaultGeometry(); viewer.loadDocumentNode(doc, viewables).then(i => { // documented loaded, any action? @@ -269,25 +280,25 @@ function onDocumentLoadSuccess(doc,eleOption) { //var allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); //var domElem = document.getElementById('all_id'); //domElem.innerText = allDbIdsStr; - let nodes = eleOption.nodes ?? []; - let element = eleOption.element ?? ""; - $(element)[0]._elevator3D = []; - $.each(nodes, function (idx, node) { - let options = { - element: $(element), - viewer: viewer, - nodeId: node, - floorHeight: eleOption.floorHeight ?? [], - inited: function () { - if (idx == nodes.length - 1) { - $(element).trigger("autodesk:loaded"); - } - } - } - let elevator3DObj = new elevator3D(options); - - }) + //let nodes = eleOption.nodes ?? []; + //let element = eleOption.element ?? ""; + //$(element)[0]._elevator3D = []; + //$.each(nodes, function (idx, node) { + // let options = { + // element: $(element), + // viewer: viewer, + // nodeId: node, + // floorHeight: eleOption.floorHeight ?? [], + // inited: function () { + // if (idx == nodes.length - 1) { + // $(element).trigger("autodesk:loaded"); + // } + // } + // } + // let elevator3DObj = new elevator3D(options); + //}) + $("#forgeViewer").trigger("autodesk:loaded"); //let tree = viewer.model.getData().instanceTree; //let nodeId = 10952; //console.log("tree", tree) diff --git a/Frontend/js/forge/modeltest.js b/Frontend/js/forge/modeltest.js new file mode 100644 index 0000000..a7edfcb --- /dev/null +++ b/Frontend/js/forge/modeltest.js @@ -0,0 +1,416 @@ +var viewer; + + + +// Initialize sensor values +//let sensorVals = []; +let fragProxy; +var targetFloorZ; +var elevatorSpeed; +// for (let i = 0; i < devices.length; i++) { +// sensorVals[i] = Math.random(); +// } + +function launchViewer(urn) { + var options = { + env: 'AutodeskProduction', + getAccessToken: getForgeToken + }; + + Autodesk.Viewing.Initializer(options, () => { + viewer = new Autodesk.Viewing.GuiViewer3D(document.getElementById('forgeViewer')); + //viewer = new Autodesk.Viewing.Viewer3D(document.getElementById('forgeViewer')); + viewer.start(); + var documentId = 'urn:' + urn; + Autodesk.Viewing.Document.load(documentId, onDocumentLoadSuccess, onDocumentLoadFailure); + + + + //test + // for (let i = 0; i < urn.length; i++) { + // Autodesk.Viewing.Document.load(urn[i]["urn"], async (doc) => { + // let viewables = doc.getRoot().getDefaultGeometry(); + // let model = await viewer.loadDocumentNode(doc, viewables, { + // preserveView: false, + // keepCurrentModels: true, + // placementTransform: (new THREE.Matrix4()).setPosition(urn[i]["xform"]), + // keepCurrentModels: true, + // globalOffset: { + // x: 0, + // y: 0, + // z: 0 + // } + // }); + + // await viewer.waitForLoadDone(); //!<<< Wait for loading materials, properties and geometries for this model (URN) + // }); + // } + + //loadHeatmaps(viewer.getAllModels()[0]); //!<<< equals to viewer.model + + + + }); +} + +function getAllLeafComponents(viewer, callback) { + var cbCount = 0; + var tree; + var jsData = [] + + function getLeafComponentsRec(current, parent) { + cbCount++; + if (tree.getChildCount(current) != 0) { + tree.enumNodeChildren(current, function (children) { + getLeafComponentsRec(children, current); + }, false); + } + var nodeName = viewer.model.getInstanceTree().getNodeName(current) + jsData.push({ id: current, parent: parent, text: nodeName }) + + if (--cbCount == 0) callback(jsData); + } + viewer.getObjectTree(function (objectTree) { + tree = objectTree; + var rootId = tree.getRootId() + var nodeName = viewer.model.getInstanceTree().getNodeName(rootId) + jsData.push({ id: rootId, parent: '#', text: nodeName }) + var allLeafComponents = getLeafComponentsRec(rootId, '#'); + + }); +} + +function onDocumentLoadSuccess(doc) { + var viewables = doc.getRoot().getDefaultGeometry(); + viewer.loadDocumentNode(doc, viewables).then(i => { + // documented loaded, any action? + }); + viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (args) => { + var currSelection = viewer.getSelection(); + var domElem = document.getElementById('id_printer'); + domElem.innerText = currSelection[0]; + }); + + viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () { + var instanceTree = viewer.model.getData().instanceTree; + var allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); + var domElem = document.getElementById('all_id'); + domElem.innerText = allDbIdsStr; + + + + let tree = viewer.model.getData().instanceTree; + let nodeId = 749;//10952; + let nodeId2 = 750; + let nodeId3 = 751; + + tree.enumNodeFragments(nodeId, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + + fragProxy.position = fragPosition + + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + //------------ add ------------- + tree.enumNodeFragments(nodeId2, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + + fragProxy.position = fragPosition + + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + tree.enumNodeFragments(nodeId3, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + let fragPosition = new THREE.Vector3(0, 0, 0);// 一樓0 二樓15 三樓 26 + + fragProxy.position = fragPosition + + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + }); + + NOP_VIEWER.getProperties(NOP_VIEWER.getSelection(), data => console.log(data)); +} + +function setElevatorFloor(floor) { + if (floor == 0) + targetFloorZ = 0; + else if (floor == 1) + targetFloorZ = 14.6;// 15; + else if (floor == 2) + targetFloorZ = 24.6;// 26; + else if (floor == 3) + targetFloorZ = 34.6; + else if (floor == 4) + targetFloorZ = 44.6; + else if (floor == 5) + targetFloorZ = 54.6; + else if (floor == 6) + targetFloorZ = 64.6; + else if (floor == 7) + targetFloorZ = 74.6; + else if (floor == 8) + targetFloorZ = 84.6; + else if (floor == 9) + targetFloorZ = 94.6; + else if (floor == 10) + targetFloorZ = 104.6; + else if (floor == 11) + targetFloorZ = 114.6; + else if (floor == 12) + targetFloorZ = 124.6; + else if (floor == -1) + targetFloorZ = -13; +} + +function setElevatorSpeed(speed) { //0.01 ~ 1 + elevatorSpeed = speed; +} + +function movElevator() { + + + let tree = viewer.model.getData().instanceTree; + let nodeId = 749; //10952; + let nodeId2 = 750; + let nodeId3 = 751; + let fragProxyZ = 0; + var movStatus = 0; // 0=no 1=up 2=down + + + if (fragProxy.position.z > targetFloorZ) { + movStatus = 2 + } + else if (fragProxy.position.z < targetFloorZ) { + movStatus = 1 + } + + if (movStatus == 0) { + return; + } + + tree.enumNodeFragments(nodeId, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 + if (movStatus == 2) { + fragProxy.position.z -= elevatorSpeed; + } + else if (movStatus == 1) { + fragProxy.position.z += elevatorSpeed; + } + + fragProxyZ = fragProxy.position.z; + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + tree.enumNodeFragments(nodeId2, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 + if (movStatus == 2) { + fragProxy.position.z -= elevatorSpeed; + } + else if (movStatus == 1) { + fragProxy.position.z += elevatorSpeed; + } + + fragProxyZ = fragProxy.position.z; + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + tree.enumNodeFragments(nodeId3, function (frag) { + fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); + fragProxy.getAnimTransform(); + //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 + if (movStatus == 2) { + fragProxy.position.z -= elevatorSpeed; + } + else if (movStatus == 1) { + fragProxy.position.z += elevatorSpeed; + } + + fragProxyZ = fragProxy.position.z; + fragProxy.updateAnimTransform() + + }); + viewer.impl.sceneUpdated(true); + + if (movStatus == 2) { + if (fragProxyZ >= targetFloorZ) { + requestAnimationFrame(movElevator); + } + } + else if (movStatus == 1) { + if (fragProxyZ <= targetFloorZ) { + requestAnimationFrame(movElevator); + } + } + + + //let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26 + + //fragProxy.position = fragPosition; + + //fragProxy.updateAnimTransform(); + + //viewer.impl.sceneUpdated(true); +} + +//function movElevator() { + + +// let tree = viewer.model.getData().instanceTree; +// let nodeId = 750;// 10952; +// let fragProxyZ = 0; +// var movStatus = 0; // 0=no 1=up 2=down + + +// if (fragProxy.position.z > targetFloorZ) { +// movStatus = 2 +// } +// else if (fragProxy.position.z < targetFloorZ) { +// movStatus = 1 +// } + +// if (movStatus == 0) { +// return; +// } + +// tree.enumNodeFragments(nodeId, function (frag) { +// fragProxy = viewer.impl.getFragmentProxy(viewer.model, frag); +// fragProxy.getAnimTransform(); +// //let fragPosition = new THREE.Vector3(0, 0, 15);// 一樓0 二樓15 三樓 26 +// if (movStatus == 2) { +// fragProxy.position.z -= elevatorSpeed; +// } +// else if (movStatus == 1) { +// fragProxy.position.z += elevatorSpeed; +// } + +// fragProxyZ = fragProxy.position.z; +// fragProxy.updateAnimTransform() + +// }); +// viewer.impl.sceneUpdated(true); + +// if (movStatus == 2) { +// if (fragProxyZ >= targetFloorZ) { +// requestAnimationFrame(movElevator); +// } +// } +// else if (movStatus == 1) { +// if (fragProxyZ <= targetFloorZ) { +// requestAnimationFrame(movElevator); +// } +// } + + +// //let fragPosition = new THREE.Vector3(position);// 一樓0 二樓15 三樓 26 + +// //fragProxy.position = fragPosition; + +// //fragProxy.updateAnimTransform(); + +// //viewer.impl.sceneUpdated(true); +//} + +function getAllDbIds(viewer) { + var instanceTree = viewer.model.getData().instanceTree; + + var allDbIdsStr = Object.keys(instanceTree.nodeAccess.dbIdToIndex); + + return allDbIdsStr.map(function (id) { return parseInt(id) }); +} + +/** + * Autodesk.Viewing.Document.load() failuire callback. + */ +function onDocumentLoadFailure(viewerErrorCode) { + console.error("onDocumentLoadFailure() - errorCode:" + viewerErrorCode); +} + +function getForgeToken(callback) { + fetch(baseApiUrl + '/api/forge/oauth/token').then(res => { + res.json().then(data => { + callback(data.dictionary.access_token, data.dictionary.expires_in); + }); + }); + //callback("eyJhbGciOiJSUzI1NiIsImtpZCI6IlU3c0dGRldUTzlBekNhSzBqZURRM2dQZXBURVdWN2VhIn0.eyJzY29wZSI6WyJkYXRhOndyaXRlIiwiZGF0YTpyZWFkIiwiYnVja2V0OnJlYWQiLCJidWNrZXQ6dXBkYXRlIiwiYnVja2V0OmNyZWF0ZSJdLCJjbGllbnRfaWQiOiJUQTNocXNGZnpRYk5PVVhLcGxkS1VLU2V3NFNKMjF3NSIsImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9hand0ZXhwNjAiLCJqdGkiOiJiemxzWE5qWElvZ2R1UjUzTUJkdlhrTTNTT01qeVB1bHJrMmdTVWJudGNTeDg1b01kRG1xejg3Z05jenJkRzhpIiwiZXhwIjoxNjY4MTgzMDM2fQ.VU3qLwTJ9nlXnomKCdk4y5UcgszGEO_zlvE7w5mWWajeBMwKLo-zw7LJEqUEajRksvssppR9SbVsjLSx-vDVc3DRhCo3jYTWKPT1T3wQrlkOSqLeIrAdnKdBDNBWKgrGJt_xcmXc3dZ3XNKf9L_F6Ex808rUlo6cem1mcPpKl1jCBDqKu1mAX7aDtZ65TTQZbGGhbG4HdnET-d1i5w4LunGN11UAHhDUW3n0SWWIBL27PiiUQONZttajhD5st6IngYLcjr93BYVyJmDF7-wm4WZlHSw2OnXIfbJcFXEd83uVv_Rej4UXjzZ0e6kHwzc2nvGvKSIFu3Nt7CabdR8CkA", 3599); +} + +async function loadHeatmaps(model) { + + const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); + + // Given a model loaded from Forge + const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(model); + + const devices = [ + { + id: "Oficina 6", + name: "Oficina-", + position: { x: 22.475382737884104, y: 7.4884431474006163, z: 3.0 }, + sensorTypes: ["temperature", "humidity"] + } + ]; + + var offset = Autodesk.viewer.model.getGlobalOffset(); + removeOffset(devices[0], offset) + + // Generates `SurfaceShadingData` after assigning each device to a room. + + const shadingData = await Autodesk.structureInfo.generateSurfaceShadingData(devices); + + // Use the resulting shading data to generate heatmap from. + await dataVizExtn.setupSurfaceShading(model, shadingData); + + // Register color stops for the heatmap. Along with the normalized sensor value + // in the range of [0.0, 1.0], `renderSurfaceShading` will interpolate the final + // heatmap color based on these specified colors. + const sensorColors = [0x0000ff, 0x00ff00, 0xffff00, 0xff0000]; + + // Set heatmap colors for temperature + const sensorType = "temperature"; + dataVizExtn.registerSurfaceShadingColors(sensorType, sensorColors); + + // Function that provides sensor value in the range of [0.0, 1.0] + + function getSensorValue(surfaceShadingPoint, sensorType) { + // The `SurfaceShadingPoint.id` property matches one of the identifiers passed + // to `generateSurfaceShadingData` function. In our case above, this will either + // be "cafeteria-entrace-01" or "cafeteria-exit-01". + const deviceId = surfaceShadingPoint.id; + + // Read the sensor data, along with its possible value range + let sensorValue = readSensorValue(deviceId, sensorType); + const maxSensorValue = getMaxSensorValue(sensorType); + const minSensorValue = getMinSensorValue(sensorType); + + // Normalize sensor value to [0, 1.0] + sensorValue = (sensorValue - minSensorValue) / (maxSensorValue - minSensorValue); + return clamp(sensorValue, 0.0, 1.0); + } + + // This value can also be a room instead of a floor + const floorName = "01 - Entry Level"; + dataVizExtn.renderSurfaceShading(floorName, sensorType, getSensorValue); +} \ No newline at end of file diff --git a/Frontend/js/n4js/bajatest.js b/Frontend/js/n4js/bajatest.js index 7e91410..495476c 100644 --- a/Frontend/js/n4js/bajatest.js +++ b/Frontend/js/n4js/bajatest.js @@ -1,4 +1,5 @@ let baja_subscribe_device_callback_func; //設定BQL訂閱之後要回傳的Function +let baja_subscribe_end_device_callback_func; //設定BQL訂閱結束之後要回傳的Function let baja_my_user_account_func; //取得帳號資料要回傳的Function var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅館棟->H,消防偵煙器->F3 window.tolSubList = []; @@ -16,15 +17,24 @@ function subscriptionDevices() { baja_subscribe_device_callback_func = callBackFunc; } } + // BQL訂閱結束回傳的Function + this.setSubscribeDeviceEndCallBack = function (callBackFunc) { + if (callBackFunc != undefined && callBackFunc != null) { + baja_subscribe_end_device_callback_func = callBackFunc; + } + } } function MyBaja() { // 取得使用者帳號 - this.setMyUserAccount = function (callBackFunc) { - if (callBackFunc != undefined && callBackFunc != null) { - baja_my_user_account_func = callBackFunc; - } + this.setMyUserAccount = function (callBackFunc = null) { + require(['baja!'], function (baja) { + console.log("baja", baja) + user_name = baja.getUserName(); + callBackFunc ? callBackFunc(user_name) : ""; + }); + }; } @@ -64,6 +74,7 @@ function BajaSubscribeDevicesByBql() { var modify_target_device = { "device_number": target_device_number ? target_device_number : null, + "device_number_full": this.$parent.getSlotPath().$names.join("_"), "point_name": point_name ? point_name : null, "value": key } @@ -88,13 +99,14 @@ function BajaSubscribeDevicesByBql() { var subStart, subFinish; var component_index = 0; var total_component_index = 0; + var totalTargetDevice = []; var readBqlFinish = new Date(Date.now()); // $("#readPath-finish-timestamp").html(readBqlFinish.toISOString()); // $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"); console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec"); - table.cursor({ before: function () { + totalTargetDevice = []; tableStart = new Date(Date.now()); $("#table-start-timestamp").html(tableStart.toISOString()); render_start = new Date(Date.now()); @@ -107,6 +119,7 @@ function BajaSubscribeDevicesByBql() { $("#sub-number").html(index + 1); total_component_index = index; + var target_device_number_split = this.getDisplay("slotPath").split('/'); var target_device_number = target_device_number_split[target_device_number_split.length - 2]; @@ -122,7 +135,7 @@ function BajaSubscribeDevicesByBql() { }); facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {}) - + var point_out_split = this.getDisplay("out").split(' '); let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]); @@ -133,10 +146,11 @@ function BajaSubscribeDevicesByBql() { var modify_target_device = { "device_number": target_device_number ? target_device_number : null, + "device_number_full": this.getDisplay("slotPath").split("slot:")[1].split('/').slice(1,-1).join("_"), "point_name": point_name ? point_name : null, "value": key } - + totalTargetDevice.push(modify_target_device); //取得component當下就更新設備點位 if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) { baja_subscribe_device_callback_func(modify_target_device); @@ -197,6 +211,10 @@ function BajaSubscribeDevicesByBql() { tableFinish = new Date(Date.now()); // $("#table-finish-timestamp").html(tableFinish.toISOString()); // $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"); + //取得component當下就更新設備點位 + if (baja_subscribe_end_device_callback_func != undefined && baja_subscribe_end_device_callback_func != null) { + baja_subscribe_end_device_callback_func(totalTargetDevice); + } console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec"); }, limit: -1, @@ -283,12 +301,7 @@ function getElevatorInfoByBaja(path, callback) { }); } -require(['baja!'], function (baja) { - user_name = baja.getUserName(); - if (baja_my_user_account_func != undefined && baja_my_user_account_func != null) { - baja_my_user_account_func(user_name); - } -}); + // baja.Ord.make('ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/H/F3|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint') // // baja.Ord.make('ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/H/E1/B1F/TestData/H_E1_B1F_TestData_Data|bql:select slotPath,out.value from control:NumericWritable') @@ -346,3 +359,159 @@ require(['baja!'], function (baja) { // }) +//測試 +/** + * 取得電表即時資料 by baja + * @param {any} devicePath + * @param {any} callback + */ + function getElectricMeterNoweDataByBaja(devicePath, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint'); + //baja.Ord.make('local:|foxs:|station:|slot:/' + devicePath + '|bql:select name, out, out.value from control:ControlPoint').get() + baja.Ord.make('local:|foxs:|station:|slot:/TPE/B1/EE/E4/R2F/NA/WHT/N1|bql:select name, out, out.value from control:ControlPoint').get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"name":"' + record.get('name') + '", "value":' + record.get('out').get('value') + '"}'; + else + _ss += ',{"name":"' + record.get('name') + '", "value":' + record.get('out').get('value') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得電表 單日kwh by baja + * @param {any} devicePath + * @param {any} date_millisecond + * @param {any} callback + */ + function getElectricMeterOneDayKwhByBaja(devicePath, date_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('transform:slot:/' + devicePath + '/History/TR_Month|bql: select * where timestamp.millis = ' + date_millisecond); + baja.Ord.make('transform:slot:/TPE/B1/EE/E4/R2F/NA/WHT/N1/History/TR_Month|bql: select * where timestamp.millis <= 1667404799000').get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) { + //_ss += '{"timestamp":"' + record.get('timestamp') + '", "kwh1":' + record.get('kwh1') + '"}'; + _ss += '{"timestamp":"' + record.get('timestamp') + '"}'; + } + else { + //_ss += ',{"timestamp":"' + record.get('timestamp') + '", "kwh1":' + record.get('kwh1') + '"}'; + _ss += ',{"timestamp":"' + record.get('timestamp') + '"}'; + } + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得電表每小時資料 by baja + * @param {any} devicePath + * @param {any} startDate_millisecond + * @param {any} endDate_millisecond + * @param {any} callback + */ + function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 + console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); + baja.Ord.make('transform:slot:/TPE/B1/EE/E4/R2F/NA/WHT/N1/History/TR_Daily|bql: select timestamp, kwh1 where timestamp.millis >= 1667232000000 and timestamp.millis <= 1667404799000').get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"kwh1":' + record.get('kwh1') + ', "timestamp":"' + record.get('timestamp') + '"}'; + else + _ss += ',{"kwh1":' + record.get('kwh1') + ', "timestamp":"' + record.get('timestamp') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 在單一系統下,取得各個系統的狀態 異常與否 + * @param {any} systemPath + * @param {any} callback + */ + function getOneSystemStateByBaja(systemPath, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) { + baja.Ord.make("local:|foxs:|alarm:|bql:select top 1 alarmData, alarmData.sourceName, sourceState where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + //if (_index == 0) + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + //else + // _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + _ss += '{"sourceState":"' + record.get('sourceState') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} \ No newline at end of file diff --git a/Frontend/js/n4js/electricmeterbaja.js b/Frontend/js/n4js/electricmeterbaja.js index 92529a6..a3b12b7 100644 --- a/Frontend/js/n4js/electricmeterbaja.js +++ b/Frontend/js/n4js/electricmeterbaja.js @@ -73,44 +73,44 @@ function getElectricMeterNoweDataByBaja(devicePath, callback) { }); } -/** - * 取得電表每小時資料 by baja - * @param {any} devicePath - * @param {any} startDate_millisecond - * @param {any} endDate_millisecond - * @param {any} callback - */ -function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { - var _result = ""; - var _ss = ""; - var _index = 0; +///** +// * 取得電表每小時資料 by baja +// * @param {any} devicePath +// * @param {any} startDate_millisecond +// * @param {any} endDate_millisecond +// * @param {any} callback +// */ +//function getElectricMeterHourDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, callback) { +// var _result = ""; +// var _ss = ""; +// var _index = 0; - require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 - console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); - baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get() - .then(function (table) { - return table.cursor({ - each: function (record) { - if (_index == 0) - _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; - else - _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; - _index++; - }, - after: function () { - _result += '{' + '"count": ' + _index + ', "data":['; - _result += _ss; - _result += ']}'; - if (typeof callback === 'function') { - callback(_result); - } - }, - limit: -1, - offset: 0 - }); - }); - }); -} +// require(['baja!'], function (baja) {//TPE/B1/EE/E4/R2F/NA/WHT/N1 +// console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); +// baja.Ord.make('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get() +// .then(function (table) { +// return table.cursor({ +// each: function (record) { +// if (_index == 0) +// _ss += '{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; +// else +// _ss += ',{"timestamp":' + record.get('timestamp') + ', "value":"' + record.get('kwh1') + '"}'; +// _index++; +// }, +// after: function () { +// _result += '{' + '"count": ' + _index + ', "data":['; +// _result += _ss; +// _result += ']}'; +// if (typeof callback === 'function') { +// callback(_result); +// } +// }, +// limit: -1, +// offset: 0 +// }); +// }); +// }); +//} /** * 取得電表 單日kwh by baja @@ -187,4 +187,124 @@ function getElectricMeterWeekDataByBaja(devicePath, startDate_millisecond, endDa }); }); }); +} + +/** + * 取得電表 期間內的平均用電量(kwh)資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDate_millisecond + * @param {any} endDate_millisecond + * @param {any} callback + */ +function getElectricMeterKwhAvgDataByBaja(devicePath, company, startDate_millisecond, endDate_millisecond, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log('transform:slot:/' + devicePath + '/History/TR_Daily|bql: select * where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond); + baja.Ord.make('local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select AVG(value) from control:ControlPoint where timestamp.millis >= ' + startDate_millisecond + ' and timestamp.millis <= ' + endDate_millisecond).get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"value":' + record.get('AVG$28value$29') + '"}'; + else + _ss += ',{"value":' + record.get('AVG$28value$29') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得點位 每小時資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDateTime + * @param {any} endDateTime + * @param {any} callback + */ +function getElectricMeterHourDataByBaja(devicePath, company, startDateTime, endDateTime, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '3600000')"); + baja.Ord.make("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '3600000')").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); +} + +/** + * 取得點位 每日資料 by baja + * @param {any} devicePath + * @param {any} company + * @param {any} startDateTime + * @param {any} endDateTime + * @param {any} callback + */ +function getElectricMeterDayDataByBaja(devicePath, company, startDateTime, endDateTime, callback) { + var _result = ""; + var _ss = ""; + var _index = 0; + + require(['baja!'], function (baja) {//TPE_B1_EE_E4_R2F_NA_WHT_N1_KWH + console.log("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '86400000')"); + baja.Ord.make("local:|foxs:|history:/" + company + "/" + devicePath + "?peroid=timerange;start=" + startDateTime + ".000+08:00;end=" + endDateTime + ".000+08:00;|bql:history:HistoryRollup.rollup(baja:RelTime '86400000')").get() + .then(function (table) { + return table.cursor({ + each: function (record) { + if (_index == 0) + _ss += '{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + else + _ss += ',{"timestamp":' + record.get('timestamp') + ', "endTimestamp":"' + record.get('endTimestamp') + ', "min":"' + record.get('min') + ', "max":"' + record.get('max') + ', "avg":"' + record.get('avg') + ', "sum":"' + record.get('sum') + '"}'; + _index++; + }, + after: function () { + _result += '{' + '"count": ' + _index + ', "data":['; + _result += _ss; + _result += ']}'; + if (typeof callback === 'function') { + callback(_result); + } + }, + limit: -1, + offset: 0 + }); + }); + }); } \ No newline at end of file diff --git a/Frontend/js/site.js b/Frontend/js/site.js index 4ad606f..55248fa 100644 --- a/Frontend/js/site.js +++ b/Frontend/js/site.js @@ -19,9 +19,66 @@ $.fn.outerHtml = function () { return $(this).prop("outerHTML"); } +/** + * fn 定義 | Loading 操作 + * @param {any} type - close / start / exceed , exceed => 繼續執行並可切換文字 + * @param {any} text - 右下角 Alert 文字 + */ +$.fn.Loading = function (type = "close",text) { + let ele = this; + let aleObj = $(this)[0]._aleObj; + + function closeLoading() { + $("body").css("overflow", "auto"); + $(aleObj.ele).YTAlert().hide(); + $(ele).animate({ opacity: 0 }, 300, () => { + $(ele).hide(); + }) + } + function showLoading() { + $("body").css("overflow", "hidden"); + let aleObj = YT.Alert.Tip(text || "讀取中,請稍後", "show"); + $(ele)[0]._aleObj = aleObj; + $(ele).show(); + $(ele).animate({ opacity: 1 }, 300); + + $(aleObj.ele).YTAlert().text(text); + } + if (type == "close") { + closeLoading(); + } else if (type == "exceed") { + $(aleObj.ele).YTAlert().text(text); + } else if (type == "start") { + showLoading(); + } + + return $(this); +} + +$.fn.YTAlert = function () { + let th = { element: this }; + th.hide = function (delay = 0) { + let obj = this; + setTimeout(function () { + $(obj.element).fadeOut(300); + alertIdArray.splice($.inArray($(obj.element).prop("id"), alertIdArray), 1); + setTimeout(function () { + $(obj.element).remove(); + }, 1000); + }, delay); + } + + th.text = function (text) { + let obj = this; + let id = $(obj.element).prop("id").split("tip-alert-")[1]; + $(`#alert-text-${id}`).text(text); + } + return th; +} + /** * 設置 bootstrap dropdown 為下拉選單 - * @param {any} menuEle .dropdown-menu element + * @param {any} menuEle - .dropdown-menu element */ function setDropdownItem(menuEle) { if ($(menuEle).find(".dropdown-item.active").length == 0) { @@ -52,6 +109,11 @@ function defDev(obj) { obj.src = defSrc; } +/** + * jquery datatable - ajax send data reset + * @param {any} table + * @param {any} sendData + */ function dtAjaxResetSendData(table,sendData) { table.context[0].ajax.data = function (d) { d = sendData; @@ -59,6 +121,7 @@ function dtAjaxResetSendData(table,sendData) { } } + /** * element 建造 * @param {any} text @@ -108,6 +171,9 @@ function creOption(text = null, value = null, data = {}, attr = {}, cls = [], na return creEle("option", text, id, name, cls, data, attr); } +/** + * 根據該棟建築底下的'所有'電梯執行緒物件 + * */ class ElevatorHandler { constructor(ele, option = {}) { this.ele = ele; @@ -124,9 +190,11 @@ class ElevatorHandler { this.init(); } + // 所有電梯初始化 init = function () { this.setTabWra(); this.setTabFloor(); + // 若已有每個設備的所在樓層,則預設到該樓層位置 if (Object.keys(this.curElevFloor).length != 0) { $.each(Object.keys(this.curElevFloor), (idx, elevKey) => { this.setElevFloor(elevKey,this.curElevFloor[elevKey]); @@ -158,16 +226,16 @@ class ElevatorHandler { for (let e = 1; e <= _elevators.length + 2; e++) { let th = creEle("th"); - th.css({ "width": `${_w}px`, "height": `${_h}px` }); + th.css({ "width": `${_w}px`, "height": `${_h}px` ,"position":"relative"}); if (e != 1 && e != _elevators.length + 2) { let elevId = _elevators[e - 2]?.id; // 電梯方框 let span = creEle("span", null, "elevator-item-" + (elevId), null, ["elevator-item"]); let spanUp = creEle("span", null, null, null, ["elevator-item-toup"]); let spanDown = creEle("span", null, null, null, ["elevator-item-todown"]); - span.css({ "width": `${_w - 3}px`, "height": `${_h - 3}px`, "top": `1.5px`, "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`}) - spanUp.css({ "width": `${_w - 3}px`, "height": `${(_h - 3) / 2}px`, "top": `1.5px`, "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`}) - spanDown.css({ "width": `${_w - 3}px`, "height": `${(_h - 3) / 2}px`, "top": `1.5px`, "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`,"top":`${1.5 + (_h-3) / 2}px`}) + span.css({ "width": `${_w - 3}px`, "height": `${_h - 3}px`, "top": `1.5px`,"left":"1.5px", "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`}) + spanUp.css({ "width": `${_w - 3}px`, "height": `${(_h - 3) / 2}px`, "top": `1.5px`, "left": "1.5px", "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`}) + spanDown.css({ "width": `${_w - 3}px`, "height": `${(_h - 3) / 2}px`, "top": `1.5px`, "left": "1.5px", "transition":`transform ${1 / this.speed}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`,"top":`${1.5 + (_h-3) / 2}px`}) th.append(spanUp); th.append(span); th.append(spanDown); @@ -221,26 +289,18 @@ class ElevatorHandler { } + // 設置某個電梯到某個樓層 setElevFloor = function (elevId, floId) { let curFloId = this.curElevFloor[elevId]; let curSort = this.floors.filter(x => x.id == curFloId).map(x => x.sort)[0]; let tarSort = this.floors.filter(x => x.id == floId).map(x => x.sort)[0]; let gapFloor = tarSort - curSort; let cssEle = [$(`#elevator-item-${elevId}`)[0], $(`#elevator-item-${elevId}`).prev("span.elevator-item-toup")[0], $(`#elevator-item-${elevId}`).next("span.elevator-item-todown")[0]] - clearTimeout(this.setTimeout); - console.log("123",this.movStatus) if (this.movStatus[elevId] != 0) { $(cssEle).css("transition", `transform ${1 / this.speed * Math.abs(gapFloor)}s cubic-bezier(0, 0, 0.62, 1) 0s`); } - //if (gapFloor < 0) { - // this.movStatus[elevId] = 2; - //} else if (gapFloor > 0) { - // this.movStatus[elevId] = 1; - //} else { - // this.movStatus[elevId] = 0; - //} + clearTimeout(this.setTimeout); this.setTimeout = setTimeout(() => { - /*this.movStatus[elevId] = 0;*/ $(cssEle).css("transition", `transform ${1 / this.speed * Math.abs(gapFloor)}s cubic-bezier(0.43, 0.05, 0.62, 1) 0s`); this.setEleUpDownStyle(elevId); }, (1 / this.speed * Math.abs(gapFloor)) * 1000) @@ -250,15 +310,19 @@ class ElevatorHandler { $(cssEle).css("transform", `translateY(${this.floorHeight * (this.floors.length - tarSort)}px)`); } + // 設定現在電梯狀態 (往上/往下/停止) setEleMovStatus = function (elevId,status) { this.movStatus[elevId] = status; } + // 電梯方框 往上或往下閃爍 setEleUpDownStyle = function (elevId) { if (this.movStatus[elevId] == 1) { + $(`#elevator-item-${elevId}`).next("span.elevator-item-todown").removeClass("light-flash-c-bd") $(`#elevator-item-${elevId}`).prev("span.elevator-item-toup").addClass("light-flash-c-bd") .css("--flash-color-1", "#44ea8e").css("--flash-color-2", "rgba(255,255,255,0)"); } else if (this.movStatus[elevId] == 2) { + $(`#elevator-item-${elevId}`).prev("span.elevator-item-toup").removeClass("light-flash-c-bd") $(`#elevator-item-${elevId}`).next("span.elevator-item-todown").addClass("light-flash-c-bd") .css("--flash-color-1", "#44ea8e").css("--flash-color-2", "rgba(255,255,255,0)"); } else { @@ -267,10 +331,12 @@ class ElevatorHandler { } } + // 設定現在某個電梯所在樓層 setCurElevFloor = function (elevId,floId) { this.curElevFloor[elevId] = floId; } + // 重新繪製 redraw = function () { $(this.ele).empty(); this.setTabFloor(); diff --git a/Frontend/js/yourteam/plugins/yt-alert/ytpop-alert.js b/Frontend/js/yourteam/plugins/yt-alert/ytpop-alert.js new file mode 100644 index 0000000..6a99500 --- /dev/null +++ b/Frontend/js/yourteam/plugins/yt-alert/ytpop-alert.js @@ -0,0 +1,120 @@ + +alertIdArray = []; +window.YT = typeof YT == "undefined" ? {} : YT; +window.YT.Alert = { Success: null, Error: null, Tip: null }; + + +YT.Alert.Success = function (text) { + let ranId = Math.floor(Math.random() * 100000); + $("body").append(``) + + //紀錄上一筆出現的alert + alertIdArray.push("success-alert-" + ranId) + alertIdArray.length > 2 ? alertIdArray.shift() : "" + $("#success-alert-" + ranId).fadeIn(300); + //判斷上一筆是否還存在頁面中 + if (typeof ($("#" + alertIdArray[0]).css("bottom")) != "undefined" && $("#" + alertIdArray[0]).css("display") != "none" && (alertIdArray[1] != "" || alertIdArray[1] != null)) { + //存在的話下一個alert出現在前一個alert上面 + let newAlertWidth = parseInt($("#" + alertIdArray[0]).css("bottom").split('px')[0]) + parseInt($("#" + alertIdArray[0]).css("height")) + 10 + "px" + $("#" + alertIdArray[1]).css("bottom", newAlertWidth); + } + $("#success-alert-" + ranId).click(function () { + $("#success-alert-" + ranId).fadeOut(300); + }) + + setTimeout(function () { $("#success-alert-" + ranId).fadeOut(300); }, 6000); + setTimeout(function () { + $("#success-alert-" + ranId).remove(); + alertIdArray.splice($.inArray("#success-alert-" + ranId, alertIdArray), 1); + }, 7000); + +} + +YT.Alert.Error = function (text) { + let ranId = Math.floor(Math.random() * 100000); + $("body").append(``) + + alertIdArray.push("danger-alert-" + ranId); + alertIdArray.length > 2 ? alertIdArray.shift() : "" + $("#danger-alert-" + ranId).fadeIn(300); + if (typeof ($("#" + alertIdArray[0]).css("bottom")) != "undefined" && $("#" + alertIdArray[0]).css("display") != "none" && (alertIdArray[1] != "" || alertIdArray[1] != null)) { + let newAlertWidth = parseInt($("#" + alertIdArray[0]).css("bottom").split('px')[0]) + parseInt($("#" + alertIdArray[0]).css("height")) + 10 + "px" + $("#" + alertIdArray[1]).css("bottom", newAlertWidth); + } + $("#danger-alert-" + ranId).click(function () { + $("#danger-alert-" + ranId).fadeOut(300); + }) + + setTimeout(function () { + $("#danger-alert-" + ranId).fadeOut(300); + alertIdArray.splice($.inArray("#danger-alert-" + ranId, alertIdArray), 1); + }, 6000); + setTimeout(function () { $("#danger-alert-" + ranId).remove(); }, 7000); + +} + +YT.Alert.Tip = function (text, type = null, color = null) { + let ranId = Math.floor(Math.random() * 100000); + $("body").append(``) + + alertIdArray.push("tip-alert-" + ranId); + alertIdArray.length > 2 ? alertIdArray.shift() : "" + if (color != null) { + $("#tip-alert-" + ranId).css("background-color", color); + } + + if (type == null) { + $("#tip-alert-" + ranId).fadeIn(300); + if (typeof ($("#" + alertIdArray[0]).css("bottom")) != "undefined" && $("#" + alertIdArray[0]).css("display") != "none" && (alertIdArray[1] != "" || alertIdArray[1] != null)) { + let newAlertWidth = parseInt($("#" + alertIdArray[0]).css("bottom").split('px')[0]) + parseInt($("#" + alertIdArray[0]).css("height")) + 10 + "px" + $("#" + alertIdArray[1]).css("bottom", newAlertWidth); + } + $("#tip-alert-" + ranId).click(function () { + $("#tip-alert-" + ranId).fadeOut(300); + }) + setTimeout(function () { + $("#tip-alert-" + ranId).fadeOut(300); + alertIdArray.splice($.inArray("#tip-alert-" + ranId, alertIdArray), 1); + }, 6000); + + setTimeout(function () { $("#tip-alert-" + ranId).remove(); }, 7000); + } else if (type == "show") { + $("#tip-alert-" + ranId).fadeIn(300); + } else if (type == "hide") { + $("#tip-alert-" + ranId).fadeOut(300); + alertIdArray.splice($.inArray("#tip-alert-" + ranId, alertIdArray), 1); + setTimeout(function () { + $("#tip-alert-" + ranId).remove(); + }, 1000); + } + return { id: "#tip-alert-" + ranId, ele: $("#tip-alert-" + ranId) }; + +} + + +//因非使用 Require 引用,$.fn 被二次引用 jquery.js 吃掉,則移至 site.js + +//$.fn.YTAlert = function () { +// let th = { element: this }; +// th.hide = function (delay = 0) { +// let obj = this; +// setTimeout(function () { +// $(obj.element).fadeOut(300); +// alertIdArray.splice($.inArray($(obj.element).prop("id"), alertIdArray), 1); +// setTimeout(function () { +// $(obj.element).remove(); +// }, 1000); +// }, delay); +// } + +// th.text = function (text) { +// let obj = this; +// let id = $(obj.element).prop("id").split("tip-alert-")[1]; +// $(`#alert-text-${id}`).text(text); +// } +// return th; +//} + diff --git a/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js b/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js index a111ec8..f6f5b32 100644 --- a/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js +++ b/Frontend/js/yourteam/plugins/yt-tab/yt-tab.js @@ -19,13 +19,14 @@ $(function () { * 初始全頁面 yt tab * */ function initTabsByEle() { - _ytTabInited = []; + /*_ytTabInited = [];*/ $("[data-tabname][data-target]:not([data-tabrole=child])").each(function (index, value) { let tabName = $(value).data("tabname"); - - var ytTab = new YT.Tab({ tabName: tabName }) - _ytTabInited.push(tabName); - + if (_ytTabInited.indexOf(tabName) == -1) { + var ytTab = new YT.Tab({ tabName: tabName }) + _ytTabInited.push(tabName); + } + }) } diff --git a/Frontend/js/yourteam/yourteam.ajax.class.js b/Frontend/js/yourteam/yourteam.ajax.class.js index 215fef6..5c115bf 100644 --- a/Frontend/js/yourteam/yourteam.ajax.class.js +++ b/Frontend/js/yourteam/yourteam.ajax.class.js @@ -58,7 +58,13 @@ class Ajax { */ successFunction = function (data,callback) { if (data && data.unauthorized == 401) { - location.href = "login.html"; + let href = location.href; + localStorage.removeItem("JWT-Authorization"); + if (href.indexOf("localhost:5966") == -1) { + location.href = "/login"; + } else { + location.href = "login.html"; + } } if (callback) { callback(data); @@ -79,6 +85,7 @@ class Ajax { window.alert("執行失敗,請聯絡客服人員。"); } else if (xhr.status == "401") { window.alert("登入時間超時,請重新登入!"); + localStorage.removeItem("JWT-Authorization"); location.href = "~/Login/Login"; } } diff --git a/Frontend/js/yourteam/yourteam.jquery.datatables.js b/Frontend/js/yourteam/yourteam.jquery.datatables.js index 85da7f2..6ef18ff 100644 --- a/Frontend/js/yourteam/yourteam.jquery.datatables.js +++ b/Frontend/js/yourteam/yourteam.jquery.datatables.js @@ -57,7 +57,7 @@ function fnInitJqDataTablesNoData(tag, dataSet = null, columns = null, columnDef "processing": true, "columns": columns, "aoColumnDefs": columnDefs, - "stateSave": true, + "stateSave": false, "pagingType": "full_numbers", "destroy": false, "initComplete": initComplete, diff --git a/Frontend/login.html b/Frontend/login.html index ab729ed..5c7da47 100644 --- a/Frontend/login.html +++ b/Frontend/login.html @@ -104,6 +104,9 @@ [ "lib/app.bundle", "lib/app.menu", + "lib/jquery-validation/dist/jquery.validate", + "lib/jquery-validation/dist/additional-methods.min", + "lib/jquery-validation/dist/localization/messages_zh_TW", /*"lib/notifications/sweetalert2/sweetalert2.bundle",*/ ], loadedMasterPack); } @@ -114,16 +117,11 @@ require( [ "init", - ], loadedJsPack); } function loadedJsPack() { - if (location.href.indexOf("localhost:5966") == -1) { - myBaja = new MyBaja(); - myBaja.setMyUserAccount(Login) - } - + if (localStorage.getItem('mitsubishi-t') == 'true') { document.getElementById("rememberme").checked = true; remember = true; diff --git a/FrontendWebApi/ApiControllers/DeviceManageController.cs b/FrontendWebApi/ApiControllers/DeviceManageController.cs index 3d3b8c8..4e25e15 100644 --- a/FrontendWebApi/ApiControllers/DeviceManageController.cs +++ b/FrontendWebApi/ApiControllers/DeviceManageController.cs @@ -226,7 +226,7 @@ namespace FrontendWebApi.ApiControllers foreach (var f in fl) { List dl = new List(); - sqlString = $@"select d.device_guid, d.full_name, d.device_coordinate, dk.device_image, d.device_number, CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url,d.status, + sqlString = $@"select d.device_guid, d.full_name, d.device_coordinate, d.priority, dk.device_image, d.device_number, CONCAT('{baseURL}', '{deviceKindFilePath}', dk.device_image) AS device_image_url,d.status, dk.device_normal_point_id, dk.device_normal_point_guid, dk.device_normal_point_col, dk.device_normal_point_value, dk.device_normal_flashing, dk.device_normal_point_name, dk.device_close_point_id, dk.device_close_point_guid, dk.device_close_point_col, dk.device_close_point_value, dk.device_close_flashing, dk.device_close_point_name, dk.device_error_point_id, dk.device_error_point_guid, dk.device_error_point_col, dk.device_error_point_value, dk.device_error_flashing, dk.device_error_point_name diff --git a/FrontendWebApi/Models/Device.cs b/FrontendWebApi/Models/Device.cs index 59a6a85..fb3e2f4 100644 --- a/FrontendWebApi/Models/Device.cs +++ b/FrontendWebApi/Models/Device.cs @@ -36,6 +36,7 @@ namespace FrontendWebApi.Models public string device_coordinate { get; set; } public string device_coordinate_3d { get; set; } public string status { get; set; } + public int priority { get; set; } public string device_status { get