bfg-common 1.5.386 → 1.5.388

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,174 +1,176 @@
1
- <template>
2
- <common-vm-actions-common-select-name-new
3
- v-if="isNewView"
4
- v-model:vm-name="vmName"
5
- v-model:is-show-help="isShowHelp"
6
- :project="props.project"
7
- :errors="errors"
8
- :data-center="props.dataCenter"
9
- @remove-validation-errors="onRemoveValidationErrors"
10
- @select-node="onSelectNode"
11
- />
12
- <common-vm-actions-common-select-name-old
13
- v-else
14
- v-model:vm-name="vmName"
15
- v-model:is-show-help="isShowHelp"
16
- :project="props.project"
17
- :errors="errors"
18
- :data-center="props.dataCenter"
19
- @remove-validation-errors="onRemoveValidationErrors"
20
- @select-node="onSelectNode"
21
- />
22
- </template>
23
-
24
- <script setup lang="ts">
25
- // import { API_UI_I_Error } from '~/lib/models/store/interfaces'
26
- import type { UI_I_Localization } from '~/lib/models/interfaces'
27
- import type { UI_T_Project } from '~/lib/models/types'
28
- import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
29
-
30
- const props = defineProps<{
31
- nameFormSubmit: null | Function
32
- show: boolean
33
- project: UI_T_Project
34
- dataCenter?: UI_I_TreeNode // для сферы
35
- }>()
36
- const emits = defineEmits<{
37
- (event: 'submit', value: [string, UI_I_TreeNode | null]): void
38
- (event: 'loading', value: boolean): void
39
- (
40
- event: 'check-name',
41
- value: [[string, UI_I_TreeNode | null], (error: any) => void]
42
- ): void
43
- (event: 'has-errors', value: boolean): void
44
- }>()
45
-
46
- const { $store }: any = useNuxtApp()
47
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
48
-
49
- const localization = computed<UI_I_Localization>(() => useLocal())
50
-
51
- const vmName = ref<string>('')
52
-
53
- const selectedNode = ref<UI_I_TreeNode | null>(null)
54
- const onSelectNode = (node: UI_I_TreeNode): void => {
55
- selectedNode.value = node
56
- }
57
-
58
- watch(
59
- () => props.nameFormSubmit,
60
- (newValue) => {
61
- newValue && submit(newValue)
62
- }
63
- )
64
-
65
- const isParentDatacenter = (node: UI_I_TreeNode | null): boolean => {
66
- if (!node) return false
67
-
68
- if (node.parent?.type === 'datacenter') return true
69
- if (node.parent?.type === 'folder') return isParentDatacenter(node.parent)
70
- return false
71
- }
72
- const submit = async (cb: Function): Promise<void> => {
73
- const name = vmName.value
74
-
75
- if (name !== '') {
76
- const isNameValid = await checkNameIsValid(name)
77
- if (!isNameValid) {
78
- cb(false)
79
- return
80
- }
81
- }
82
-
83
- if (props.project === 'sphere') {
84
- // const isDatacenterFolder = isParentDatacenter(selectedNode.value)
85
-
86
- if (
87
- // selectedNode.value?.type !== 'datacenter' &&
88
- // selectedNode.value?.type === 'folder' &&
89
- // !isDatacenterFolder
90
- // TODO рефакторинг, здесь сейчас проверяем является ли выбранный элемент датацентром или папкой(вм)
91
- ![3, 7].includes(selectedNode.value?.kind)
92
- ) {
93
- showValidationErrors([
94
- localization.value.common.enterValidLocationVirtualMachine,
95
- ])
96
- cb(false)
97
- return
98
- }
99
- }
100
-
101
- onRemoveValidationErrors()
102
- emits('submit', [name, selectedNode.value])
103
- cb(true)
104
- }
105
- const checkNameIsValid = async (name: string): Promise<boolean> => {
106
- emits('loading', true)
107
-
108
- return new Promise((resolve) => {
109
- emits('check-name', [
110
- [name, selectedNode.value],
111
- (error) => {
112
- emits('loading', false)
113
-
114
- const status = error?.statusCode || 200
115
- switch (status) {
116
- case 405: // Invalid kind
117
- showValidationErrors([
118
- localization.value.common.kindValidationDescription,
119
- ])
120
- resolve(false)
121
- break
122
- case 406: // Invalid name
123
- showValidationErrors([
124
- localization.value.common.vmNameValidationDescription,
125
- ])
126
- resolve(false)
127
- break
128
- case 409: // Name exist
129
- showValidationErrors([
130
- localization.value.common.vmNameExistInSelectedLocation,
131
- ])
132
- resolve(false)
133
- break
134
- }
135
-
136
- resolve(true)
137
- },
138
- ])
139
- })
140
- }
141
-
142
- const errors = ref<string[]>([])
143
- const showValidationErrors = (data: string[]): void => {
144
- errors.value = data
145
- }
146
- const onRemoveValidationErrors = (): void => {
147
- errors.value = []
148
- }
149
- watch(
150
- errors,
151
- (newValue) => {
152
- emits('has-errors', !newValue.length)
153
- },
154
- { immediate: true, deep: true }
155
- )
156
-
157
- watch(
158
- () => props.show,
159
- (newValue) => {
160
- if (!newValue) return
161
-
162
- const input = document.getElementById('virtual-machine-name')
163
- if (!input) return
164
-
165
- setTimeout(() => {
166
- input.focus()
167
- }, 0)
168
- }
169
- )
170
-
171
- const isShowHelp = ref<boolean>(false)
172
- </script>
173
-
174
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <common-vm-actions-common-select-name-new
3
+ v-if="isNewView"
4
+ v-model:vm-name="vmName"
5
+ v-model:is-show-help="isShowHelp"
6
+ :project="props.project"
7
+ :errors="errors"
8
+ :data-center="props.dataCenter"
9
+ @remove-validation-errors="onRemoveValidationErrors"
10
+ @select-node="onSelectNode"
11
+ />
12
+ <common-vm-actions-common-select-name-old
13
+ v-else
14
+ v-model:vm-name="vmName"
15
+ v-model:is-show-help="isShowHelp"
16
+ :project="props.project"
17
+ :errors="errors"
18
+ :data-center="props.dataCenter"
19
+ @remove-validation-errors="onRemoveValidationErrors"
20
+ @select-node="onSelectNode"
21
+ />
22
+ </template>
23
+
24
+ <script setup lang="ts">
25
+ // import { API_UI_I_Error } from '~/lib/models/store/interfaces'
26
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
27
+ import type { UI_T_Project } from '~/lib/models/types'
28
+ import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
29
+
30
+ const props = defineProps<{
31
+ nameFormSubmit: null | Function
32
+ show: boolean
33
+ project: UI_T_Project
34
+ dataCenter?: UI_I_TreeNode // для сферы
35
+ existName?: string
36
+ }>()
37
+ const emits = defineEmits<{
38
+ (event: 'submit', value: [string, UI_I_TreeNode | null]): void
39
+ (event: 'loading', value: boolean): void
40
+ (
41
+ event: 'check-name',
42
+ value: [[string, UI_I_TreeNode | null], (error: any) => void]
43
+ ): void
44
+ (event: 'has-errors', value: boolean): void
45
+ }>()
46
+
47
+ const { $store }: any = useNuxtApp()
48
+ const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
49
+
50
+ const localization = computed<UI_I_Localization>(() => useLocal())
51
+
52
+ // TODO 100
53
+ const vmName = ref<string>(props.existName || '')
54
+
55
+ const selectedNode = ref<UI_I_TreeNode | null>(null)
56
+ const onSelectNode = (node: UI_I_TreeNode): void => {
57
+ selectedNode.value = node
58
+ }
59
+
60
+ watch(
61
+ () => props.nameFormSubmit,
62
+ (newValue) => {
63
+ newValue && submit(newValue)
64
+ }
65
+ )
66
+
67
+ const isParentDatacenter = (node: UI_I_TreeNode | null): boolean => {
68
+ if (!node) return false
69
+
70
+ if (node.parent?.type === 'datacenter') return true
71
+ if (node.parent?.type === 'folder') return isParentDatacenter(node.parent)
72
+ return false
73
+ }
74
+ const submit = async (cb: Function): Promise<void> => {
75
+ const name = vmName.value
76
+
77
+ if (name !== '') {
78
+ const isNameValid = await checkNameIsValid(name)
79
+ if (!isNameValid) {
80
+ cb(false)
81
+ return
82
+ }
83
+ }
84
+
85
+ if (props.project === 'sphere') {
86
+ // const isDatacenterFolder = isParentDatacenter(selectedNode.value)
87
+
88
+ if (
89
+ // selectedNode.value?.type !== 'datacenter' &&
90
+ // selectedNode.value?.type === 'folder' &&
91
+ // !isDatacenterFolder
92
+ // TODO рефакторинг, здесь сейчас проверяем является ли выбранный элемент датацентром или папкой(вм)
93
+ ![3, 7].includes(selectedNode.value?.kind)
94
+ ) {
95
+ showValidationErrors([
96
+ localization.value.common.enterValidLocationVirtualMachine,
97
+ ])
98
+ cb(false)
99
+ return
100
+ }
101
+ }
102
+
103
+ onRemoveValidationErrors()
104
+ emits('submit', [name, selectedNode.value])
105
+ cb(true)
106
+ }
107
+ const checkNameIsValid = async (name: string): Promise<boolean> => {
108
+ emits('loading', true)
109
+
110
+ return new Promise((resolve) => {
111
+ emits('check-name', [
112
+ [name, selectedNode.value],
113
+ (error) => {
114
+ emits('loading', false)
115
+
116
+ const status = error?.statusCode || 200
117
+ switch (status) {
118
+ case 405: // Invalid kind
119
+ showValidationErrors([
120
+ localization.value.common.kindValidationDescription,
121
+ ])
122
+ resolve(false)
123
+ break
124
+ case 406: // Invalid name
125
+ showValidationErrors([
126
+ localization.value.common.vmNameValidationDescription,
127
+ ])
128
+ resolve(false)
129
+ break
130
+ case 409: // Name exist
131
+ showValidationErrors([
132
+ localization.value.common.vmNameExistInSelectedLocation,
133
+ ])
134
+ resolve(false)
135
+ break
136
+ }
137
+
138
+ resolve(true)
139
+ },
140
+ ])
141
+ })
142
+ }
143
+
144
+ const errors = ref<string[]>([])
145
+ const showValidationErrors = (data: string[]): void => {
146
+ errors.value = data
147
+ }
148
+ const onRemoveValidationErrors = (): void => {
149
+ errors.value = []
150
+ }
151
+ watch(
152
+ errors,
153
+ (newValue) => {
154
+ emits('has-errors', !newValue.length)
155
+ },
156
+ { immediate: true, deep: true }
157
+ )
158
+
159
+ watch(
160
+ () => props.show,
161
+ (newValue) => {
162
+ if (!newValue) return
163
+
164
+ const input = document.getElementById('virtual-machine-name')
165
+ if (!input) return
166
+
167
+ setTimeout(() => {
168
+ input.focus()
169
+ }, 0)
170
+ }
171
+ )
172
+
173
+ const isShowHelp = ref<boolean>(false)
174
+ </script>
175
+
176
+ <style scoped lang="scss"></style>