@flexem/fc-gui 3.0.0-alpha.66 → 3.0.0-alpha.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ import { find, isNil, pull, remove } from 'lodash';
8
8
  import { AlarmState } from './alarm-state-enum';
9
9
  export class AlarmElement extends ConditionalDisplayElement {
10
10
  constructor(element, injector, permissionChecker, variableCommunicator, variableStore, alarmsStore, signalRAppId) {
11
+ var _a, _b;
11
12
  super(element, permissionChecker, variableCommunicator, variableStore, signalRAppId);
12
13
  this.alarmsStore = alarmsStore;
13
14
  this.displayOption = {
@@ -32,54 +33,61 @@ export class AlarmElement extends ConditionalDisplayElement {
32
33
  this.localization = injector.get(LOCALIZATION);
33
34
  this.variableCommunicator = variableCommunicator;
34
35
  this.timePeriods = this.getValidTimePeriods();
35
- this.currentTimePeriod = this.model.filterSetting.refreshCycle;
36
36
  this.pageSize = this.model.generalSetting.pageSize;
37
- this.currentTimePeriod = this.model.filterSetting.displayPeriod;
38
- this.updateQueryTimeRange();
39
- if (this.model.filterSetting.alarmType) {
40
- this.refreshIntervalId = setInterval(() => {
41
- this.loadFirstPage();
42
- this.logger.debug(`[GUI]Refresh Alarm Table:${d3.time.format('%x %X')(new Date())}`);
43
- }, this.model.filterSetting.refreshCycle * 60 * 1000);
44
- }
45
- else {
46
- variableCommunicator.subscribeUserDeviceAlarms(signalRAppId).subscribe(alarmWithAppId => {
47
- if (alarmWithAppId.appId !== this.signalRAppId) {
48
- return;
49
- }
50
- const alarm = alarmWithAppId.alarm;
51
- if (!find(this.model.filterSetting.detailsData, alarmName => alarmName === alarm.name)) {
52
- return;
53
- }
54
- const currentAlarm = this.currentAlarmList.find(re => re.name === alarm.name);
55
- if (alarm.state === AlarmState.AlarmStateTriggered.valueOf()) {
56
- if (!isNil(currentAlarm)) {
37
+ if (this.model.filterSetting) {
38
+ this.currentTimePeriod = (_a = this.model.filterSetting) === null || _a === void 0 ? void 0 : _a.refreshCycle;
39
+ this.currentTimePeriod = (_b = this.model.filterSetting) === null || _b === void 0 ? void 0 : _b.displayPeriod;
40
+ this.updateQueryTimeRange();
41
+ if (this.model.filterSetting.alarmType) {
42
+ this.refreshIntervalId = setInterval(() => {
43
+ this.loadFirstPage();
44
+ this.logger.debug(`[GUI]Refresh Alarm Table:${d3.time.format('%x %X')(new Date())}`);
45
+ }, this.model.filterSetting.refreshCycle * 60 * 1000);
46
+ }
47
+ else {
48
+ variableCommunicator.subscribeUserDeviceAlarms(signalRAppId).subscribe(alarmWithAppId => {
49
+ if (alarmWithAppId.appId !== this.signalRAppId) {
57
50
  return;
58
51
  }
59
- pull(this.currentAlarmList, this.currentAlarmList.find(record => alarm.name === record.name));
60
- this.currentAlarmList.unshift(alarm);
61
- this.totalCount += 1;
62
- }
63
- else {
64
- if (isNil(currentAlarm)) {
52
+ const alarm = alarmWithAppId.alarm;
53
+ if (!find(this.model.filterSetting.detailsData, alarmName => alarmName === alarm.name)) {
65
54
  return;
66
55
  }
67
- remove(this.currentAlarmList, currentAlarm);
68
- this.totalCount -= 1;
69
- }
70
- this.alarmList = [];
71
- this.currentAlarmList.forEach(item => {
72
- this.alarmList.push([
73
- item.name,
74
- item.message,
75
- item.alarmLevel,
76
- moment(item.triggeredTime).format('YYYY-MM-DD HH:mm:ss')
77
- ]);
56
+ const currentAlarm = this.currentAlarmList.find(re => re.name === alarm.name);
57
+ if (alarm.state === AlarmState.AlarmStateTriggered.valueOf()) {
58
+ if (!isNil(currentAlarm)) {
59
+ return;
60
+ }
61
+ pull(this.currentAlarmList, this.currentAlarmList.find(record => alarm.name === record.name));
62
+ this.currentAlarmList.unshift(alarm);
63
+ this.totalCount += 1;
64
+ }
65
+ else {
66
+ if (isNil(currentAlarm)) {
67
+ return;
68
+ }
69
+ remove(this.currentAlarmList, currentAlarm);
70
+ this.totalCount -= 1;
71
+ }
72
+ this.alarmList = [];
73
+ this.currentAlarmList.forEach(item => {
74
+ this.alarmList.push([
75
+ item.name,
76
+ item.message,
77
+ item.alarmLevel,
78
+ moment(item.triggeredTime).format('YYYY-MM-DD HH:mm:ss')
79
+ ]);
80
+ });
81
+ this.renderElement();
78
82
  });
79
- this.renderElement();
80
- });
83
+ }
84
+ this.init();
85
+ }
86
+ else {
87
+ this.totalCount = 0;
88
+ this.alarmList = [];
89
+ this.renderElement();
81
90
  }
82
- this.init();
83
91
  }
84
92
  dispose() {
85
93
  clearInterval(this.refreshIntervalId);
@@ -100,40 +108,45 @@ export class AlarmElement extends ConditionalDisplayElement {
100
108
  return timePeriods;
101
109
  }
102
110
  init() {
111
+ this.rootElement.selectAll('*').remove();
103
112
  if (this.model.filterSetting.alarmType) {
104
113
  const input = new GetAlarmsArgs(this.model.filterSetting.detailsData, this.startTime, this.endTime, this.pageSize, this.page * this.pageSize);
105
114
  this.alarmsStore.getHistoryAlarms(input).subscribe(result => {
106
- this.totalCount = result.totalCount;
107
- this.alarmList = result.items.map(item => [
108
- item.name,
109
- item.message,
110
- item.alarmLevel,
111
- item.triggeredTime.format('YYYY-MM-DD HH:mm:ss')
112
- ]);
113
- this.renderElement();
115
+ if (!result.error) {
116
+ this.totalCount = result.totalCount;
117
+ this.alarmList = result.items.map(item => [
118
+ item.name,
119
+ item.message,
120
+ item.alarmLevel,
121
+ item.triggeredTime.format('YYYY-MM-DD HH:mm:ss')
122
+ ]);
123
+ this.renderElement();
124
+ }
114
125
  });
115
126
  }
116
127
  else {
117
128
  const input = new GetAlarmsArgs(this.model.filterSetting.detailsData, undefined, undefined, this.pageSize, this.page * this.pageSize);
118
129
  this.alarmsStore.getCurrentAlarms(input).subscribe(result => {
119
- this.totalCount = result.totalCount;
120
- this.currentAlarmList = result.items;
121
- this.alarmList = this.currentAlarmList.map(item => [
122
- item.name,
123
- item.message,
124
- item.alarmLevel,
125
- item.triggeredTime.format('YYYY-MM-DD HH:mm:ss')
126
- ]);
127
- this.renderElement();
130
+ if (!result.error) {
131
+ this.totalCount = result.totalCount;
132
+ this.currentAlarmList = result.items;
133
+ this.alarmList = this.currentAlarmList.map(item => [
134
+ item.name,
135
+ item.message,
136
+ item.alarmLevel,
137
+ item.triggeredTime.format('YYYY-MM-DD HH:mm:ss')
138
+ ]);
139
+ this.renderElement();
140
+ }
128
141
  });
129
142
  }
130
143
  }
131
144
  renderElement() {
132
- this.rootElement.selectAll('*').remove();
133
145
  const elementHeight = this.model.size.height;
134
146
  this.element = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
135
147
  this.element.setAttribute('width', this.model.size.width.toString());
136
148
  this.element.setAttribute('height', elementHeight.toString());
149
+ this.$element.append(this.element);
137
150
  const table = document.createElement('table');
138
151
  table.style.cssText = `border: 2px solid ${this.model.generalSetting.stroke};
139
152
  height: ${elementHeight - 39}`;
@@ -215,14 +228,14 @@ export class AlarmElement extends ConditionalDisplayElement {
215
228
  table.appendChild(tr);
216
229
  }
217
230
  this.element.appendChild(table);
218
- this.$element.append(this.element);
219
231
  this.renderOperationArea(this.model.size.width, elementHeight - 39);
220
232
  }
221
233
  renderOperationArea(chartWidth, chartHeight) {
234
+ var _a;
222
235
  const operationArea = this.rootElement.append('g').attr('transform', `translate(0,${chartHeight + this.displayOption.operationAreaMarginTop})`)
223
236
  .append('foreignObject').attr('width', chartWidth).attr('height', this.displayOption.operationAreaHeight).attr('fill', 'none')
224
237
  .append('xhtml:div').style('height', (this.displayOption.operationAreaHeight - 4) + 'px').style('overflow', 'hidden').style('margin-top', '4px');
225
- if (this.model.filterSetting.alarmType) {
238
+ if ((_a = this.model.filterSetting) === null || _a === void 0 ? void 0 : _a.alarmType) {
226
239
  const selectElement = operationArea.append('select').style('margin-left', this.displayOption.marginLeft + 'px')
227
240
  .style('font-size', this.displayOption.operationSelectFontSize).on('change', () => {
228
241
  const displayTimePeriod = this.rootElement.select('select').property('value');
@@ -283,7 +296,9 @@ export class AlarmElement extends ConditionalDisplayElement {
283
296
  this.init();
284
297
  }
285
298
  loadNextPage() {
286
- const last_page = Math.ceil(this.totalCount / this.pageSize) - 1;
299
+ let last_page = Math.ceil(this.totalCount / this.pageSize);
300
+ if (last_page)
301
+ last_page--;
287
302
  if (this.page < last_page) {
288
303
  this.page++;
289
304
  }
@@ -296,7 +311,10 @@ export class AlarmElement extends ConditionalDisplayElement {
296
311
  this.init();
297
312
  }
298
313
  loadLastPage() {
299
- this.page = Math.ceil(this.totalCount / this.pageSize) - 1;
314
+ let last_page = Math.ceil(this.totalCount / this.pageSize);
315
+ if (last_page)
316
+ last_page--;
317
+ this.page = last_page;
300
318
  this.init();
301
319
  }
302
320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "main": "bundles/fc-gui.umd.js",
3
- "version": "3.0.0-alpha.66",
3
+ "version": "3.0.0-alpha.67",
4
4
  "module": "public_api.js",
5
5
  "typings": "public_api.d.ts",
6
6
  "license": "UNLICENSED",