goblin-desktop 2.0.0 → 2.0.2

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 (130) hide show
  1. package/README.md +108 -108
  2. package/builders/wizard.js +478 -478
  3. package/contexts.js +13 -13
  4. package/desktop-manager.js +10 -10
  5. package/desktop-window.js +13 -13
  6. package/desktop.js +13 -13
  7. package/lib/service.js +135 -135
  8. package/package.json +36 -36
  9. package/password-wizard.js +13 -13
  10. package/quest-run-wizard.js +13 -13
  11. package/taskbar.js +13 -13
  12. package/widgets/audio/sfx.js +177 -177
  13. package/widgets/board/view.js +37 -37
  14. package/widgets/board/widget.js +65 -65
  15. package/widgets/contexts/logic-handlers.js +36 -36
  16. package/widgets/contexts/service.js +40 -40
  17. package/widgets/contexts/view.js +22 -22
  18. package/widgets/contexts/widget.js +147 -147
  19. package/widgets/datagrid/datagrid-entity.js +82 -82
  20. package/widgets/datagrid/datagrid-headers.js +272 -272
  21. package/widgets/datagrid/datagrid-item.js +82 -82
  22. package/widgets/datagrid/styles.js +13 -13
  23. package/widgets/datagrid/widget.js +191 -191
  24. package/widgets/datagrid-cell/styles.js +52 -52
  25. package/widgets/datagrid-cell/widget.js +41 -41
  26. package/widgets/default/view.js +91 -91
  27. package/widgets/desktop/compensator.js +9 -9
  28. package/widgets/desktop/logic-handlers.js +237 -237
  29. package/widgets/desktop/service.js +816 -816
  30. package/widgets/desktop/styles.js +28 -28
  31. package/widgets/desktop/widget.js +175 -175
  32. package/widgets/desktop-clock/styles.js +69 -69
  33. package/widgets/desktop-clock/widget.js +387 -387
  34. package/widgets/desktop-clock-clock/styles.js +56 -56
  35. package/widgets/desktop-clock-clock/widget.js +96 -96
  36. package/widgets/desktop-clock-menu/styles.js +129 -129
  37. package/widgets/desktop-clock-menu/widget.js +63 -63
  38. package/widgets/desktop-connection-status/reducer.js +15 -15
  39. package/widgets/desktop-connection-status/styles.js +44 -44
  40. package/widgets/desktop-connection-status/widget.js +129 -129
  41. package/widgets/desktop-content/widget.js +68 -68
  42. package/widgets/desktop-footer/reducer.js +31 -31
  43. package/widgets/desktop-footer/styles.js +36 -36
  44. package/widgets/desktop-footer/widget.js +52 -52
  45. package/widgets/desktop-monitors/styles.js +155 -155
  46. package/widgets/desktop-monitors/widget.js +273 -273
  47. package/widgets/desktop-notebook/styles.js +155 -155
  48. package/widgets/desktop-notebook/widget.js +253 -253
  49. package/widgets/desktop-notifications/styles.js +147 -147
  50. package/widgets/desktop-notifications/widget.js +231 -231
  51. package/widgets/desktop-scale/reducer.js +15 -15
  52. package/widgets/desktop-scale/styles.js +48 -48
  53. package/widgets/desktop-scale/widget.js +172 -172
  54. package/widgets/desktop-state-monitor/styles.js +72 -72
  55. package/widgets/desktop-state-monitor/widget.js +123 -123
  56. package/widgets/desktop-taskbar/widget.js +57 -57
  57. package/widgets/desktop-themes-menu/widget.js +121 -121
  58. package/widgets/desktop-topbar/widget.js +201 -201
  59. package/widgets/desktop-window/service.js +56 -56
  60. package/widgets/desktop-window/styles.js +22 -22
  61. package/widgets/desktop-window/widget.js +70 -70
  62. package/widgets/detail/view.js +40 -40
  63. package/widgets/detail/widget.js +125 -125
  64. package/widgets/editor/widget.js +80 -80
  65. package/widgets/entity-alerts/styles.js +77 -77
  66. package/widgets/entity-alerts/widget.js +328 -328
  67. package/widgets/entity-list/view.js +36 -36
  68. package/widgets/entity-list/widget.js +209 -209
  69. package/widgets/entity-list-item/widget.js +68 -68
  70. package/widgets/entity-row/styles.js +104 -104
  71. package/widgets/entity-row/widget.js +523 -523
  72. package/widgets/entity-row-button/styles.js +46 -46
  73. package/widgets/entity-row-button/widget.js +57 -57
  74. package/widgets/entity-view/reducer.js +20 -20
  75. package/widgets/entity-view/styles.js +90 -90
  76. package/widgets/entity-view/widget.js +516 -516
  77. package/widgets/facet-checkbox/styles.js +17 -17
  78. package/widgets/facet-checkbox/widget.js +43 -43
  79. package/widgets/facet-filter/widget.js +94 -94
  80. package/widgets/facet-filter-add/styles.js +30 -30
  81. package/widgets/facet-filter-add/widget.js +105 -105
  82. package/widgets/facet-filter-button/styles.js +74 -74
  83. package/widgets/facet-filter-button/widget.js +214 -214
  84. package/widgets/facet-filter-list-dialog/styles.js +59 -59
  85. package/widgets/facet-filter-list-dialog/widget.js +253 -253
  86. package/widgets/facet-filter-list-dialog-footer/styles.js +22 -22
  87. package/widgets/facet-filter-list-dialog-footer/widget.js +105 -105
  88. package/widgets/facet-filter-range-dialog/styles.js +82 -82
  89. package/widgets/facet-filter-range-dialog/widget.js +398 -398
  90. package/widgets/facet-filter-range-dialog-footer/styles.js +22 -22
  91. package/widgets/facet-filter-range-dialog-footer/widget.js +182 -182
  92. package/widgets/gamepad/widget.js +75 -75
  93. package/widgets/helpers/facet-helpers.js +105 -105
  94. package/widgets/hinter/reducer.js +35 -35
  95. package/widgets/hinter/styles.js +79 -79
  96. package/widgets/hinter/view.js +31 -31
  97. package/widgets/hinter/widget.js +292 -292
  98. package/widgets/junction/styles.js +22 -22
  99. package/widgets/junction/widget.js +50 -50
  100. package/widgets/main-tab-menu/widget.js +136 -136
  101. package/widgets/map/view.js +49 -49
  102. package/widgets/map/widget.js +65 -65
  103. package/widgets/monitor/widget.js +66 -66
  104. package/widgets/navigating-layer/widget.js +25 -25
  105. package/widgets/notifications-button/widget.js +44 -44
  106. package/widgets/password-wizard/service.js +53 -53
  107. package/widgets/password-wizard/ui.js +66 -66
  108. package/widgets/plugin/styles.js +294 -294
  109. package/widgets/plugin/widget.js +636 -636
  110. package/widgets/quest-run-wizard/service.js +49 -49
  111. package/widgets/quest-run-wizard/ui.js +25 -25
  112. package/widgets/search/styles.js +80 -80
  113. package/widgets/search/widget.js +286 -284
  114. package/widgets/simple/view.js +29 -29
  115. package/widgets/status-filters/widget.js +121 -121
  116. package/widgets/tab/styles.js +16 -16
  117. package/widgets/tab/widget.js +88 -88
  118. package/widgets/tab-content/widget.js +35 -35
  119. package/widgets/tabs/widget.js +48 -48
  120. package/widgets/taskbar/service.js +99 -99
  121. package/widgets/taskbar/view.js +24 -24
  122. package/widgets/taskbar/widget.js +169 -169
  123. package/widgets/widget-doc-caller/widget.js +55 -55
  124. package/widgets/wizard/widget.js +299 -299
  125. package/widgets/wizard-buttons/widget.js +107 -107
  126. package/widgets/workitem/styles.js +281 -281
  127. package/widgets/workitem/view.js +62 -62
  128. package/widgets/workitem/widget.js +967 -940
  129. package/widgets/workitem-dialog/widget.js +86 -86
  130. 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)();