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,636 +1,636 @@
1
- //T:2019-02-27
2
-
3
- import React from 'react';
4
- import ReactDOM from 'react-dom';
5
- import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed';
6
- import Widget from 'goblin-laboratory/widgets/widget';
7
- import {Unit} from 'goblin-theme';
8
- const px = Unit.toPx;
9
-
10
- import Workitem from 'goblin-desktop/widgets/workitem/widget';
11
- import Container from 'goblin-gadgets/widgets/container/widget';
12
- import Button from 'goblin-gadgets/widgets/button/widget';
13
- import Label from 'goblin-gadgets/widgets/label/widget';
14
- import Field from 'goblin-gadgets/widgets/field/widget';
15
- import DragCab from 'goblin-gadgets/widgets/drag-cab/widget';
16
- import Combo from 'goblin-gadgets/widgets/combo/widget';
17
-
18
- import importer from 'goblin_importer';
19
- import T from 't';
20
-
21
- const uiImporter = importer('ui');
22
-
23
- /******************************************************************************/
24
-
25
- class Plugin extends Widget {
26
- constructor() {
27
- super(...arguments);
28
-
29
- this._refs = {};
30
- this._scrollEntityId = null;
31
- this.comboButton = null;
32
-
33
- this.state = {
34
- showActionMenu: false,
35
- };
36
-
37
- this.onAction = this.onAction.bind(this);
38
- this.onActionAdd = this.onActionAdd.bind(this);
39
- this.onSwapExtended = this.onSwapExtended.bind(this);
40
- this.onDeleteEntity = this.onDeleteEntity.bind(this);
41
- this.onEditEntity = this.onEditEntity.bind(this);
42
- this.onEntityDragged = this.onEntityDragged.bind(this);
43
- this.doProxy = this.doProxy.bind(this);
44
- this.open = this.open.bind(this);
45
- this.close = this.close.bind(this);
46
- }
47
-
48
- get showActionMenu() {
49
- return this.state.showActionMenu;
50
- }
51
-
52
- set showActionMenu(value) {
53
- this.setState({
54
- showActionMenu: value,
55
- });
56
- }
57
-
58
- _scrollIntoView(duration) {
59
- if (
60
- !this._scrollEntityId ||
61
- !this._refs[this._scrollEntityId] ||
62
- this._scrollEntityId !== this.props.extendedId
63
- ) {
64
- return;
65
- }
66
-
67
- scrollIntoViewIfNeeded(this._refs[this._scrollEntityId], {
68
- duration,
69
- // HACK: we need to fix the transitions in order to remove this offset
70
- offset: {
71
- top: 3,
72
- },
73
- });
74
- }
75
-
76
- componentDidUpdate() {
77
- this._scrollIntoView(150);
78
- }
79
-
80
- onAction(actionName) {
81
- const service = this.props.namespace;
82
- switch (actionName) {
83
- case 'add':
84
- this.doAs(service, actionName);
85
- break;
86
- case 'clear':
87
- this.doAs(service, actionName);
88
- break;
89
- default:
90
- this.doAs(service, 'do-action', {action: actionName});
91
- }
92
- }
93
-
94
- onActionAdd() {
95
- this.onAction('add');
96
- }
97
-
98
- onSwapExtended(entityId) {
99
- this._scrollEntityId = entityId;
100
- this.dispatch({type: 'TOGGLE_EXTENDED', entityId});
101
- }
102
-
103
- onDeleteEntity(entityId) {
104
- const service = this.props.namespace;
105
- this.doAs(service, 'remove', {entityId});
106
- }
107
-
108
- onEditEntity(entityId) {
109
- const service = this.props.namespace;
110
- this.doAs(service, 'edit', {entityId});
111
- }
112
-
113
- onEntityDragged(selectedIds, toId, ownerId, ownerKind) {
114
- const service = this.props.namespace;
115
- if (ownerId === this.props.id) {
116
- this.doAs(service, 'drag', {
117
- fromId: selectedIds[0],
118
- toId: toId,
119
- });
120
- } else {
121
- this.doAs(service, 'remove', {
122
- entityId: selectedIds[0],
123
- });
124
- this.cmd(`${service}.add`, {
125
- id: ownerId,
126
- entityId: selectedIds[0],
127
- });
128
- }
129
- }
130
-
131
- getActionMenuList(numberOfIds) {
132
- const list = [];
133
-
134
- if (this.props.actionMenu) {
135
- for (const item of this.props.actionMenu) {
136
- if (!item.min || item.min <= numberOfIds) {
137
- list.push({
138
- glyph: item.glyph,
139
- text: item.text,
140
- action: () => this.onAction(item.actionName),
141
- });
142
- }
143
- }
144
- }
145
-
146
- if (
147
- numberOfIds > 0 &&
148
- (!this.props.arity || !this.props.arity.startsWith('1'))
149
- ) {
150
- if (list.length > 0) {
151
- list.push({
152
- separator: true,
153
- });
154
- }
155
- list.push({
156
- glyph: 'solid/trash',
157
- text: T('Tout supprimer'),
158
- action: () => this.onAction('clear'),
159
- });
160
- }
161
-
162
- return list;
163
- }
164
-
165
- doProxy(index) {
166
- return (action, args) => {
167
- const workitemId = `${this.props.editorWidget}${
168
- this.props.mode ? `@${this.props.mode}` : ''
169
- }@${this.context.desktopId}@${this.props.entityIds.get(index)}`;
170
- this.doFor(workitemId, action, args);
171
- };
172
- }
173
-
174
- open() {
175
- this.showActionMenu = true;
176
- }
177
-
178
- close() {
179
- this.showActionMenu = false;
180
- }
181
-
182
- /******************************************************************************/
183
-
184
- renderHeaderSearch() {
185
- if (this.props.searchHinter) {
186
- return (
187
- <Field
188
- shape="rounded"
189
- labelGlyph="solid/search"
190
- labelWidth="24px"
191
- fieldWidth="180px"
192
- hintText={T('Ajouter existant')}
193
- tooltip={T(
194
- 'Ajouter un élément existant en le choisissant dans une liste'
195
- )}
196
- kind="hinter"
197
- required={false}
198
- hinter={this.props.searchHinter}
199
- horizontalSpacing="large"
200
- />
201
- );
202
- } else {
203
- return null;
204
- }
205
- }
206
-
207
- renderHeaderActionMenuButton(numberOfIds) {
208
- const list = this.getActionMenuList(numberOfIds);
209
- if (list.length > 0) {
210
- return (
211
- <Button
212
- ref={(x) => (this.comboButton = x)}
213
- glyph="solid/ellipsis-h"
214
- horizontalSpacing="large"
215
- active={this.showActionMenu}
216
- onClick={this.open}
217
- />
218
- );
219
- } else {
220
- return null;
221
- }
222
- }
223
-
224
- renderHeaderActionMenu(numberOfIds) {
225
- if (this.showActionMenu) {
226
- const node = ReactDOM.findDOMNode(this.comboButton);
227
- const rect = node.getBoundingClientRect();
228
- const top = Unit.add(
229
- px(rect.bottom),
230
- this.context.theme.shapes.flyingBalloonTriangleSize
231
- );
232
-
233
- return (
234
- <Combo
235
- menuType="menu"
236
- left={(rect.left + rect.right) / 2}
237
- top={top}
238
- list={this.getActionMenuList(numberOfIds)}
239
- close={this.close}
240
- />
241
- );
242
- } else {
243
- return null;
244
- }
245
- }
246
-
247
- renderHeaderAdd(numberOfIds) {
248
- const canAdd =
249
- !this.props.disableAdd &&
250
- (!this.props.arity ||
251
- this.props.arity.endsWith('n') ||
252
- (this.props.arity === '0..1' && numberOfIds === 0));
253
-
254
- if (canAdd) {
255
- return (
256
- <Button
257
- glyph="solid/plus"
258
- text={this.props.addText || T('Ajouter')}
259
- tooltip={this.props.addTooltip}
260
- glyphPosition="right"
261
- onClick={this.onActionAdd}
262
- />
263
- );
264
- } else {
265
- return null;
266
- }
267
- }
268
-
269
- renderHeader(numberOfIds) {
270
- const headerClass =
271
- this.props.entityIds.size === 0
272
- ? this.styles.classNames.headerEmpty
273
- : this.styles.classNames.header;
274
-
275
- const title = this.props.pluginTitle
276
- ? this.props.pluginTitle
277
- : this.props.title;
278
-
279
- if (this.props.readonly) {
280
- return (
281
- <div className={headerClass}>
282
- <Label text={title} grow="1" kind="title" />
283
- </div>
284
- );
285
- } else {
286
- return (
287
- <div className={headerClass}>
288
- <Label text={title} grow="1" kind="title" />
289
- {this.renderHeaderSearch()}
290
- {this.renderHeaderActionMenuButton(numberOfIds)}
291
- {this.renderHeaderAdd(numberOfIds)}
292
- {this.renderHeaderActionMenu(numberOfIds)}
293
- </div>
294
- );
295
- }
296
- }
297
-
298
- renderItem(entityId, extended, index) {
299
- const workitemUI = uiImporter(this.props.editorWidget);
300
- const workitemId = `${this.props.editorWidget}${
301
- this.props.mode ? `@${this.props.mode}` : ''
302
- }@${this.context.desktopId}@${this.props.entityIds.get(index)}`;
303
-
304
- if (!workitemUI.plugin) {
305
- return null;
306
- }
307
-
308
- const itemClass = extended
309
- ? this.props.embedded
310
- ? this.styles.classNames.extendedEmbeddedItem
311
- : this.styles.classNames.extendedItem
312
- : this.props.embedded
313
- ? this.styles.classNames.compactedEmbeddedItem
314
- : this.styles.classNames.compactedItem;
315
-
316
- const key1 = this.props.readonly ? 'readonly' : 'edit';
317
- const key2 = extended ? 'extend' : 'compact';
318
-
319
- let UI = workitemUI.plugin[key1][key2];
320
- //let UI = this.WithState(
321
- // workitemUI.plugin[key1][key2],
322
- // 'entityId'
323
- //)('.entityId');
324
-
325
- if (
326
- workitemUI.mappers &&
327
- workitemUI.mappers.plugin &&
328
- workitemUI.mappers.plugin[key1] &&
329
- workitemUI.mappers.plugin[key1][key2]
330
- ) {
331
- UI = this.mapWidget(
332
- UI,
333
- workitemUI.mappers.plugin[key1][key2],
334
- `backend.${entityId}`
335
- );
336
- }
337
-
338
- const type = entityId.split('@', 1)[0];
339
- const Loader = (props) => {
340
- if (props.loaded) {
341
- return (
342
- <Workitem
343
- id={workitemId}
344
- entityId={entityId}
345
- kind="form"
346
- readonly={this.props.readonly}
347
- dragServiceId={this.props.dragServiceId}
348
- >
349
- {this.buildLoader(entityId, () => (
350
- <UI
351
- id={workitemId}
352
- theme={this.context.theme}
353
- entityId={entityId}
354
- embeddedLevel={this.props.embeddedLevel}
355
- origin={this.props.origin}
356
- contextId={this.context.contextId}
357
- do={this.doProxy(index)}
358
- entitySchema={this.getSchema(type)}
359
- />
360
- ))}
361
- </Workitem>
362
- );
363
- } else {
364
- return (
365
- <Container busy={true}>
366
- <Label text={T('chargement...')} />
367
- </Container>
368
- );
369
- }
370
- };
371
-
372
- const LoadedWorkitem = this.mapWidget(
373
- Loader,
374
- (wid) => ({loaded: !!wid}),
375
- `backend.${workitemId}.id`
376
- );
377
-
378
- return (
379
- <div className={itemClass}>
380
- <LoadedWorkitem />
381
- </div>
382
- );
383
- }
384
-
385
- renderButtons(entityId, extended, numberOfIds) {
386
- if (extended) {
387
- const buttonsClass = this.props.readonly
388
- ? this.props.embedded
389
- ? this.styles.classNames.extendedEmbeddedReadonlyButtons
390
- : this.styles.classNames.extendedReadonlyButtons
391
- : this.props.embedded
392
- ? this.styles.classNames.extendedEmbeddedButtons
393
- : this.styles.classNames.extendedButtons;
394
-
395
- const canDelete =
396
- !this.props.readonly &&
397
- !this.props.disableDelete &&
398
- (!this.props.arity ||
399
- this.props.arity.startsWith('0') ||
400
- numberOfIds > 1);
401
-
402
- const kind = this.props.readonly ? 'plugin-light' : 'plugin-dark';
403
-
404
- let otherButtons = null;
405
- if (this.props.buttons) {
406
- otherButtons = this.props.buttons(entityId);
407
- }
408
-
409
- return (
410
- <div className={buttonsClass}>
411
- <Button
412
- width="32px"
413
- kind={kind}
414
- glyph="solid/angle-up"
415
- glyphSize="180%"
416
- tooltip={T('Replier')}
417
- active={false}
418
- activeColor={
419
- this.context.theme.palette.recurrenceExtendedBoxBackground
420
- }
421
- onClick={() => this.onSwapExtended(entityId)}
422
- />
423
- <Button
424
- width="32px"
425
- kind={kind}
426
- glyph="solid/pencil"
427
- tooltip={T('Editer')}
428
- onClick={() => this.onEditEntity(entityId)}
429
- />
430
- {otherButtons}
431
- {canDelete ? (
432
- <Button
433
- width="32px"
434
- kind={kind}
435
- glyph="solid/trash"
436
- tooltip={T('Supprimer')}
437
- onClick={() => this.onDeleteEntity(entityId)}
438
- />
439
- ) : null}
440
- </div>
441
- );
442
- } else {
443
- const buttonsClass = this.props.readonly
444
- ? this.props.embedded
445
- ? this.styles.classNames.compactedEmbeddedReadonlyButtons
446
- : this.styles.classNames.compactedReadonlyButtons
447
- : this.props.embedded
448
- ? this.styles.classNames.compactedEmbeddedButtons
449
- : this.styles.classNames.compactedButtons;
450
-
451
- const kind =
452
- this.props.readonly || !this.props.embedded
453
- ? 'plugin-light'
454
- : 'plugin-dark';
455
-
456
- return (
457
- <div className={buttonsClass}>
458
- {this.props.readonly && !this.props.embedded ? (
459
- <Button
460
- width="32px"
461
- kind={kind}
462
- glyph="solid/pencil"
463
- tooltip={T('Editer')}
464
- onClick={() => this.onEditEntity(entityId)}
465
- />
466
- ) : null}
467
- <Button
468
- width="32px"
469
- kind={kind}
470
- glyph="solid/angle-down"
471
- glyphSize="180%"
472
- tooltip={T('Etendre')}
473
- active={false}
474
- activeColor={
475
- this.context.theme.palette.recurrenceExtendedBoxBackground
476
- }
477
- onClick={() => this.onSwapExtended(entityId)}
478
- />
479
- </div>
480
- );
481
- }
482
- }
483
-
484
- renderRowContent(entityId, extended, numberOfIds, index) {
485
- const rowClass = extended
486
- ? this.props.embedded
487
- ? this.styles.classNames.extendedEmbeddedRow
488
- : this.styles.classNames.extendedRow
489
- : numberOfIds > 1 && this.props.horizontalSeparator !== 'compact'
490
- ? this.props.embedded
491
- ? this.styles.classNames.compactedEmbeddedDashedRow
492
- : this.styles.classNames.compactedDashedRow
493
- : this.props.embedded
494
- ? this.styles.classNames.compactedEmbeddedRow
495
- : this.styles.classNames.compactedRow;
496
-
497
- return (
498
- <Container
499
- kind="row-draggable"
500
- key={index}
501
- ref={(n) => {
502
- if (n) {
503
- this._refs[entityId] = ReactDOM.findDOMNode(n);
504
- }
505
- }}
506
- >
507
- <div className={rowClass}>
508
- {this.renderItem(entityId, extended, index)}
509
- {this.renderButtons(entityId, extended, numberOfIds)}
510
- </div>
511
- </Container>
512
- );
513
- }
514
-
515
- renderRow(entityId, extended, dragEnabled, numberOfIds, index) {
516
- if (dragEnabled) {
517
- return (
518
- <DragCab
519
- key={index}
520
- dragController={this.props.dragType || this.props.id}
521
- dragOwnerId={entityId}
522
- dragMode="handle"
523
- dragHandleWidth={this.context.theme.shapes.containerMargin}
524
- direction="vertical"
525
- color={this.context.theme.palette.dragAndDropHover}
526
- thickness={this.context.theme.shapes.dragAndDropTicketThickness}
527
- overSpacing="0px"
528
- verticalSpacing="0px"
529
- radius="0px"
530
- doClickAction={() => this.onSwapExtended(entityId)}
531
- doDragEnding={this.onEntityDragged}
532
- >
533
- {this.renderRowContent(entityId, extended, numberOfIds, index)}
534
- </DragCab>
535
- );
536
- } else {
537
- return this.renderRowContent(entityId, extended, numberOfIds, index);
538
- }
539
- }
540
-
541
- renderRows(entityIds) {
542
- const dragEnabled =
543
- !this.props.readonly && (entityIds.length > 1 || !!this.props.dragType);
544
-
545
- let index = 0;
546
-
547
- return entityIds.map((entityId) => {
548
- const extended = entityId === this.props.extendedId;
549
- return this.renderRow(
550
- entityId,
551
- extended,
552
- dragEnabled,
553
- entityIds.length,
554
- index++
555
- );
556
- });
557
- }
558
-
559
- renderDefault() {
560
- const entityIds = this.props.entityIds.valueSeq().toArray();
561
- if (entityIds.length === 0 && this.props.readonly && this.props.embedded) {
562
- return null;
563
- }
564
-
565
- let boxClass = null;
566
- if (!this.props.entityIds || this.props.entityIds.size === 0) {
567
- boxClass = this.props.embedded
568
- ? this.styles.classNames.emptyembeddedBox
569
- : this.styles.classNames.emptyBox;
570
- } else {
571
- boxClass = this.props.embedded
572
- ? this.styles.classNames.embeddedBox
573
- : this.styles.classNames.box;
574
- }
575
-
576
- return (
577
- <div className={boxClass}>
578
- {this.renderHeader(entityIds.length)}
579
- <Container
580
- kind="column"
581
- dragController={this.props.dragType || this.props.id}
582
- dragSource={this.props.id}
583
- dragOwnerId={this.props.id}
584
- >
585
- {this.renderRows(entityIds)}
586
- </Container>
587
- </div>
588
- );
589
- }
590
-
591
- render() {
592
- this._refs = {};
593
-
594
- if (!this.props.id || !this.props.entityIds) {
595
- return null;
596
- }
597
-
598
- if (!this.props.editorWidget) {
599
- return null;
600
- }
601
-
602
- return this.renderDefault();
603
- }
604
- }
605
-
606
- /******************************************************************************/
607
-
608
- const select = (root) => (state, id) => (prop) => {
609
- if (!id) {
610
- return null;
611
- }
612
- const target = state.get(`${root}.${id}`);
613
- if (!target) {
614
- return null;
615
- }
616
- return target.get(prop);
617
- };
618
-
619
- const withBackend = select('backend');
620
- const withWidget = select('widgets');
621
-
622
- export default Widget.connect((state, props) => {
623
- const plugin = withBackend(state, props.id);
624
- const entity = withBackend(state, plugin('forEntity'));
625
- const widget = withWidget(state, props.id);
626
- return {
627
- id: props.id,
628
- title: plugin('title'),
629
- editorWidget: plugin('editorWidget'),
630
- arity: plugin('arity'),
631
- mode: plugin('mode'),
632
- entityIds: entity(plugin('entityPath')),
633
- namespace: `${plugin('type')}-plugin`,
634
- extendedId: widget('extendedId'),
635
- };
636
- })(Plugin);
1
+ //T:2019-02-27
2
+
3
+ import React from 'react';
4
+ import ReactDOM from 'react-dom';
5
+ import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed';
6
+ import Widget from 'goblin-laboratory/widgets/widget';
7
+ import {Unit} from 'goblin-theme';
8
+ const px = Unit.toPx;
9
+
10
+ import Workitem from 'goblin-desktop/widgets/workitem/widget';
11
+ import Container from 'goblin-gadgets/widgets/container/widget';
12
+ import Button from 'goblin-gadgets/widgets/button/widget';
13
+ import Label from 'goblin-gadgets/widgets/label/widget';
14
+ import Field from 'goblin-gadgets/widgets/field/widget';
15
+ import DragCab from 'goblin-gadgets/widgets/drag-cab/widget';
16
+ import Combo from 'goblin-gadgets/widgets/combo/widget';
17
+
18
+ import importer from 'goblin_importer';
19
+ import T from 't';
20
+
21
+ const uiImporter = importer('ui');
22
+
23
+ /******************************************************************************/
24
+
25
+ class Plugin extends Widget {
26
+ constructor() {
27
+ super(...arguments);
28
+
29
+ this._refs = {};
30
+ this._scrollEntityId = null;
31
+ this.comboButton = null;
32
+
33
+ this.state = {
34
+ showActionMenu: false,
35
+ };
36
+
37
+ this.onAction = this.onAction.bind(this);
38
+ this.onActionAdd = this.onActionAdd.bind(this);
39
+ this.onSwapExtended = this.onSwapExtended.bind(this);
40
+ this.onDeleteEntity = this.onDeleteEntity.bind(this);
41
+ this.onEditEntity = this.onEditEntity.bind(this);
42
+ this.onEntityDragged = this.onEntityDragged.bind(this);
43
+ this.doProxy = this.doProxy.bind(this);
44
+ this.open = this.open.bind(this);
45
+ this.close = this.close.bind(this);
46
+ }
47
+
48
+ get showActionMenu() {
49
+ return this.state.showActionMenu;
50
+ }
51
+
52
+ set showActionMenu(value) {
53
+ this.setState({
54
+ showActionMenu: value,
55
+ });
56
+ }
57
+
58
+ _scrollIntoView(duration) {
59
+ if (
60
+ !this._scrollEntityId ||
61
+ !this._refs[this._scrollEntityId] ||
62
+ this._scrollEntityId !== this.props.extendedId
63
+ ) {
64
+ return;
65
+ }
66
+
67
+ scrollIntoViewIfNeeded(this._refs[this._scrollEntityId], {
68
+ duration,
69
+ // HACK: we need to fix the transitions in order to remove this offset
70
+ offset: {
71
+ top: 3,
72
+ },
73
+ });
74
+ }
75
+
76
+ componentDidUpdate() {
77
+ this._scrollIntoView(150);
78
+ }
79
+
80
+ onAction(actionName) {
81
+ const service = this.props.namespace;
82
+ switch (actionName) {
83
+ case 'add':
84
+ this.doAs(service, actionName);
85
+ break;
86
+ case 'clear':
87
+ this.doAs(service, actionName);
88
+ break;
89
+ default:
90
+ this.doAs(service, 'do-action', {action: actionName});
91
+ }
92
+ }
93
+
94
+ onActionAdd() {
95
+ this.onAction('add');
96
+ }
97
+
98
+ onSwapExtended(entityId) {
99
+ this._scrollEntityId = entityId;
100
+ this.dispatch({type: 'TOGGLE_EXTENDED', entityId});
101
+ }
102
+
103
+ onDeleteEntity(entityId) {
104
+ const service = this.props.namespace;
105
+ this.doAs(service, 'remove', {entityId});
106
+ }
107
+
108
+ onEditEntity(entityId) {
109
+ const service = this.props.namespace;
110
+ this.doAs(service, 'edit', {entityId});
111
+ }
112
+
113
+ onEntityDragged(selectedIds, toId, ownerId, ownerKind) {
114
+ const service = this.props.namespace;
115
+ if (ownerId === this.props.id) {
116
+ this.doAs(service, 'drag', {
117
+ fromId: selectedIds[0],
118
+ toId: toId,
119
+ });
120
+ } else {
121
+ this.doAs(service, 'remove', {
122
+ entityId: selectedIds[0],
123
+ });
124
+ this.cmd(`${service}.add`, {
125
+ id: ownerId,
126
+ entityId: selectedIds[0],
127
+ });
128
+ }
129
+ }
130
+
131
+ getActionMenuList(numberOfIds) {
132
+ const list = [];
133
+
134
+ if (this.props.actionMenu) {
135
+ for (const item of this.props.actionMenu) {
136
+ if (!item.min || item.min <= numberOfIds) {
137
+ list.push({
138
+ glyph: item.glyph,
139
+ text: item.text,
140
+ action: () => this.onAction(item.actionName),
141
+ });
142
+ }
143
+ }
144
+ }
145
+
146
+ if (
147
+ numberOfIds > 0 &&
148
+ (!this.props.arity || !this.props.arity.startsWith('1'))
149
+ ) {
150
+ if (list.length > 0) {
151
+ list.push({
152
+ separator: true,
153
+ });
154
+ }
155
+ list.push({
156
+ glyph: 'solid/trash',
157
+ text: T('Tout supprimer'),
158
+ action: () => this.onAction('clear'),
159
+ });
160
+ }
161
+
162
+ return list;
163
+ }
164
+
165
+ doProxy(index) {
166
+ return (action, args) => {
167
+ const workitemId = `${this.props.editorWidget}${
168
+ this.props.mode ? `@${this.props.mode}` : ''
169
+ }@${this.context.desktopId}@${this.props.entityIds.get(index)}`;
170
+ this.doFor(workitemId, action, args);
171
+ };
172
+ }
173
+
174
+ open() {
175
+ this.showActionMenu = true;
176
+ }
177
+
178
+ close() {
179
+ this.showActionMenu = false;
180
+ }
181
+
182
+ /******************************************************************************/
183
+
184
+ renderHeaderSearch() {
185
+ if (this.props.searchHinter) {
186
+ return (
187
+ <Field
188
+ shape="rounded"
189
+ labelGlyph="solid/search"
190
+ labelWidth="24px"
191
+ fieldWidth="180px"
192
+ hintText={T('Ajouter existant')}
193
+ tooltip={T(
194
+ 'Ajouter un élément existant en le choisissant dans une liste'
195
+ )}
196
+ kind="hinter"
197
+ required={false}
198
+ hinter={this.props.searchHinter}
199
+ horizontalSpacing="large"
200
+ />
201
+ );
202
+ } else {
203
+ return null;
204
+ }
205
+ }
206
+
207
+ renderHeaderActionMenuButton(numberOfIds) {
208
+ const list = this.getActionMenuList(numberOfIds);
209
+ if (list.length > 0) {
210
+ return (
211
+ <Button
212
+ ref={(x) => (this.comboButton = x)}
213
+ glyph="solid/ellipsis-h"
214
+ horizontalSpacing="large"
215
+ active={this.showActionMenu}
216
+ onClick={this.open}
217
+ />
218
+ );
219
+ } else {
220
+ return null;
221
+ }
222
+ }
223
+
224
+ renderHeaderActionMenu(numberOfIds) {
225
+ if (this.showActionMenu) {
226
+ const node = ReactDOM.findDOMNode(this.comboButton);
227
+ const rect = node.getBoundingClientRect();
228
+ const top = Unit.add(
229
+ px(rect.bottom),
230
+ this.context.theme.shapes.flyingBalloonTriangleSize
231
+ );
232
+
233
+ return (
234
+ <Combo
235
+ menuType="menu"
236
+ left={(rect.left + rect.right) / 2}
237
+ top={top}
238
+ list={this.getActionMenuList(numberOfIds)}
239
+ close={this.close}
240
+ />
241
+ );
242
+ } else {
243
+ return null;
244
+ }
245
+ }
246
+
247
+ renderHeaderAdd(numberOfIds) {
248
+ const canAdd =
249
+ !this.props.disableAdd &&
250
+ (!this.props.arity ||
251
+ this.props.arity.endsWith('n') ||
252
+ (this.props.arity === '0..1' && numberOfIds === 0));
253
+
254
+ if (canAdd) {
255
+ return (
256
+ <Button
257
+ glyph="solid/plus"
258
+ text={this.props.addText || T('Ajouter')}
259
+ tooltip={this.props.addTooltip}
260
+ glyphPosition="right"
261
+ onClick={this.onActionAdd}
262
+ />
263
+ );
264
+ } else {
265
+ return null;
266
+ }
267
+ }
268
+
269
+ renderHeader(numberOfIds) {
270
+ const headerClass =
271
+ this.props.entityIds.size === 0
272
+ ? this.styles.classNames.headerEmpty
273
+ : this.styles.classNames.header;
274
+
275
+ const title = this.props.pluginTitle
276
+ ? this.props.pluginTitle
277
+ : this.props.title;
278
+
279
+ if (this.props.readonly) {
280
+ return (
281
+ <div className={headerClass}>
282
+ <Label text={title} grow="1" kind="title" />
283
+ </div>
284
+ );
285
+ } else {
286
+ return (
287
+ <div className={headerClass}>
288
+ <Label text={title} grow="1" kind="title" />
289
+ {this.renderHeaderSearch()}
290
+ {this.renderHeaderActionMenuButton(numberOfIds)}
291
+ {this.renderHeaderAdd(numberOfIds)}
292
+ {this.renderHeaderActionMenu(numberOfIds)}
293
+ </div>
294
+ );
295
+ }
296
+ }
297
+
298
+ renderItem(entityId, extended, index) {
299
+ const workitemUI = uiImporter(this.props.editorWidget);
300
+ const workitemId = `${this.props.editorWidget}${
301
+ this.props.mode ? `@${this.props.mode}` : ''
302
+ }@${this.context.desktopId}@${this.props.entityIds.get(index)}`;
303
+
304
+ if (!workitemUI.plugin) {
305
+ return null;
306
+ }
307
+
308
+ const itemClass = extended
309
+ ? this.props.embedded
310
+ ? this.styles.classNames.extendedEmbeddedItem
311
+ : this.styles.classNames.extendedItem
312
+ : this.props.embedded
313
+ ? this.styles.classNames.compactedEmbeddedItem
314
+ : this.styles.classNames.compactedItem;
315
+
316
+ const key1 = this.props.readonly ? 'readonly' : 'edit';
317
+ const key2 = extended ? 'extend' : 'compact';
318
+
319
+ let UI = workitemUI.plugin[key1][key2];
320
+ //let UI = this.WithState(
321
+ // workitemUI.plugin[key1][key2],
322
+ // 'entityId'
323
+ //)('.entityId');
324
+
325
+ if (
326
+ workitemUI.mappers &&
327
+ workitemUI.mappers.plugin &&
328
+ workitemUI.mappers.plugin[key1] &&
329
+ workitemUI.mappers.plugin[key1][key2]
330
+ ) {
331
+ UI = this.mapWidget(
332
+ UI,
333
+ workitemUI.mappers.plugin[key1][key2],
334
+ `backend.${entityId}`
335
+ );
336
+ }
337
+
338
+ const type = entityId.split('@', 1)[0];
339
+ const Loader = (props) => {
340
+ if (props.loaded) {
341
+ return (
342
+ <Workitem
343
+ id={workitemId}
344
+ entityId={entityId}
345
+ kind="form"
346
+ readonly={this.props.readonly}
347
+ dragServiceId={this.props.dragServiceId}
348
+ >
349
+ {this.buildLoader(entityId, () => (
350
+ <UI
351
+ id={workitemId}
352
+ theme={this.context.theme}
353
+ entityId={entityId}
354
+ embeddedLevel={this.props.embeddedLevel}
355
+ origin={this.props.origin}
356
+ contextId={this.context.contextId}
357
+ do={this.doProxy(index)}
358
+ entitySchema={this.getSchema(type)}
359
+ />
360
+ ))}
361
+ </Workitem>
362
+ );
363
+ } else {
364
+ return (
365
+ <Container busy={true}>
366
+ <Label text={T('chargement...')} />
367
+ </Container>
368
+ );
369
+ }
370
+ };
371
+
372
+ const LoadedWorkitem = this.mapWidget(
373
+ Loader,
374
+ (wid) => ({loaded: !!wid}),
375
+ `backend.${workitemId}.id`
376
+ );
377
+
378
+ return (
379
+ <div className={itemClass}>
380
+ <LoadedWorkitem />
381
+ </div>
382
+ );
383
+ }
384
+
385
+ renderButtons(entityId, extended, numberOfIds) {
386
+ if (extended) {
387
+ const buttonsClass = this.props.readonly
388
+ ? this.props.embedded
389
+ ? this.styles.classNames.extendedEmbeddedReadonlyButtons
390
+ : this.styles.classNames.extendedReadonlyButtons
391
+ : this.props.embedded
392
+ ? this.styles.classNames.extendedEmbeddedButtons
393
+ : this.styles.classNames.extendedButtons;
394
+
395
+ const canDelete =
396
+ !this.props.readonly &&
397
+ !this.props.disableDelete &&
398
+ (!this.props.arity ||
399
+ this.props.arity.startsWith('0') ||
400
+ numberOfIds > 1);
401
+
402
+ const kind = this.props.readonly ? 'plugin-light' : 'plugin-dark';
403
+
404
+ let otherButtons = null;
405
+ if (this.props.buttons) {
406
+ otherButtons = this.props.buttons(entityId);
407
+ }
408
+
409
+ return (
410
+ <div className={buttonsClass}>
411
+ <Button
412
+ width="32px"
413
+ kind={kind}
414
+ glyph="solid/angle-up"
415
+ glyphSize="180%"
416
+ tooltip={T('Replier')}
417
+ active={false}
418
+ activeColor={
419
+ this.context.theme.palette.recurrenceExtendedBoxBackground
420
+ }
421
+ onClick={() => this.onSwapExtended(entityId)}
422
+ />
423
+ <Button
424
+ width="32px"
425
+ kind={kind}
426
+ glyph="solid/pencil"
427
+ tooltip={T('Editer')}
428
+ onClick={() => this.onEditEntity(entityId)}
429
+ />
430
+ {otherButtons}
431
+ {canDelete ? (
432
+ <Button
433
+ width="32px"
434
+ kind={kind}
435
+ glyph="solid/trash"
436
+ tooltip={T('Supprimer')}
437
+ onClick={() => this.onDeleteEntity(entityId)}
438
+ />
439
+ ) : null}
440
+ </div>
441
+ );
442
+ } else {
443
+ const buttonsClass = this.props.readonly
444
+ ? this.props.embedded
445
+ ? this.styles.classNames.compactedEmbeddedReadonlyButtons
446
+ : this.styles.classNames.compactedReadonlyButtons
447
+ : this.props.embedded
448
+ ? this.styles.classNames.compactedEmbeddedButtons
449
+ : this.styles.classNames.compactedButtons;
450
+
451
+ const kind =
452
+ this.props.readonly || !this.props.embedded
453
+ ? 'plugin-light'
454
+ : 'plugin-dark';
455
+
456
+ return (
457
+ <div className={buttonsClass}>
458
+ {this.props.readonly && !this.props.embedded ? (
459
+ <Button
460
+ width="32px"
461
+ kind={kind}
462
+ glyph="solid/pencil"
463
+ tooltip={T('Editer')}
464
+ onClick={() => this.onEditEntity(entityId)}
465
+ />
466
+ ) : null}
467
+ <Button
468
+ width="32px"
469
+ kind={kind}
470
+ glyph="solid/angle-down"
471
+ glyphSize="180%"
472
+ tooltip={T('Etendre')}
473
+ active={false}
474
+ activeColor={
475
+ this.context.theme.palette.recurrenceExtendedBoxBackground
476
+ }
477
+ onClick={() => this.onSwapExtended(entityId)}
478
+ />
479
+ </div>
480
+ );
481
+ }
482
+ }
483
+
484
+ renderRowContent(entityId, extended, numberOfIds, index) {
485
+ const rowClass = extended
486
+ ? this.props.embedded
487
+ ? this.styles.classNames.extendedEmbeddedRow
488
+ : this.styles.classNames.extendedRow
489
+ : numberOfIds > 1 && this.props.horizontalSeparator !== 'compact'
490
+ ? this.props.embedded
491
+ ? this.styles.classNames.compactedEmbeddedDashedRow
492
+ : this.styles.classNames.compactedDashedRow
493
+ : this.props.embedded
494
+ ? this.styles.classNames.compactedEmbeddedRow
495
+ : this.styles.classNames.compactedRow;
496
+
497
+ return (
498
+ <Container
499
+ kind="row-draggable"
500
+ key={index}
501
+ ref={(n) => {
502
+ if (n) {
503
+ this._refs[entityId] = ReactDOM.findDOMNode(n);
504
+ }
505
+ }}
506
+ >
507
+ <div className={rowClass}>
508
+ {this.renderItem(entityId, extended, index)}
509
+ {this.renderButtons(entityId, extended, numberOfIds)}
510
+ </div>
511
+ </Container>
512
+ );
513
+ }
514
+
515
+ renderRow(entityId, extended, dragEnabled, numberOfIds, index) {
516
+ if (dragEnabled) {
517
+ return (
518
+ <DragCab
519
+ key={index}
520
+ dragController={this.props.dragType || this.props.id}
521
+ dragOwnerId={entityId}
522
+ dragMode="handle"
523
+ dragHandleWidth={this.context.theme.shapes.containerMargin}
524
+ direction="vertical"
525
+ color={this.context.theme.palette.dragAndDropHover}
526
+ thickness={this.context.theme.shapes.dragAndDropTicketThickness}
527
+ overSpacing="0px"
528
+ verticalSpacing="0px"
529
+ radius="0px"
530
+ doClickAction={() => this.onSwapExtended(entityId)}
531
+ doDragEnding={this.onEntityDragged}
532
+ >
533
+ {this.renderRowContent(entityId, extended, numberOfIds, index)}
534
+ </DragCab>
535
+ );
536
+ } else {
537
+ return this.renderRowContent(entityId, extended, numberOfIds, index);
538
+ }
539
+ }
540
+
541
+ renderRows(entityIds) {
542
+ const dragEnabled =
543
+ !this.props.readonly && (entityIds.length > 1 || !!this.props.dragType);
544
+
545
+ let index = 0;
546
+
547
+ return entityIds.map((entityId) => {
548
+ const extended = entityId === this.props.extendedId;
549
+ return this.renderRow(
550
+ entityId,
551
+ extended,
552
+ dragEnabled,
553
+ entityIds.length,
554
+ index++
555
+ );
556
+ });
557
+ }
558
+
559
+ renderDefault() {
560
+ const entityIds = this.props.entityIds.valueSeq().toArray();
561
+ if (entityIds.length === 0 && this.props.readonly && this.props.embedded) {
562
+ return null;
563
+ }
564
+
565
+ let boxClass = null;
566
+ if (!this.props.entityIds || this.props.entityIds.size === 0) {
567
+ boxClass = this.props.embedded
568
+ ? this.styles.classNames.emptyembeddedBox
569
+ : this.styles.classNames.emptyBox;
570
+ } else {
571
+ boxClass = this.props.embedded
572
+ ? this.styles.classNames.embeddedBox
573
+ : this.styles.classNames.box;
574
+ }
575
+
576
+ return (
577
+ <div className={boxClass}>
578
+ {this.renderHeader(entityIds.length)}
579
+ <Container
580
+ kind="column"
581
+ dragController={this.props.dragType || this.props.id}
582
+ dragSource={this.props.id}
583
+ dragOwnerId={this.props.id}
584
+ >
585
+ {this.renderRows(entityIds)}
586
+ </Container>
587
+ </div>
588
+ );
589
+ }
590
+
591
+ render() {
592
+ this._refs = {};
593
+
594
+ if (!this.props.id || !this.props.entityIds) {
595
+ return null;
596
+ }
597
+
598
+ if (!this.props.editorWidget) {
599
+ return null;
600
+ }
601
+
602
+ return this.renderDefault();
603
+ }
604
+ }
605
+
606
+ /******************************************************************************/
607
+
608
+ const select = (root) => (state, id) => (prop) => {
609
+ if (!id) {
610
+ return null;
611
+ }
612
+ const target = state.get(`${root}.${id}`);
613
+ if (!target) {
614
+ return null;
615
+ }
616
+ return target.get(prop);
617
+ };
618
+
619
+ const withBackend = select('backend');
620
+ const withWidget = select('widgets');
621
+
622
+ export default Widget.connect((state, props) => {
623
+ const plugin = withBackend(state, props.id);
624
+ const entity = withBackend(state, plugin('forEntity'));
625
+ const widget = withWidget(state, props.id);
626
+ return {
627
+ id: props.id,
628
+ title: plugin('title'),
629
+ editorWidget: plugin('editorWidget'),
630
+ arity: plugin('arity'),
631
+ mode: plugin('mode'),
632
+ entityIds: entity(plugin('entityPath')),
633
+ namespace: `${plugin('type')}-plugin`,
634
+ extendedId: widget('extendedId'),
635
+ };
636
+ })(Plugin);