update tag

This commit is contained in:
lesion 2022-12-13 15:37:04 +01:00
parent 06b35b0cd0
commit dcb954918a
No known key found for this signature in database
GPG key ID: 352918250B012177
6 changed files with 54 additions and 15 deletions

View file

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

View file

@ -9,19 +9,28 @@ v-container
v-dialog(v-model='dialog' width='600' :fullscreen='$vuetify.breakpoint.xsOnly')
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
p {{newTag}}
v-form(v-model='valid' ref='form' lazy-validation)
v-text-field(
:rules="[$validators.required('common.name')]"
:label="$t('common.tag')"
v-model='tag.tag'
:placeholder='$t("common.tag")')
v-combobox(v-model='newTag'
:prepend-icon="mdiTag"
hide-no-data
persistent-hint
: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-spacer
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') }}
v-card-text
@ -44,7 +53,7 @@ v-container
</template>
<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 debounce from 'lodash/debounce'
import get from 'lodash/get'
@ -52,11 +61,12 @@ import get from 'lodash/get'
export default {
data( {$store} ) {
return {
mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever,
mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown, mdiDeleteForever, mdiTag,
loading: false,
dialog: false,
valid: false,
tag: {},
newTag: '',
tags: [],
search: '',
headers: [
@ -75,18 +85,21 @@ export default {
methods: {
editTag(item) {
this.tag.tag = item.tag
this.tag.count = item.count
this.dialog = true
},
async saveTag() {
if (!this.$refs.form.validate()) return
this.loading = true
await this.$axios.$put('/tag', this.tag)
await this.$fetch()
this.loading = false
this.dialog = false
this.$nextTick( async () => {
await this.$axios.$put('/tag', { tag: this.tag.tag, newTag: this.newTag })
await this.$fetch()
this.loading = false
this.dialog = false
})
},
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 }
try {
await this.$axios.$delete(`/tag/${encodeURIComponent(tag.tag)}`)

View file

@ -214,6 +214,7 @@
"hide_resource": "Hide resource",
"delete_resource": "Delete 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",
"filter_instances": "Filter instances",
"filter_users": "Filter users",
@ -245,6 +246,8 @@
"footer_links": "Footer links",
"delete_footer_link_confirm": "Sure to remove this link?",
"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",
"show_smtp_setup": "Email settings",
"smtp_hostname": "SMTP Hostname",

View file

@ -240,6 +240,8 @@
"footer_links": "Collegamenti del piè di pagina",
"delete_footer_link_confirm": "Vuoi eliminare questo collegamento?",
"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",
"show_smtp_setup": "Impostazioni email",
"widget": "Widget",

View file

@ -88,6 +88,24 @@ module.exports = {
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) {
log.info('Remove tag', req.params.tag)

View file

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