feat: ListLabels script setup (#2416)
Co-authored-by: Dominik Pschenitschni <mail@celement.de> Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2416 Reviewed-by: konrad <k@knt.li> Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de> Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
parent
ba2605af1b
commit
89e428b4d2
2 changed files with 68 additions and 80 deletions
|
@ -22,7 +22,7 @@ export default class LabelModel extends AbstractModel<ILabel> implements ILabel
|
||||||
created: Date = null
|
created: Date = null
|
||||||
updated: Date = null
|
updated: Date = null
|
||||||
|
|
||||||
constructor(data: Partial<ILabel>) {
|
constructor(data: Partial<ILabel> = {}) {
|
||||||
super()
|
super()
|
||||||
this.assignData(data)
|
this.assignData(data)
|
||||||
|
|
||||||
|
|
|
@ -109,90 +109,78 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import {defineComponent} from 'vue'
|
import {computed, nextTick, ref} from 'vue'
|
||||||
import {mapState as mapVuexState} from 'vuex'
|
import {useI18n} from 'vue-i18n'
|
||||||
import {mapState} from 'pinia'
|
|
||||||
|
|
||||||
import LabelModel from '../../models/label'
|
import BaseButton from '@/components/base/BaseButton.vue'
|
||||||
|
import Editor from '@/components/input/AsyncEditor'
|
||||||
|
import ColorPicker from '@/components/input/colorPicker.vue'
|
||||||
|
|
||||||
|
import LabelModel from '@/models/label'
|
||||||
import type {ILabel} from '@/modelTypes/ILabel'
|
import type {ILabel} from '@/modelTypes/ILabel'
|
||||||
import {useLabelStore} from '@/stores/labels'
|
import {useLabelStore} from '@/stores/labels'
|
||||||
|
|
||||||
import BaseButton from '@/components/base/BaseButton.vue'
|
import { useTitle } from '@/composables/useTitle'
|
||||||
import AsyncEditor from '@/components/input/AsyncEditor'
|
import { useStore } from '@/store'
|
||||||
import ColorPicker from '@/components/input/colorPicker.vue'
|
|
||||||
import { setTitle } from '@/helpers/setTitle'
|
const {t} = useI18n({useScope: 'global'})
|
||||||
|
|
||||||
|
const labelEditLabel = ref<ILabel>(new LabelModel())
|
||||||
|
const isLabelEdit = ref(false)
|
||||||
|
const editorActive = ref(false)
|
||||||
|
const showDeleteModal = ref(false)
|
||||||
|
const labelToDelete = ref<ILabel>(null)
|
||||||
|
|
||||||
|
useTitle(() => t('label.title'))
|
||||||
|
|
||||||
|
const store = useStore()
|
||||||
|
const userInfo = computed(() => store.state.auth.info)
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'ListLabels',
|
|
||||||
components: {
|
|
||||||
BaseButton,
|
|
||||||
ColorPicker,
|
|
||||||
editor: AsyncEditor,
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
labelEditLabel: new LabelModel(),
|
|
||||||
isLabelEdit: false,
|
|
||||||
editorActive: false,
|
|
||||||
showDeleteModal: false,
|
|
||||||
labelToDelete: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
labelStore.loadAllLabels()
|
labelStore.loadAllLabels()
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
setTitle(this.$t('label.title'))
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapVuexState({
|
|
||||||
userInfo: state => state.auth.info,
|
|
||||||
}),
|
|
||||||
...mapState(useLabelStore, {
|
|
||||||
// Alphabetically sort the labels
|
// Alphabetically sort the labels
|
||||||
labels: state => Object.values(state.labels).sort((f, s) => f.title > s.title ? 1 : -1),
|
const labels = computed(() => Object.values(labelStore.labels).sort((f, s) => f.title > s.title ? 1 : -1))
|
||||||
loading: state => state.isLoading,
|
const loading = computed(() =>labelStore.isLoading)
|
||||||
}),
|
|
||||||
},
|
function deleteLabel(label: ILabel) {
|
||||||
methods: {
|
showDeleteModal.value = false
|
||||||
deleteLabel(label: ILabel) {
|
isLabelEdit.value = false
|
||||||
this.showDeleteModal = false
|
|
||||||
this.isLabelEdit = false
|
|
||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
return labelStore.deleteLabel(label)
|
return labelStore.deleteLabel(label)
|
||||||
},
|
}
|
||||||
editLabelSubmit() {
|
|
||||||
|
function editLabelSubmit() {
|
||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
return labelStore.updateLabel(this.labelEditLabel)
|
return labelStore.updateLabel(labelEditLabel.value)
|
||||||
},
|
}
|
||||||
editLabel(label: ILabel) {
|
|
||||||
if (label.createdBy.id !== this.userInfo.id) {
|
function editLabel(label: ILabel) {
|
||||||
|
if (label.createdBy.id !== userInfo.value.id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Duplicating the label to make sure it does not look like changes take effect immediatly as the label
|
// Duplicating the label to make sure it does not look like changes take effect immediatly as the label
|
||||||
// object passed to this function here still has a reference to the store.
|
// object passed to this function here still has a reference to the store.
|
||||||
this.labelEditLabel = new LabelModel({
|
labelEditLabel.value = new LabelModel({
|
||||||
...label,
|
...label,
|
||||||
// The model does not support passing dates into it directly so we need to convert them first
|
// The model does not support passing dates into it directly so we need to convert them first
|
||||||
created: +label.created,
|
created: +label.created,
|
||||||
updated: +label.updated,
|
updated: +label.updated,
|
||||||
})
|
})
|
||||||
this.isLabelEdit = true
|
isLabelEdit.value = true
|
||||||
|
|
||||||
// This makes the editor trigger its mounted function again which makes it forget every input
|
// This makes the editor trigger its mounted function again which makes it forget every input
|
||||||
// it currently has in its textarea. This is a counter-hack to a hack inside of vue-easymde
|
// it currently has in its textarea. This is a counter-hack to a hack inside of vue-easymde
|
||||||
// which made it impossible to detect change from the outside. Therefore the component would
|
// which made it impossible to detect change from the outside. Therefore the component would
|
||||||
// not update if new content from the outside was made available.
|
// not update if new content from the outside was made available.
|
||||||
// See https://github.com/NikulinIlya/vue-easymde/issues/3
|
// See https://github.com/NikulinIlya/vue-easymde/issues/3
|
||||||
this.editorActive = false
|
editorActive.value = false
|
||||||
this.$nextTick(() => this.editorActive = true)
|
nextTick(() => editorActive.value = true)
|
||||||
},
|
}
|
||||||
showDeleteDialoge(label: ILabel) {
|
|
||||||
this.labelToDelete = label
|
function showDeleteDialoge(label: ILabel) {
|
||||||
this.showDeleteModal = true
|
labelToDelete.value = label
|
||||||
},
|
showDeleteModal.value = true
|
||||||
},
|
}
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue