goblin-desktop 2.1.2 → 2.1.3

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.
Files changed (143) hide show
  1. package/.editorconfig +9 -9
  2. package/.eslintrc.js +28 -28
  3. package/.zou-flow +3 -3
  4. package/README.md +108 -108
  5. package/builders/builders.js +3 -3
  6. package/builders/wizard.js +457 -457
  7. package/contexts.js +13 -13
  8. package/desktop-manager.js +10 -10
  9. package/desktop-window.js +13 -13
  10. package/desktop.js +13 -13
  11. package/lib/service.js +137 -137
  12. package/package.json +36 -36
  13. package/password-wizard.js +13 -13
  14. package/quest-run-wizard.js +13 -13
  15. package/taskbar.js +13 -13
  16. package/widgets/audio/sfx.js +177 -177
  17. package/widgets/board/view.js +37 -37
  18. package/widgets/board/widget.js +65 -65
  19. package/widgets/contexts/logic-handlers.js +36 -36
  20. package/widgets/contexts/service.js +40 -40
  21. package/widgets/contexts/view.js +22 -22
  22. package/widgets/contexts/widget.js +147 -147
  23. package/widgets/datagrid/datagrid-entity.js +82 -82
  24. package/widgets/datagrid/datagrid-headers.js +272 -272
  25. package/widgets/datagrid/styles.js +13 -13
  26. package/widgets/datagrid/widget.js +192 -192
  27. package/widgets/datagrid-cell/styles.js +52 -52
  28. package/widgets/datagrid-cell/widget.js +41 -41
  29. package/widgets/datagrid-item/styles.js +15 -15
  30. package/widgets/datagrid-item/widget.js +74 -74
  31. package/widgets/default/view.js +142 -142
  32. package/widgets/desktop/compensator.js +9 -9
  33. package/widgets/desktop/logic-handlers.js +237 -237
  34. package/widgets/desktop/reducer.js +35 -35
  35. package/widgets/desktop/service.js +828 -828
  36. package/widgets/desktop/styles.js +28 -28
  37. package/widgets/desktop/widget.js +175 -175
  38. package/widgets/desktop-clock/styles.js +69 -69
  39. package/widgets/desktop-clock/widget.js +387 -387
  40. package/widgets/desktop-clock-clock/styles.js +56 -56
  41. package/widgets/desktop-clock-clock/widget.js +96 -96
  42. package/widgets/desktop-clock-menu/styles.js +129 -129
  43. package/widgets/desktop-clock-menu/widget.js +63 -63
  44. package/widgets/desktop-connection-status/reducer.js +15 -15
  45. package/widgets/desktop-connection-status/styles.js +44 -44
  46. package/widgets/desktop-connection-status/widget.js +129 -129
  47. package/widgets/desktop-content/widget.js +68 -68
  48. package/widgets/desktop-footer/reducer.js +31 -31
  49. package/widgets/desktop-footer/styles.js +36 -36
  50. package/widgets/desktop-footer/widget.js +52 -52
  51. package/widgets/desktop-monitors/styles.js +155 -155
  52. package/widgets/desktop-monitors/widget.js +272 -272
  53. package/widgets/desktop-notebook/styles.js +155 -155
  54. package/widgets/desktop-notebook/widget.js +252 -252
  55. package/widgets/desktop-notifications/styles.js +147 -147
  56. package/widgets/desktop-notifications/widget.js +231 -231
  57. package/widgets/desktop-scale/reducer.js +15 -15
  58. package/widgets/desktop-scale/styles.js +48 -48
  59. package/widgets/desktop-scale/widget.js +172 -172
  60. package/widgets/desktop-state-monitor/styles.js +72 -72
  61. package/widgets/desktop-state-monitor/widget.js +123 -123
  62. package/widgets/desktop-taskbar/widget.js +57 -57
  63. package/widgets/desktop-themes-menu/widget.js +121 -121
  64. package/widgets/desktop-topbar/widget.js +201 -201
  65. package/widgets/desktop-window/service.js +56 -56
  66. package/widgets/desktop-window/styles.js +22 -22
  67. package/widgets/desktop-window/widget.js +70 -70
  68. package/widgets/detail/compensator.js +17 -17
  69. package/widgets/detail/view.js +40 -40
  70. package/widgets/detail/widget.js +125 -125
  71. package/widgets/editor/widget.js +83 -83
  72. package/widgets/entity-alerts/styles.js +77 -77
  73. package/widgets/entity-alerts/widget.js +328 -328
  74. package/widgets/entity-list/styles.js +66 -66
  75. package/widgets/entity-list/view.js +36 -36
  76. package/widgets/entity-list/widget.js +209 -209
  77. package/widgets/entity-list-item/widget.js +68 -68
  78. package/widgets/entity-row/styles.js +105 -105
  79. package/widgets/entity-row/widget.js +524 -524
  80. package/widgets/entity-row-button/styles.js +46 -46
  81. package/widgets/entity-row-button/widget.js +57 -57
  82. package/widgets/entity-view/reducer.js +20 -20
  83. package/widgets/entity-view/styles.js +90 -90
  84. package/widgets/entity-view/widget.js +516 -516
  85. package/widgets/facet-checkbox/styles.js +17 -17
  86. package/widgets/facet-checkbox/widget.js +43 -43
  87. package/widgets/facet-filter/widget.js +94 -94
  88. package/widgets/facet-filter-add/styles.js +30 -30
  89. package/widgets/facet-filter-add/widget.js +105 -105
  90. package/widgets/facet-filter-button/styles.js +74 -74
  91. package/widgets/facet-filter-button/widget.js +214 -214
  92. package/widgets/facet-filter-list-dialog/styles.js +59 -59
  93. package/widgets/facet-filter-list-dialog/widget.js +253 -253
  94. package/widgets/facet-filter-list-dialog-footer/styles.js +22 -22
  95. package/widgets/facet-filter-list-dialog-footer/widget.js +105 -105
  96. package/widgets/facet-filter-range-dialog/styles.js +82 -82
  97. package/widgets/facet-filter-range-dialog/widget.js +399 -399
  98. package/widgets/facet-filter-range-dialog-footer/styles.js +22 -22
  99. package/widgets/facet-filter-range-dialog-footer/widget.js +182 -182
  100. package/widgets/gamepad/widget.js +75 -75
  101. package/widgets/helpers/facet-helpers.js +105 -105
  102. package/widgets/hinter/reducer.js +35 -35
  103. package/widgets/hinter/styles.js +79 -79
  104. package/widgets/hinter/view.js +31 -31
  105. package/widgets/hinter/widget.js +291 -291
  106. package/widgets/junction/styles.js +22 -22
  107. package/widgets/junction/widget.js +50 -50
  108. package/widgets/main-tab-menu/styles.js +17 -17
  109. package/widgets/main-tab-menu/widget.js +136 -136
  110. package/widgets/map/view.js +49 -49
  111. package/widgets/map/widget.js +65 -65
  112. package/widgets/monitor/reducer.js +15 -15
  113. package/widgets/monitor/widget.js +66 -66
  114. package/widgets/navigating-layer/widget.js +25 -25
  115. package/widgets/notifications-button/widget.js +44 -44
  116. package/widgets/password-wizard/service.js +53 -53
  117. package/widgets/password-wizard/ui.js +66 -66
  118. package/widgets/plugin/reducer.js +19 -19
  119. package/widgets/plugin/styles.js +294 -294
  120. package/widgets/plugin/widget.js +638 -637
  121. package/widgets/quest-run-wizard/service.js +49 -49
  122. package/widgets/quest-run-wizard/ui.js +25 -25
  123. package/widgets/search/styles.js +80 -80
  124. package/widgets/search/widget.js +285 -285
  125. package/widgets/simple/view.js +29 -29
  126. package/widgets/status-filters/widget.js +121 -121
  127. package/widgets/tab/styles.js +16 -16
  128. package/widgets/tab/widget.js +89 -89
  129. package/widgets/tab-content/widget.js +35 -35
  130. package/widgets/tabs/widget.js +48 -48
  131. package/widgets/taskbar/service.js +99 -99
  132. package/widgets/taskbar/view.js +24 -24
  133. package/widgets/taskbar/widget.js +167 -167
  134. package/widgets/widget-doc-caller/reducer.js +15 -15
  135. package/widgets/widget-doc-caller/styles.js +20 -20
  136. package/widgets/widget-doc-caller/widget.js +55 -55
  137. package/widgets/wizard/widget.js +299 -299
  138. package/widgets/wizard-buttons/widget.js +111 -111
  139. package/widgets/workitem/styles.js +281 -281
  140. package/widgets/workitem/view.js +62 -62
  141. package/widgets/workitem/widget.js +972 -972
  142. package/widgets/workitem-dialog/widget.js +86 -86
  143. package/widgets/workitem-fields/widget.js +63 -63
@@ -1,516 +1,516 @@
1
- //T:2019-02-27
2
-
3
- import React from 'react';
4
- import Widget from 'goblin-laboratory/widgets/widget';
5
- import throttle from 'lodash/throttle';
6
- import List from 'goblin-gadgets/widgets/list/widget';
7
- import TableCell from 'goblin-gadgets/widgets/table-cell/widget';
8
- import TableHeaderDragManager from 'goblin-gadgets/widgets/table-header-drag-manager/widget';
9
- import EntityListItem from 'goblin-desktop/widgets/entity-list-item/widget';
10
- import Shredder from 'xcraft-core-shredder';
11
- import Button from 'goblin-gadgets/widgets/button/widget';
12
- import T from 't';
13
- import MouseTrap from 'mousetrap';
14
- import {Unit} from 'goblin-theme';
15
- import ListHelpers from 'goblin-workshop/lib/list-helpers.js';
16
-
17
- /******************************************************************************/
18
-
19
- class EntityView extends Widget {
20
- constructor() {
21
- super(...arguments);
22
-
23
- this.state = {
24
- variant: 'bar',
25
- };
26
-
27
- this._entityIds = [];
28
-
29
- this._drillDownInternal = this._drillDownInternal.bind(this);
30
- this._drillDown = throttle(this._drillDownInternal, 100).bind(this);
31
- this.drillDown = this.drillDown.bind(this);
32
- this.selectRow = this.selectRow.bind(this);
33
- this.editRow = this.editRow.bind(this);
34
- this.onEditColumns = this.onEditColumns.bind(this);
35
- this.onSortColumn = this.onSortColumn.bind(this);
36
- this.onWidthChanged = this.onWidthChanged.bind(this);
37
- this.onColumnMoved = this.onColumnMoved.bind(this);
38
- this.onKeyUp = this.onKeyUp.bind(this);
39
- this.onKeyDown = this.onKeyDown.bind(this);
40
- this.onKeyValidate = this.onKeyValidate.bind(this);
41
- this._setDetail = this._setDetail.bind(this);
42
- this.setDetail = throttle(this._setDetail, 1200);
43
- }
44
-
45
- //#region get/set
46
- get variant() {
47
- return this.state.variant;
48
- }
49
-
50
- set variant(value) {
51
- this.setState({
52
- variant: value,
53
- });
54
- }
55
- //#endregion
56
-
57
- componentDidMount() {
58
- MouseTrap.bind('up', this.onKeyUp, 'keydown');
59
- MouseTrap.bind('down', this.onKeyDown, 'keydown');
60
- MouseTrap.bind('return', this.onKeyValidate);
61
- }
62
-
63
- componentWillUnmount() {
64
- super.componentWillUnmount();
65
- MouseTrap.unbind('up');
66
- MouseTrap.unbind('down');
67
- MouseTrap.unbind('return');
68
- }
69
-
70
- get firstColumnWidth() {
71
- if (this.props.settings) {
72
- const userWidth = this.props.settings.get('widths.id@first-column', null);
73
- if (userWidth) {
74
- return userWidth;
75
- }
76
- }
77
-
78
- return '50px';
79
- }
80
-
81
- getEstimatedWidth(columns) {
82
- let width = ListHelpers.getEstimatedWidth(columns, this.props.settings);
83
-
84
- // Add left and right margins of rows.
85
- width = Unit.add(width, '40px');
86
-
87
- // Add width of first column (and his right margin).
88
- width = Unit.add(width, this.firstColumnWidth);
89
- width = Unit.add(width, '10px');
90
-
91
- // Add right margin after each column.
92
- width = Unit.add(width, Unit.multiply('10px', columns.length));
93
-
94
- return width;
95
- }
96
-
97
- get sorting() {
98
- if (this.props.settings) {
99
- const sorting = this.props.settings.get('sorting', null);
100
- if (sorting) {
101
- return sorting.toJS();
102
- }
103
- }
104
-
105
- return {
106
- columnId: this.props.columnIds.get(0),
107
- direction: 'asc',
108
- };
109
- }
110
-
111
- get filterPaths() {
112
- // TODO...
113
- return ['meta.summaries.description', 'meta.summaries.info'];
114
- }
115
-
116
- getEntityId(rowId) {
117
- const state = new Shredder(this.getState().backend);
118
- return state.get(`list@${this.props.id}.list.${rowId}-item`);
119
- }
120
-
121
- getEntityCount() {
122
- const state = new Shredder(this.getState().backend);
123
- return state.get(`list@${this.props.id}.count`);
124
- }
125
-
126
- getSelectedRowId() {
127
- const state = new Shredder(this.getState().widgets);
128
- return state.get(`${this.props.id}.selectedRowId`);
129
- }
130
-
131
- editRow(rowId, navigate) {
132
- const entityId = this.getEntityId(rowId);
133
- this.doFor(this.props.id, 'open-entity-workitem', {
134
- entityId,
135
- navigate,
136
- });
137
- }
138
-
139
- _setDetail(entityId) {
140
- this.doFor(this.props.id, 'setDetail', {
141
- entityId,
142
- });
143
- }
144
-
145
- selectRow(rowId) {
146
- if (rowId < 0 || rowId >= this.getEntityCount()) {
147
- return;
148
- }
149
- const entityId = this.getEntityId(rowId);
150
- this.dispatch({type: 'select-row', rowId, entityId});
151
- if (entityId && this.props.hinter) {
152
- this.setDetail(entityId);
153
- }
154
- }
155
-
156
- onKeyUp() {
157
- let rowId = parseInt(this.getSelectedRowId());
158
- if (isNaN(rowId)) {
159
- rowId = 1;
160
- }
161
- this.selectRow(rowId - 1);
162
- }
163
-
164
- onKeyDown() {
165
- let rowId = parseInt(this.getSelectedRowId());
166
- if (isNaN(rowId)) {
167
- rowId = -1;
168
- }
169
- this.selectRow(rowId + 1);
170
- }
171
-
172
- onKeyValidate() {
173
- const rowId = parseInt(this.getSelectedRowId());
174
- if (isNaN(rowId)) {
175
- return;
176
- }
177
- this.editRow(rowId);
178
- }
179
-
180
- onEditColumns() {
181
- this.doFor(this.props.id, 'open-entity-workitem', {
182
- entityId: `view@${this.props.type}`,
183
- });
184
- }
185
-
186
- _drillDownInternal() {
187
- let view = null;
188
- if (this.props.view) {
189
- if (this.props.view.toJS) {
190
- view = {view: this.props.view.toJS()};
191
- } else {
192
- view = {view: this.props.view};
193
- }
194
- }
195
- this.doFor(this.props.id, 'drill-down', {
196
- entityIds: this._entityIds,
197
- ...view,
198
- });
199
- this._entityIds = [];
200
- }
201
-
202
- drillDown(entityId) {
203
- this._entityIds.push(entityId);
204
- this._drillDown();
205
- }
206
-
207
- static get wiring() {
208
- return {
209
- id: 'id',
210
- type: 'type',
211
- };
212
- }
213
-
214
- onSortColumn(index, columns) {
215
- if (this.props.hasFilter || index === 0) {
216
- return;
217
- }
218
-
219
- const columnId = this.props.columnIds.get(index - 1);
220
- const sorting = this.sorting;
221
- if (sorting.columnId === columnId) {
222
- sorting.direction = sorting.direction === 'asc' ? 'desc' : 'asc';
223
- } else {
224
- sorting.columnId = columnId;
225
- sorting.direction = 'asc';
226
- }
227
-
228
- this.setUserSettings('set-view-column-sorting', {
229
- viewId: `view@${this.props.type}`,
230
- columnId: sorting.columnId,
231
- direction: sorting.direction,
232
- });
233
-
234
- const cell = columns[index - 1];
235
- const path = ListHelpers.getColumnPath(cell);
236
-
237
- this.doFor(this.props.id, 'sort-list', {
238
- key: path,
239
- dir: sorting.direction,
240
- });
241
- }
242
-
243
- onWidthChanged(index, width) {
244
- console.log(`onWidthChanged index=${index} width=${width}`);
245
-
246
- if (index === 0) {
247
- this.setUserSettings('set-view-column-width', {
248
- viewId: `view@${this.props.type}`,
249
- columnId: 'id@first-column',
250
- width,
251
- });
252
- } else {
253
- index--;
254
- const columnId = this.props.columnIds.get(index);
255
- this.setUserSettings('set-view-column-width', {
256
- viewId: `view@${this.props.type}`,
257
- columnId,
258
- width,
259
- });
260
- }
261
- }
262
-
263
- onColumnMoved(indexSrc, indexDst) {
264
- console.log(`onColumnMoved indexSrc=${indexSrc} indexDst=${indexDst}`);
265
- indexSrc--;
266
- indexDst--;
267
-
268
- if (indexDst > indexSrc) {
269
- indexDst--; // if moved from left to right, skip the initial column (indexSrc).
270
- }
271
-
272
- const c = this.props.columnIds.valueSeq().toArray();
273
- const srcId = c[indexSrc];
274
- c.splice(indexSrc, 1); // Firstly, remove the column at initial position.
275
- c.splice(indexDst, 0, srcId); // Secondly, insert the column at new position.
276
-
277
- this.setUserSettings('set-view-columns-order', {
278
- viewId: `view@${this.props.type}`,
279
- columnIds: c,
280
- });
281
- }
282
-
283
- /******************************************************************************/
284
-
285
- renderHeaderCell(cell, index) {
286
- let text = ListHelpers.getColumnHeaderText(cell);
287
- const columnId = this.props.columnIds.get(index);
288
- const sorting = this.sorting;
289
- if (sorting.columnId === columnId && !this.props.hasFilter) {
290
- const glyph =
291
- sorting.direction === 'asc' ? 'solid/caret-down' : 'solid/caret-up';
292
- text = new Shredder({text, glyph});
293
- }
294
-
295
- return (
296
- <TableCell
297
- key={index}
298
- isLast={false}
299
- isHeader={true}
300
- verticalAlign="center"
301
- {...ListHelpers.getColumnProps(cell, this.props.settings)}
302
- text={text}
303
- />
304
- );
305
- }
306
-
307
- renderHeader(columns) {
308
- const columnsData = [];
309
- let index = 0;
310
- columnsData.push({index: index++, width: this.firstColumnWidth});
311
- for (const column of columns) {
312
- const props = ListHelpers.getColumnProps(column, this.props.settings);
313
- columnsData.push({index: index++, width: props.width});
314
- }
315
-
316
- return (
317
- <div
318
- className={
319
- this.props.hasFilter
320
- ? this.styles.classNames.headerFilter
321
- : this.styles.classNames.header
322
- }
323
- >
324
- <TableCell
325
- isLast={false}
326
- isHeader={true}
327
- verticalAlign="center"
328
- width={this.firstColumnWidth}
329
- text={T('N°')}
330
- />
331
- {columns.map((c, i) => this.renderHeaderCell(c, i))}
332
- <TableHeaderDragManager
333
- height="44px"
334
- marginLeft="20px"
335
- columns={columnsData}
336
- fixedColumns={[0]}
337
- widthChanged={(index, width) => this.onWidthChanged(index, width)}
338
- columnMoved={(src, dst) => this.onColumnMoved(src, dst)}
339
- columnClicked={(index) => this.onSortColumn(index, columns)}
340
- />
341
- </div>
342
- );
343
- }
344
-
345
- renderRows(columns) {
346
- const listId = `list@${this.props.id}`;
347
-
348
- return (
349
- <div className={this.styles.classNames.rows}>
350
- <List
351
- id={listId}
352
- type={'variable'}
353
- renderItem={EntityListItem}
354
- data={{
355
- firstColumnWidth: this.firstColumnWidth,
356
- filterPaths: this.filterPaths,
357
- hasFilter: this.props.hasFilter,
358
- onDrillDown: this.drillDown,
359
- onRenewTTL: this.renewTTL,
360
- columns: columns,
361
- settings: this.props.settings,
362
- onSelect: this.selectRow,
363
- onEdit: this.editRow,
364
- useView: this.props.view ? true : false,
365
- serviceId: this.props.id,
366
- variant: this.variant,
367
- schema: this.getSchema(this.props.type)
368
- }}
369
- />
370
- </div>
371
- );
372
- }
373
-
374
- renderButton() {
375
- if (!this.props.prototypeMode) {
376
- return null;
377
- }
378
-
379
- return (
380
- <div className={this.styles.classNames.button}>
381
- <Button
382
- width="30px"
383
- height="30px"
384
- glyph="solid/columns"
385
- tooltip={T('Choisir les colonnes')}
386
- onClick={this.onEditColumns}
387
- />
388
- </div>
389
- );
390
- }
391
-
392
- renderVariants() {
393
- if (!this.props.prototypeMode) {
394
- return null;
395
- }
396
-
397
- return (
398
- <div className={this.styles.classNames.variants}>
399
- <Button
400
- width="28px"
401
- height="20px"
402
- fontSize="75%"
403
- text="J"
404
- tooltip={T('Jauge verticale')}
405
- horizontalSpacing="overlap"
406
- active={this.variant === 'gauge'}
407
- onClick={() => (this.variant = 'gauge')}
408
- />
409
- <Button
410
- width="28px"
411
- height="20px"
412
- fontSize="75%"
413
- text="B"
414
- tooltip={T('Barre verticale')}
415
- horizontalSpacing="overlap"
416
- active={this.variant === 'bar'}
417
- onClick={() => (this.variant = 'bar')}
418
- />
419
- <Button
420
- width="28px"
421
- height="20px"
422
- fontSize="75%"
423
- text="C"
424
- tooltip={T('Carnaval')}
425
- horizontalSpacing="overlap"
426
- active={this.variant === 'carnaval'}
427
- onClick={() => (this.variant = 'carnaval')}
428
- />
429
- </div>
430
- );
431
- }
432
-
433
- render() {
434
- const {id, columnIds, isBad, type} = this.props;
435
- if (!id || !columnIds) {
436
- return null;
437
- }
438
-
439
- if (isBad) {
440
- this.setUserSettings('reset-view-column', {
441
- viewId: `view@${type}`,
442
- });
443
- return null;
444
- }
445
-
446
- return this.buildCollectionLoader(
447
- columnIds.valueSeq().toArray(),
448
- ({collection}) => {
449
- const columns = collection;
450
- const width = this.getEstimatedWidth(columns);
451
- const widthStyle = {
452
- minWidth: width,
453
- };
454
-
455
- return (
456
- <div className={this.styles.classNames.entityView}>
457
- <div className={this.styles.classNames.list}>
458
- <div
459
- className={this.styles.classNames.content}
460
- style={widthStyle}
461
- >
462
- {this.renderHeader(columns)}
463
- {this.renderRows(columns)}
464
- </div>
465
- </div>
466
- {this.renderButton(columns)}
467
- {this.renderVariants(columns)}
468
- </div>
469
- );
470
- },
471
- null
472
- );
473
- }
474
- }
475
-
476
- /******************************************************************************/
477
-
478
- const ConnectedEntityView = Widget.connect((state, props) => {
479
- if (!props.type) {
480
- return {};
481
- }
482
-
483
- const hasFilter = !!state.get(`widgets.${props.id}.value`, null);
484
-
485
- const view = state.get(`backend.view@${props.type}`);
486
- let columnIds = view.get('columns');
487
-
488
- const clientSessionId = state.get(`backend.${window.labId}.clientSessionId`);
489
- const userView = state.get(
490
- `backend.${clientSessionId}.views.view@${props.type}`
491
- );
492
- let isBad = false;
493
- if (userView) {
494
- const order = userView.get('order');
495
- if (order.size > 0) {
496
- isBad = order.some((id) => !columnIds.includes(id));
497
- if (!isBad) {
498
- columnIds = order;
499
- }
500
- }
501
- }
502
-
503
- const userSession = Widget.getUserSession(state);
504
- const prototypeMode = userSession.get('prototypeMode');
505
-
506
- return {
507
- isBad,
508
- hasFilter,
509
- columnIds,
510
- view: view.get('query'),
511
- settings: userView,
512
- prototypeMode,
513
- };
514
- })(EntityView);
515
-
516
- export default Widget.Wired(ConnectedEntityView)();
1
+ //T:2019-02-27
2
+
3
+ import React from 'react';
4
+ import Widget from 'goblin-laboratory/widgets/widget';
5
+ import throttle from 'lodash/throttle';
6
+ import List from 'goblin-gadgets/widgets/list/widget';
7
+ import TableCell from 'goblin-gadgets/widgets/table-cell/widget';
8
+ import TableHeaderDragManager from 'goblin-gadgets/widgets/table-header-drag-manager/widget';
9
+ import EntityListItem from 'goblin-desktop/widgets/entity-list-item/widget';
10
+ import Shredder from 'xcraft-core-shredder';
11
+ import Button from 'goblin-gadgets/widgets/button/widget';
12
+ import T from 't';
13
+ import MouseTrap from 'mousetrap';
14
+ import {Unit} from 'goblin-theme';
15
+ import ListHelpers from 'goblin-workshop/lib/list-helpers.js';
16
+
17
+ /******************************************************************************/
18
+
19
+ class EntityView extends Widget {
20
+ constructor() {
21
+ super(...arguments);
22
+
23
+ this.state = {
24
+ variant: 'bar',
25
+ };
26
+
27
+ this._entityIds = [];
28
+
29
+ this._drillDownInternal = this._drillDownInternal.bind(this);
30
+ this._drillDown = throttle(this._drillDownInternal, 100).bind(this);
31
+ this.drillDown = this.drillDown.bind(this);
32
+ this.selectRow = this.selectRow.bind(this);
33
+ this.editRow = this.editRow.bind(this);
34
+ this.onEditColumns = this.onEditColumns.bind(this);
35
+ this.onSortColumn = this.onSortColumn.bind(this);
36
+ this.onWidthChanged = this.onWidthChanged.bind(this);
37
+ this.onColumnMoved = this.onColumnMoved.bind(this);
38
+ this.onKeyUp = this.onKeyUp.bind(this);
39
+ this.onKeyDown = this.onKeyDown.bind(this);
40
+ this.onKeyValidate = this.onKeyValidate.bind(this);
41
+ this._setDetail = this._setDetail.bind(this);
42
+ this.setDetail = throttle(this._setDetail, 1200);
43
+ }
44
+
45
+ //#region get/set
46
+ get variant() {
47
+ return this.state.variant;
48
+ }
49
+
50
+ set variant(value) {
51
+ this.setState({
52
+ variant: value,
53
+ });
54
+ }
55
+ //#endregion
56
+
57
+ componentDidMount() {
58
+ MouseTrap.bind('up', this.onKeyUp, 'keydown');
59
+ MouseTrap.bind('down', this.onKeyDown, 'keydown');
60
+ MouseTrap.bind('return', this.onKeyValidate);
61
+ }
62
+
63
+ componentWillUnmount() {
64
+ super.componentWillUnmount();
65
+ MouseTrap.unbind('up');
66
+ MouseTrap.unbind('down');
67
+ MouseTrap.unbind('return');
68
+ }
69
+
70
+ get firstColumnWidth() {
71
+ if (this.props.settings) {
72
+ const userWidth = this.props.settings.get('widths.id@first-column', null);
73
+ if (userWidth) {
74
+ return userWidth;
75
+ }
76
+ }
77
+
78
+ return '50px';
79
+ }
80
+
81
+ getEstimatedWidth(columns) {
82
+ let width = ListHelpers.getEstimatedWidth(columns, this.props.settings);
83
+
84
+ // Add left and right margins of rows.
85
+ width = Unit.add(width, '40px');
86
+
87
+ // Add width of first column (and his right margin).
88
+ width = Unit.add(width, this.firstColumnWidth);
89
+ width = Unit.add(width, '10px');
90
+
91
+ // Add right margin after each column.
92
+ width = Unit.add(width, Unit.multiply('10px', columns.length));
93
+
94
+ return width;
95
+ }
96
+
97
+ get sorting() {
98
+ if (this.props.settings) {
99
+ const sorting = this.props.settings.get('sorting', null);
100
+ if (sorting) {
101
+ return sorting.toJS();
102
+ }
103
+ }
104
+
105
+ return {
106
+ columnId: this.props.columnIds.get(0),
107
+ direction: 'asc',
108
+ };
109
+ }
110
+
111
+ get filterPaths() {
112
+ // TODO...
113
+ return ['meta.summaries.description', 'meta.summaries.info'];
114
+ }
115
+
116
+ getEntityId(rowId) {
117
+ const state = new Shredder(this.getState().backend);
118
+ return state.get(`list@${this.props.id}.list.${rowId}-item`);
119
+ }
120
+
121
+ getEntityCount() {
122
+ const state = new Shredder(this.getState().backend);
123
+ return state.get(`list@${this.props.id}.count`);
124
+ }
125
+
126
+ getSelectedRowId() {
127
+ const state = new Shredder(this.getState().widgets);
128
+ return state.get(`${this.props.id}.selectedRowId`);
129
+ }
130
+
131
+ editRow(rowId, navigate) {
132
+ const entityId = this.getEntityId(rowId);
133
+ this.doFor(this.props.id, 'open-entity-workitem', {
134
+ entityId,
135
+ navigate,
136
+ });
137
+ }
138
+
139
+ _setDetail(entityId) {
140
+ this.doFor(this.props.id, 'setDetail', {
141
+ entityId,
142
+ });
143
+ }
144
+
145
+ selectRow(rowId) {
146
+ if (rowId < 0 || rowId >= this.getEntityCount()) {
147
+ return;
148
+ }
149
+ const entityId = this.getEntityId(rowId);
150
+ this.dispatch({type: 'select-row', rowId, entityId});
151
+ if (entityId && this.props.hinter) {
152
+ this.setDetail(entityId);
153
+ }
154
+ }
155
+
156
+ onKeyUp() {
157
+ let rowId = parseInt(this.getSelectedRowId());
158
+ if (isNaN(rowId)) {
159
+ rowId = 1;
160
+ }
161
+ this.selectRow(rowId - 1);
162
+ }
163
+
164
+ onKeyDown() {
165
+ let rowId = parseInt(this.getSelectedRowId());
166
+ if (isNaN(rowId)) {
167
+ rowId = -1;
168
+ }
169
+ this.selectRow(rowId + 1);
170
+ }
171
+
172
+ onKeyValidate() {
173
+ const rowId = parseInt(this.getSelectedRowId());
174
+ if (isNaN(rowId)) {
175
+ return;
176
+ }
177
+ this.editRow(rowId);
178
+ }
179
+
180
+ onEditColumns() {
181
+ this.doFor(this.props.id, 'open-entity-workitem', {
182
+ entityId: `view@${this.props.type}`,
183
+ });
184
+ }
185
+
186
+ _drillDownInternal() {
187
+ let view = null;
188
+ if (this.props.view) {
189
+ if (this.props.view.toJS) {
190
+ view = {view: this.props.view.toJS()};
191
+ } else {
192
+ view = {view: this.props.view};
193
+ }
194
+ }
195
+ this.doFor(this.props.id, 'drill-down', {
196
+ entityIds: this._entityIds,
197
+ ...view,
198
+ });
199
+ this._entityIds = [];
200
+ }
201
+
202
+ drillDown(entityId) {
203
+ this._entityIds.push(entityId);
204
+ this._drillDown();
205
+ }
206
+
207
+ static get wiring() {
208
+ return {
209
+ id: 'id',
210
+ type: 'type',
211
+ };
212
+ }
213
+
214
+ onSortColumn(index, columns) {
215
+ if (this.props.hasFilter || index === 0) {
216
+ return;
217
+ }
218
+
219
+ const columnId = this.props.columnIds.get(index - 1);
220
+ const sorting = this.sorting;
221
+ if (sorting.columnId === columnId) {
222
+ sorting.direction = sorting.direction === 'asc' ? 'desc' : 'asc';
223
+ } else {
224
+ sorting.columnId = columnId;
225
+ sorting.direction = 'asc';
226
+ }
227
+
228
+ this.setUserSettings('set-view-column-sorting', {
229
+ viewId: `view@${this.props.type}`,
230
+ columnId: sorting.columnId,
231
+ direction: sorting.direction,
232
+ });
233
+
234
+ const cell = columns[index - 1];
235
+ const path = ListHelpers.getColumnPath(cell);
236
+
237
+ this.doFor(this.props.id, 'sort-list', {
238
+ key: path,
239
+ dir: sorting.direction,
240
+ });
241
+ }
242
+
243
+ onWidthChanged(index, width) {
244
+ console.log(`onWidthChanged index=${index} width=${width}`);
245
+
246
+ if (index === 0) {
247
+ this.setUserSettings('set-view-column-width', {
248
+ viewId: `view@${this.props.type}`,
249
+ columnId: 'id@first-column',
250
+ width,
251
+ });
252
+ } else {
253
+ index--;
254
+ const columnId = this.props.columnIds.get(index);
255
+ this.setUserSettings('set-view-column-width', {
256
+ viewId: `view@${this.props.type}`,
257
+ columnId,
258
+ width,
259
+ });
260
+ }
261
+ }
262
+
263
+ onColumnMoved(indexSrc, indexDst) {
264
+ console.log(`onColumnMoved indexSrc=${indexSrc} indexDst=${indexDst}`);
265
+ indexSrc--;
266
+ indexDst--;
267
+
268
+ if (indexDst > indexSrc) {
269
+ indexDst--; // if moved from left to right, skip the initial column (indexSrc).
270
+ }
271
+
272
+ const c = this.props.columnIds.valueSeq().toArray();
273
+ const srcId = c[indexSrc];
274
+ c.splice(indexSrc, 1); // Firstly, remove the column at initial position.
275
+ c.splice(indexDst, 0, srcId); // Secondly, insert the column at new position.
276
+
277
+ this.setUserSettings('set-view-columns-order', {
278
+ viewId: `view@${this.props.type}`,
279
+ columnIds: c,
280
+ });
281
+ }
282
+
283
+ /******************************************************************************/
284
+
285
+ renderHeaderCell(cell, index) {
286
+ let text = ListHelpers.getColumnHeaderText(cell);
287
+ const columnId = this.props.columnIds.get(index);
288
+ const sorting = this.sorting;
289
+ if (sorting.columnId === columnId && !this.props.hasFilter) {
290
+ const glyph =
291
+ sorting.direction === 'asc' ? 'solid/caret-down' : 'solid/caret-up';
292
+ text = new Shredder({text, glyph});
293
+ }
294
+
295
+ return (
296
+ <TableCell
297
+ key={index}
298
+ isLast={false}
299
+ isHeader={true}
300
+ verticalAlign="center"
301
+ {...ListHelpers.getColumnProps(cell, this.props.settings)}
302
+ text={text}
303
+ />
304
+ );
305
+ }
306
+
307
+ renderHeader(columns) {
308
+ const columnsData = [];
309
+ let index = 0;
310
+ columnsData.push({index: index++, width: this.firstColumnWidth});
311
+ for (const column of columns) {
312
+ const props = ListHelpers.getColumnProps(column, this.props.settings);
313
+ columnsData.push({index: index++, width: props.width});
314
+ }
315
+
316
+ return (
317
+ <div
318
+ className={
319
+ this.props.hasFilter
320
+ ? this.styles.classNames.headerFilter
321
+ : this.styles.classNames.header
322
+ }
323
+ >
324
+ <TableCell
325
+ isLast={false}
326
+ isHeader={true}
327
+ verticalAlign="center"
328
+ width={this.firstColumnWidth}
329
+ text={T('N°')}
330
+ />
331
+ {columns.map((c, i) => this.renderHeaderCell(c, i))}
332
+ <TableHeaderDragManager
333
+ height="44px"
334
+ marginLeft="20px"
335
+ columns={columnsData}
336
+ fixedColumns={[0]}
337
+ widthChanged={(index, width) => this.onWidthChanged(index, width)}
338
+ columnMoved={(src, dst) => this.onColumnMoved(src, dst)}
339
+ columnClicked={(index) => this.onSortColumn(index, columns)}
340
+ />
341
+ </div>
342
+ );
343
+ }
344
+
345
+ renderRows(columns) {
346
+ const listId = `list@${this.props.id}`;
347
+
348
+ return (
349
+ <div className={this.styles.classNames.rows}>
350
+ <List
351
+ id={listId}
352
+ type={'variable'}
353
+ renderItem={EntityListItem}
354
+ data={{
355
+ firstColumnWidth: this.firstColumnWidth,
356
+ filterPaths: this.filterPaths,
357
+ hasFilter: this.props.hasFilter,
358
+ onDrillDown: this.drillDown,
359
+ onRenewTTL: this.renewTTL,
360
+ columns: columns,
361
+ settings: this.props.settings,
362
+ onSelect: this.selectRow,
363
+ onEdit: this.editRow,
364
+ useView: this.props.view ? true : false,
365
+ serviceId: this.props.id,
366
+ variant: this.variant,
367
+ schema: this.getSchema(this.props.type)
368
+ }}
369
+ />
370
+ </div>
371
+ );
372
+ }
373
+
374
+ renderButton() {
375
+ if (!this.props.prototypeMode) {
376
+ return null;
377
+ }
378
+
379
+ return (
380
+ <div className={this.styles.classNames.button}>
381
+ <Button
382
+ width="30px"
383
+ height="30px"
384
+ glyph="solid/columns"
385
+ tooltip={T('Choisir les colonnes')}
386
+ onClick={this.onEditColumns}
387
+ />
388
+ </div>
389
+ );
390
+ }
391
+
392
+ renderVariants() {
393
+ if (!this.props.prototypeMode) {
394
+ return null;
395
+ }
396
+
397
+ return (
398
+ <div className={this.styles.classNames.variants}>
399
+ <Button
400
+ width="28px"
401
+ height="20px"
402
+ fontSize="75%"
403
+ text="J"
404
+ tooltip={T('Jauge verticale')}
405
+ horizontalSpacing="overlap"
406
+ active={this.variant === 'gauge'}
407
+ onClick={() => (this.variant = 'gauge')}
408
+ />
409
+ <Button
410
+ width="28px"
411
+ height="20px"
412
+ fontSize="75%"
413
+ text="B"
414
+ tooltip={T('Barre verticale')}
415
+ horizontalSpacing="overlap"
416
+ active={this.variant === 'bar'}
417
+ onClick={() => (this.variant = 'bar')}
418
+ />
419
+ <Button
420
+ width="28px"
421
+ height="20px"
422
+ fontSize="75%"
423
+ text="C"
424
+ tooltip={T('Carnaval')}
425
+ horizontalSpacing="overlap"
426
+ active={this.variant === 'carnaval'}
427
+ onClick={() => (this.variant = 'carnaval')}
428
+ />
429
+ </div>
430
+ );
431
+ }
432
+
433
+ render() {
434
+ const {id, columnIds, isBad, type} = this.props;
435
+ if (!id || !columnIds) {
436
+ return null;
437
+ }
438
+
439
+ if (isBad) {
440
+ this.setUserSettings('reset-view-column', {
441
+ viewId: `view@${type}`,
442
+ });
443
+ return null;
444
+ }
445
+
446
+ return this.buildCollectionLoader(
447
+ columnIds.valueSeq().toArray(),
448
+ ({collection}) => {
449
+ const columns = collection;
450
+ const width = this.getEstimatedWidth(columns);
451
+ const widthStyle = {
452
+ minWidth: width,
453
+ };
454
+
455
+ return (
456
+ <div className={this.styles.classNames.entityView}>
457
+ <div className={this.styles.classNames.list}>
458
+ <div
459
+ className={this.styles.classNames.content}
460
+ style={widthStyle}
461
+ >
462
+ {this.renderHeader(columns)}
463
+ {this.renderRows(columns)}
464
+ </div>
465
+ </div>
466
+ {this.renderButton(columns)}
467
+ {this.renderVariants(columns)}
468
+ </div>
469
+ );
470
+ },
471
+ null
472
+ );
473
+ }
474
+ }
475
+
476
+ /******************************************************************************/
477
+
478
+ const ConnectedEntityView = Widget.connect((state, props) => {
479
+ if (!props.type) {
480
+ return {};
481
+ }
482
+
483
+ const hasFilter = !!state.get(`widgets.${props.id}.value`, null);
484
+
485
+ const view = state.get(`backend.view@${props.type}`);
486
+ let columnIds = view.get('columns');
487
+
488
+ const clientSessionId = state.get(`backend.${window.labId}.clientSessionId`);
489
+ const userView = state.get(
490
+ `backend.${clientSessionId}.views.view@${props.type}`
491
+ );
492
+ let isBad = false;
493
+ if (userView) {
494
+ const order = userView.get('order');
495
+ if (order.size > 0) {
496
+ isBad = order.some((id) => !columnIds.includes(id));
497
+ if (!isBad) {
498
+ columnIds = order;
499
+ }
500
+ }
501
+ }
502
+
503
+ const userSession = Widget.getUserSession(state);
504
+ const prototypeMode = userSession.get('prototypeMode');
505
+
506
+ return {
507
+ isBad,
508
+ hasFilter,
509
+ columnIds,
510
+ view: view.get('query'),
511
+ settings: userView,
512
+ prototypeMode,
513
+ };
514
+ })(EntityView);
515
+
516
+ export default Widget.Wired(ConnectedEntityView)();