@eturnity/eturnity_reusable_components 6.43.0 → 6.43.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "6.43.0",
3
+ "version": "6.43.2",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
@@ -11,11 +11,14 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@vueform/slider": "1.0.5",
14
- "core-js": "^3.31.1",
15
14
  "html-loader": "0.5.5",
15
+ "postcss": "^8.4.25",
16
16
  "v-click-outside": "2.1.4",
17
17
  "vue": "2.6.11",
18
- "vue-styled-components": "1.6.0"
18
+ "vue-styled-components": "1.6.0",
19
+ "vue2-datepicker": "3.11.1",
20
+ "vuedraggable": "2.24.3",
21
+ "core-js": "^3.31.1"
19
22
  },
20
23
  "devDependencies": {
21
24
  "@storybook/addon-actions": "6.2.8",
@@ -60,4 +63,4 @@
60
63
  "author": "Aaron Enser",
61
64
  "license": "ISC",
62
65
  "homepage": "https://bitbucket.org/eturnitydevs/eturnity_reusable_components#readme"
63
- }
66
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ // Add your PostCSS plugins here
4
+ // Example: require('autoprefixer')
5
+ }
6
+ }
@@ -0,0 +1,3 @@
1
+ <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M11.4545 4.45454L8.90909 7H10.8182C10.8182 9.10636 9.10636 10.8182 7 10.8182C6.35727 10.8182 5.74636 10.6591 5.21818 10.3727L4.28909 11.3018C5.07182 11.7982 6.00091 12.0909 7 12.0909C9.81273 12.0909 12.0909 9.81272 12.0909 7H14L11.4545 4.45454ZM3.18182 7C3.18182 4.89363 4.89364 3.18182 7 3.18182C7.64273 3.18182 8.25364 3.34091 8.78182 3.62727L9.71091 2.69818C8.92818 2.20182 7.99909 1.90909 7 1.90909C4.18727 1.90909 1.90909 4.18727 1.90909 7H0L2.54545 9.54545L5.09091 7H3.18182Z" fill="#263238"/>
3
+ </svg>
@@ -0,0 +1,645 @@
1
+ <template>
2
+ <container-wrapper>
3
+ <upper-container v-if="filterViews && filterViews.length">
4
+ <view-container :maxWidth="activeView.length">
5
+ <select-component
6
+ @click.native.stop
7
+ selectWidth="100%"
8
+ selectHeight="36px"
9
+ fontSize="13px"
10
+ :label="$gettext('active_filter')"
11
+ alignItems="vertical"
12
+ >
13
+ <template #selector>
14
+ <option-title>
15
+ {{ activeView }}
16
+ </option-title>
17
+ </template>
18
+ <template #dropdown>
19
+ <Option
20
+ v-for="(item, idx) in filterViews"
21
+ :key="idx + '_view'"
22
+ @click.native="$emit('on-view-select', item)"
23
+ :value="item.name"
24
+ >{{ item.name }}
25
+ <delete-icon @click.native.stop="$emit('on-view-delete', item)"
26
+ /></Option>
27
+ </template>
28
+ </select-component>
29
+ </view-container>
30
+ <reset-button @click="$emit('on-reset-filters')">
31
+ <icon :name="'update'" size="14px" :color="theme.colors.blue" />
32
+ <div>{{ $gettext('reset_filters') }}</div>
33
+ </reset-button>
34
+ </upper-container>
35
+ <column-wrapper
36
+ :numCols="filterData.length"
37
+ :hasActiveView="!!filterViews && !!filterViews.length"
38
+ >
39
+ <column-container
40
+ v-for="(item, idx) in filterData"
41
+ :key="idx + '_filterdata'"
42
+ >
43
+ <column-title :showBorder="idx + 1 !== filterData.length">
44
+ {{ item.columnName }}
45
+ </column-title>
46
+ <row-container v-if="item.type === 'columns'">
47
+ <checkbox-container>
48
+ <draggable
49
+ @change="onDragChange({ data: item.dataOptions })"
50
+ handle=".drag-container"
51
+ style="display: contents"
52
+ ghost-class="ghost"
53
+ :setData="modifyDragItem"
54
+ v-model="item.dataOptions"
55
+ >
56
+ <checkbox-wrapper
57
+ v-for="(column, index) in item.dataOptions"
58
+ :key="index + 'dataOption'"
59
+ >
60
+ <drag-container class="drag-container">
61
+ <icon :name="'duplicate-1'" size="12px" />
62
+ </drag-container>
63
+ <checkbox
64
+ :label="column.text"
65
+ :isChecked="column.selected"
66
+ @on-event-handler="
67
+ onChange({
68
+ dataType: item.type,
69
+ value: $event,
70
+ choice: column.choice
71
+ })
72
+ "
73
+ size="small"
74
+ :isDisabled="column.selected && isCheckboxDisabled"
75
+ />
76
+ </checkbox-wrapper>
77
+ </draggable>
78
+ </checkbox-container>
79
+ </row-container>
80
+ <row-container v-if="item.type === 'filter'" showBorder>
81
+ <row-wrapper
82
+ v-for="(filter, index) in item.dataOptions"
83
+ :key="index + '_field'"
84
+ >
85
+ <select-component
86
+ v-if="isMultipleSelector(filter.filter_type)"
87
+ selectWidth="100%"
88
+ selectHeight="36px"
89
+ fontSize="13px"
90
+ :label="filter.label"
91
+ alignItems="vertical"
92
+ :disabled="!filter.choices.length"
93
+ >
94
+ <template #selector>
95
+ <option-title>
96
+ {{ filter.selectedText }}
97
+ </option-title>
98
+ </template>
99
+ <template #dropdown>
100
+ <dropdown-checkbox-container @click.stop>
101
+ <checkbox
102
+ v-for="(filterOption, optionIdx) in filter.choices"
103
+ :key="optionIdx + 'optionIdx'"
104
+ :label="filterOption.text"
105
+ :isChecked="filterOption.selected"
106
+ @on-event-handler="
107
+ onChange({
108
+ dataType: item.type,
109
+ value: $event,
110
+ choice: filterOption.choice,
111
+ field: filter.field
112
+ })
113
+ "
114
+ size="small"
115
+ />
116
+ </dropdown-checkbox-container>
117
+ </template>
118
+ </select-component>
119
+ <section-container v-else-if="isRangeSelector(filter.filter_type)">
120
+ <row-label>{{ filter.label }}</row-label>
121
+ <grid-container>
122
+ <input-number
123
+ :placeholder="
124
+ filter.unit
125
+ ? $gettext('min') + ' (' + filter.unit + ')'
126
+ : $gettext('min')
127
+ "
128
+ :numberPrecision="2"
129
+ :value="filter.range.start"
130
+ @input-change="
131
+ onChange({
132
+ dataType: item.type,
133
+ value: $event,
134
+ choice: 'start',
135
+ field: filter.field
136
+ })
137
+ "
138
+ fontSize="13px"
139
+ inputHeight="36px"
140
+ :unitName="filter.unit"
141
+ />
142
+ <input-number
143
+ :placeholder="
144
+ filter.unit
145
+ ? $gettext('max') + ' (' + filter.unit + ')'
146
+ : $gettext('max')
147
+ "
148
+ :numberPrecision="2"
149
+ :value="filter.range.end"
150
+ @input-change="
151
+ onChange({
152
+ dataType: item.type,
153
+ value: $event,
154
+ choice: 'end',
155
+ field: filter.field
156
+ })
157
+ "
158
+ fontSize="13px"
159
+ inputHeight="36px"
160
+ :unitName="filter.unit"
161
+ />
162
+ </grid-container>
163
+ </section-container>
164
+ <section-container
165
+ v-else-if="isDateSelector(filter.filter_type)"
166
+ @click.stop
167
+ >
168
+ <row-label>{{ filter.label }}</row-label>
169
+ <grid-container>
170
+ <date-picker-input
171
+ :placeholder="$gettext('Date from')"
172
+ :lang="getDatePickerLanguage()"
173
+ type="date"
174
+ :value="filter.range.start"
175
+ @change="
176
+ onChange({
177
+ dataType: item.type,
178
+ value: $event,
179
+ choice: 'start',
180
+ field: filter.field
181
+ })
182
+ "
183
+ @focus="onDatepickerFocus(filter.range)"
184
+ @close="onDatepickerBlur()"
185
+ format="YYYY-MM-DD"
186
+ valueType="format"
187
+ :disabled-date="disableFutureDates"
188
+ />
189
+ <date-picker-input
190
+ :placeholder="$gettext('Date to')"
191
+ :lang="getDatePickerLanguage()"
192
+ type="date"
193
+ :value="filter.range.end"
194
+ @change="
195
+ onChange({
196
+ dataType: item.type,
197
+ value: $event,
198
+ choice: 'end',
199
+ field: filter.field
200
+ })
201
+ "
202
+ @focus="onDatepickerFocus(filter.range)"
203
+ @close="onDatepickerBlur()"
204
+ format="YYYY-MM-DD"
205
+ valueType="format"
206
+ :disabled-date="disablePastDates"
207
+ />
208
+ </grid-container>
209
+ </section-container>
210
+ <select-component
211
+ v-else
212
+ selectWidth="100%"
213
+ selectHeight="36px"
214
+ fontSize="13px"
215
+ :label="filter.label"
216
+ alignItems="vertical"
217
+ :disabled="!filter.choices.length"
218
+ >
219
+ <template #selector="{ selectedValue }">
220
+ <option-title>
221
+ {{
222
+ getSelectedValue({
223
+ value: selectedValue,
224
+ options: filter.choices,
225
+ filter
226
+ })
227
+ }}
228
+ </option-title>
229
+ </template>
230
+ <template #dropdown>
231
+ <Option
232
+ v-for="(filterOption, filterIdx) in filter.choices"
233
+ :key="filterIdx + '_filterIdx'"
234
+ :value="filterOption.choice"
235
+ >{{ filterOption.text }}</Option
236
+ >
237
+ </template>
238
+ </select-component>
239
+ </row-wrapper>
240
+ </row-container>
241
+ </column-container>
242
+ </column-wrapper>
243
+ <button-container>
244
+ <main-button
245
+ v-if="buttonText.apply_view"
246
+ type="primary"
247
+ :text="buttonText.apply_view"
248
+ @click.native="$emit('on-apply-current-view')"
249
+ />
250
+ <main-button
251
+ type="secondary"
252
+ v-if="buttonText.save_view"
253
+ :text="buttonText.save_view"
254
+ @click.native="$emit('on-save-new-view')"
255
+ />
256
+ <main-button
257
+ type="cancel"
258
+ v-if="buttonText.cancel"
259
+ :text="buttonText.cancel"
260
+ @click.native="$emit('on-cancel-view')"
261
+ />
262
+ </button-container>
263
+ </container-wrapper>
264
+ </template>
265
+
266
+ <script>
267
+ import styled from 'vue-styled-components'
268
+ import DatePicker from 'vue2-datepicker'
269
+ import SelectComponent from '../inputs/select'
270
+ import Option from '../inputs/select/option'
271
+ import InputNumber from '../inputs/inputNumber'
272
+ import MainButton from '../buttons/mainButton'
273
+ import Checkbox from '../inputs/checkbox'
274
+ import draggable from 'vuedraggable'
275
+ import Icon from '../icon'
276
+ import DeleteIcon from '../deleteIcon'
277
+ import { datePickerLang } from '../../helpers/translateLang'
278
+ import theme from '@/assets/theme.js'
279
+ import 'vue2-datepicker/index.css'
280
+ import 'vue2-datepicker/locale/de'
281
+ import 'vue2-datepicker/locale/en'
282
+ import 'vue2-datepicker/locale/es'
283
+ import 'vue2-datepicker/locale/fr'
284
+ import 'vue2-datepicker/locale/it'
285
+
286
+ const ContainerWrapper = styled.div`
287
+ position: absolute;
288
+ margin-top: 4px;
289
+ background-color: ${(props) => props.theme.colors.white};
290
+ min-width: 100%;
291
+ width: max-content;
292
+ border: 1px solid ${(props) => props.theme.colors.grey4};
293
+ border-radius: 4px;
294
+ z-index: 9999;
295
+ font-size: 13px;
296
+ `
297
+
298
+ const ColAttrs = { numCols: Number, hasActiveView: Boolean }
299
+ const ColumnWrapper = styled('div', ColAttrs)`
300
+ display: grid;
301
+ grid-template-columns: repeat(${(props) => props.numCols}, auto);
302
+
303
+ ${({ hasActiveView, theme }) =>
304
+ hasActiveView &&
305
+ `
306
+ border-top: 1px solid ${theme.colors.grey4};
307
+ `}
308
+ `
309
+
310
+ const TitleAttrs = { showBorder: Boolean }
311
+ const ColumnTitle = styled('div', TitleAttrs)`
312
+ font-size: 14px;
313
+ font-weight: 700;
314
+ color: ${(props) => props.theme.colors.eturnityGrey};
315
+ padding: 10px 14px;
316
+ ${({ showBorder, theme }) =>
317
+ showBorder &&
318
+ `
319
+ border-right: 1px solid ${theme.colors.grey4};
320
+ `}
321
+ `
322
+
323
+ const ButtonContainer = styled.div`
324
+ display: flex;
325
+ gap: 10px;
326
+ padding: 15px;
327
+ `
328
+
329
+ const ColumnContainer = styled.div``
330
+
331
+ const DragContainer = styled.div`
332
+ cursor: grab;
333
+
334
+ &:active {
335
+ cursor: grabbing;
336
+ }
337
+ `
338
+
339
+ const RowContainer = styled('div', TitleAttrs)`
340
+ padding: 10px 14px;
341
+ width: 300px;
342
+
343
+ ${({ showBorder, theme }) =>
344
+ showBorder &&
345
+ `
346
+ border-right: 1px solid ${theme.colors.grey4};
347
+ `}
348
+
349
+ .ghost {
350
+ opacity: 0.5;
351
+ background-color: #e5fcb4;
352
+ }
353
+ `
354
+
355
+ const OptionTitle = styled.div`
356
+ cursor: pointer !important;
357
+ `
358
+
359
+ const CheckboxContainer = styled.div`
360
+ display: grid;
361
+ gap: 6px;
362
+ `
363
+
364
+ const CheckboxWrapper = styled.div`
365
+ display: grid;
366
+ grid-template-columns: auto 1fr;
367
+ gap: 16px;
368
+ padding: 2px;
369
+ align-items: center;
370
+ `
371
+
372
+ const DropdownCheckboxContainer = styled.div`
373
+ display: grid;
374
+ gap: 6px;
375
+ width: 100%;
376
+ padding: 12px 10px;
377
+ `
378
+
379
+ const RowWrapper = styled.div`
380
+ margin-bottom: 12px;
381
+ `
382
+
383
+ const DatePickerInput = styled(DatePicker)`
384
+ border: 1px solid ${(props) => props.theme.colors.grey4};
385
+ border-radius: 4px;
386
+ padding: 7px 12px 7px 7px;
387
+ width: 100%;
388
+ position: relative;
389
+
390
+ &.mx-datepicker {
391
+ width: 100% !important;
392
+ max-width: 100%;
393
+ height: 36px;
394
+ align-self: flex-end;
395
+ }
396
+
397
+ .mx-input-wrapper {
398
+ position: unset;
399
+
400
+ input {
401
+ border: none;
402
+ height: auto;
403
+ padding: 0;
404
+ font-size: 13px;
405
+ box-shadow: none;
406
+ color: #393939;
407
+ vertical-align: bottom;
408
+ }
409
+
410
+ .mx-input-append {
411
+ top: 1px;
412
+ }
413
+ }
414
+
415
+ .mx-input-append {
416
+ left: 0;
417
+ top: 5px;
418
+ height: auto;
419
+ cursor: pointer;
420
+ }
421
+ `
422
+
423
+ const LabelAttrs = {
424
+ marginTop: Boolean
425
+ }
426
+ const RowLabel = styled('div', LabelAttrs)`
427
+ font-weight: 700;
428
+ font-size: 13px;
429
+ margin-bottom: 8px;
430
+ margin-top: ${(props) => (props.marginTop ? '12px' : '0')};
431
+ `
432
+
433
+ const SectionContainer = styled.div``
434
+
435
+ const GridContainer = styled.div`
436
+ display: grid;
437
+ grid-template-columns: 1fr 1fr;
438
+ grid-gap: 12px;
439
+ `
440
+
441
+ const ViewContainerAttrs = { maxWidth: Number }
442
+ const ViewContainer = styled('div', ViewContainerAttrs)`
443
+ max-width: ${(props) =>
444
+ props.maxWidth && props.maxWidth > 300 ? props.maxWidth + 'ch' : '300px'};
445
+ `
446
+
447
+ const UpperContainer = styled.div`
448
+ display: grid;
449
+ grid-gap: 20px
450
+ grid-template-columns: 1fr 1fr;
451
+ padding: 10px 14px;
452
+ `
453
+
454
+ const ResetButton = styled.div`
455
+ display: inline-flex;
456
+ gap: 16px;
457
+ width: max-content;
458
+ margin-top: 20px;
459
+ align-self: center;
460
+ font-size: 13px;
461
+ color: ${(props) => props.theme.colors.blue};
462
+ cursor: pointer;
463
+ `
464
+
465
+ export default {
466
+ name: 'filter-settings',
467
+ components: {
468
+ ContainerWrapper,
469
+ ColumnWrapper,
470
+ ColumnTitle,
471
+ ColumnContainer,
472
+ SelectComponent,
473
+ RowContainer,
474
+ OptionTitle,
475
+ Option,
476
+ ButtonContainer,
477
+ MainButton,
478
+ CheckboxContainer,
479
+ CheckboxWrapper,
480
+ Checkbox,
481
+ RowWrapper,
482
+ DropdownCheckboxContainer,
483
+ draggable,
484
+ Icon,
485
+ DragContainer,
486
+ InputNumber,
487
+ DatePickerInput,
488
+ RowLabel,
489
+ SectionContainer,
490
+ GridContainer,
491
+ ViewContainer,
492
+ DeleteIcon,
493
+ UpperContainer,
494
+ ResetButton
495
+ },
496
+ props: {
497
+ filterData: {
498
+ required: true
499
+ },
500
+ hasActiveView: {
501
+ required: false
502
+ },
503
+ buttonText: {
504
+ required: true
505
+ // example:
506
+ // {
507
+ // 'save_new_view': '$gettext("save_new_view")',
508
+ // 'cancel': '$gettext("cancel")',
509
+ // 'save_view': '$gettext("save_view")'
510
+ // }
511
+ },
512
+ filterViews: {
513
+ required: true
514
+ },
515
+ activeLanguage: {
516
+ required: false
517
+ },
518
+ settingsTranslations: {
519
+ required: false
520
+ },
521
+ activeView: {
522
+ required: false
523
+ }
524
+ },
525
+ data() {
526
+ return {
527
+ selectedDates: null,
528
+ value1: null,
529
+ dateStart: null,
530
+ dateEnd: null
531
+ }
532
+ },
533
+ methods: {
534
+ onChange({ dataType, value, choice, field }) {
535
+ if (
536
+ dataType === 'columns' &&
537
+ this.isCheckboxDisabled &&
538
+ value === false
539
+ ) {
540
+ return
541
+ }
542
+ const data = { dataType, value, choice, field }
543
+ this.$emit('on-filter-change', data)
544
+ },
545
+ onDatepickerFocus(range) {
546
+ this.dateStart = range.start
547
+ this.dateEnd = range.end
548
+ this.$emit('on-prevent-close', true)
549
+ },
550
+ onDatepickerBlur() {
551
+ this.$emit('on-prevent-close', false)
552
+ },
553
+ disablePastDates(date) {
554
+ const dateString = this.dateStart
555
+ if (!dateString) {
556
+ return
557
+ }
558
+ const dateParts = dateString.split('-')
559
+
560
+ const year = parseInt(dateParts[0])
561
+ const month = parseInt(dateParts[1]) - 1 // Subtract 1 since January is month 0
562
+ const day = parseInt(dateParts[2])
563
+
564
+ const currentDate = new Date(year, month, day)
565
+ const selectedDate = new Date(date)
566
+
567
+ // Disable dates that are greater than or equal to the current date
568
+ return selectedDate <= currentDate
569
+ },
570
+ disableFutureDates(date) {
571
+ const dateString = this.dateEnd
572
+ if (!dateString) {
573
+ return
574
+ }
575
+ const dateParts = dateString.split('-')
576
+
577
+ const year = parseInt(dateParts[0])
578
+ const month = parseInt(dateParts[1]) - 1 // Subtract 1 since January is month 0
579
+ const day = parseInt(dateParts[2])
580
+
581
+ const currentDate = new Date(year, month, day)
582
+ const selectedDate = new Date(date)
583
+
584
+ // Disable dates that are greater than or equal to the current date
585
+ return selectedDate >= currentDate
586
+ },
587
+ getDatePickerLanguage() {
588
+ return datePickerLang(this.activeLanguage)
589
+ },
590
+ onDragChange({ data }) {
591
+ this.$emit('on-drag-change', data)
592
+ },
593
+ modifyDragItem(dataTransfer) {
594
+ const isSafari = /^((?!chrome|android).)*safari/i.test(
595
+ navigator.userAgent
596
+ )
597
+ // prevents the dragged element from dragging the whole row as a "ghost"
598
+ // Safari fix because this does not work on Safari
599
+ let img = new Image()
600
+ if (!isSafari) {
601
+ dataTransfer.setDragImage(img, 0, 0)
602
+ } else {
603
+ img.src =
604
+ 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
605
+ dataTransfer.setDragImage(img, 0, 0)
606
+ }
607
+ },
608
+ getSelectedValue({ value, options, filter }) {
609
+ const foundItem = options.find((item) => item.choice === value)
610
+ return foundItem ? foundItem.text : value ? value : filter.selectedText
611
+ },
612
+ isMultipleSelector(type) {
613
+ return type === 'multi_select_integer' || type === 'multi_select_string'
614
+ },
615
+ isRangeSelector(type) {
616
+ return type === 'integer_range'
617
+ },
618
+ isDateSelector(type) {
619
+ return type === 'datetime'
620
+ }
621
+ },
622
+ computed: {
623
+ isCheckboxDisabled() {
624
+ // if only 1 item left, disable checkbox
625
+ let isDisabled = false
626
+ let columnsData = this.filterData.filter(
627
+ (item) => item.type === 'columns'
628
+ )
629
+ if (columnsData.length) {
630
+ columnsData = columnsData[0]
631
+ const filteredColumns = columnsData.dataOptions.filter(
632
+ (item) => item.selected
633
+ )
634
+ if (filteredColumns.length === 1) {
635
+ isDisabled = true
636
+ }
637
+ }
638
+ return isDisabled
639
+ },
640
+ theme() {
641
+ return theme
642
+ }
643
+ }
644
+ }
645
+ </script>