update tag

This commit is contained in:
lesion
2022-12-13 15:37:04 +01:00
parent 06b35b0cd0
commit dcb954918a
6 changed files with 54 additions and 15 deletions

View File

@@ -33,7 +33,7 @@ v-container
:prepend-icon="mdiTagMultiple" :prepend-icon="mdiTagMultiple"
chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint
:disabled="!collection.id" :disabled="!collection.id"
placeholder='Tutte' placeholder='All'
@input.native='searchTags' @input.native='searchTags'
@focus='searchTags' @focus='searchTags'
:delimiters="[',', ';']" :delimiters="[',', ';']"

View File

@@ -9,19 +9,28 @@ v-container
v-dialog(v-model='dialog' width='600' :fullscreen='$vuetify.breakpoint.xsOnly') v-dialog(v-model='dialog' width='600' :fullscreen='$vuetify.breakpoint.xsOnly')
v-card v-card
v-card-title {{ $t('admin.edit_tag') }} v-card-title {{$t('admin.edit_tag')}} -
strong.ml-2 {{tag.tag}}
v-card-subtitle {{$tc('admin.edit_tag_help', tag.count)}}
v-card-text v-card-text
p {{newTag}}
v-form(v-model='valid' ref='form' lazy-validation) v-form(v-model='valid' ref='form' lazy-validation)
v-text-field( v-combobox(v-model='newTag'
:rules="[$validators.required('common.name')]" :prepend-icon="mdiTag"
:label="$t('common.tag')" hide-no-data
v-model='tag.tag' persistent-hint
:placeholder='$t("common.tag")') :items="tags"
:return-object='false'
item-value='tag'
item-text='tag'
:label="$t('common.tags')")
template(v-slot:item="{ item, on, attrs }")
span "{{item.tag}}" <small>({{item.count}})</small>
v-card-actions v-card-actions
v-spacer v-spacer
v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.cancel') }} v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.cancel') }}
v-btn(@click='savePlace' color='primary' outlined :loading='loading' v-btn(@click='saveTag' color='primary' outlined :loading='loading'
:disable='!valid || loading') {{ $t('common.save') }} :disable='!valid || loading') {{ $t('common.save') }}
v-card-text v-card-text
@@ -44,7 +53,7 @@ v-container
</template> </template>
<script> <script>
import { mdiPencil, mdiChevronLeft, mdiChevronRight, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever } from '@mdi/js' import { mdiPencil, mdiChevronLeft, mdiChevronRight, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever, mdiTag } from '@mdi/js'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import get from 'lodash/get' import get from 'lodash/get'
@@ -52,11 +61,12 @@ import get from 'lodash/get'
export default { export default {
data( {$store} ) { data( {$store} ) {
return { return {
mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever, mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever, mdiTag,
loading: false, loading: false,
dialog: false, dialog: false,
valid: false, valid: false,
tag: {}, tag: {},
newTag: '',
tags: [], tags: [],
search: '', search: '',
headers: [ headers: [
@@ -75,18 +85,21 @@ export default {
methods: { methods: {
editTag(item) { editTag(item) {
this.tag.tag = item.tag this.tag.tag = item.tag
this.tag.count = item.count
this.dialog = true this.dialog = true
}, },
async saveTag() { async saveTag() {
if (!this.$refs.form.validate()) return if (!this.$refs.form.validate()) return
this.loading = true this.loading = true
await this.$axios.$put('/tag', this.tag) this.$nextTick( async () => {
await this.$fetch() await this.$axios.$put('/tag', { tag: this.tag.tag, newTag: this.newTag })
this.loading = false await this.$fetch()
this.dialog = false this.loading = false
this.dialog = false
})
}, },
async removeTag(tag) { async removeTag(tag) {
const ret = await this.$root.$confirm('admin.delete_tag_confirm', { tag: tag.tag }) const ret = await this.$root.$confirm('admin.delete_tag_confirm', { tag: tag.tag, n: tag.count })
if (!ret) { return } if (!ret) { return }
try { try {
await this.$axios.$delete(`/tag/${encodeURIComponent(tag.tag)}`) await this.$axios.$delete(`/tag/${encodeURIComponent(tag.tag)}`)

View File

@@ -214,6 +214,7 @@
"hide_resource": "Hide resource", "hide_resource": "Hide resource",
"delete_resource": "Delete resource", "delete_resource": "Delete resource",
"delete_resource_confirm": "Are you sure you want to delete this resource?", "delete_resource_confirm": "Are you sure you want to delete this resource?",
"delete_tag_confirm": "Are you sure you want to remove the tag \"{tag}\"? The tag will be removed from {n} events.",
"block_user": "Block user", "block_user": "Block user",
"filter_instances": "Filter instances", "filter_instances": "Filter instances",
"filter_users": "Filter users", "filter_users": "Filter users",
@@ -245,6 +246,8 @@
"footer_links": "Footer links", "footer_links": "Footer links",
"delete_footer_link_confirm": "Sure to remove this link?", "delete_footer_link_confirm": "Sure to remove this link?",
"edit_place": "Edit place", "edit_place": "Edit place",
"edit_tag": "Edit tag",
"edit_tag_help": "You can change the tag by replacing it with a new one or merging it with an existing one. The {n} associated events will also be changed.",
"new_announcement": "New announcement", "new_announcement": "New announcement",
"show_smtp_setup": "Email settings", "show_smtp_setup": "Email settings",
"smtp_hostname": "SMTP Hostname", "smtp_hostname": "SMTP Hostname",

View File

@@ -240,6 +240,8 @@
"footer_links": "Collegamenti del piè di pagina", "footer_links": "Collegamenti del piè di pagina",
"delete_footer_link_confirm": "Vuoi eliminare questo collegamento?", "delete_footer_link_confirm": "Vuoi eliminare questo collegamento?",
"edit_place": "Modifica luogo", "edit_place": "Modifica luogo",
"edit_tag": "Modifica tag",
"edit_tag_help": "Puoi cambiare il tag sostituendolo con uno nuovo o unendolo ad uno gia' esistente. Verranno modificati anche i {n} eventi associati",
"new_announcement": "Nuovo annuncio", "new_announcement": "Nuovo annuncio",
"show_smtp_setup": "Impostazioni email", "show_smtp_setup": "Impostazioni email",
"widget": "Widget", "widget": "Widget",

View File

@@ -88,6 +88,24 @@ module.exports = {
res.json(place) res.json(place)
}, },
async updateTag (req, res) {
const oldtag = await Tag.findByPk(req.body.tag)
const newtag = await Tag.findByPk(req.body.newTag)
// if the new tag does not exists, just rename the old one
if (!newtag) {
oldtag.tag = req.body.newTag
await oldtag.update({ tag: req.body.newTag })
} else {
// in case it exists:
// - search for events with old tag
const events = await oldtag.getEvents()
// - substitute it with the new one
await oldtag.removeEvents(events)
await newtag.addEvents(events)
}
res.sendStatus(200)
},
async remove (req, res) { async remove (req, res) {
log.info('Remove tag', req.params.tag) log.info('Remove tag', req.params.tag)

View File

@@ -162,6 +162,7 @@ if (config.status !== 'READY') {
api.get('/export/:type', cors, exportController.export) api.get('/export/:type', cors, exportController.export)
// - PLACES
api.get('/places', isAdmin, placeController.getAll) api.get('/places', isAdmin, placeController.getAll)
api.get('/place/:placeName', cors, placeController.getEvents) api.get('/place/:placeName', cors, placeController.getEvents)
api.get('/place', cors, placeController.search) api.get('/place', cors, placeController.search)
@@ -169,10 +170,12 @@ if (config.status !== 'READY') {
api.get('/placeOSM/Photon/:place_details', cors, placeController._photon) api.get('/placeOSM/Photon/:place_details', cors, placeController._photon)
api.put('/place', isAdmin, placeController.updatePlace) api.put('/place', isAdmin, placeController.updatePlace)
// - TAGS
api.get('/tags', isAdmin, tagController.getAll) api.get('/tags', isAdmin, tagController.getAll)
api.get('/tag', cors, tagController.search) api.get('/tag', cors, tagController.search)
api.get('/tag/:tag', cors, tagController.getEvents) api.get('/tag/:tag', cors, tagController.getEvents)
api.delete('/tag/:tag', isAdmin, tagController.remove) api.delete('/tag/:tag', isAdmin, tagController.remove)
api.put('/tag', isAdmin, tagController.updateTag)
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES // - FEDIVERSE INSTANCES, MODERATION, RESOURCES