991 lines
37 KiB
JavaScript
991 lines
37 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
|
|
*/
|
|
let baja_my_user_account_func, //設定使用者帳號
|
|
baja_prepare_specify_subscribe_devices = [], //設定要訂閱的設備
|
|
baja_all_emergency_devices = [], //所有緊急應變的設備
|
|
baja_emergency_alarm_func, //設定回傳的緊急應變設備編號Function
|
|
baja_target_func, //設定回傳指定訂閱設備編號Function
|
|
baja_specify_subscribe_real_time_device = [], //設定即時顯示的設備
|
|
baja_target_real_time_func; //設定回傳即時顯示設備的Function
|
|
|
|
var baja_specify_alarm_device_number = [];
|
|
var baja_emergency_alarm_device_number = []; //要回傳的緊急應變的異常設備
|
|
var baja_specify_real_time_device_number = [];
|
|
|
|
var user_name = "";
|
|
|
|
function MyBaja() {
|
|
this.setMyUserAccount = function (callBackFunc) {
|
|
|
|
if (callBackFunc != undefined && callBackFunc != null) {
|
|
baja_my_user_account_func = callBackFunc;
|
|
}
|
|
};
|
|
|
|
this.setPrepareSubscribeDevices = function (devices) {
|
|
baja_prepare_specify_subscribe_devices = devices;
|
|
BajaSpecifySubscribeDevices(); //執行訂閱設備
|
|
};
|
|
|
|
//設定要回傳緊急應變的Function
|
|
this.setEmergencyCallBack = function (callBackFunc) {
|
|
if (callBackFunc != undefined && callBackFunc != null) {
|
|
baja_emergency_alarm_func = callBackFunc;
|
|
}
|
|
}
|
|
|
|
this.setCallBack = function (callBackFunc) {
|
|
if (callBackFunc != undefined && callBackFunc != null) {
|
|
baja_target_func = callBackFunc;
|
|
}
|
|
};
|
|
|
|
this.setSSC = function (device) {
|
|
SetDeviceSSCPoint(device)
|
|
}
|
|
|
|
this.setSubscribeRealtimeReportDevices = function (devices) {
|
|
|
|
devices.map(function (device) {
|
|
device.points.map(function (point) {
|
|
point.is_complete = false;
|
|
})
|
|
});
|
|
|
|
baja_specify_subscribe_real_time_device = devices;
|
|
|
|
BajaSpecifySubscribeRealtimeReportDevices(); //執行訂閱設備
|
|
};
|
|
|
|
this.setRealtimeReportCallBack = function (callBackFunc) {
|
|
if (callBackFunc != undefined && callBackFunc != null) {
|
|
baja_target_real_time_func = callBackFunc;
|
|
}
|
|
};
|
|
}
|
|
|
|
function SetDeviceSSCPoint(device) {
|
|
console.log("設定開關");
|
|
require(['baja!'], function (baja) {
|
|
|
|
var sub = new baja.Subscriber();
|
|
var device_number_split = device.device_number.split("_");
|
|
device_number_split = device_number_split.map(function (item) {
|
|
var first = item.substr(0, 1);
|
|
if (!isNaN(parseInt(first))) {
|
|
return "$3" + item;
|
|
} else {
|
|
return item;
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 針對傳入設備抓取點位
|
|
*/
|
|
baja.Ord.make("local:|foxs:|station:|slot:/Arena/" + device_number_split.slice(0, 4).join("/") + "/" + device.device_number)
|
|
.get()
|
|
.then(function (folder) {
|
|
folder.getSlots().isComponent().eachValue(function (point) {
|
|
if (point.getDisplayName() == "SSC") {
|
|
sub.subscribe({
|
|
comps: point,
|
|
});
|
|
|
|
point.set1({
|
|
value: device.SSC
|
|
})
|
|
|
|
sub.unsubscribeAll();
|
|
sub.detach();
|
|
}
|
|
});
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
function update_baja_specify_alarm_device_number(point) {
|
|
var target_device_number = point.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
|
var point_name = point.getDisplayName();
|
|
|
|
// console.log("target_device_number", target_device_number)
|
|
// console.log(point.getOutDisplay());
|
|
|
|
|
|
var facets_split = point.getFacets1().$cEncStr.split('|');
|
|
var facets_arr = [];
|
|
facets_split.forEach(function (item, index) {
|
|
facets_arr.push(item.split('=s:'));
|
|
});
|
|
|
|
var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
|
|
|
var point_out_split = point.getOutDisplay().split(' ');
|
|
|
|
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
|
|
|
|
//判斷設備是否已存在
|
|
var index = baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
if (index < 0) {
|
|
//設備不存在則新增
|
|
|
|
baja_specify_alarm_device_number.push(
|
|
{
|
|
device_number: target_device_number,
|
|
points: {},
|
|
// finish: 1,
|
|
// alarm_timestamp: str_date
|
|
});
|
|
|
|
//新增點位
|
|
if (key != undefined && key != null && point_name != "ER") {
|
|
var mypoint = { [point_name]: key }
|
|
} else {
|
|
var mypoint = { [point_name]: point_out_split[0] }
|
|
}
|
|
|
|
var renew_index = baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
baja_specify_alarm_device_number[renew_index].points = mypoint;
|
|
|
|
} else {
|
|
//設備存在則修改
|
|
|
|
//判斷點位是否存在
|
|
var point_key = Object.keys(baja_specify_alarm_device_number[index].points).find(k => k === point_name);
|
|
if (point_key != undefined && point_key != null && point_name != "ER") {
|
|
baja_specify_alarm_device_number[index].points[point_key] = key
|
|
} else {
|
|
baja_specify_alarm_device_number[index].points[point_name] = point_out_split[0]
|
|
}
|
|
}
|
|
// if (temp[0].facets != undefined || temp[0].facets != null) {
|
|
// let key = Object.keys(temp[0].facets).find(k => temp[0].facets[k] === arr_point_alarm[0]);
|
|
|
|
// date = new Date();
|
|
// str_date = date.getFullYear() + ("0" + (date.getMonth() + 1)).slice(-2) + ("0" + date.getDate()).slice(-2) + ("0" + date.getHours()).slice(-2) + ("0" + date.getMinutes()).slice(-2) + ("0" + date.getSeconds()).slice(-2)
|
|
|
|
// if (/true/.test(key)) {
|
|
|
|
// if (baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number) < 0) {
|
|
// baja_specify_alarm_device_number.push({ device_number: target_device_number, finish: 1, alarm_timestamp: str_date });
|
|
// }
|
|
// } else if (/false/.test(key)) {
|
|
|
|
// var index = baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
|
|
// if (index >= 0) {
|
|
// baja_specify_alarm_device_number.splice(index, 1);
|
|
// }
|
|
// }
|
|
// console.log("baja_specify_alarm_device_number", baja_specify_alarm_device_number);
|
|
// }
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 使用者指定要訂閱設備的Function
|
|
*/
|
|
function BajaSpecifySubscribeDevices() {
|
|
console.log("設定指定設備");
|
|
require(['baja!'], function (baja) {
|
|
|
|
var sub = new baja.Subscriber();
|
|
|
|
sub.attach('changed', function (prop) {
|
|
// console.log("sub changed", prop)
|
|
|
|
if (prop.getName() === 'out') {
|
|
// console.log(`變更的項目${this.getDisplayName()}`, this);
|
|
update_baja_specify_alarm_device_number(this)
|
|
|
|
var target_device_number = this.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
|
var point_name = this.getDisplayName();
|
|
|
|
var modify_target_device = {
|
|
"device_number": target_device_number ? target_device_number : null,
|
|
"point_name": point_name ? point_name : null
|
|
}
|
|
|
|
if (baja_target_func != undefined && baja_target_func != null) {
|
|
baja_target_func(baja_specify_alarm_device_number, modify_target_device);
|
|
}
|
|
}
|
|
});
|
|
|
|
var start = new Date().getTime();
|
|
var total = 0;
|
|
var pre_subtime = 0
|
|
var temp_subtime = 0;
|
|
var total_subtime = 0;
|
|
console.log("設備迴圈開始執行", start);
|
|
|
|
baja_prepare_specify_subscribe_devices.forEach(function (device, index) {
|
|
// var string_change_start = new Date().getTime();
|
|
var device_number_split = device.device_number.split("_");
|
|
device_number_split = device_number_split.map(function (item) {
|
|
var first = item.substr(0, 1);
|
|
if (!isNaN(parseInt(first))) {
|
|
return "$3" + item;
|
|
} else {
|
|
return item;
|
|
}
|
|
});
|
|
// var string_change_end = new Date().getTime();
|
|
// console.log("字串路徑替換花費時間", (string_change_end - string_change_start) / 1000 + "sec")
|
|
|
|
/**
|
|
* 針對傳入設備抓取點位
|
|
*/
|
|
baja.Ord.make("local:|foxs:|station:|slot:/Arena/" + device_number_split.slice(0, 4).join("/") + "/" + device.device_number)
|
|
.get()
|
|
.then(function (folder) {
|
|
var sub_start = new Date().getTime();
|
|
|
|
if (temp_subtime == 0) {
|
|
pre_subtime = start;
|
|
}
|
|
temp_subtime = (sub_start - pre_subtime)
|
|
pre_subtime = sub_start;
|
|
|
|
total_subtime += temp_subtime;
|
|
console.log("進入多資料夾設備的時間點", sub_start)
|
|
console.log("進入多資料夾設備花費時間", temp_subtime / 1000 + "sec")
|
|
console.log("進入多資料夾設備總花費時間", total_subtime / 1000 + "sec")
|
|
folder.getSlots().isComponent().eachValue(function (point) {
|
|
|
|
// console.log(folder.getDisplayName() + " point ", point.getDisplayName())
|
|
// var point_name = point.getDisplayName();
|
|
|
|
// var temp = baja_prepare_specify_subscribe_devices.filter(function (item, index) {
|
|
// return item.device_number == folder.getDisplayName();
|
|
// });
|
|
|
|
var target_device_number = point.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
|
var point_name = point.getDisplayName()
|
|
|
|
// console.log("target_device_number", target_device_number)
|
|
// console.log(point.getOutDisplay());
|
|
|
|
var point_type_name = point.getType().getTypeName();
|
|
|
|
if (point_type_name.search("TextBlock") == -1) { //排除點位名稱為TextBlock
|
|
var facets_arr = [];
|
|
if (point.getFacets1 != undefined && typeof point.getFacets1 == 'function') {
|
|
var facets_split = point.getFacets1().$cEncStr.split('|');
|
|
facets_split.forEach(function (item, index) {
|
|
facets_arr.push(item.split('=s:'));
|
|
});
|
|
}
|
|
|
|
var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
|
|
|
var point_out_split = point.getOutDisplay().split(' ');
|
|
|
|
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
|
|
|
|
//判斷設備是否已存在
|
|
var index = baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
if (index < 0) {
|
|
//設備不存在則新增
|
|
|
|
baja_specify_alarm_device_number.push(
|
|
{
|
|
device_number: target_device_number,
|
|
points: {},
|
|
// finish: 1,
|
|
// alarm_timestamp: str_date
|
|
});
|
|
|
|
//新增點位
|
|
if (key != undefined && key != null && point_name != "ER") {
|
|
var mypoint = { [point_name]: key }
|
|
} else {
|
|
var mypoint = { [point_name]: point_out_split[0] }
|
|
}
|
|
|
|
var renew_index = baja_specify_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
baja_specify_alarm_device_number[renew_index].points = mypoint;
|
|
|
|
} else {
|
|
//設備存在則修改
|
|
|
|
//判斷點位是否存在
|
|
var point_key = Object.keys(baja_specify_alarm_device_number[index].points).find(k => k === point_name);
|
|
if (point_key != undefined && point_key != null) {
|
|
baja_specify_alarm_device_number[index].points[point_key] = key
|
|
} else {
|
|
baja_specify_alarm_device_number[index].points[point_name] = point_out_split[0]
|
|
}
|
|
}
|
|
|
|
sub.subscribe({
|
|
comps: point,
|
|
});
|
|
}
|
|
});
|
|
|
|
sub_end = new Date().getTime();
|
|
console.log("多資料夾設備所有點位訂閱花費時間", (sub_end - sub_start) / 1000 + "sec")
|
|
total += (sub_end - sub_start)
|
|
console.log("多資料夾設備當前訂閱總花費時間", total / 1000 + "sec")
|
|
});
|
|
});
|
|
|
|
var end = new Date().getTime();
|
|
console.log("設備迴圈結束執行", (end - start) / 1000 + "sec")
|
|
});
|
|
}
|
|
|
|
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);
|
|
}
|
|
});
|
|
|
|
|
|
function update_baja_emergency_alarm_device_number(point) {
|
|
var target_device_number = point.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
|
|
|
var arr_point_alarm = point.getOutDisplay().split(' ');
|
|
|
|
var temp = baja_all_emergency_devices.filter(function (item, index) {
|
|
return item.device_number == target_device_number;
|
|
});
|
|
|
|
if (temp[0].facets != undefined || temp[0].facets != null) {
|
|
let key = Object.keys(temp[0].facets).find(k => temp[0].facets[k] === arr_point_alarm[0]);
|
|
|
|
date = new Date();
|
|
str_date = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2)
|
|
|
|
if (/true/.test(key)) {
|
|
if (baja_emergency_alarm_device_number.findIndex(x => x.device_number == target_device_number) < 0) {
|
|
baja_emergency_alarm_device_number.push({ device_number: target_device_number, finish: 1, alarm_timestamp: str_date });
|
|
}
|
|
} else if (/false/.test(key)) {
|
|
|
|
var index = baja_emergency_alarm_device_number.findIndex(x => x.device_number == target_device_number)
|
|
|
|
if (index >= 0) {
|
|
baja_emergency_alarm_device_number.splice(index, 1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
require(['baja!'], function (baja) {
|
|
console.log("設定緊急指定設備");
|
|
var sub = new baja.Subscriber();
|
|
|
|
sub.attach('changed', function (prop) {
|
|
if (prop.getName() === 'out') {
|
|
update_baja_emergency_alarm_device_number(this);
|
|
}
|
|
|
|
//執行使用者傳入的function
|
|
baja_emergency_alarm_func(baja_emergency_alarm_device_number);
|
|
});
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena|bql:select * from kitControl:Or where name like '%ER%'")
|
|
// // baja.Ord.make("local:|foxs:|station:|slot:/Arena|bql:select * from kitControl:Or where name like '%ER%'")
|
|
// .get({
|
|
// cursor: {
|
|
// before: function () {
|
|
// },
|
|
// each: function (item, index) {
|
|
// // console.log("SlotPath", this.getDisplay("slotPath"));
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath"))
|
|
// .get()
|
|
// .then(function (component) {
|
|
// // console.log("component", component);
|
|
// var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
|
// var facets_split = component.getFacets1().$cEncStr.split('|');
|
|
// var facets_arr = [];
|
|
// facets_split.forEach(function (item, index) {
|
|
// facets_arr.push(item.split('=s:'));
|
|
// });
|
|
|
|
// // console.log(component.$parent.getOutDisplay());
|
|
|
|
// var emergency_device = {
|
|
// device_number: target_device_number,
|
|
// facets: facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
|
// }
|
|
|
|
// baja_all_emergency_devices.push(emergency_device)
|
|
|
|
// sub.subscribe({
|
|
// comps: component,
|
|
// });
|
|
|
|
// //初始判斷是否有發生alarm
|
|
// var arr_point_alarm = component.getOutDisplay().split(' ');
|
|
|
|
// let key = Object.keys(emergency_device.facets).find(k => emergency_device.facets[k] === arr_point_alarm[0]);
|
|
|
|
// date = new Date();
|
|
// str_date = date.getFullYear() + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + ("0" + date.getDate()).slice(-2) + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2)
|
|
// if (/true/.test(key)) {
|
|
// if (baja_emergency_alarm_device_number.findIndex(x => x.device_number == emergency_device.device_number) < 0) {
|
|
// baja_emergency_alarm_device_number.push({ device_number: emergency_device.device_number, finish: 1, alarm_timestamp: str_date });
|
|
// }
|
|
// } else if (/false/.test(key)) {
|
|
// var index = baja_emergency_alarm_device_number.findIndex(x => x.device_number == emergency_device.device_number)
|
|
|
|
// if (index >= 0) {
|
|
// baja_emergency_alarm_device_number.splice(index, 1);
|
|
// }
|
|
// }
|
|
|
|
// if (baja_emergency_alarm_func != undefined) {
|
|
// //執行使用者傳入的function
|
|
// baja_emergency_alarm_func(baja_emergency_alarm_device_number);
|
|
// }
|
|
|
|
// });
|
|
|
|
// },
|
|
// after: function () {
|
|
|
|
// },
|
|
// limit: -1, // Specify optional limit on the number of records (defaults to 10)
|
|
// offset: 0 // Specify optional record offset (defaults to 0)
|
|
// }
|
|
// });
|
|
});
|
|
|
|
|
|
|
|
function update_baja_specify_real_time_device_number(baja_realtime) {
|
|
|
|
var is_all_complete = true;
|
|
for (var i = 0; i < baja_specify_subscribe_real_time_device.length; i++) {
|
|
for (var j = 0; j < baja_specify_subscribe_real_time_device[i].points.length; j++) {
|
|
if (is_all_complete && baja_specify_subscribe_real_time_device[i].points[j].is_complete) {
|
|
//不做任何事
|
|
} else {
|
|
is_all_complete = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!is_all_complete){
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (is_all_complete) {
|
|
baja_target_real_time_func(baja_realtime);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 使用者指定要即時顯示的設備
|
|
*/
|
|
function BajaSpecifySubscribeRealtimeReportDevices() {
|
|
require(['baja!'], function (baja) {
|
|
|
|
// var sub = new baja.Subscriber();
|
|
|
|
// sub.attach('changed', function (prop) {
|
|
// // console.log("sub changed", prop)
|
|
|
|
// if (prop.getName() === 'out') {
|
|
// update_baja_specify_real_time_device_number(this)
|
|
// }
|
|
|
|
// if (baja_target_real_time_func != undefined && baja_target_real_time_func != null) {
|
|
// baja_target_real_time_func(baja_specify_real_time_device_number);
|
|
// }
|
|
// });
|
|
|
|
// // baja.Ord.make('station:|slot:/BajaScriptExamples/Components/Ramp').get({ subscriber: sub });
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/B/B1F/MVCB/H_B_B1F_MVCB_MVCBH/V1")
|
|
// // baja.Ord.make("local:|foxs:|alarm:|bql:select * where ackState = 'unacked' order by timestamp desc")
|
|
// .get().then(function (point) {
|
|
// // console.log(folder)
|
|
// // folder.getSlots().eachValue(function (point) {
|
|
// // console.log(point)
|
|
// // })
|
|
|
|
// sub.subscribe({
|
|
// comps: point,
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
var baja_realtime = [];
|
|
baja_specify_subscribe_real_time_device.map(function (device, index) {
|
|
device.points.forEach(function (point, index) {
|
|
|
|
// baja.Ord.make("local:|foxs:|history:/FIC_Center/" + device.device_number + "_" + point.point_name + "|view: history: HistoryTable")
|
|
baja.Ord.make("local:|foxs:|history:/FIC_Center/" + device.device_number + "_" + point.point_name + "?period=today|bql:select top 100 order by timestamp desc")
|
|
.get(function (table) {
|
|
// console.log(table)
|
|
table.cursor({
|
|
before: function () {
|
|
},
|
|
each: function (item, index) {
|
|
|
|
var timestamp = this.getDisplay("timestamp");
|
|
// timestamp_split = timestamp.split(" ")
|
|
// timestamp = timestamp_split[timestamp_split.length - 1];
|
|
var realtimeIndex = Object.keys(baja_realtime).findIndex(k => k === timestamp);
|
|
|
|
if (realtimeIndex > 0) { //表示有找到時間點
|
|
var device_number_obj = baja_realtime[timestamp].find(x => x.device_number === device.device_number && x.point === point.point_name);
|
|
if (device_number_obj == undefined || device_number_obj == null) {
|
|
var temp_obj = {
|
|
"device_number": device.device_number,
|
|
"point": point.point_name,
|
|
"unit": point.unit,
|
|
"value": this.getDisplay("value")
|
|
}
|
|
|
|
baja_realtime[timestamp].push(temp_obj)
|
|
}
|
|
} else {
|
|
var temp_obj = {
|
|
"device_number": device.device_number,
|
|
"point": point.point_name,
|
|
"unit": point.unit,
|
|
"value": this.getDisplay("value")
|
|
}
|
|
|
|
baja_realtime[timestamp] = [temp_obj];
|
|
}
|
|
},
|
|
after: function () {
|
|
point.is_complete = true;
|
|
update_baja_specify_real_time_device_number(baja_realtime)
|
|
// baja_target_real_time_func(baja_realtime);
|
|
},
|
|
limit: -1,
|
|
offset: 0
|
|
});
|
|
|
|
}).then(function (table) {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
// 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(point) {
|
|
// $(`#${light.$propInParent.$displayName}`).html(light.getOutDisplay());
|
|
// console.log(light);
|
|
// $("#Ramp1").html(light.getOutDisplay());
|
|
console.log("update function point:", point);
|
|
|
|
$(`#${point.getDisplayName()}-value`).html(point.getOutDisplay());
|
|
}
|
|
|
|
function update_6w(point) {
|
|
// $(`#${light.$propInParent.$displayName}`).html(light.getOutDisplay());
|
|
// console.log(light);
|
|
// $("#Ramp1").html(light.getOutDisplay());
|
|
console.log("update function point:", point);
|
|
|
|
$(`#${point.getDisplayName()}-value`).html(point.getOutDisplay());
|
|
}
|
|
|
|
function updateIP(point) {
|
|
console.log("updateIP function point:", point);
|
|
$(`#${point.getDisplayName()}-ip`).html(point.getPingHost());
|
|
}
|
|
|
|
// Called whenever the Ramp changes.
|
|
// sub.attach('changed', function (prop) {
|
|
// console.log("sub changed", prop)
|
|
// // if (prop.getName() === 'out') { update(this); }
|
|
// // if (prop.getName() === 'out') { update_6w(this); }
|
|
// // if (prop.getName() === 'pingHost') { updateIP(this); }
|
|
|
|
// if (prop.getName() === 'out') {
|
|
// console.log(`變更的項目${this.getDisplayName()}`, this);
|
|
// // update_baja_specify_alarm_device_number(this)
|
|
// }
|
|
// // baja_target_func(baja_specify_alarm_device_number);
|
|
// });
|
|
|
|
// function update_baja_specify_alarm_device_number(point) {
|
|
// var target_device_number = point.getDisplayName().split('_').slice(0, 5).join('_');
|
|
// console.log("target_device_number", target_device_number)
|
|
// console.log(point.getOutDisplay());
|
|
|
|
// var arr_point_alarm = point.getOutDisplay().split(' ');
|
|
// if (arr_point_alarm[0] === "true") {
|
|
// if (baja_specify_alarm_device_number.indexOf(target_device_number) < 0) {
|
|
// baja_specify_alarm_device_number.push(target_device_number);
|
|
// }
|
|
// } else if (arr_point_alarm[0] === "false") {
|
|
// if (baja_specify_alarm_device_number.indexOf(target_device_number) >= 0) {
|
|
// baja_specify_alarm_device_number.splice(baja_specify_alarm_device_number.indexOf(target_device_number), 1);
|
|
// }
|
|
// }
|
|
|
|
// console.log("baja_specify_alarm_device_number", baja_specify_alarm_device_number);
|
|
// }
|
|
// 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
|
|
// 紀錄可能會有機會抓到東西 local:|foxs:|station:|slot:/Drivers/BcpBacnetNetwork: select * from alarm:AlarmSourceExt
|
|
// 抓取確認並倒排 local:|foxs:|alarm:|bql:select * from where ackState='acked' order by timestamp desc
|
|
// 抓取未確認並倒排的設備 local:|foxs:|alarm:|bql:select * where ackState = 'unacked' order by timestamp desc
|
|
// Alarm 表格
|
|
// var tableHtml = "";
|
|
// baja.Ord.make("local:|foxs:|alarm:|bql:select * where ackState = 'unacked' order by timestamp 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);
|
|
// }
|
|
|
|
// var tableHtml = "";
|
|
// var baja_realtime = [];
|
|
// baja.Ord.make("local:|foxs:|history:/FIC_Center/H_B_B1F_MVCB_MVCBH_V1|view:history:HistoryTable")
|
|
// .get(function (table) {
|
|
// console.log(table)
|
|
// table.cursor({
|
|
// before: function () {
|
|
// },
|
|
// each: function (item, index) {
|
|
// // var tableContentHtml = "<tr>" +
|
|
// // "<td>" + (index + 1) + "</td>" +
|
|
// // "<td>" + this.getDisplay("timestamp") + "</td>" +
|
|
// // "<td>" + this.getDisplay("trendFlags") + "</td>" +
|
|
// // "<td>" + this.getDisplay("status") + "</td>" +
|
|
// // "<td>" + this.getDisplay("value") + "</td>" +
|
|
// // "</tr>";
|
|
|
|
// var timestamp = this.getDisplay("timestamp");
|
|
|
|
// var realtimeIndex = Object.keys(baja_realtime).findIndex(k => k === timestamp);
|
|
|
|
// if (realtimeIndex > 0) { //表示有找到時間點
|
|
// var device_number_obj = baja_realtime[timestamp].find(x => x.device_number === 'H_B_B1F_MVCB_MVCBH' && x.point === 'V1');
|
|
// if (device_number_obj == undefined || device_number_obj == null) {
|
|
// var temp_obj = {
|
|
// "device_number": 'H_B_B1F_MVCB_MVCBH',
|
|
// "point": "V1",
|
|
// "value": this.getDisplay("value")
|
|
// }
|
|
|
|
// baja_realtime[timestamp].push(temp_obj)
|
|
// }
|
|
// } else {
|
|
// var temp_obj = {
|
|
// "device_number": 'H_B_B1F_MVCB_MVCBH',
|
|
// "point": "V1",
|
|
// "value": this.getDisplay("value")
|
|
// }
|
|
|
|
// baja_realtime[timestamp] = temp_obj;
|
|
// }
|
|
|
|
// // $("#alarm-table > table tbody").append(tableContentHtml);
|
|
// },
|
|
// after: function () {
|
|
// // tableHtml += "</table>";
|
|
// },
|
|
// limit: -1,
|
|
// offset: 0
|
|
// });
|
|
|
|
// // table.cursor(function (e, index) {
|
|
// // console.log(e)
|
|
|
|
// // tableContentHtml = "<tr>" +
|
|
// // "<td>" + (index + 1) + "</td>" +
|
|
// // "<td>" + this.getDisplay("timestamp") + "</td>" +
|
|
// // "<td>" + this.getDisplay("trendFlags") + "</td>" +
|
|
// // "<td>" + this.getDisplay("status") + "</td>" +
|
|
// // "<td>" + this.getDisplay("value") + "</td>" +
|
|
// // "</tr>";
|
|
|
|
// // $("#alarm-table > table tbody").append(tableContentHtml);
|
|
// // });
|
|
|
|
// }).then(function (table) {
|
|
|
|
// // tableHtml = "<table border='1'>" +
|
|
// // "<thead>" +
|
|
// // "<tr>" +
|
|
// // "<th>序</th>" +
|
|
// // "<th>Timestamp</th>" +
|
|
// // "<th>trendFlags</th>" +
|
|
// // "<th>status</th>" +
|
|
// // "<th>value</th>" +
|
|
// // "</tr>" +
|
|
// // "</thead>" +
|
|
// // "<tbody>" +
|
|
// // "</tbody>" +
|
|
// // "</table>";
|
|
|
|
// // console.log("baja_realtime", baja_realtime);
|
|
|
|
// // baja_target_real_time_func(baja_specify_real_time_device_number);
|
|
|
|
|
|
// // $("#alarm-table").append(tableHtml);
|
|
// });
|
|
|
|
|
|
//在update 的function 可以查看到Boolean狀態 local:|foxs:|station:|slot:/BajaScriptExamples/Components/BooleanWritable
|
|
|
|
// Resolve the ORD to the Ramp and update the text.
|
|
// baja.Ord.make('local:|foxs:|station:|slot:/Arena/H/B/B4F/FE/H_B_B4F_2A_01/H_B_B4F_2A_01_ST').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("local:|foxs:|station:|slot:/Arena|bql:select * from baja:Component where name like '%ER'")
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/B/B4F/$31A")
|
|
// .get()
|
|
// .then(function (folders) {
|
|
// batch = new baja.comm.Batch();
|
|
// console.log("查看指定路徑資料夾資訊", folders);
|
|
// console.log("取得指定路徑Slots", folders.getSlots())
|
|
|
|
// folders.getSlots().eachValue(function (folder, index) {
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:" + folder.getSlotPath().getNames().join("/"))
|
|
// .get()
|
|
// .then(function (folder) {
|
|
// console.log("folder", folder)
|
|
// folder.getSlots().is("control:BooleanWritable").eachValue(function (point) {
|
|
|
|
|
|
// console.log(folder.getDisplayName() + " point", point)
|
|
// console.log(folder.getDisplayName() + " Facets", point.getFacets1().$cEncStr);
|
|
|
|
// $("#auto-append-wrap").append(`<div id="${point.getDisplayName()}">
|
|
// <label>${point.getDisplayName()}</label>
|
|
// <div id="${point.getDisplayName()}-value" style="text-align: center;"></div>
|
|
// </div>`)
|
|
// sub.subscribe({
|
|
// comps: point,
|
|
// // batch: batch
|
|
// });
|
|
|
|
// points.push(point);
|
|
|
|
// });
|
|
// });
|
|
// });
|
|
|
|
// // batch.commit();
|
|
// });
|
|
|
|
/**
|
|
* 抓所有設備有ER的Component
|
|
*/
|
|
// var tableHtml = "";
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena|bql:select * from kitControl:Or where name like '%ER%'")
|
|
// .get({
|
|
// cursor: {
|
|
// before: function () {
|
|
// },
|
|
// each: function (item, index) {
|
|
// console.log("SlotPath", this.getDisplay("slotPath"));
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath"))
|
|
// .get()
|
|
// .then(function(component){
|
|
// console.log("component", component);
|
|
|
|
// sub.subscribe({
|
|
// comps: component,
|
|
// });
|
|
// });
|
|
|
|
// },
|
|
// after: function () {
|
|
|
|
// },
|
|
// limit: 10, // Specify optional limit on the number of records (defaults to 10)
|
|
// offset: 0 // Specify optional record offset (defaults to 0)
|
|
// }
|
|
// });
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/B/B5F/$32A/$301")
|
|
// .get()
|
|
// .then(function (folder) {
|
|
|
|
// var batch = new baja.comm.Batch();
|
|
// console.log("H_B_B5F_2A_01 folder", folder);
|
|
// // For each point, invoke the 'set' Action and subscribe the point so we can
|
|
// // listen for changes.
|
|
|
|
// console.log("H_B_B5F_2A_01 Slots", folder.getSlots())
|
|
// folder.getSlots().is("control:BooleanWritable").eachValue(function (point) {
|
|
// console.log("H_B_B5F_2A_01的point", 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();
|
|
// });
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/C/B5F/VRC")
|
|
// .get()
|
|
// .then(function (folders) {
|
|
// console.log("CCTV");
|
|
// console.log("查看指定路徑資料夾資訊", folders);
|
|
// console.log("取得指定路徑Slots", folders.getSlots())
|
|
|
|
// folders.getSlots().eachValue(function (folder, index) {
|
|
|
|
// baja.Ord.make("local:|foxs:|station:|slot:" + folder.getSlotPath().getNames().join("/"))
|
|
// .get()
|
|
// .then(function (folder) {
|
|
// console.log("folder", folder)
|
|
// console.log("folder getSlots", folder.getSlots())
|
|
|
|
// folder.getSlots().is("vykonPro:ConnectionFailover").eachValue(function (point) {
|
|
|
|
// console.log(folder.getDisplayName() + " point", point)
|
|
|
|
// $("#ip-auto-append-wrap").append(`<div id="${point.getDisplayName()}">
|
|
// <label>${point.getDisplayName()}</label>
|
|
// <div id="${point.getDisplayName()}-ip" style="text-align: center;"></div>
|
|
// </div>`)
|
|
// sub.subscribe({
|
|
// comps: point
|
|
// });
|
|
// });
|
|
// });
|
|
// });
|
|
// });
|
|
|
|
// baja.Ord.make('local:|foxs:|station:|slot:/BajaScriptExamples/bajatest')
|
|
// .get()
|
|
// .then(function (folder) {
|
|
// folder.getSlots().is("kitControl:Ramp").eachValue(function (point) {
|
|
|
|
// console.log(folder.getDisplayName() + " point", point)
|
|
|
|
// $("#6w-point-auto-append-wrap").append(`<div id="${point.getDisplayName()}">
|
|
// <label>${point.getDisplayName()}</label>
|
|
// <div id="${point.getDisplayName()}-value" style="text-align: center;"></div>
|
|
// </div>`)
|
|
// sub.subscribe({
|
|
// comps: point,
|
|
// batch: batch
|
|
// });
|
|
// });
|
|
// })
|
|
// 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();
|
|
// });
|
|
|
|
});
|