bfg-common 1.2.203 → 1.2.205

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,215 +1,215 @@
1
- <template>
2
- <div class="select-name">
3
- <atoms-alert
4
- v-show="errors.length"
5
- status="alert-danger"
6
- :items="errors"
7
- @remove="onRemoveValidationErrors"
8
- />
9
-
10
- <form id="virtual-machine-form" @submit.prevent>
11
- <label for="virtual-machine-name"
12
- >{{ localization.virtualMachineName }}:</label
13
- >
14
- <input id="virtual-machine-name" v-model.trim="vmName" type="text" />
15
- <div id="vm-name-help-icon" class="content-signpost relative">
16
- <atoms-the-icon
17
- class="icon-show-help"
18
- fill="#0072a3"
19
- width="24px"
20
- height="24px"
21
- name="info-circle"
22
- @click="isShowHelp = !isShowHelp"
23
- />
24
- <atoms-tooltip-signpost
25
- v-if="isShowHelp"
26
- test-id="help-signpost"
27
- elem-id="vm-name-help-icon"
28
- @hide="isShowHelp = false"
29
- >
30
- <p>
31
- {{ localization.vmNameValidationDescription2 }}
32
- </p>
33
- </atoms-tooltip-signpost>
34
- </div>
35
- </form>
36
-
37
- <template v-if="props.project === 'sphere'">
38
- <p class="new-vm-name-and-folder-instructions mt-1">
39
- {{ localization.selectLocationVirtualMachine }}
40
- </p>
41
- <div class="tree-view-wrap">
42
- <common-vm-actions-add-folder-tree-view
43
- :data-center="props.dataCenter"
44
- @select-node="onSelectNode"
45
- />
46
- </div>
47
- </template>
48
- </div>
49
- </template>
50
-
51
- <script setup lang="ts">
52
- // import { API_UI_I_Error } from '~/models/store/interfaces'
53
- import { UI_I_Localization } from '~/models/interfaces'
54
- import { UI_T_Project } from '~/models/types'
55
- import { UI_I_TreeNode } from '~/components/common/recursionTree/models/interfaces'
56
-
57
- const props = defineProps<{
58
- nameFormSubmit: number
59
- show: boolean
60
- project: UI_T_Project
61
- dataCenter?: UI_I_TreeNode // для сферы
62
- }>()
63
- const emits = defineEmits<{
64
- (event: 'submit', value: [string, UI_I_TreeNode | null]): void
65
- (event: 'loading', value: boolean): void
66
- (
67
- event: 'check-name',
68
- value: [[string, UI_I_TreeNode | null], (error: any) => void]
69
- ): void
70
- }>()
71
-
72
- const localization = computed<UI_I_Localization>(() => useLocal())
73
-
74
- const vmName = ref<string>('')
75
-
76
- const selectedNode = ref<UI_I_TreeNode | null>(null)
77
- const onSelectNode = (node: UI_I_TreeNode): void => {
78
- selectedNode.value = node
79
- }
80
-
81
- watch(
82
- () => props.nameFormSubmit,
83
- () => {
84
- submit()
85
- }
86
- )
87
-
88
- const isParentDatacenter = (node: UI_I_TreeNode | null): boolean => {
89
- if (!node) return false
90
-
91
- if (node.parent?.type === 'datacenter') return true
92
- if (node.parent?.type === 'folder') return isParentDatacenter(node.parent)
93
- return false
94
- }
95
- const submit = async (): Promise<void> => {
96
- const name = vmName.value
97
-
98
- if (name !== '') {
99
- const isNameValid = await checkNameIsValid(name)
100
- if (!isNameValid) return
101
- }
102
-
103
- if (props.project === 'sphere') {
104
- const isDatacenterFolder = isParentDatacenter(selectedNode.value)
105
-
106
- if (
107
- selectedNode.value?.type !== 'datacenter' &&
108
- selectedNode.value?.type === 'folder' &&
109
- !isDatacenterFolder
110
- ) {
111
- showValidationErrors([
112
- localization.value.enterValidLocationVirtualMachine,
113
- ])
114
- return
115
- }
116
- }
117
-
118
- onRemoveValidationErrors()
119
- emits('submit', [name, selectedNode.value])
120
- }
121
- const checkNameIsValid = async (name: string): Promise<boolean> => {
122
- emits('loading', true)
123
-
124
- return new Promise((resolve) => {
125
- emits('check-name', [
126
- [name, selectedNode.value],
127
- (error) => {
128
- emits('loading', false)
129
-
130
- const status = error?.statusCode || 200
131
- switch (status) {
132
- case 406: // Invalid name
133
- showValidationErrors([
134
- localization.value.vmNameValidationDescription2,
135
- ])
136
- resolve(false)
137
- break
138
- case 409: // Name exist
139
- showValidationErrors([
140
- localization.value.vmNameExistInSelectedLocation,
141
- ])
142
- resolve(false)
143
- break
144
- }
145
-
146
- resolve(true)
147
- },
148
- ])
149
- })
150
- }
151
-
152
- const errors = ref<string[]>([])
153
- const showValidationErrors = (data: string[]): void => {
154
- errors.value = data
155
- }
156
- const onRemoveValidationErrors = (): void => {
157
- errors.value = []
158
- }
159
-
160
- watch(
161
- () => props.show,
162
- (newValue) => {
163
- if (!newValue) return
164
-
165
- const input = document.getElementById('virtual-machine-name')
166
- if (!input) return
167
-
168
- setTimeout(() => {
169
- input.focus()
170
- }, 0)
171
- }
172
- )
173
-
174
- const isShowHelp = ref<boolean>(false)
175
- </script>
176
-
177
- <style scoped lang="scss">
178
- .select-name {
179
- form {
180
- display: flex;
181
- align-items: center;
182
- padding-top: 20px;
183
-
184
- label {
185
- width: 216px;
186
- }
187
- input {
188
- width: 345px;
189
- }
190
- }
191
-
192
- .tree-view-wrap {
193
- position: relative;
194
- border: 1px solid #000;
195
- padding: 5px;
196
- max-height: 300px;
197
- min-height: 200px;
198
- overflow: auto;
199
- margin-bottom: 10px;
200
- }
201
- }
202
- .content-signpost {
203
- .icon-show-help {
204
- cursor: pointer;
205
- }
206
-
207
- .help-title {
208
- font-size: 22px;
209
- margin-bottom: 24px;
210
- }
211
- .signpost {
212
- max-width: 360px;
213
- }
214
- }
215
- </style>
1
+ <template>
2
+ <div class="select-name">
3
+ <atoms-alert
4
+ v-show="errors.length"
5
+ status="alert-danger"
6
+ :items="errors"
7
+ @remove="onRemoveValidationErrors"
8
+ />
9
+
10
+ <form id="virtual-machine-form" @submit.prevent>
11
+ <label for="virtual-machine-name"
12
+ >{{ localization.virtualMachineName }}:</label
13
+ >
14
+ <input id="virtual-machine-name" v-model.trim="vmName" type="text" />
15
+ <div id="vm-name-help-icon" class="content-signpost relative">
16
+ <atoms-the-icon
17
+ class="icon-show-help"
18
+ fill="#0072a3"
19
+ width="24px"
20
+ height="24px"
21
+ name="info-circle"
22
+ @click="isShowHelp = !isShowHelp"
23
+ />
24
+ <atoms-tooltip-signpost
25
+ v-if="isShowHelp"
26
+ test-id="help-signpost"
27
+ elem-id="vm-name-help-icon"
28
+ @hide="isShowHelp = false"
29
+ >
30
+ <p>
31
+ {{ localization.vmNameValidationDescription2 }}
32
+ </p>
33
+ </atoms-tooltip-signpost>
34
+ </div>
35
+ </form>
36
+
37
+ <template v-if="props.project === 'sphere'">
38
+ <p class="new-vm-name-and-folder-instructions mt-1">
39
+ {{ localization.selectLocationVirtualMachine }}
40
+ </p>
41
+ <div class="tree-view-wrap">
42
+ <common-vm-actions-add-folder-tree-view
43
+ :data-center="props.dataCenter"
44
+ @select-node="onSelectNode"
45
+ />
46
+ </div>
47
+ </template>
48
+ </div>
49
+ </template>
50
+
51
+ <script setup lang="ts">
52
+ // import { API_UI_I_Error } from '~/models/store/interfaces'
53
+ import { UI_I_Localization } from '~/models/interfaces'
54
+ import { UI_T_Project } from '~/models/types'
55
+ import { UI_I_TreeNode } from '~/components/common/recursionTree/models/interfaces'
56
+
57
+ const props = defineProps<{
58
+ nameFormSubmit: number
59
+ show: boolean
60
+ project: UI_T_Project
61
+ dataCenter?: UI_I_TreeNode // для сферы
62
+ }>()
63
+ const emits = defineEmits<{
64
+ (event: 'submit', value: [string, UI_I_TreeNode | null]): void
65
+ (event: 'loading', value: boolean): void
66
+ (
67
+ event: 'check-name',
68
+ value: [[string, UI_I_TreeNode | null], (error: any) => void]
69
+ ): void
70
+ }>()
71
+
72
+ const localization = computed<UI_I_Localization>(() => useLocal())
73
+
74
+ const vmName = ref<string>('')
75
+
76
+ const selectedNode = ref<UI_I_TreeNode | null>(null)
77
+ const onSelectNode = (node: UI_I_TreeNode): void => {
78
+ selectedNode.value = node
79
+ }
80
+
81
+ watch(
82
+ () => props.nameFormSubmit,
83
+ () => {
84
+ submit()
85
+ }
86
+ )
87
+
88
+ const isParentDatacenter = (node: UI_I_TreeNode | null): boolean => {
89
+ if (!node) return false
90
+
91
+ if (node.parent?.type === 'datacenter') return true
92
+ if (node.parent?.type === 'folder') return isParentDatacenter(node.parent)
93
+ return false
94
+ }
95
+ const submit = async (): Promise<void> => {
96
+ const name = vmName.value
97
+
98
+ if (name !== '') {
99
+ const isNameValid = await checkNameIsValid(name)
100
+ if (!isNameValid) return
101
+ }
102
+
103
+ if (props.project === 'sphere') {
104
+ const isDatacenterFolder = isParentDatacenter(selectedNode.value)
105
+
106
+ if (
107
+ selectedNode.value?.type !== 'datacenter' &&
108
+ selectedNode.value?.type === 'folder' &&
109
+ !isDatacenterFolder
110
+ ) {
111
+ showValidationErrors([
112
+ localization.value.enterValidLocationVirtualMachine,
113
+ ])
114
+ return
115
+ }
116
+ }
117
+
118
+ onRemoveValidationErrors()
119
+ emits('submit', [name, selectedNode.value])
120
+ }
121
+ const checkNameIsValid = async (name: string): Promise<boolean> => {
122
+ emits('loading', true)
123
+
124
+ return new Promise((resolve) => {
125
+ emits('check-name', [
126
+ [name, selectedNode.value],
127
+ (error) => {
128
+ emits('loading', false)
129
+
130
+ const status = error?.statusCode || 200
131
+ switch (status) {
132
+ case 406: // Invalid name
133
+ showValidationErrors([
134
+ localization.value.vmNameValidationDescription2,
135
+ ])
136
+ resolve(false)
137
+ break
138
+ case 409: // Name exist
139
+ showValidationErrors([
140
+ localization.value.vmNameExistInSelectedLocation,
141
+ ])
142
+ resolve(false)
143
+ break
144
+ }
145
+
146
+ resolve(true)
147
+ },
148
+ ])
149
+ })
150
+ }
151
+
152
+ const errors = ref<string[]>([])
153
+ const showValidationErrors = (data: string[]): void => {
154
+ errors.value = data
155
+ }
156
+ const onRemoveValidationErrors = (): void => {
157
+ errors.value = []
158
+ }
159
+
160
+ watch(
161
+ () => props.show,
162
+ (newValue) => {
163
+ if (!newValue) return
164
+
165
+ const input = document.getElementById('virtual-machine-name')
166
+ if (!input) return
167
+
168
+ setTimeout(() => {
169
+ input.focus()
170
+ }, 0)
171
+ }
172
+ )
173
+
174
+ const isShowHelp = ref<boolean>(false)
175
+ </script>
176
+
177
+ <style scoped lang="scss">
178
+ .select-name {
179
+ form {
180
+ display: flex;
181
+ align-items: center;
182
+ padding-top: 20px;
183
+
184
+ label {
185
+ width: 216px;
186
+ }
187
+ input {
188
+ width: 345px;
189
+ }
190
+ }
191
+
192
+ .tree-view-wrap {
193
+ position: relative;
194
+ border: 1px solid #000;
195
+ padding: 5px;
196
+ max-height: 300px;
197
+ min-height: 200px;
198
+ overflow: auto;
199
+ margin-bottom: 10px;
200
+ }
201
+ }
202
+ .content-signpost {
203
+ .icon-show-help {
204
+ cursor: pointer;
205
+ }
206
+
207
+ .help-title {
208
+ font-size: 22px;
209
+ margin-bottom: 24px;
210
+ }
211
+ .signpost {
212
+ max-width: 360px;
213
+ }
214
+ }
215
+ </style>