Skip to content

Commit 778634c

Browse files
committed
New AdminUI: tags tab. In development.
1 parent 1013062 commit 778634c

File tree

3 files changed

+58
-17
lines changed

3 files changed

+58
-17
lines changed

src/AdminUI/src/App.vue

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<v-app-bar app height="48">
44
<v-app-bar-title class="text-subtitle-1">
55
<router-link to="/" class="text-decoration-none">
6-
{{ $t('app.title') }}
6+
<v-tooltip :text="version">
7+
<template v-slot:activator="{ props }">
8+
<span v-bind="props">{{ $t('app.title') }}</span>
9+
</template>
10+
</v-tooltip>
711
</router-link>
812
</v-app-bar-title>
913
<v-spacer></v-spacer>
@@ -72,6 +76,7 @@ import { useI18n } from 'vue-i18n';
7276
import { useRouter } from 'vue-router';
7377
import { STORAGE_KEY } from './i18n';
7478
79+
const version = ref("v0.38-alpha");
7580
const router = useRouter();
7681
const theme = ref('dark');
7782
const vuetifyTheme = useTheme();
@@ -147,16 +152,16 @@ const changePwd = () => {
147152
if (newPassword.value !== confirmNewPassword.value) {
148153
errorMessage.value = t('login.passwordMismatch')
149154
setTimeout(() => {
150-
errorMessage.value = ""
151-
}, 1500)
155+
errorMessage.value = ""
156+
}, 1500)
152157
return
153158
}
154159
155160
if (newPassword.value.trim() === "" || newPassword.value.trim().length < 4) {
156161
errorMessage.value = t('login.invalidNewPassword')
157162
setTimeout(() => {
158-
errorMessage.value = ""
159-
}, 1500)
163+
errorMessage.value = ""
164+
}, 1500)
160165
return
161166
}
162167
@@ -185,13 +190,13 @@ const changePwd = () => {
185190
} else {
186191
errorMessage.value = t('login.changePasswordFailed')
187192
setTimeout(() => {
188-
errorMessage.value = ""
189-
}, 1500)
193+
errorMessage.value = ""
194+
}, 1500)
190195
}
191196
})
192-
.catch((err) => {
197+
.catch((err) => {
193198
console.warn(err)
194-
errorMessage.value = t('login.changePasswordError')
199+
errorMessage.value = t('login.changePasswordError')
195200
setTimeout(() => {
196201
errorMessage.value = ""
197202
}, 1500)

src/AdminUI/src/components/TagsTab.vue

+43-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<v-card>
5151
<v-card-title class="headline">{{
5252
$t('admin.tags.confirmErase')
53-
}}</v-card-title>
53+
}}</v-card-title>
5454
<v-card-text>
5555
<v-text-field density="compact" readonly variant="outlined" v-model="editedTag._id"
5656
:label="$t('admin.tags.eraseId')"></v-text-field>
@@ -76,7 +76,8 @@
7676
</v-card-title>
7777

7878
<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>
8081
<v-text-field v-model="editedTag.tag" :label="$t('admin.tags.editName')"></v-text-field>
8182
<v-text-field v-model="editedTag.description" :label="$t('admin.tags.editDescription')"></v-text-field>
8283
<v-text-field v-model="editedTag.ungroupedDescription"
@@ -216,7 +217,7 @@
216217
<v-btn color="orange darken-1" text variant="tonal" @click="closeEditTag">
217218
{{ $t('common.cancel') }}
218219
</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">
220221
{{ $t('common.save') }}
221222
</v-btn>
222223
</v-card-actions>
@@ -318,6 +319,7 @@ const { t } = useI18n()
318319
const dialogEditTag = ref(false)
319320
const dialogDeleteTag = ref(false)
320321
const dialogAddParcel = ref(false)
322+
const isNewTag = ref(false)
321323
const tags = ref([])
322324
const protocolConnections = ref([])
323325
const protocolDriveNameByConnNumber = ref([])
@@ -367,7 +369,7 @@ const defaultTagValue = ref({
367369
historianDeadBand: 0,
368370
historianPeriod: 0,
369371
})
370-
const editedTag = ref({...defaultTagValue.value})
372+
const editedTag = ref({ ...defaultTagValue.value })
371373
372374
const headers = computed(() => [
373375
{
@@ -420,13 +422,15 @@ const handleOptionsUpdate = (newOptions) => {
420422
}
421423
422424
const newTagOpenDialog = async () => {
425+
isNewTag.value = true
423426
error.value = false;
424427
editedTag.value = Object.assign({}, defaultTagValue.value);
425428
await fetchProtocolConnections()
426429
dialogEditTag.value = true;
427430
}
428431
429432
const editTagOpenDialog = async (item) => {
433+
isNewTag.value = false
430434
error.value = false;
431435
editedTag.value = Object.assign({}, item);
432436
await fetchProtocolConnections()
@@ -447,8 +451,8 @@ const deleteTag = async () => {
447451
'Content-Type': 'application/json',
448452
},
449453
body: JSON.stringify({
450-
tag: editedTag.tag,
451-
_id: editedTag._id,
454+
tag: editedTag.value.tag,
455+
_id: editedTag.value._id,
452456
}),
453457
})
454458
const json = await response.json()
@@ -469,6 +473,38 @@ const closeDeleteTag = () => {
469473
dialogDeleteTag.value = false
470474
}
471475
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+
472508
const updateTag = async () => {
473509
try {
474510
const response = await fetch('/Invoke/auth/updateTag', {
@@ -477,7 +513,7 @@ const updateTag = async () => {
477513
Accept: 'application/json',
478514
'Content-Type': 'application/json',
479515
},
480-
body: JSON.stringify(editedTag),
516+
body: JSON.stringify(editedTag.value),
481517
})
482518
const json = await response.json()
483519
if (json.error) { console.log(json); error.value = true; }

src/AdminUI/src/locales/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@
528528
"eraseName": "Tag name",
529529
"newTag": "New Tag",
530530
"editTag": "Edit Tag",
531-
"editId": "Tag _id (unique numeric point key)",
531+
"editId": "Tag _id (unique numeric point key, empty for auto-assign)",
532532
"editName": "Tag name (unique string key)",
533533
"editDescription": "Description",
534534
"editUngroupedDescription": "Ungrouped Description",

0 commit comments

Comments
 (0)