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