@ntlab/sipd-tu-bridge-ui 1.2.0 → 1.4.0

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.
package/controller/ui.js CHANGED
@@ -132,6 +132,11 @@ class UiController extends Controller {
132
132
  /** @type {import('..').SipdApi} */
133
133
  const api = req.app.api;
134
134
  switch (req.params.op) {
135
+ case 'remove':
136
+ if (req.body.error) {
137
+ Object.assign(result, await api.query({cmd: 'clean-err', error: req.body.error}));
138
+ }
139
+ break;
135
140
  case 'restart':
136
141
  Object.assign(result, await api.query({cmd: 'restart'}));
137
142
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ntlab/sipd-tu-bridge-ui",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "SIPD Penatausahaan Bridge Web Interface",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,11 @@ img.logo {
22
22
  .ui.container.queue-result {
23
23
  max-width: 22.5em;
24
24
  }
25
+ .ui.container.err-message {
26
+ max-width: 20em;
27
+ }
25
28
  .ui.container.err-data {
26
- max-width: 40em;
29
+ max-width: 25em;
27
30
  }
28
31
  }
29
32
 
@@ -34,8 +37,11 @@ img.logo {
34
37
  .ui.container.queue-result {
35
38
  max-width: 17.5em;
36
39
  }
40
+ .ui.container.err-message {
41
+ max-width: 15em;
42
+ }
37
43
  .ui.container.err-data {
38
- max-width: 30em;
44
+ max-width: 20em;
39
45
  }
40
46
  }
41
47
 
@@ -46,14 +52,18 @@ img.logo {
46
52
  .ui.container.queue-result {
47
53
  max-width: 12.5em;
48
54
  }
55
+ .ui.container.err-message {
56
+ max-width: 12.5em;
57
+ }
49
58
  .ui.container.err-data {
50
- max-width: 20em;
59
+ max-width: 15em;
51
60
  }
52
61
  }
53
62
 
54
63
  @media only screen and (max-width: 767.98px) {
55
64
  .ui.container.queue-name,
56
65
  .ui.container.queue-result,
66
+ .ui.container.err-message,
57
67
  .ui.container.err-data {
58
68
  max-width: 75vw;
59
69
  margin-left: 0 !important;
@@ -6,11 +6,12 @@
6
6
  <th><%= _('Screen') %></th>
7
7
  <th><%= _('Error') %></th>
8
8
  <th><%= _('Data') %></th>
9
+ <th><%= _('Action') %></th>
9
10
  </tr>
10
11
  </thead>
11
12
  </table>
12
13
  <%_ script.create('JQuery')
13
- .useDependencies(['SemanticUI/Loader', 'SemanticUI/Dialog'])
14
+ .useDependencies(['SemanticUI/Loader', 'SemanticUI/Dialog/Confirm'])
14
15
  .add(`
15
16
  $.error = $.loader($('div[data-tab="error"] table'), {
16
17
  url: '${route('Ui', {name: 'error', page: 'PAGE'})}',
@@ -27,23 +28,9 @@ $.error = $.loader($('div[data-tab="error"] table'), {
27
28
  counter.addClass('hidden');
28
29
  }
29
30
  }
30
- $('a.err-img-view').on('click', function(e) {
31
+ $('a.err-clicker').on('click', function(e) {
31
32
  e.preventDefault();
32
- const a = $(this);
33
- const dlg = $.ntdlg.create(
34
- 'err-img-view-dlg',
35
- a.data('tooltip'),
36
- \`<img class="ui fluid image" src="\${a.find('img').attr('src')}" style="max-height: 70vh;">\`, {
37
- size: 'fullscreen',
38
- buttons: {
39
- okay: {
40
- type: 'green approve',
41
- caption: '<i class="check icon"></i>${_('Ok')}',
42
- }
43
- }
44
- }
45
- );
46
- $.ntdlg.show(dlg);
33
+ self.handle($(this));
47
34
  });
48
35
  if (self.loading) {
49
36
  self.loading = false;
@@ -51,20 +38,95 @@ $.error = $.loader($('div[data-tab="error"] table'), {
51
38
  }
52
39
  });
53
40
  $.error.toRow = function(data) {
54
- return $(
55
- \`<tr><td>\${data.nr}</td>
56
- <td>\${this.toImg($.toStr(data.image), data.filename)}</td>
57
- <td>\${$.toStr(data.error)}</td>
58
- <td><div class="ui scrolling container err-data">\${$.hidePayload($.toStr(data.data))}</div></td>
41
+ return $(\`
42
+ <tr><td>\${data.nr}</td>
43
+ <td>\${this.toImg($.toStr(data.image), data.filename)}</td>
44
+ <td>\${this.toPayload(data.error, '${_('Error Message')}')}</td>
45
+ <td>\${this.toPayload(data.data, '${_('Error Data')}')}</td>
46
+ <td>
47
+ <a href="#" class="err-clicker" data-op="delete" data-filename="\${data.filename}" role="button"><i class="trash alternate outline red icon"></i></a>
48
+ </td>
59
49
  </tr>\`);
60
50
  }
61
51
  $.error.toImg = function(data, alt) {
62
52
  if (data) {
63
- return \`<a href="#" class="err-img-view" data-tooltip="\${alt}" data-position="right center">
64
- <img class="ui medium rounded bordered image" src="\${data}" alt="\${alt}">
53
+ return \`
54
+ <a href="#" class="err-clicker" data-op="view" data-title="\${alt}" data-tooltip="\${alt}" data-position="right center">
55
+ <img class="ui medium rounded bordered image" src="\${data}" alt="\${alt}">
56
+ </a>\`;
57
+ }
58
+ }
59
+ $.error.toPayload = function(data, title) {
60
+ if (data) {
61
+ if (typeof data === 'string' && data.startsWith('{')) {
62
+ try {
63
+ data = JSON.parse(data);
64
+ }
65
+ catch (err) {
66
+ }
67
+ }
68
+ const payload = $.toStr(data);
69
+ let excerpt = payload;
70
+ if (excerpt.length > 100) {
71
+ excerpt = excerpt.substr(0, 100);
72
+ if (excerpt.includes('\\n')) {
73
+ excerpt = excerpt.substr(0, excerpt.lastIndexOf('\\n'));
74
+ } else if (excerpt.includes(' ')) {
75
+ excerpt = excerpt.substr(0, excerpt.lastIndexOf(' '));
76
+ } else if (excerpt.includes('-')) {
77
+ excerpt = excerpt.substr(0, excerpt.lastIndexOf('-'));
78
+ }
79
+ excerpt += '&hellip;';
80
+ }
81
+ return \`
82
+ <a href="#" class="err-clicker" data-op="view" data-title="\${title}">
83
+ <span>\${excerpt}</span>
84
+ <pre style="display: none;">\${payload}</pre>
65
85
  </a>\`;
66
86
  }
67
87
  }
88
+ $.error.handle = function(el) {
89
+ switch (el.data('op')) {
90
+ case 'view':
91
+ let content, size = 'large';
92
+ const img = el.find('img'), pre = el.find('pre');
93
+ if (img.length) {
94
+ content = \`<img class="ui fluid image" src="\${img.attr('src')}" style="max-height: 70vh;">\`;
95
+ size = 'fullscreen';
96
+ }
97
+ if (pre.length) {
98
+ content = \`<div class="ui fluid scrolling container"><pre>\${pre.text()}</pre></div>\`;
99
+ }
100
+ const dlg = $.ntdlg.create('err-view-dlg', el.data('title'), content, {
101
+ size,
102
+ buttons: {
103
+ okay: {
104
+ type: 'green approve',
105
+ caption: '<i class="check icon"></i>${_('Ok')}',
106
+ }
107
+ }
108
+ });
109
+ $.ntdlg.show(dlg);
110
+ break;
111
+ case 'delete':
112
+ $.ntdlg.confirm(
113
+ 'err-delete-confirm-dlg',
114
+ '${_('Confirm')}',
115
+ '${_('Are you sure want to remove error <code>%ERR%</code>?')}'.replace(/%ERR%/g, el.data('filename')),
116
+ $.ntdlg.ICON_QUESTION,
117
+ function() {
118
+ $.post('${route('Ui', {name: 'task', op: 'remove'})}', {error: el.data('filename')})
119
+ .done(function(json) {
120
+ $.tasks.notify(json);
121
+ if (json.success) {
122
+ self.reload();
123
+ }
124
+ });
125
+ }
126
+ );
127
+ break;
128
+ }
129
+ }
68
130
  $.error.reload = function() {
69
131
  const self = this;
70
132
  if (!self.loading) {
@@ -36,20 +36,20 @@ $.queue = $.loader($('div[data-tab="queue"] table'), {
36
36
  }
37
37
  });
38
38
  $.queue.toRow = function(data) {
39
- return $(
40
- \`<tr><td>\${data.nr}</td>
41
- <td>\${$.toStr(data.id)}</td>
42
- <td>\${$.toStr(data.type)}</td>
43
- <td><div class="ui scrolling container queue-name">\${$.hidePayload($.toStr(data.name))}</div></td>
44
- <td>\${this.toStatus(data.status)}</td>
45
- <td><div class="ui scrolling container queue-result">\${$.hidePayload($.toStr(data.result))}</div></td>
46
- <td>\${$.toStr(data.time)}</td>
39
+ return $(\`
40
+ <tr><td>\${data.nr}</td>
41
+ <td>\${$.toStr(data.id)}</td>
42
+ <td>\${$.toStr(data.type)}</td>
43
+ <td><div class="ui scrolling container queue-name">\${$.hidePayload($.toStr(data.name))}</div></td>
44
+ <td>\${this.toStatus(data.status)}</td>
45
+ <td><div class="ui scrolling container queue-result">\${$.hidePayload($.toStr(data.result))}</div></td>
46
+ <td>\${$.toStr(data.time)}</td>
47
47
  </tr>\`);
48
48
  }
49
49
  $.queue.toStatus = function(data) {
50
50
  const icon = {
51
51
  new: 'pause circle outline',
52
- processing: 'spinner',
52
+ processing: 'loading spinner',
53
53
  done: 'green check',
54
54
  error: 'red times',
55
55
  timeout: 'clock outline',
package/views/ui/util.ejs CHANGED
@@ -47,12 +47,12 @@ $.hidePayload = function(message) {
47
47
  }
48
48
  return message;
49
49
  }
50
+ $.isPayload = function(data) {
51
+ return Array.isArray(data) || typeof data === 'object' && data.constructor.name === 'Object';
52
+ }
50
53
  $.toStr = function(o) {
51
- if (
52
- Array.isArray(o) ||
53
- typeof o === 'object' && o.constructor.name === 'Object'
54
- ) {
55
- return JSON.stringify(o);
54
+ if ($.isPayload(o)) {
55
+ return JSON.stringify(o, null, ' ');
56
56
  } else if (o !== undefined && o !== null) {
57
57
  return o.toString();
58
58
  }