bfg-common 1.4.722 → 1.4.723

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.
@@ -1,487 +1,494 @@
1
- <template>
2
- <div class="chart-options-modal">
3
- <atoms-modal
4
- width="1150px"
5
- :show="true"
6
- :title="localization.inventoryMonitor.chartOptions"
7
- :disabled-submit="isDisabledSubmit"
8
- @hide="onHide"
9
- @submit="onSubmit"
10
- >
11
- <template #modalBody>
12
- <common-monitor-advanced-tools-chart-options-modal-notification
13
- v-show="isShowAlerts"
14
- :alerts="alerts"
15
- @remove="onRemoveAlerts"
16
- />
17
- <div>
18
- <common-pages-hardware-health-history-testimony-tools-chart-options-modal-actions
19
- :is-disabled-save="!currentSelectedRows.length"
20
- :options-names="optionsNames"
21
- :selected-chart-option-name="localSelectedChartOptionName"
22
- @save="onSaveOptions"
23
- @check-validation="checkValidations"
24
- @select-local-option-name="onSelectLocalOptionName"
25
- @delete-chart-name="onDeleteChartName"
26
- />
27
-
28
- <div class="horizontal-flex-container chart-options-content">
29
- <common-pages-hardware-health-history-testimony-tools-chart-options-modal-metrics
30
- v-model:selected-metric="selectedMetric"
31
- :metrics-items="metricsItems"
32
- />
33
- <common-pages-hardware-health-history-testimony-tools-chart-options-modal-counters
34
- :chart="selectedMetric"
35
- :selected-power-keys="localSelectedPowerCountersKeys"
36
- :selected-temperature-keys="localSelectedTemperatureCountersKeys"
37
- :power-counters-table-data="props.powerCountersTableData"
38
- :temperature-counters-table-data="
39
- props.temperatureCountersTableData
40
- "
41
- :language="props.language"
42
- :selected-chart-type="localSelectedChartType"
43
- :selected-timespan-type="localSelectedTimespanType"
44
- :units-count="localUnitsCount"
45
- :timespan-period-type="localTimespanPeriodType"
46
- :selected-custom-time="localCustomTime"
47
- :custom-date-from="props.customDateFrom"
48
- :custom-date-to="props.customDateTo"
49
- :custom-time-from="props.customTimeFrom"
50
- :custom-time-to="props.customTimeTo"
51
- @select-power-row="onSelectPowerRow"
52
- @select-temperature-row="onSelectTemperatureRow"
53
- @update-chart-type="selectedChartTypeLocal = $event"
54
- @update-custom-time="localCustomTime = $event"
55
- @update-timespan-type="timespanType = $event"
56
- @update-unit-count="unitCount = $event"
57
- @update-timespan-period-type="localTimespanPeriodType = $event"
58
- @update-custom-date-from="onUpdateCustomDateFrom"
59
- @update-custom-date-to="onUpdateCustomDateTo"
60
- @update-custom-time-from="onUpdateCustomTimeFrom"
61
- @update-custom-time-to="onUpdateCustomTimeTo"
62
- />
63
- </div>
64
- </div>
65
- </template>
66
- </atoms-modal>
67
- </div>
68
- </template>
69
-
70
- <script setup lang="ts">
71
- import type { UI_I_Localization } from '~/lib/models/interfaces'
72
- import type { UI_I_VerticalTabs } from '~/components/atoms/tabs/lib/models/interfaces'
73
- import type { UI_T_Chart } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/models/types'
74
- import type { UI_I_OptionsForm } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/models/interfaces'
75
- import type { UI_I_HardwareHealthSensorsGraph } from '~/components/common/pages/hardwareHealth/historyTestimony/lib/models/interfaces'
76
- import { metricsFunc } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/config/optionsMetrics'
77
- import { checkDateFunc } from '~/components/common/monitor/overview/filters/customIntervalModal/lib/config/dateChecker'
78
- import { getValidDateByOptionFunc } from '~/components/common/monitor/lib/config/getValidDateByOption'
79
- import { getCurrentOptionsStorageFunc } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/lib/config/toolbar'
80
-
81
- const props = defineProps<{
82
- selectedChartOptionName: string
83
- selectedMetric: UI_T_Chart
84
- selectedPowerCountersKeys: number[]
85
- powerSelectedRowsLocal: UI_I_HardwareHealthSensorsGraph[]
86
- selectedTemperatureCountersKeys: number[]
87
- temperatureSelectedRowsLocal: UI_I_HardwareHealthSensorsGraph[]
88
- unitsCount: number
89
- powerCountersTableData: UI_I_HardwareHealthSensorsGraph[]
90
- temperatureCountersTableData: UI_I_HardwareHealthSensorsGraph[]
91
- language: string
92
- selectedTimespanType: string
93
- customDateFrom: string
94
- customDateTo: string
95
- customTimeFrom: string
96
- customTimeTo: string
97
- timespanPeriodType: string
98
- }>()
99
-
100
- const emits = defineEmits<{
101
- (event: 'hide'): void
102
- (event: 'select-metric-local', value: string): void
103
- (
104
- event: 'power-selected-rows-local',
105
- value: UI_I_HardwareHealthSensorsGraph[]
106
- ): void
107
- (
108
- event: 'temperature-selected-rows-local',
109
- value: UI_I_HardwareHealthSensorsGraph[]
110
- ): void
111
- (event: 'update-chart-type', value: string): void
112
- (event: 'update-timespan-type', value: string): void
113
- (event: 'update-unit-count', value: number): void
114
- (event: 'update-timespan-period-type', value: string): void
115
- (event: 'update-custom-time', value: string): void
116
- (event: 'delete-option'): void
117
- (event: 'save-option-name'): void
118
- (event: 'update-custom-date-from', value: string): void
119
- (event: 'update-custom-date-to', value: string): void
120
- (event: 'update-custom-time-from', value: string): void
121
- (event: 'update-custom-time-to', value: string): void
122
- (event: 'submit-options', value: UI_I_OptionsForm): void
123
- }>()
124
-
125
- const routeType = '' + useRoute().params.type
126
-
127
- const localization = computed<UI_I_Localization>(() => useLocal())
128
-
129
- const localCustomDateFrom = ref<string>('')
130
- const onUpdateCustomDateFrom = (value: string): void => {
131
- localCustomDateFrom.value = value
132
- }
133
- const localCustomDateTo = ref<string>('')
134
- const onUpdateCustomDateTo = (value: string): void => {
135
- localCustomDateTo.value = value
136
- }
137
- const localCustomTimeFrom = ref<string>('')
138
- const onUpdateCustomTimeFrom = (value: string): void => {
139
- localCustomTimeFrom.value = value
140
- }
141
- const localCustomTimeTo = ref<string>('')
142
- const onUpdateCustomTimeTo = (value: string): void => {
143
- localCustomTimeTo.value = value
144
- }
145
-
146
- const metricsItems = computed<UI_I_VerticalTabs[]>(() =>
147
- metricsFunc(localization.value)
148
- )
149
- const selectedMetric = ref<UI_T_Chart>(
150
- props.selectedMetric || '' + metricsItems.value[0]?.value
151
- )
152
-
153
- const localSelectedPowerCountersKeys = ref<number[]>([])
154
- watch(
155
- () => props.selectedPowerCountersKeys,
156
- (newValue) => {
157
- localSelectedPowerCountersKeys.value = newValue
158
- },
159
- { immediate: true, deep: true }
160
- )
161
-
162
- const localSelectedTemperatureCountersKeys = ref<number[]>([])
163
- watch(
164
- () => props.selectedTemperatureCountersKeys,
165
- (newValue) => {
166
- localSelectedTemperatureCountersKeys.value = newValue
167
- },
168
- { immediate: true, deep: true }
169
- )
170
-
171
- const localSelectedChartType = ref<string>('')
172
-
173
- const localSelectedTimespanType = ref<string>('')
174
- watch(
175
- () => props.selectedTimespanType,
176
- (newValue) => {
177
- localSelectedTimespanType.value = newValue
178
- },
179
- { immediate: true }
180
- )
181
-
182
- const localUnitsCount = ref<number>(0)
183
- watch(
184
- () => props.unitsCount,
185
- (newValue) => {
186
- localUnitsCount.value = newValue
187
- },
188
- { immediate: true }
189
- )
190
-
191
- const localTimespanPeriodType = ref<string>('')
192
- watch(
193
- () => props.timespanPeriodType,
194
- (newValue) => {
195
- localTimespanPeriodType.value = newValue
196
- },
197
- { immediate: true }
198
- )
199
-
200
- const localCustomTime = ref<string>('')
201
-
202
- const isShowAlerts = ref<boolean>(false)
203
- const alerts = ref<string[]>([])
204
-
205
- const onRemoveAlerts = (): void => {
206
- isShowAlerts.value = false
207
- alerts.value = []
208
- }
209
-
210
- const onHide = (): void => {
211
- emits('hide')
212
- }
213
-
214
- const onSelectPowerRow = (data: UI_I_HardwareHealthSensorsGraph[]): void => {
215
- emits('power-selected-rows-local', data)
216
- }
217
- const onSelectTemperatureRow = (
218
- data: UI_I_HardwareHealthSensorsGraph[]
219
- ): void => {
220
- emits('temperature-selected-rows-local', data)
221
- }
222
-
223
- const currentSelectedRows = computed<UI_I_HardwareHealthSensorsGraph[]>(() => {
224
- let result: UI_I_HardwareHealthSensorsGraph[] = []
225
-
226
- switch (selectedMetric.value) {
227
- case 'power':
228
- result = props.powerSelectedRowsLocal
229
- break
230
- case 'temperature':
231
- result = props.temperatureSelectedRowsLocal
232
- break
233
- }
234
-
235
- return result
236
- })
237
-
238
- const selectedChartTypeLocal = ref<string>('')
239
-
240
- const checkValidations = (): boolean => {
241
- const checkDateResult = checkDateFunc(
242
- localization.value,
243
- localCustomDateFrom.value,
244
- localCustomDateTo.value,
245
- localCustomTimeFrom.value,
246
- localCustomTimeTo.value
247
- )
248
-
249
- if (isDisabledSubmit.value) {
250
- alerts.value = [localization.value.inventoryMonitor.noCountersSelected]
251
- isShowAlerts.value = true
252
- return false
253
- } else if (
254
- timespanType.value === 'custom_interval' &&
255
- localTimespanPeriodType.value === 'period' &&
256
- checkDateResult !== '' &&
257
- typeof checkDateResult === 'string'
258
- ) {
259
- alerts.value = [checkDateResult]
260
- isShowAlerts.value = true
261
- return false
262
- }
263
-
264
- return true
265
- }
266
-
267
- const localSelectedChartOptionName = ref<string>('')
268
- watch(
269
- () => props.selectedChartOptionName,
270
- (newValue) => {
271
- localSelectedChartOptionName.value = newValue
272
- },
273
- { immediate: true }
274
- )
275
-
276
- const selectedLocalOptionName = ref<string>('')
277
-
278
- const currentFieldsByArray = (
279
- data: UI_I_HardwareHealthSensorsGraph[]
280
- ): string => {
281
- const result: string[] = []
282
- data.forEach((item) => {
283
- result.push(item.nameEn)
284
- })
285
- return result.join('>>')
286
- }
287
-
288
- const onSubmit = (): void => {
289
- if (!checkValidations()) return
290
-
291
- if (['select_options', 'default'].includes(selectedLocalOptionName.value))
292
- selectedLocalOptionName.value = 'custom'
293
-
294
- onSaveOptions(selectedLocalOptionName.value)
295
-
296
- const currentFields = currentFieldsByArray(currentSelectedRows.value)
297
-
298
- const validPeriod = getValidDateByOptionFunc(
299
- timespanType.value,
300
- null,
301
- unitCount.value,
302
- localCustomTime.value
303
- )
304
- if (
305
- timespanType.value === 'custom_interval' &&
306
- localTimespanPeriodType.value === 'period'
307
- ) {
308
- const checkDateResult = checkDateFunc(
309
- localization.value,
310
- localCustomDateFrom.value,
311
- localCustomDateTo.value,
312
- localCustomTimeFrom.value,
313
- localCustomTimeTo.value
314
- )
315
- if (Array.isArray(checkDateResult)) {
316
- validPeriod[0] = checkDateResult[0]
317
- validPeriod[1] = checkDateResult[1]
318
- }
319
- }
320
-
321
- const savedObject = {
322
- fields: currentFields,
323
- optionName: selectedLocalOptionName.value,
324
- metric: selectedMetric.value,
325
- periodName: timespanType.value,
326
- periodType: localTimespanPeriodType.value,
327
- unitCount: unitCount.value,
328
- localTimespanType: localCustomTime.value,
329
- dateFrom: localCustomDateFrom.value,
330
- timeFrom: localCustomTimeFrom.value,
331
- dateTo: localCustomDateTo.value,
332
- timeTo: localCustomTimeTo.value,
333
- chartType: selectedChartTypeLocal.value,
334
- period: validPeriod,
335
- }
336
-
337
- emits('update-timespan-period-type', savedObject.periodType)
338
- emits('submit-options', savedObject)
339
- onHide()
340
- }
341
-
342
- const timespanType = ref<string>('')
343
- const unitCount = ref<number>(1)
344
-
345
- const optionsNames = ref<string[]>([])
346
-
347
- const onSaveOptions = (name: string): void => {
348
- const counters = currentSelectedRows.value.map((item) => {
349
- return {
350
- id: item.id,
351
- name: item.nameEn,
352
- }
353
- })
354
- let chartType = 'line_graph'
355
- if (selectedChartTypeLocal.value === 'spline') chartType = 'line_graph'
356
- else if (selectedChartTypeLocal.value === 'area') chartType = 'stacked_graph'
357
-
358
- const saveOptionsData = {
359
- routeType,
360
- chartType,
361
- counters,
362
- metric: selectedMetric.value,
363
- timespan: {
364
- periodType: localTimespanPeriodType.value,
365
- units: localCustomTime.value,
366
- unitsCount: unitCount.value,
367
- type: timespanType.value,
368
- },
369
- }
370
- useLocalStorage(`${name}ChartOptionsSensors`, saveOptionsData)
371
- optionsNames.value = getCurrentOptionsStorageFunc()
372
- localSelectedChartOptionName.value = name
373
- emits('save-option-name')
374
- }
375
-
376
- const setSelectOptions = (): void => {
377
- selectedMetric.value = props.selectedMetric || metricsItems.value[0]?.value
378
- }
379
-
380
- const setDefaultOptions = (): void => {
381
- selectedMetric.value = metricsItems.value[0]?.value
382
- localSelectedPowerCountersKeys.value = []
383
- localSelectedTemperatureCountersKeys.value = []
384
- localSelectedChartType.value = 'spline'
385
- localSelectedTimespanType.value = ''
386
- localUnitsCount.value = 0
387
- localTimespanPeriodType.value = ''
388
- localCustomTime.value = ''
389
- }
390
-
391
- const setCustomOptions = (name: string): void => {
392
- const selectedValue = useLocalStorage(name + 'ChartOptionsSensors', undefined)
393
-
394
- if (selectedValue.routeType !== routeType) return
395
-
396
- let currentChartType = ''
397
- if (selectedValue.chartType === 'line_graph') currentChartType = 'spline'
398
- else if (selectedValue.chartType === 'stacked_graph')
399
- currentChartType = 'area'
400
-
401
- selectedMetric.value = selectedValue.metric
402
- if (selectedMetric.value === 'power')
403
- localSelectedPowerCountersKeys.value = selectedValue.counters.map(
404
- (item) => item.id
405
- )
406
- if (selectedMetric.value === 'temperature')
407
- localSelectedTemperatureCountersKeys.value = selectedValue.counters.map(
408
- (item) => item.id
409
- )
410
- localSelectedChartType.value = currentChartType
411
- localSelectedTimespanType.value = selectedValue.timespan.type
412
- localUnitsCount.value = selectedValue.timespan.unitsCount
413
- localTimespanPeriodType.value = selectedValue.timespan.periodType
414
- localCustomTime.value = selectedValue.timespan.units
415
- }
416
-
417
- const onSelectLocalOptionName = (name: string): void => {
418
- selectedLocalOptionName.value = name
419
-
420
- if (optionsNames.value.includes(name)) setCustomOptions(name)
421
- else if (name === 'default') setDefaultOptions()
422
- else if (name === 'select_options') setSelectOptions()
423
- }
424
-
425
- watch(
426
- localSelectedChartOptionName,
427
- (newValue) => {
428
- if (!newValue) return
429
-
430
- setCustomOptions(newValue)
431
- },
432
- { immediate: true }
433
- )
434
-
435
- const onDeleteChartName = (name: string): void => {
436
- window.localStorage.removeItem(name + 'ChartOptionsSensors')
437
- optionsNames.value = getCurrentOptionsStorageFunc()
438
- setSelectOptions()
439
- emits('delete-option')
440
- }
441
-
442
- const isDisabledSubmit = computed<boolean>(
443
- () => !currentSelectedRows.value.length
444
- )
445
-
446
- watch(
447
- selectedMetric,
448
- (newValue) => {
449
- emits('select-metric-local', newValue)
450
- },
451
- { immediate: true }
452
- )
453
-
454
- onMounted(() => {
455
- optionsNames.value = getCurrentOptionsStorageFunc(routeType)
456
- })
457
- </script>
458
-
459
- <style scoped lang="scss">
460
- .chart-options-modal {
461
- .loader-on :deep(.modal-body) {
462
- display: flex;
463
- align-items: center;
464
- justify-content: center;
465
- }
466
- :deep(.modal-title) {
467
- text-transform: capitalize;
468
- }
469
-
470
- #loader {
471
- min-height: 90px;
472
- text-align: center;
473
- }
474
-
475
- .chart-options-content {
476
- display: flex;
477
- flex-direction: row;
478
- flex-basis: 90%;
479
- overflow-y: hidden;
480
- }
481
- }
482
- @media (max-width: 1024px) {
483
- .chart-options-content {
484
- flex-direction: column !important;
485
- }
486
- }
487
- </style>
1
+ <template>
2
+ <div class="chart-options-modal">
3
+ <atoms-modal
4
+ width="1150px"
5
+ :show="true"
6
+ :title="localization.inventoryMonitor.chartOptions"
7
+ :disabled-submit="isDisabledSubmit"
8
+ @hide="onHide"
9
+ @submit="onSubmit"
10
+ >
11
+ <template #modalBody>
12
+ <common-monitor-advanced-tools-chart-options-modal-notification
13
+ v-show="isShowAlerts"
14
+ :alerts="alerts"
15
+ @remove="onRemoveAlerts"
16
+ />
17
+ <div>
18
+ <common-pages-hardware-health-history-testimony-tools-chart-options-modal-actions
19
+ :is-disabled-save="!currentSelectedRows.length"
20
+ :options-names="optionsNames"
21
+ :selected-chart-option-name="localSelectedChartOptionName"
22
+ @save="onSaveOptions"
23
+ @check-validation="checkValidations"
24
+ @select-local-option-name="onSelectLocalOptionName"
25
+ @delete-chart-name="onDeleteChartName"
26
+ />
27
+
28
+ <div class="horizontal-flex-container chart-options-content">
29
+ <common-pages-hardware-health-history-testimony-tools-chart-options-modal-metrics
30
+ v-model:selected-metric="selectedMetric"
31
+ :metrics-items="metricsItems"
32
+ />
33
+ <common-pages-hardware-health-history-testimony-tools-chart-options-modal-counters
34
+ :chart="selectedMetric"
35
+ :selected-power-keys="localSelectedPowerCountersKeys"
36
+ :selected-temperature-keys="localSelectedTemperatureCountersKeys"
37
+ :power-counters-table-data="props.powerCountersTableData"
38
+ :temperature-counters-table-data="
39
+ props.temperatureCountersTableData
40
+ "
41
+ :language="props.language"
42
+ :selected-chart-type="localSelectedChartType"
43
+ :selected-timespan-type="localSelectedTimespanType"
44
+ :units-count="localUnitsCount"
45
+ :timespan-period-type="localTimespanPeriodType"
46
+ :selected-custom-time="localCustomTime"
47
+ :custom-date-from="props.customDateFrom"
48
+ :custom-date-to="props.customDateTo"
49
+ :custom-time-from="props.customTimeFrom"
50
+ :custom-time-to="props.customTimeTo"
51
+ :valid-date-end="props.validDateEnd"
52
+ @select-power-row="onSelectPowerRow"
53
+ @select-temperature-row="onSelectTemperatureRow"
54
+ @update-chart-type="selectedChartTypeLocal = $event"
55
+ @update-custom-time="localCustomTime = $event"
56
+ @update-timespan-type="timespanType = $event"
57
+ @update-unit-count="unitCount = $event"
58
+ @update-timespan-period-type="localTimespanPeriodType = $event"
59
+ @update-custom-date-from="onUpdateCustomDateFrom"
60
+ @update-custom-date-to="onUpdateCustomDateTo"
61
+ @update-custom-time-from="onUpdateCustomTimeFrom"
62
+ @update-custom-time-to="onUpdateCustomTimeTo"
63
+ />
64
+ </div>
65
+ </div>
66
+ </template>
67
+ </atoms-modal>
68
+ </div>
69
+ </template>
70
+
71
+ <script setup lang="ts">
72
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
73
+ import type { UI_I_VerticalTabs } from '~/components/atoms/tabs/lib/models/interfaces'
74
+ import type { UI_T_Chart } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/models/types'
75
+ import type { UI_I_OptionsForm } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/models/interfaces'
76
+ import type { UI_I_HardwareHealthSensorsGraph } from '~/components/common/pages/hardwareHealth/historyTestimony/lib/models/interfaces'
77
+ import { metricsFunc } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/chartOptionsModal/lib/config/optionsMetrics'
78
+ import { checkDateFunc } from '~/components/common/monitor/overview/filters/customIntervalModal/lib/config/dateChecker'
79
+ import { getValidDateByOptionFunc } from '~/components/common/monitor/lib/config/getValidDateByOption'
80
+ import { getCurrentOptionsStorageFunc } from '~/components/common/pages/hardwareHealth/historyTestimony/tools/lib/config/toolbar'
81
+
82
+ const props = defineProps<{
83
+ selectedChartOptionName: string
84
+ selectedMetric: UI_T_Chart
85
+ selectedPowerCountersKeys: number[]
86
+ powerSelectedRowsLocal: UI_I_HardwareHealthSensorsGraph[]
87
+ selectedTemperatureCountersKeys: number[]
88
+ temperatureSelectedRowsLocal: UI_I_HardwareHealthSensorsGraph[]
89
+ unitsCount: number
90
+ powerCountersTableData: UI_I_HardwareHealthSensorsGraph[]
91
+ temperatureCountersTableData: UI_I_HardwareHealthSensorsGraph[]
92
+ language: string
93
+ selectedTimespanType: string
94
+ customDateFrom: string
95
+ customDateTo: string
96
+ customTimeFrom: string
97
+ customTimeTo: string
98
+ timespanPeriodType: string
99
+ validDateEnd: number
100
+ formatDate: string
101
+ }>()
102
+
103
+ const emits = defineEmits<{
104
+ (event: 'hide'): void
105
+ (event: 'select-metric-local', value: string): void
106
+ (
107
+ event: 'power-selected-rows-local',
108
+ value: UI_I_HardwareHealthSensorsGraph[]
109
+ ): void
110
+ (
111
+ event: 'temperature-selected-rows-local',
112
+ value: UI_I_HardwareHealthSensorsGraph[]
113
+ ): void
114
+ (event: 'update-chart-type', value: string): void
115
+ (event: 'update-timespan-type', value: string): void
116
+ (event: 'update-unit-count', value: number): void
117
+ (event: 'update-timespan-period-type', value: string): void
118
+ (event: 'update-custom-time', value: string): void
119
+ (event: 'delete-option'): void
120
+ (event: 'save-option-name'): void
121
+ (event: 'update-custom-date-from', value: string): void
122
+ (event: 'update-custom-date-to', value: string): void
123
+ (event: 'update-custom-time-from', value: string): void
124
+ (event: 'update-custom-time-to', value: string): void
125
+ (event: 'submit-options', value: UI_I_OptionsForm): void
126
+ }>()
127
+
128
+ const routeType = '' + useRoute().params.type
129
+
130
+ const localization = computed<UI_I_Localization>(() => useLocal())
131
+
132
+ const localCustomDateFrom = ref<string>('')
133
+ const onUpdateCustomDateFrom = (value: string): void => {
134
+ localCustomDateFrom.value = value
135
+ }
136
+ const localCustomDateTo = ref<string>('')
137
+ const onUpdateCustomDateTo = (value: string): void => {
138
+ localCustomDateTo.value = value
139
+ }
140
+ const localCustomTimeFrom = ref<string>('')
141
+ const onUpdateCustomTimeFrom = (value: string): void => {
142
+ localCustomTimeFrom.value = value
143
+ }
144
+ const localCustomTimeTo = ref<string>('')
145
+ const onUpdateCustomTimeTo = (value: string): void => {
146
+ localCustomTimeTo.value = value
147
+ }
148
+
149
+ const metricsItems = computed<UI_I_VerticalTabs[]>(() =>
150
+ metricsFunc(localization.value)
151
+ )
152
+ const selectedMetric = ref<UI_T_Chart>(
153
+ props.selectedMetric || '' + metricsItems.value[0]?.value
154
+ )
155
+
156
+ const localSelectedPowerCountersKeys = ref<number[]>([])
157
+ watch(
158
+ () => props.selectedPowerCountersKeys,
159
+ (newValue) => {
160
+ localSelectedPowerCountersKeys.value = newValue
161
+ },
162
+ { immediate: true, deep: true }
163
+ )
164
+
165
+ const localSelectedTemperatureCountersKeys = ref<number[]>([])
166
+ watch(
167
+ () => props.selectedTemperatureCountersKeys,
168
+ (newValue) => {
169
+ localSelectedTemperatureCountersKeys.value = newValue
170
+ },
171
+ { immediate: true, deep: true }
172
+ )
173
+
174
+ const localSelectedChartType = ref<string>('')
175
+
176
+ const localSelectedTimespanType = ref<string>('')
177
+ watch(
178
+ () => props.selectedTimespanType,
179
+ (newValue) => {
180
+ localSelectedTimespanType.value = newValue
181
+ },
182
+ { immediate: true }
183
+ )
184
+
185
+ const localUnitsCount = ref<number>(0)
186
+ watch(
187
+ () => props.unitsCount,
188
+ (newValue) => {
189
+ localUnitsCount.value = newValue
190
+ },
191
+ { immediate: true }
192
+ )
193
+
194
+ const localTimespanPeriodType = ref<string>('')
195
+ watch(
196
+ () => props.timespanPeriodType,
197
+ (newValue) => {
198
+ localTimespanPeriodType.value = newValue
199
+ },
200
+ { immediate: true }
201
+ )
202
+
203
+ const localCustomTime = ref<string>('')
204
+
205
+ const isShowAlerts = ref<boolean>(false)
206
+ const alerts = ref<string[]>([])
207
+
208
+ const onRemoveAlerts = (): void => {
209
+ isShowAlerts.value = false
210
+ alerts.value = []
211
+ }
212
+
213
+ const onHide = (): void => {
214
+ emits('hide')
215
+ }
216
+
217
+ const onSelectPowerRow = (data: UI_I_HardwareHealthSensorsGraph[]): void => {
218
+ emits('power-selected-rows-local', data)
219
+ }
220
+ const onSelectTemperatureRow = (
221
+ data: UI_I_HardwareHealthSensorsGraph[]
222
+ ): void => {
223
+ emits('temperature-selected-rows-local', data)
224
+ }
225
+
226
+ const currentSelectedRows = computed<UI_I_HardwareHealthSensorsGraph[]>(() => {
227
+ let result: UI_I_HardwareHealthSensorsGraph[] = []
228
+
229
+ switch (selectedMetric.value) {
230
+ case 'power':
231
+ result = props.powerSelectedRowsLocal
232
+ break
233
+ case 'temperature':
234
+ result = props.temperatureSelectedRowsLocal
235
+ break
236
+ }
237
+
238
+ return result
239
+ })
240
+
241
+ const selectedChartTypeLocal = ref<string>('')
242
+
243
+ const checkValidations = (): boolean => {
244
+ const checkDateResult = checkDateFunc(
245
+ localization.value,
246
+ localCustomDateFrom.value,
247
+ localCustomDateTo.value,
248
+ localCustomTimeFrom.value,
249
+ localCustomTimeTo.value,
250
+ props.validDateEnd,
251
+ props.formatDate
252
+ )
253
+
254
+ if (isDisabledSubmit.value) {
255
+ alerts.value = [localization.value.inventoryMonitor.noCountersSelected]
256
+ isShowAlerts.value = true
257
+ return false
258
+ } else if (
259
+ timespanType.value === 'custom_interval' &&
260
+ localTimespanPeriodType.value === 'period' &&
261
+ checkDateResult !== '' &&
262
+ typeof checkDateResult === 'string'
263
+ ) {
264
+ alerts.value = [checkDateResult]
265
+ isShowAlerts.value = true
266
+ return false
267
+ }
268
+
269
+ return true
270
+ }
271
+
272
+ const localSelectedChartOptionName = ref<string>('')
273
+ watch(
274
+ () => props.selectedChartOptionName,
275
+ (newValue) => {
276
+ localSelectedChartOptionName.value = newValue
277
+ },
278
+ { immediate: true }
279
+ )
280
+
281
+ const selectedLocalOptionName = ref<string>('')
282
+
283
+ const currentFieldsByArray = (
284
+ data: UI_I_HardwareHealthSensorsGraph[]
285
+ ): string => {
286
+ const result: string[] = []
287
+ data.forEach((item) => {
288
+ result.push(item.nameEn)
289
+ })
290
+ return result.join('>>')
291
+ }
292
+
293
+ const onSubmit = (): void => {
294
+ if (!checkValidations()) return
295
+
296
+ if (['select_options', 'default'].includes(selectedLocalOptionName.value))
297
+ selectedLocalOptionName.value = 'custom'
298
+
299
+ onSaveOptions(selectedLocalOptionName.value)
300
+
301
+ const currentFields = currentFieldsByArray(currentSelectedRows.value)
302
+
303
+ const validPeriod = getValidDateByOptionFunc(
304
+ timespanType.value,
305
+ null,
306
+ unitCount.value,
307
+ localCustomTime.value
308
+ )
309
+ if (
310
+ timespanType.value === 'custom_interval' &&
311
+ localTimespanPeriodType.value === 'period'
312
+ ) {
313
+ const checkDateResult = checkDateFunc(
314
+ localization.value,
315
+ localCustomDateFrom.value,
316
+ localCustomDateTo.value,
317
+ localCustomTimeFrom.value,
318
+ localCustomTimeTo.value,
319
+ props.validDateEnd,
320
+ props.formatDate
321
+ )
322
+ if (Array.isArray(checkDateResult)) {
323
+ validPeriod[0] = checkDateResult[0]
324
+ validPeriod[1] = checkDateResult[1]
325
+ }
326
+ }
327
+
328
+ const savedObject = {
329
+ fields: currentFields,
330
+ optionName: selectedLocalOptionName.value,
331
+ metric: selectedMetric.value,
332
+ periodName: timespanType.value,
333
+ periodType: localTimespanPeriodType.value,
334
+ unitCount: unitCount.value,
335
+ localTimespanType: localCustomTime.value,
336
+ dateFrom: localCustomDateFrom.value,
337
+ timeFrom: localCustomTimeFrom.value,
338
+ dateTo: localCustomDateTo.value,
339
+ timeTo: localCustomTimeTo.value,
340
+ chartType: selectedChartTypeLocal.value,
341
+ period: validPeriod,
342
+ }
343
+
344
+ emits('update-timespan-period-type', savedObject.periodType)
345
+ emits('submit-options', savedObject)
346
+ onHide()
347
+ }
348
+
349
+ const timespanType = ref<string>('')
350
+ const unitCount = ref<number>(1)
351
+
352
+ const optionsNames = ref<string[]>([])
353
+
354
+ const onSaveOptions = (name: string): void => {
355
+ const counters = currentSelectedRows.value.map((item) => {
356
+ return {
357
+ id: item.id,
358
+ name: item.nameEn,
359
+ }
360
+ })
361
+ let chartType = 'line_graph'
362
+ if (selectedChartTypeLocal.value === 'spline') chartType = 'line_graph'
363
+ else if (selectedChartTypeLocal.value === 'area') chartType = 'stacked_graph'
364
+
365
+ const saveOptionsData = {
366
+ routeType,
367
+ chartType,
368
+ counters,
369
+ metric: selectedMetric.value,
370
+ timespan: {
371
+ periodType: localTimespanPeriodType.value,
372
+ units: localCustomTime.value,
373
+ unitsCount: unitCount.value,
374
+ type: timespanType.value,
375
+ },
376
+ }
377
+ useLocalStorage(`${name}ChartOptionsSensors`, saveOptionsData)
378
+ optionsNames.value = getCurrentOptionsStorageFunc()
379
+ localSelectedChartOptionName.value = name
380
+ emits('save-option-name')
381
+ }
382
+
383
+ const setSelectOptions = (): void => {
384
+ selectedMetric.value = props.selectedMetric || metricsItems.value[0]?.value
385
+ }
386
+
387
+ const setDefaultOptions = (): void => {
388
+ selectedMetric.value = metricsItems.value[0]?.value
389
+ localSelectedPowerCountersKeys.value = []
390
+ localSelectedTemperatureCountersKeys.value = []
391
+ localSelectedChartType.value = 'spline'
392
+ localSelectedTimespanType.value = ''
393
+ localUnitsCount.value = 0
394
+ localTimespanPeriodType.value = ''
395
+ localCustomTime.value = ''
396
+ }
397
+
398
+ const setCustomOptions = (name: string): void => {
399
+ const selectedValue = useLocalStorage(name + 'ChartOptionsSensors', undefined)
400
+
401
+ if (selectedValue.routeType !== routeType) return
402
+
403
+ let currentChartType = ''
404
+ if (selectedValue.chartType === 'line_graph') currentChartType = 'spline'
405
+ else if (selectedValue.chartType === 'stacked_graph')
406
+ currentChartType = 'area'
407
+
408
+ selectedMetric.value = selectedValue.metric
409
+ if (selectedMetric.value === 'power')
410
+ localSelectedPowerCountersKeys.value = selectedValue.counters.map(
411
+ (item) => item.id
412
+ )
413
+ if (selectedMetric.value === 'temperature')
414
+ localSelectedTemperatureCountersKeys.value = selectedValue.counters.map(
415
+ (item) => item.id
416
+ )
417
+ localSelectedChartType.value = currentChartType
418
+ localSelectedTimespanType.value = selectedValue.timespan.type
419
+ localUnitsCount.value = selectedValue.timespan.unitsCount
420
+ localTimespanPeriodType.value = selectedValue.timespan.periodType
421
+ localCustomTime.value = selectedValue.timespan.units
422
+ }
423
+
424
+ const onSelectLocalOptionName = (name: string): void => {
425
+ selectedLocalOptionName.value = name
426
+
427
+ if (optionsNames.value.includes(name)) setCustomOptions(name)
428
+ else if (name === 'default') setDefaultOptions()
429
+ else if (name === 'select_options') setSelectOptions()
430
+ }
431
+
432
+ watch(
433
+ localSelectedChartOptionName,
434
+ (newValue) => {
435
+ if (!newValue) return
436
+
437
+ setCustomOptions(newValue)
438
+ },
439
+ { immediate: true }
440
+ )
441
+
442
+ const onDeleteChartName = (name: string): void => {
443
+ window.localStorage.removeItem(name + 'ChartOptionsSensors')
444
+ optionsNames.value = getCurrentOptionsStorageFunc()
445
+ setSelectOptions()
446
+ emits('delete-option')
447
+ }
448
+
449
+ const isDisabledSubmit = computed<boolean>(
450
+ () => !currentSelectedRows.value.length
451
+ )
452
+
453
+ watch(
454
+ selectedMetric,
455
+ (newValue) => {
456
+ emits('select-metric-local', newValue)
457
+ },
458
+ { immediate: true }
459
+ )
460
+
461
+ onMounted(() => {
462
+ optionsNames.value = getCurrentOptionsStorageFunc(routeType)
463
+ })
464
+ </script>
465
+
466
+ <style scoped lang="scss">
467
+ .chart-options-modal {
468
+ .loader-on :deep(.modal-body) {
469
+ display: flex;
470
+ align-items: center;
471
+ justify-content: center;
472
+ }
473
+ :deep(.modal-title) {
474
+ text-transform: capitalize;
475
+ }
476
+
477
+ #loader {
478
+ min-height: 90px;
479
+ text-align: center;
480
+ }
481
+
482
+ .chart-options-content {
483
+ display: flex;
484
+ flex-direction: row;
485
+ flex-basis: 90%;
486
+ overflow-y: hidden;
487
+ }
488
+ }
489
+ @media (max-width: 1024px) {
490
+ .chart-options-content {
491
+ flex-direction: column !important;
492
+ }
493
+ }
494
+ </style>