50
50
<v-card >
51
51
<v-card-title class =" headline" >{{
52
52
$t('admin.tags.confirmErase')
53
- }}</v-card-title >
53
+ }}</v-card-title >
54
54
<v-card-text >
55
55
<v-text-field density =" compact" readonly variant =" outlined" v-model =" editedTag._id"
56
56
:label =" $t('admin.tags.eraseId')" ></v-text-field >
76
76
</v-card-title >
77
77
78
78
<v-card-text >
79
- <v-text-field v-model =" editedTag._id" :label =" $t('admin.tags.editId')" ></v-text-field >
79
+ <v-text-field type =" number" v-model =" editedTag._id" :label =" $t('admin.tags.editId')" :disabled =" !isNewTag"
80
+ min =" 0" ></v-text-field >
80
81
<v-text-field v-model =" editedTag.tag" :label =" $t('admin.tags.editName')" ></v-text-field >
81
82
<v-text-field v-model =" editedTag.description" :label =" $t('admin.tags.editDescription')" ></v-text-field >
82
83
<v-text-field v-model =" editedTag.ungroupedDescription"
216
217
<v-btn color =" orange darken-1" text variant =" tonal" @click =" closeEditTag" >
217
218
{{ $t('common.cancel') }}
218
219
</v-btn >
219
- <v-btn color =" blue darken-1" text variant =" tonal" @click =" updateTag " >
220
+ <v-btn color =" blue darken-1" text variant =" tonal" @click =" updateOrCreateTag " >
220
221
{{ $t('common.save') }}
221
222
</v-btn >
222
223
</v-card-actions >
@@ -318,6 +319,7 @@ const { t } = useI18n()
318
319
const dialogEditTag = ref (false )
319
320
const dialogDeleteTag = ref (false )
320
321
const dialogAddParcel = ref (false )
322
+ const isNewTag = ref (false )
321
323
const tags = ref ([])
322
324
const protocolConnections = ref ([])
323
325
const protocolDriveNameByConnNumber = ref ([])
@@ -367,7 +369,7 @@ const defaultTagValue = ref({
367
369
historianDeadBand: 0 ,
368
370
historianPeriod: 0 ,
369
371
})
370
- const editedTag = ref ({... defaultTagValue .value })
372
+ const editedTag = ref ({ ... defaultTagValue .value })
371
373
372
374
const headers = computed (() => [
373
375
{
@@ -420,13 +422,15 @@ const handleOptionsUpdate = (newOptions) => {
420
422
}
421
423
422
424
const newTagOpenDialog = async () => {
425
+ isNewTag .value = true
423
426
error .value = false ;
424
427
editedTag .value = Object .assign ({}, defaultTagValue .value );
425
428
await fetchProtocolConnections ()
426
429
dialogEditTag .value = true ;
427
430
}
428
431
429
432
const editTagOpenDialog = async (item ) => {
433
+ isNewTag .value = false
430
434
error .value = false ;
431
435
editedTag .value = Object .assign ({}, item);
432
436
await fetchProtocolConnections ()
@@ -447,8 +451,8 @@ const deleteTag = async () => {
447
451
' Content-Type' : ' application/json' ,
448
452
},
449
453
body: JSON .stringify ({
450
- tag: editedTag .tag ,
451
- _id: editedTag ._id ,
454
+ tag: editedTag .value . tag ,
455
+ _id: editedTag .value . _id ,
452
456
}),
453
457
})
454
458
const json = await response .json ()
@@ -469,6 +473,38 @@ const closeDeleteTag = () => {
469
473
dialogDeleteTag .value = false
470
474
}
471
475
476
+ const updateOrCreateTag = async () => {
477
+ if (editedTag .value ._id ) {
478
+ await updateTag ();
479
+ } else {
480
+ await createTag ();
481
+ }
482
+ }
483
+
484
+ const createTag = async () => {
485
+ try {
486
+ const response = await fetch (' /Invoke/auth/createTag' , {
487
+ method: ' post' ,
488
+ headers: {
489
+ Accept: ' application/json' ,
490
+ ' Content-Type' : ' application/json' ,
491
+ },
492
+ body: JSON .stringify (editedTag .value ),
493
+ })
494
+ const json = await response .json ()
495
+ if (json .error || ! json ._id ) {
496
+ console .warn (json)
497
+ error .value = true
498
+ return
499
+ }
500
+ dialogEditTag .value = false
501
+ } catch (err) {
502
+ console .warn (err)
503
+ error .value = true
504
+ }
505
+ fetchTags ()
506
+ }
507
+
472
508
const updateTag = async () => {
473
509
try {
474
510
const response = await fetch (' /Invoke/auth/updateTag' , {
@@ -477,7 +513,7 @@ const updateTag = async () => {
477
513
Accept: ' application/json' ,
478
514
' Content-Type' : ' application/json' ,
479
515
},
480
- body: JSON .stringify (editedTag),
516
+ body: JSON .stringify (editedTag . value ),
481
517
})
482
518
const json = await response .json ()
483
519
if (json .error ) { console .log (json); error .value = true ; }
0 commit comments