stage: Order editing

pull/7619/head
Ruslan Semak 8 months ago
parent 2570dff99b
commit a8e115306f

@ -87,18 +87,23 @@
td td
v-edit-dialog( v-edit-dialog(
:return-value.sync='props.item.orderPriority' :return-value.sync='props.item.orderPriority'
@open='startEdit(props.item)'
@save='savePriority(props.item)' @save='savePriority(props.item)'
@cancel='cancelEdit()'
large large
persistent
) )
div {{ props.item.orderPriority }} div {{ props.item.orderPriority }}
template(v-slot:input) template(v-slot:input)
v-text-field( v-text-field(
v-model='props.item.orderPriority' v-model.number='editPriorityValue'
type='number' type='number'
label='Edit Priority' label='Edit Priority'
single-line single-line
autofocus autofocus
:rules='[v => !!v || "Priority is required", v => v >= 0 || "Must be positive"]' :rules='[v => !!v || "Priority is required", v => v >= 0 || "Must be positive"]'
@keydown.enter='saveEdit(props.item)'
@keydown.esc='cancelEdit'
) )
template(slot='no-data') template(slot='no-data')
v-alert.ma-3(icon='mdi-alert', :value='true', outlined) No pages to display. v-alert.ma-3(icon='mdi-alert', :value='true', outlined) No pages to display.
@ -135,6 +140,9 @@ export default {
{ text: 'Not Published', value: false } { text: 'Not Published', value: false }
], ],
paths: [], paths: [],
editPriorityValue: null,
editingItem: null,
originalPriorities: new Map(),
loading: false loading: false
} }
}, },
@ -164,6 +172,61 @@ export default {
} }
}, },
methods: { methods: {
startEdit(item) {
this.editingItem = item
this.editPriorityValue = item.orderPriority
this.originalPriorities.set(item.id, item.orderPriority)
},
saveEdit(item) {
if (this.editingItem && this.editingItem.id === item.id) {
item.orderPriority = this.editPriorityValue
this.savePriority(item)
}
},
cancelEdit() {
if (this.editingItem) {
const originalPriority = this.originalPriorities.get(this.editingItem.id)
if (originalPriority !== undefined) {
this.editingItem.orderPriority = originalPriority
}
this.originalPriorities.delete(this.editingItem.id)
this.editingItem = null
}
},
async savePriority(item) {
try {
// ruslan: И на стороне сервера сделать чтобы в текущей папке всё пересчитывалось
// Только здесь делаем фактическое сохранение
// await this.$apollo.mutate({
// mutation: updatePagePriorityMutation,
// variables: {
// id: item.id,
// priority: item.orderPriority
// }
// })
this.$store.commit('showNotification', {
message: 'Priority updated successfully',
style: 'success',
icon: 'check'
})
await this.refresh()
} catch (error) {
this.cancelEdit()
this.$store.commit('showNotification', {
message: 'Failed to update priority',
style: 'error',
icon: 'error'
})
} finally {
this.editingItem = null
}
},
async refresh() { async refresh() {
await this.$apollo.queries.pages.refetch() await this.$apollo.queries.pages.refetch()
this.$store.commit('showNotification', { this.$store.commit('showNotification', {
@ -171,8 +234,6 @@ export default {
style: 'success', style: 'success',
icon: 'cached' icon: 'cached'
}) })
this.paths = [{ text: 'aaa', value: null }]
}, },
updatePathSelector(pages) { updatePathSelector(pages) {
const paths = Array.from(new Set(pages.filter(p => p.path.includes('/')).map(p => p.path.split('/')[0]))) const paths = Array.from(new Set(pages.filter(p => p.path.includes('/')).map(p => p.path.split('/')[0])))
@ -193,7 +254,6 @@ export default {
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
update: function (data) { update: function (data) {
const pages = data.pages.list.map(p => { const pages = data.pages.list.map(p => {
console.log('randomed')
p.orderPriority = Math.round(Math.random() * 100) p.orderPriority = Math.round(Math.random() * 100)
return p return p
}) })

@ -4,7 +4,7 @@
top top
multi-line multi-line
v-model='notificationState' v-model='notificationState'
:timeout='2000' :timeout='1500'
) )
.text-left .text-left
v-icon.mr-3(dark) mdi-{{ notification.icon }} v-icon.mr-3(dark) mdi-{{ notification.icon }}
@ -46,7 +46,7 @@ export default {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
left: 0; left: 0;
animation: nav-notify-anim 2s linear; animation: nav-notify-anim 1.5s linear;
} }
} }
} }

Loading…
Cancel
Save