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,399 +1,399 @@
1
- import React from 'react';
2
- import Widget from 'goblin-laboratory/widgets/widget';
3
- import DialogModal from 'goblin-gadgets/widgets/dialog-modal/widget';
4
- import Label from 'goblin-gadgets/widgets/label/widget';
5
- import Button from 'goblin-gadgets/widgets/button/widget';
6
- import TextFieldTypedNC from 'goblin-gadgets/widgets/text-field-typed-nc/widget';
7
- import Slider from 'goblin-gadgets/widgets/slider/widget';
8
- import CheckList from 'goblin-gadgets/widgets/check-list/widget';
9
- import FacetFilterRangeDialogFooter from '../facet-filter-range-dialog-footer/widget.js';
10
- import Junction from '../junction/widget.js';
11
- import {date as DateConverters} from 'xcraft-core-converters';
12
- import T from 't';
13
- import {Unit} from 'goblin-theme';
14
- const px = Unit.toPx;
15
-
16
- /******************************************************************************/
17
-
18
- class FacetFilterRangeDialog extends Widget {
19
- constructor() {
20
- super(...arguments);
21
-
22
- this.setFilter = this.setFilter.bind(this);
23
- this.handleChangeUseRange = this.handleChangeUseRange.bind(this);
24
- this.handleFieldFrom = this.handleFieldFrom.bind(this);
25
- this.handleFieldTo = this.handleFieldTo.bind(this);
26
- this.handleSlider = this.handleSlider.bind(this);
27
- this.onClose = this.onClose.bind(this);
28
-
29
- this.width = 480;
30
- this.sliderThickness = 24; // according to lib\goblin-gadgets\widgets\slider\styles.js
31
- }
32
-
33
- onClose() {
34
- this.props.onClose();
35
- }
36
-
37
- handleChangeUseRange(value) {
38
- if (value === 'all') {
39
- this.doAs('list', 'clear-range', {
40
- filterName: this.props.name,
41
- });
42
- } else {
43
- this.setFilter(this.props.min, this.props.max);
44
- }
45
- }
46
-
47
- setFilter(from, to, mode) {
48
- from = this.externalToSlider(from);
49
- to = this.externalToSlider(to);
50
-
51
- const min = this.externalToSlider(this.props.min);
52
- const max = this.externalToSlider(this.props.max);
53
-
54
- from = Math.max(Math.min(from, max), min);
55
- to = Math.max(Math.min(to, max), min);
56
-
57
- from = this.sliderToExternal(from);
58
- to = this.sliderToExternal(to);
59
-
60
- this.doAs('list', 'set-range', {
61
- filterName: this.props.name,
62
- from,
63
- to,
64
- mode,
65
- });
66
- }
67
-
68
- handleFieldFrom(value) {
69
- const from = this.externalToSlider(value);
70
- const to = this.externalToSlider(this.props.to);
71
- this.setFilter(value, this.sliderToExternal(Math.max(from, to)));
72
- }
73
-
74
- handleFieldTo(value) {
75
- const from = this.externalToSlider(this.props.from);
76
- const to = this.externalToSlider(value);
77
- this.setFilter(this.sliderToExternal(Math.min(from, to)), value);
78
- }
79
-
80
- handleSlider(value) {
81
- const a = value.split(';');
82
- const from = this.sliderToExternal(a[0]);
83
- const to = this.sliderToExternal(a[1]);
84
- this.setFilter(from, to);
85
- }
86
-
87
- /******************************************************************************/
88
-
89
- get hasRange() {
90
- return this.props.min !== null && this.props.max !== null;
91
- }
92
-
93
- externalToDisplayed(value) {
94
- if (this.props.type === 'date') {
95
- return DateConverters.getDisplayed(value);
96
- } else {
97
- return value;
98
- }
99
- }
100
-
101
- externalToSlider(value) {
102
- if (this.props.type === 'date') {
103
- value = DateConverters.canonicalToJs(value);
104
- const min = DateConverters.canonicalToJs(this.props.min);
105
- const days = (value - min) / (1000 * 60 * 60 * 24);
106
- return Math.round(days);
107
- } else {
108
- return value - this.props.min;
109
- }
110
- }
111
-
112
- sliderToExternal(n) {
113
- if (this.props.type === 'date') {
114
- if (typeof n === 'string') {
115
- n = parseInt(n);
116
- }
117
- const date = DateConverters.canonicalToJs(this.props.min);
118
- date.setDate(date.getDate() + n);
119
- return DateConverters.jsToCanonical(date);
120
- } else {
121
- return n + this.props.min;
122
- }
123
- }
124
-
125
- /******************************************************************************/
126
-
127
- renderClose() {
128
- return (
129
- <div className={this.styles.classNames.closeButton}>
130
- <Button
131
- border="none"
132
- glyph="solid/times"
133
- glyphSize="120%"
134
- tooltip={T('Fermer')}
135
- height="32px"
136
- width="32px"
137
- onClick={this.onClose}
138
- />
139
- </div>
140
- );
141
- }
142
-
143
- renderRadios() {
144
- const list = [{name: 'all', description: T('Tout')}];
145
-
146
- if (this.hasRange) {
147
- list.push({name: 'range', description: T('Intervalle')});
148
- }
149
-
150
- return (
151
- <div className={this.styles.classNames.radios}>
152
- <div className={this.styles.classNames.checkList}>
153
- <CheckList
154
- kind="radio"
155
- direction="row"
156
- selectionMode="single"
157
- list={list}
158
- value={this.hasRange && this.props.useRange ? 'range' : 'all'}
159
- selectionChanged={this.handleChangeUseRange}
160
- />
161
- </div>
162
- </div>
163
- );
164
- }
165
-
166
- renderFields(parentRect) {
167
- if (!this.hasRange || !this.props.useRange) {
168
- return null;
169
- }
170
-
171
- let minDate, maxDate, min, max;
172
-
173
- if (this.props.type === 'date') {
174
- minDate = this.props.min;
175
- maxDate = this.props.max;
176
- } else {
177
- min = this.props.min;
178
- max = this.props.max;
179
- }
180
-
181
- return (
182
- <div className={this.styles.classNames.fields}>
183
- <TextFieldTypedNC
184
- parentRect={parentRect}
185
- type={this.props.type}
186
- minDate={minDate}
187
- maxDate={maxDate}
188
- min={min}
189
- max={max}
190
- mode="hard"
191
- value={this.props.from}
192
- onChange={this.handleFieldFrom}
193
- />
194
- <Label grow="1" />
195
- {this.props.max > this.props.min ? (
196
- <TextFieldTypedNC
197
- parentRect={parentRect}
198
- type={this.props.type}
199
- minDate={minDate}
200
- maxDate={maxDate}
201
- min={min}
202
- max={max}
203
- mode="hard"
204
- value={this.props.to}
205
- onChange={this.handleFieldTo}
206
- />
207
- ) : null}
208
- </div>
209
- );
210
- }
211
-
212
- renderJunction() {
213
- if (!this.hasRange || !this.props.useRange) {
214
- return null;
215
- }
216
-
217
- const min = this.externalToSlider(this.props.min);
218
- const max = this.externalToSlider(this.props.max);
219
- const from = Math.max(this.externalToSlider(this.props.from), min);
220
- const to = Math.min(this.externalToSlider(this.props.to), max);
221
-
222
- const w = this.width - 30 * 2;
223
-
224
- const fieldWidth = 150;
225
- let x1From = fieldWidth / 2;
226
- let x1To = w - fieldWidth / 2;
227
-
228
- const sliderWidth = w - this.sliderThickness;
229
- const x2From =
230
- this.sliderThickness / 2 +
231
- ((from - min) / Math.max(max - min, 1)) * sliderWidth;
232
- const x2To =
233
- this.sliderThickness / 2 +
234
- ((to - min) / Math.max(max - min, 1)) * sliderWidth;
235
-
236
- if (x2From > x1From - 20 && x2From < x1From + 20) {
237
- x1From = x2From;
238
- }
239
- if (x2To > x1To - 20 && x2To < x1To + 20) {
240
- x1To = x2To;
241
- }
242
-
243
- const h = 30;
244
- const shift = 3;
245
- let yFrom, yTo;
246
- if (x2To < x1From + shift && x2From !== x2To) {
247
- yFrom = h / 2 - shift;
248
- yTo = h / 2 + shift;
249
- } else if (x2From > x1To - shift && x2From !== x2To) {
250
- yFrom = h / 2 + shift;
251
- yTo = h / 2 - shift;
252
- } else {
253
- yFrom = h / 2;
254
- yTo = h / 2;
255
- }
256
-
257
- const color = this.context.theme.palette.buttonBorder;
258
-
259
- return (
260
- <div className={this.styles.classNames.junctions}>
261
- <Junction color={color} w={w} h={h} y={yFrom} x1={x1From} x2={x2From} />
262
- {this.props.max > this.props.min ? (
263
- <Junction color={color} w={w} h={h} y={yTo} x1={x1To} x2={x2To} />
264
- ) : null}
265
- </div>
266
- );
267
- }
268
-
269
- renderSliders() {
270
- if (!this.hasRange || !this.props.useRange) {
271
- return null;
272
- }
273
-
274
- const value1 = this.externalToSlider(this.props.from);
275
- const value2 = this.externalToSlider(this.props.to);
276
- const value = `${value1};${value2}`;
277
-
278
- return (
279
- <div className={this.styles.classNames.sliders}>
280
- <Slider
281
- grow="1"
282
- direction="horizontal"
283
- barColor="#0f0"
284
- barPosition="middle"
285
- disabled={this.props.max === this.props.min}
286
- min={0}
287
- max={this.externalToSlider(this.props.max)}
288
- step={1}
289
- value={value}
290
- changeMode="throttled"
291
- throttleDelay={200}
292
- onChange={this.handleSlider}
293
- />
294
- </div>
295
- );
296
- }
297
-
298
- renderMinMax() {
299
- if (!this.hasRange || !this.props.useRange) {
300
- return null;
301
- }
302
-
303
- const min = this.externalToDisplayed(this.props.min);
304
- const max = this.externalToDisplayed(this.props.max);
305
-
306
- return (
307
- <div className={this.styles.classNames.minmax}>
308
- <Label fontSize="70%" disabled={true} text={min} />
309
- <Label grow="1" />
310
- {this.props.max > this.props.min ? (
311
- <Label fontSize="70%" disabled={true} text={max} justify="end" />
312
- ) : null}
313
- </div>
314
- );
315
- }
316
-
317
- renderFooter() {
318
- return (
319
- <FacetFilterRangeDialogFooter
320
- id={this.props.id}
321
- name={this.props.name}
322
- type={this.props.type}
323
- min={this.props.min}
324
- max={this.props.max}
325
- from={this.props.from}
326
- to={this.props.to}
327
- useRange={this.hasRange && this.props.useRange}
328
- setFilter={this.setFilter}
329
- />
330
- );
331
- }
332
-
333
- // Build UI for range of dates or number.
334
- renderRange(parentRect) {
335
- return (
336
- <div className={this.styles.classNames.facetFilterDialog}>
337
- {this.renderRadios()}
338
- <div className={this.styles.classNames.content}>
339
- {this.renderFields(parentRect)}
340
- {this.renderJunction()}
341
- {this.renderSliders()}
342
- {this.renderMinMax()}
343
- </div>
344
- {this.renderFooter()}
345
- {this.renderClose()}
346
- </div>
347
- );
348
- }
349
-
350
- render() {
351
- if (this.props.loading) {
352
- return null;
353
- }
354
-
355
- const r = this.props.parentButtonRect;
356
- const centerY = r.top + r.height / 2;
357
- const width = this.width;
358
- const height = 280;
359
- const shiftY = 0;
360
-
361
- const parentRect = {
362
- left: r.right + 40,
363
- right: r.right + 40 + width,
364
- top: centerY - height / 2,
365
- bottom: centerY + height / 2,
366
- };
367
-
368
- return (
369
- <DialogModal
370
- width={px(width)}
371
- height={px(height)}
372
- left={px(r.right + 40)}
373
- center={px(centerY)}
374
- triangleShift={px(shiftY)}
375
- backgroundClose={true}
376
- close={this.onClose}
377
- >
378
- {this.renderRange(parentRect)}
379
- </DialogModal>
380
- );
381
- }
382
- }
383
-
384
- /******************************************************************************/
385
-
386
- export default Widget.connect((state, props) => {
387
- const range = state.get(`backend.${props.id}.ranges.${props.name}`);
388
- if (range) {
389
- const useRange = range.get('useRange', false);
390
- const min = range.get('min');
391
- const max = range.get('max');
392
- const from = range.get('from', min);
393
- const to = range.get('to', max);
394
-
395
- return {useRange, min, max, from, to};
396
- } else {
397
- return {loading: true};
398
- }
399
- })(FacetFilterRangeDialog);
1
+ import React from 'react';
2
+ import Widget from 'goblin-laboratory/widgets/widget';
3
+ import DialogModal from 'goblin-gadgets/widgets/dialog-modal/widget';
4
+ import Label from 'goblin-gadgets/widgets/label/widget';
5
+ import Button from 'goblin-gadgets/widgets/button/widget';
6
+ import TextFieldTypedNC from 'goblin-gadgets/widgets/text-field-typed-nc/widget';
7
+ import Slider from 'goblin-gadgets/widgets/slider/widget';
8
+ import CheckList from 'goblin-gadgets/widgets/check-list/widget';
9
+ import FacetFilterRangeDialogFooter from '../facet-filter-range-dialog-footer/widget.js';
10
+ import Junction from '../junction/widget.js';
11
+ import {date as DateConverters} from 'xcraft-core-converters';
12
+ import T from 't';
13
+ import {Unit} from 'goblin-theme';
14
+ const px = Unit.toPx;
15
+
16
+ /******************************************************************************/
17
+
18
+ class FacetFilterRangeDialog extends Widget {
19
+ constructor() {
20
+ super(...arguments);
21
+
22
+ this.setFilter = this.setFilter.bind(this);
23
+ this.handleChangeUseRange = this.handleChangeUseRange.bind(this);
24
+ this.handleFieldFrom = this.handleFieldFrom.bind(this);
25
+ this.handleFieldTo = this.handleFieldTo.bind(this);
26
+ this.handleSlider = this.handleSlider.bind(this);
27
+ this.onClose = this.onClose.bind(this);
28
+
29
+ this.width = 480;
30
+ this.sliderThickness = 24; // according to lib\goblin-gadgets\widgets\slider\styles.js
31
+ }
32
+
33
+ onClose() {
34
+ this.props.onClose();
35
+ }
36
+
37
+ handleChangeUseRange(value) {
38
+ if (value === 'all') {
39
+ this.doAs('list', 'clear-range', {
40
+ filterName: this.props.name,
41
+ });
42
+ } else {
43
+ this.setFilter(this.props.min, this.props.max);
44
+ }
45
+ }
46
+
47
+ setFilter(from, to, mode) {
48
+ from = this.externalToSlider(from);
49
+ to = this.externalToSlider(to);
50
+
51
+ const min = this.externalToSlider(this.props.min);
52
+ const max = this.externalToSlider(this.props.max);
53
+
54
+ from = Math.max(Math.min(from, max), min);
55
+ to = Math.max(Math.min(to, max), min);
56
+
57
+ from = this.sliderToExternal(from);
58
+ to = this.sliderToExternal(to);
59
+
60
+ this.doAs('list', 'set-range', {
61
+ filterName: this.props.name,
62
+ from,
63
+ to,
64
+ mode,
65
+ });
66
+ }
67
+
68
+ handleFieldFrom(value) {
69
+ const from = this.externalToSlider(value);
70
+ const to = this.externalToSlider(this.props.to);
71
+ this.setFilter(value, this.sliderToExternal(Math.max(from, to)));
72
+ }
73
+
74
+ handleFieldTo(value) {
75
+ const from = this.externalToSlider(this.props.from);
76
+ const to = this.externalToSlider(value);
77
+ this.setFilter(this.sliderToExternal(Math.min(from, to)), value);
78
+ }
79
+
80
+ handleSlider(value) {
81
+ const a = value.split(';');
82
+ const from = this.sliderToExternal(a[0]);
83
+ const to = this.sliderToExternal(a[1]);
84
+ this.setFilter(from, to);
85
+ }
86
+
87
+ /******************************************************************************/
88
+
89
+ get hasRange() {
90
+ return this.props.min !== null && this.props.max !== null;
91
+ }
92
+
93
+ externalToDisplayed(value) {
94
+ if (this.props.type === 'date') {
95
+ return DateConverters.getDisplayed(value);
96
+ } else {
97
+ return value;
98
+ }
99
+ }
100
+
101
+ externalToSlider(value) {
102
+ if (this.props.type === 'date') {
103
+ value = DateConverters.canonicalToJs(value);
104
+ const min = DateConverters.canonicalToJs(this.props.min);
105
+ const days = (value - min) / (1000 * 60 * 60 * 24);
106
+ return Math.round(days);
107
+ } else {
108
+ return value - this.props.min;
109
+ }
110
+ }
111
+
112
+ sliderToExternal(n) {
113
+ if (this.props.type === 'date') {
114
+ if (typeof n === 'string') {
115
+ n = parseInt(n);
116
+ }
117
+ const date = DateConverters.canonicalToJs(this.props.min);
118
+ date.setDate(date.getDate() + n);
119
+ return DateConverters.jsToCanonical(date);
120
+ } else {
121
+ return n + this.props.min;
122
+ }
123
+ }
124
+
125
+ /******************************************************************************/
126
+
127
+ renderClose() {
128
+ return (
129
+ <div className={this.styles.classNames.closeButton}>
130
+ <Button
131
+ border="none"
132
+ glyph="solid/times"
133
+ glyphSize="120%"
134
+ tooltip={T('Fermer')}
135
+ height="32px"
136
+ width="32px"
137
+ onClick={this.onClose}
138
+ />
139
+ </div>
140
+ );
141
+ }
142
+
143
+ renderRadios() {
144
+ const list = [{name: 'all', description: T('Tout')}];
145
+
146
+ if (this.hasRange) {
147
+ list.push({name: 'range', description: T('Intervalle')});
148
+ }
149
+
150
+ return (
151
+ <div className={this.styles.classNames.radios}>
152
+ <div className={this.styles.classNames.checkList}>
153
+ <CheckList
154
+ kind="radio"
155
+ direction="row"
156
+ selectionMode="single"
157
+ list={list}
158
+ value={this.hasRange && this.props.useRange ? 'range' : 'all'}
159
+ selectionChanged={this.handleChangeUseRange}
160
+ />
161
+ </div>
162
+ </div>
163
+ );
164
+ }
165
+
166
+ renderFields(parentRect) {
167
+ if (!this.hasRange || !this.props.useRange) {
168
+ return null;
169
+ }
170
+
171
+ let minDate, maxDate, min, max;
172
+
173
+ if (this.props.type === 'date') {
174
+ minDate = this.props.min;
175
+ maxDate = this.props.max;
176
+ } else {
177
+ min = this.props.min;
178
+ max = this.props.max;
179
+ }
180
+
181
+ return (
182
+ <div className={this.styles.classNames.fields}>
183
+ <TextFieldTypedNC
184
+ parentRect={parentRect}
185
+ type={this.props.type}
186
+ minDate={minDate}
187
+ maxDate={maxDate}
188
+ min={min}
189
+ max={max}
190
+ mode="hard"
191
+ value={this.props.from}
192
+ onChange={this.handleFieldFrom}
193
+ />
194
+ <Label grow="1" />
195
+ {this.props.max > this.props.min ? (
196
+ <TextFieldTypedNC
197
+ parentRect={parentRect}
198
+ type={this.props.type}
199
+ minDate={minDate}
200
+ maxDate={maxDate}
201
+ min={min}
202
+ max={max}
203
+ mode="hard"
204
+ value={this.props.to}
205
+ onChange={this.handleFieldTo}
206
+ />
207
+ ) : null}
208
+ </div>
209
+ );
210
+ }
211
+
212
+ renderJunction() {
213
+ if (!this.hasRange || !this.props.useRange) {
214
+ return null;
215
+ }
216
+
217
+ const min = this.externalToSlider(this.props.min);
218
+ const max = this.externalToSlider(this.props.max);
219
+ const from = Math.max(this.externalToSlider(this.props.from), min);
220
+ const to = Math.min(this.externalToSlider(this.props.to), max);
221
+
222
+ const w = this.width - 30 * 2;
223
+
224
+ const fieldWidth = 150;
225
+ let x1From = fieldWidth / 2;
226
+ let x1To = w - fieldWidth / 2;
227
+
228
+ const sliderWidth = w - this.sliderThickness;
229
+ const x2From =
230
+ this.sliderThickness / 2 +
231
+ ((from - min) / Math.max(max - min, 1)) * sliderWidth;
232
+ const x2To =
233
+ this.sliderThickness / 2 +
234
+ ((to - min) / Math.max(max - min, 1)) * sliderWidth;
235
+
236
+ if (x2From > x1From - 20 && x2From < x1From + 20) {
237
+ x1From = x2From;
238
+ }
239
+ if (x2To > x1To - 20 && x2To < x1To + 20) {
240
+ x1To = x2To;
241
+ }
242
+
243
+ const h = 30;
244
+ const shift = 3;
245
+ let yFrom, yTo;
246
+ if (x2To < x1From + shift && x2From !== x2To) {
247
+ yFrom = h / 2 - shift;
248
+ yTo = h / 2 + shift;
249
+ } else if (x2From > x1To - shift && x2From !== x2To) {
250
+ yFrom = h / 2 + shift;
251
+ yTo = h / 2 - shift;
252
+ } else {
253
+ yFrom = h / 2;
254
+ yTo = h / 2;
255
+ }
256
+
257
+ const color = this.context.theme.palette.buttonBorder;
258
+
259
+ return (
260
+ <div className={this.styles.classNames.junctions}>
261
+ <Junction color={color} w={w} h={h} y={yFrom} x1={x1From} x2={x2From} />
262
+ {this.props.max > this.props.min ? (
263
+ <Junction color={color} w={w} h={h} y={yTo} x1={x1To} x2={x2To} />
264
+ ) : null}
265
+ </div>
266
+ );
267
+ }
268
+
269
+ renderSliders() {
270
+ if (!this.hasRange || !this.props.useRange) {
271
+ return null;
272
+ }
273
+
274
+ const value1 = this.externalToSlider(this.props.from);
275
+ const value2 = this.externalToSlider(this.props.to);
276
+ const value = `${value1};${value2}`;
277
+
278
+ return (
279
+ <div className={this.styles.classNames.sliders}>
280
+ <Slider
281
+ grow="1"
282
+ direction="horizontal"
283
+ barColor="#0f0"
284
+ barPosition="middle"
285
+ disabled={this.props.max === this.props.min}
286
+ min={0}
287
+ max={this.externalToSlider(this.props.max)}
288
+ step={1}
289
+ value={value}
290
+ changeMode="throttled"
291
+ throttleDelay={200}
292
+ onChange={this.handleSlider}
293
+ />
294
+ </div>
295
+ );
296
+ }
297
+
298
+ renderMinMax() {
299
+ if (!this.hasRange || !this.props.useRange) {
300
+ return null;
301
+ }
302
+
303
+ const min = this.externalToDisplayed(this.props.min);
304
+ const max = this.externalToDisplayed(this.props.max);
305
+
306
+ return (
307
+ <div className={this.styles.classNames.minmax}>
308
+ <Label fontSize="70%" disabled={true} text={min} />
309
+ <Label grow="1" />
310
+ {this.props.max > this.props.min ? (
311
+ <Label fontSize="70%" disabled={true} text={max} justify="end" />
312
+ ) : null}
313
+ </div>
314
+ );
315
+ }
316
+
317
+ renderFooter() {
318
+ return (
319
+ <FacetFilterRangeDialogFooter
320
+ id={this.props.id}
321
+ name={this.props.name}
322
+ type={this.props.type}
323
+ min={this.props.min}
324
+ max={this.props.max}
325
+ from={this.props.from}
326
+ to={this.props.to}
327
+ useRange={this.hasRange && this.props.useRange}
328
+ setFilter={this.setFilter}
329
+ />
330
+ );
331
+ }
332
+
333
+ // Build UI for range of dates or number.
334
+ renderRange(parentRect) {
335
+ return (
336
+ <div className={this.styles.classNames.facetFilterDialog}>
337
+ {this.renderRadios()}
338
+ <div className={this.styles.classNames.content}>
339
+ {this.renderFields(parentRect)}
340
+ {this.renderJunction()}
341
+ {this.renderSliders()}
342
+ {this.renderMinMax()}
343
+ </div>
344
+ {this.renderFooter()}
345
+ {this.renderClose()}
346
+ </div>
347
+ );
348
+ }
349
+
350
+ render() {
351
+ if (this.props.loading) {
352
+ return null;
353
+ }
354
+
355
+ const r = this.props.parentButtonRect;
356
+ const centerY = r.top + r.height / 2;
357
+ const width = this.width;
358
+ const height = 280;
359
+ const shiftY = 0;
360
+
361
+ const parentRect = {
362
+ left: r.right + 40,
363
+ right: r.right + 40 + width,
364
+ top: centerY - height / 2,
365
+ bottom: centerY + height / 2,
366
+ };
367
+
368
+ return (
369
+ <DialogModal
370
+ width={px(width)}
371
+ height={px(height)}
372
+ left={px(r.right + 40)}
373
+ center={px(centerY)}
374
+ triangleShift={px(shiftY)}
375
+ backgroundClose={true}
376
+ close={this.onClose}
377
+ >
378
+ {this.renderRange(parentRect)}
379
+ </DialogModal>
380
+ );
381
+ }
382
+ }
383
+
384
+ /******************************************************************************/
385
+
386
+ export default Widget.connect((state, props) => {
387
+ const range = state.get(`backend.${props.id}.ranges.${props.name}`);
388
+ if (range) {
389
+ const useRange = range.get('useRange', false);
390
+ const min = range.get('min');
391
+ const max = range.get('max');
392
+ const from = range.get('from', min);
393
+ const to = range.get('to', max);
394
+
395
+ return {useRange, min, max, from, to};
396
+ } else {
397
+ return {loading: true};
398
+ }
399
+ })(FacetFilterRangeDialog);