166 lines
7.1 KiB
JavaScript
166 lines
7.1 KiB
JavaScript
/*
|
|
This code snippet is taken from from the 'gettingStarted' BajaScript tutorial.
|
|
More information can be found by navigating to this ORD...
|
|
|
|
module://docDeveloper/doc/jsdoc/bajaux-ux/tutorial-gettingStarted.html
|
|
*/
|
|
|
|
// Subscribe to a Ramp. When it changes, print out the results.
|
|
require(['baja!'], function (baja) {
|
|
"use strict";
|
|
|
|
// A Subscriber is used to listen to Component events in Niagara.
|
|
var sub = new baja.Subscriber();
|
|
|
|
// This shows a dialog. The function passed into 'showOk' is used to generate the dialog
|
|
// box's content.
|
|
// dialogs.showOk(function (dlg, jq) {
|
|
// jq.text("Loading...");
|
|
|
|
// The 'update' method is called whenever the text needs to be updated.
|
|
function update(light) {
|
|
// $(`#${light.$propInParent.$displayName}`).html(light.getOutDisplay());
|
|
|
|
$("#Ramp1").html(light.getOutDisplay());
|
|
}
|
|
|
|
// Called whenever the Ramp changes.
|
|
sub.attach('changed', function (prop) {
|
|
if (prop.getName() === 'out') { update(this); }
|
|
});
|
|
// https://127.0.0.1:8443/bajaux/webwidget/view:alarm:DatabaseView?theme=Zebra&formFactor=max&userLocalWbRc=true&attachAfterInit=false
|
|
// 目前 OK local:|foxs:|alarm:|bql:select * from openAlarms
|
|
// 目前 OK local:|foxs:|alarm:|bql:select * from ackPendingAlarms
|
|
// 目前 OK 10.1.1.130:|foxs:|alarm:|bql:select * from ackPendingAlarms
|
|
// 目前 OK alarm:|bql:select * from ackPendingAlarms
|
|
// 沒資料 local:|foxs:|alarm:|view:alarm:AlarmDbView
|
|
// local:|foxs:|station:|slot:/Services/OrionAlarmService
|
|
// 應該有資料 欄位錯誤 service:alarmOrion:OrionAlarmService|slot:defaultAlarmClass1
|
|
// 應該有資料 service:alarm:AlarmService|slot:defaultAlarmClass
|
|
// 終於有 acked local:|foxs:|alarm:|bql:select * from where ackState='acked
|
|
// Alarm 表格 where uuid = 'eab7bdaa-c220-4724-bec7-7865824c5ba3'
|
|
//ip:greencloud.fic.com.tw|foxs:|alarm:select * from where Timestamp order by desc
|
|
var tableHtml = "";
|
|
baja.Ord.make("local:|foxs:|alarm:select * from where Timestamp order by desc ").get({
|
|
cursor: {
|
|
before: function () {
|
|
// This gets called before iteration starts through the table.
|
|
// Therefore, this is where we create the headers
|
|
tableHtml = "<table border='1'>" +
|
|
"<tr>" +
|
|
"<th>序</th>" +
|
|
"<th>Timestamp</th>" +
|
|
"<th>uuid</th>" +
|
|
"<th>Source State</th>" +
|
|
"<th>ackState</th>" +
|
|
"<th>ackRequired</th>" +
|
|
"<th>Source</th>" +
|
|
"<th>alarmClass</th>" +
|
|
"<th>priority</th>" +
|
|
"<th>normalTime</th>" +
|
|
"<th>ackTime</th>" +
|
|
"<th>user</th>" +
|
|
"<th>alarmData</th>" +
|
|
"<th>alarmTransition</th>" +
|
|
"<th>lastUpdate</th>" +
|
|
"</tr>";
|
|
// Tip: one could call this.getCollection().getColumns() to access all the columns.
|
|
},
|
|
each: function (item, index) {
|
|
// Build up a row. Use 'getDisplay' to get a nice server formatted String.
|
|
tableHtml += "<tr>" +
|
|
"<td>" + (index+1) + "</td>" +
|
|
"<td>" + this.getDisplay("timestamp") + "</td>" +
|
|
"<td>" + this.getDisplay("uuid") + "</td>" +
|
|
"<td>" + this.getDisplay("sourceState") + "</td>" +
|
|
"<td>" + this.getDisplay("ackState") + "</td>" +
|
|
"<td>" + this.getDisplay("ackRequired") + "</td>" +
|
|
"<td>" + this.getDisplay("source") + "</td>" +
|
|
"<td>" + this.getDisplay("alarmClass") + "</td>" +
|
|
"<td>" + this.getDisplay("priority") + "</td>" +
|
|
"<td>" + this.getDisplay("normalTime") + "</td>" +
|
|
"<td>" + this.getDisplay("ackTime") + "</td>" +
|
|
"<td>" + this.getDisplay("user") + "</td>" +
|
|
"<td>" + this.getDisplay("alarmData") + "</td>" +
|
|
"<td>" + this.getDisplay("alarmTransition") + "</td>" +
|
|
"<td>" + this.getDisplay("lastUpdate") + "</td>" +
|
|
"</tr>";
|
|
},
|
|
after: function () {
|
|
// After iteration, add the end table element and pop up a dialog.
|
|
tableHtml += "</table>";
|
|
},
|
|
limit: 100, // Specify optional limit on the number of records (defaults to 10)
|
|
offset: 0 // Specify optional record offset (defaults to 0)
|
|
}
|
|
}).then(updateAlarmTable);
|
|
|
|
function updateAlarmTable(){
|
|
$("#alarm-table").append(tableHtml);
|
|
}
|
|
|
|
|
|
|
|
// Resolve the ORD to the Ramp and update the text.
|
|
// baja.Ord.make('station:|slot:/BajaScriptExamples/bajatest/Ramp1').get({subscriber: sub})
|
|
// .then(update);
|
|
|
|
|
|
// baja.Ord.make('local:|alarm:|bql:select * from openAlarms').get({subscriber: sub})
|
|
// .then(update);
|
|
// var val = 17;
|
|
|
|
// baja.Ord.make("station:|slot:/Arena/旅館/前鋒PLC/B5F/消防系統")
|
|
// baja.Ord.make("station:|slot:/Arena/旅館")
|
|
// .get()
|
|
// .then(function (folder) {
|
|
// var batch = new baja.comm.Batch();
|
|
|
|
// // For each point, invoke the 'set' Action and subscribe the point so we can
|
|
// // listen for changes.
|
|
// folder.getSlots().is("control:BooleanWritable").eachValue(function (point) {
|
|
// sub.subscribe({
|
|
// comps: point,
|
|
// batch: batch // Pass the batch in. Doing this won't make the network call yet.
|
|
// });
|
|
|
|
// // The auto-generated action method name is called 'set1' instead of 'set'.
|
|
// // This is because there's already a method called 'set' used in 'baja.Complex'.
|
|
// // point.set1({
|
|
// // value: val,
|
|
// // batch: batch // Pass the batch in. Doing this won't make the network call yet.
|
|
// // });
|
|
// });
|
|
|
|
// // Committing the batch will now make the network call.
|
|
// batch.commit();
|
|
// });
|
|
|
|
|
|
$('.light_check').css("display", "none");
|
|
// $('.light_check').on('click', function(e){
|
|
|
|
// });
|
|
|
|
// })
|
|
// A Promise is an amazing way to handle asynchronous events in JavaScript. For
|
|
// more information on the Promise library we use, please visit https://github.com/petkaantonov/bluebird.
|
|
// .promise()
|
|
// .finally(function () {
|
|
// Called when the dialog is closed.
|
|
|
|
// Unsubscribe the Component so we're no longer listening to live
|
|
// events.
|
|
// sub.unsubscribeAll();
|
|
|
|
// Detach all subscription handlers to ensure we don't unnecessarily
|
|
// create memory leaks.
|
|
// sub.detach();
|
|
// });
|
|
});
|
|
|
|
$(function(){
|
|
|
|
|
|
})
|
|
|