2019-01-14 22:40:30 +01:00
|
|
|
import Vue from 'vue'
|
2019-02-01 04:10:31 +01:00
|
|
|
import { Component, Watch } from 'vue-property-decorator'
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
import { SingleTodo } from '../SingleTodo'
|
2019-02-27 02:58:41 +01:00
|
|
|
import { ITodo, ITodosState, IDrag, IGlobalState, ICfgServer } from '@src/model'
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
import { tools } from '../../../store/Modules/tools'
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
import { GlobalStore, Todos } from '@store'
|
2019-01-31 13:52:52 +01:00
|
|
|
import { UserStore } from '@store'
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-20 11:53:56 +01:00
|
|
|
// _.cloneDeep( Per clonare un oggetto
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
import { Getter, State, Mutation } from 'vuex-class'
|
|
|
|
|
import { costanti } from '@src/store/Modules/costanti'
|
2019-02-27 02:58:41 +01:00
|
|
|
const namespace: string = 'Todos'
|
2019-02-19 18:44:48 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
@Component({
|
2019-01-29 03:12:18 +01:00
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
components: { SingleTodo },
|
|
|
|
|
filters: {
|
|
|
|
|
capitalize: function (value) {
|
|
|
|
|
if (!value) return ''
|
|
|
|
|
value = value.toString()
|
|
|
|
|
return value.charAt(0).toUpperCase() + value.slice(1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-14 22:40:30 +01:00
|
|
|
})
|
|
|
|
|
export default class Todo extends Vue {
|
|
|
|
|
$q: any
|
|
|
|
|
filter: boolean = false
|
|
|
|
|
title: string = ''
|
2019-02-20 17:54:48 +01:00
|
|
|
todotop: string = ''
|
|
|
|
|
todobottom: string = ''
|
2019-01-16 02:26:43 +01:00
|
|
|
drag: boolean = true
|
|
|
|
|
startpos: number = 0
|
2019-01-27 19:09:48 +01:00
|
|
|
listPriorityLabel: number[] = []
|
|
|
|
|
arrPrior: number[] = []
|
|
|
|
|
itemDragStart: any = null
|
2019-02-04 04:17:50 +01:00
|
|
|
polling = null
|
2019-02-14 18:38:23 +01:00
|
|
|
loadDone: boolean = false
|
2019-02-27 02:58:41 +01:00
|
|
|
public inddragging: number = -1
|
2019-02-20 11:53:56 +01:00
|
|
|
public service: any
|
2019-02-20 17:54:48 +01:00
|
|
|
public actualMaxPosition: number = 15
|
2019-02-20 20:59:18 +01:00
|
|
|
public scrollable = true
|
2019-02-27 02:58:41 +01:00
|
|
|
public categoryAtt: string = ''
|
2019-03-04 17:28:29 +01:00
|
|
|
// public showtype: number = Todos.state.showtype
|
2019-01-30 01:05:31 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
$refs: {
|
|
|
|
|
single: SingleTodo[]
|
|
|
|
|
}
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
@Getter('todos_dacompletare', { namespace })
|
|
|
|
|
public todos_dacompletare: (state: ITodosState, category: string) => ITodo[]
|
2019-02-03 14:40:20 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
@Getter('todos_completati', { namespace })
|
|
|
|
|
public todos_completati: (state: ITodosState, category: string) => ITodo[]
|
2019-02-03 14:40:20 +01:00
|
|
|
|
2019-01-29 03:12:18 +01:00
|
|
|
@Watch('$route.params.category') changecat() {
|
2019-02-27 02:58:41 +01:00
|
|
|
this.categoryAtt = this.$route.params.category
|
2019-01-29 03:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
get showtype () {
|
|
|
|
|
return Todos.state.showtype
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set showtype (value) {
|
|
|
|
|
// console.log('showtype', value)
|
|
|
|
|
GlobalStore.mutations.setShowType(value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clickaggshowtype () {
|
|
|
|
|
// console.log('1B) clickaggshowtype Todos.state.showtype=', Todos.state.showtype)
|
|
|
|
|
// Todos.state.showtype = costanti.ShowTypeTask.SHOW_ALL
|
|
|
|
|
// console.log('2B) Dopo: showtype=', this.showtype)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadval (e) {
|
|
|
|
|
console.log('1) loadval, showtype=', this.showtype)
|
|
|
|
|
this.showtype = Todos.state.showtype
|
|
|
|
|
console.log('2) Dopo: showtype=', this.showtype)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
get doneTodosCount() {
|
|
|
|
|
return Todos.getters.doneTodosCount(this.categoryAtt)
|
2019-02-03 14:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
get menuPopupConfigTodo() {
|
|
|
|
|
return tools.menuPopupConfigTodo[UserStore.state.lang]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get listOptionShowTask() {
|
|
|
|
|
return tools.listOptionShowTask[UserStore.state.lang]
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
get TodosCount() {
|
|
|
|
|
return Todos.getters.TodosCount(this.categoryAtt)
|
2019-02-14 18:38:23 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
get todos_vista() {
|
2019-02-14 18:38:23 +01:00
|
|
|
let mystr = ''
|
2019-02-27 02:58:41 +01:00
|
|
|
const arr = Todos.getters.todos_dacompletare(this.categoryAtt)
|
|
|
|
|
for (let ind in arr) {
|
|
|
|
|
mystr += this.getstrelem(arr[ind]) + '\n'
|
|
|
|
|
}
|
2019-02-14 18:38:23 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
return mystr + ''
|
2019-02-14 18:38:23 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// get mytodos_dacompletare() {
|
|
|
|
|
// return todos_dacompletare(this.categoryAtt)
|
|
|
|
|
// }
|
2019-02-14 18:38:23 +01:00
|
|
|
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// @Watch('$route', { immediate: true, deep: true })
|
|
|
|
|
// onUrlChange(newVal: any) {
|
|
|
|
|
// // Some action
|
|
|
|
|
// }
|
2019-02-03 02:40:24 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// Computed:
|
|
|
|
|
get reload_fromServer() {
|
|
|
|
|
return Todos.state.reload_fromServer
|
2019-01-29 03:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
set reload_fromServer(value: number) {
|
|
|
|
|
Todos.state.reload_fromServer = value
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getmyid(id) {
|
|
|
|
|
return 'row' + id
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 17:28:29 +01:00
|
|
|
showTask(field_value) {
|
|
|
|
|
return field_value === tools.MenuAction.SHOW_TASK
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
onStart() {
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
this.startpos = 0
|
2019-01-27 19:09:48 +01:00
|
|
|
this.itemDragStart = null
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
logelem(mystr, elem) {
|
2019-02-27 02:58:41 +01:00
|
|
|
console.log(mystr, 'elem [', elem._id, '] ', elem.descr, ' Pr(', this.getPriorityByInd(elem.priority), ') [', elem.id_prev, '] modif=', elem.modified)
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
getstrelem(elem) {
|
|
|
|
|
return 'elem [' + elem._id + '] ' + elem.descr + ' Pr(' + this.getPriorityByInd(elem.priority) + ') [ID_PREV=' + elem.id_prev + '] modif=' + elem.modified + ' '
|
2019-01-27 21:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// getPriorityToSet(ind1, ind2) {
|
|
|
|
|
// let elem1 = this.getelem(ind1)
|
|
|
|
|
// let elem2 = this.getelem(ind2)
|
|
|
|
|
//
|
|
|
|
|
// if ((elem1 !== null) && (elem2 !== null)) {
|
|
|
|
|
// if (elem1.priority === elem2.priority) {
|
|
|
|
|
// return elem1.priority
|
|
|
|
|
// } else {
|
|
|
|
|
// // if different priority then take the first
|
|
|
|
|
// return elem1.priority
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// return (elem1 != null) ? elem1.priority : ((elem2 != null) ? elem2.priority : null)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
2019-01-27 21:49:10 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
getCompleted(ind1, ind2) {
|
|
|
|
|
// let elem1 = this.getelem(ind1)
|
|
|
|
|
// let elem2 = this.getelem(ind2)
|
|
|
|
|
//
|
|
|
|
|
// if ((elem1 !== null) && (elem2 !== null)) {
|
|
|
|
|
// if (elem1.completed === elem2.completed) {
|
|
|
|
|
// return elem1.completed
|
|
|
|
|
// } else {
|
|
|
|
|
// return elem1.completed
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// return (elem1 != null) ? elem1.completed : ((elem2 != null) ? elem2.completed : null)
|
|
|
|
|
// }
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 21:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
getTitlePriority(priority) {
|
2019-01-27 21:49:10 +01:00
|
|
|
let cl = ''
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
if (priority === tools.Todos.PRIORITY_HIGH)
|
2019-01-27 21:49:10 +01:00
|
|
|
cl = 'high_priority'
|
2019-02-27 02:58:41 +01:00
|
|
|
else if (priority === tools.Todos.PRIORITY_NORMAL)
|
2019-01-27 21:49:10 +01:00
|
|
|
cl = 'medium_priority'
|
2019-02-27 02:58:41 +01:00
|
|
|
else if (priority === tools.Todos.PRIORITY_LOW)
|
2019-01-27 21:49:10 +01:00
|
|
|
cl = 'low_priority'
|
|
|
|
|
|
|
|
|
|
return cl + ' titlePriority'
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-20 19:17:29 +01:00
|
|
|
logga_arr(myarr: ITodo[]) {
|
|
|
|
|
let mystr = '\n'
|
|
|
|
|
myarr.forEach(item => {
|
2019-02-27 02:58:41 +01:00
|
|
|
mystr += '[' + item.pos + '] ' + item.descr + ' Pr(' + this.getPriorityByInd(item.priority) + ') [' + item.id_prev + '] modif=' + item.modified + '\n'
|
2019-02-20 19:17:29 +01:00
|
|
|
// mystr += '[' + item.pos + '] ' + item.descr + '\n'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return mystr
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
async onEnd(itemdragend) {
|
2019-02-27 02:58:41 +01:00
|
|
|
console.log('************ END DRAG: ', itemdragend)
|
|
|
|
|
this.inddragging = -1
|
2019-02-20 19:17:29 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
await Todos.actions.swapElems(itemdragend)
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
// If the newIndex is between another priority, then change priority
|
2019-01-27 21:49:10 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// if (!changecompleted) {
|
|
|
|
|
// // if I changed the completed, I don't have to put in other list priority
|
|
|
|
|
// let newpriority = this.getPriorityToSet(indini, indfine)
|
|
|
|
|
// if (newpriority != null && newpriority >= 0) {
|
|
|
|
|
// myobj.modified = (myobj.priority !== newpriority) ? true : myobj.modified
|
|
|
|
|
// myobj.priority = newpriority
|
|
|
|
|
// console.log('NewPriority: ', newpriority)
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2019-02-03 19:28:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// let completed = this.getCompleted(indini, indfine)
|
|
|
|
|
// let changecompleted = false
|
|
|
|
|
// if (completed != null) {
|
|
|
|
|
// myobj.modified = (myobj.completed !== completed) ? true : myobj.modified
|
|
|
|
|
// myobj.completed = completed
|
|
|
|
|
// changecompleted = true
|
|
|
|
|
// console.log('Newcompleted: ', completed, 'modif', myobj.modified)
|
|
|
|
|
// }
|
2019-02-20 19:17:29 +01:00
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
private getElementIndex(el: any) {
|
|
|
|
|
return [].slice.call(el.parentElement.children).indexOf(el)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
private getElementOldIndex(el: any) {
|
|
|
|
|
return parseInt(el.attributes['index'].value)
|
|
|
|
|
}
|
2019-02-20 11:53:56 +01:00
|
|
|
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
private getElementParentId(el: any) {
|
|
|
|
|
const elem = [].slice.call(el.parentElement.children)
|
|
|
|
|
console.log('elem', elem)
|
|
|
|
|
const id = elem.attributes['id'].substring(3)
|
|
|
|
|
return id
|
2019-02-20 11:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
private getElementId(el: any) {
|
|
|
|
|
console.log(' el ', el)
|
|
|
|
|
const id = el.attributes['id'].value.substring(3)
|
|
|
|
|
return id
|
2019-02-20 11:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
created() {
|
|
|
|
|
const $service = this.$dragula.$service
|
2019-02-20 17:54:48 +01:00
|
|
|
$service.options('first',
|
|
|
|
|
{
|
2019-02-20 19:17:29 +01:00
|
|
|
// isContainer: function (el) {
|
|
|
|
|
// return el.classList.contains('dragula-container')
|
|
|
|
|
// },
|
2019-02-20 17:54:48 +01:00
|
|
|
moves: function (el, source, handle, sibling) {
|
2019-02-20 19:17:29 +01:00
|
|
|
// console.log('moves')
|
2019-02-20 17:54:48 +01:00
|
|
|
return !el.classList.contains('donotdrag') // elements are always draggable by default
|
|
|
|
|
},
|
|
|
|
|
accepts: function (el, target, source, sibling) {
|
|
|
|
|
// console.log('accepts dragging '+ el.id + ' from ' + source.id + ' to ' + target.id)
|
|
|
|
|
return true // elements can be dropped in any of the `containers` by default
|
|
|
|
|
},
|
|
|
|
|
invalid: function (el, handle) {
|
2019-02-20 19:17:29 +01:00
|
|
|
// console.log('invalid')
|
2019-02-20 17:54:48 +01:00
|
|
|
return el.classList.contains('donotdrag') // don't prevent any drags from initiating by default
|
|
|
|
|
},
|
|
|
|
|
direction: 'vertical'
|
|
|
|
|
})
|
2019-02-20 11:53:56 +01:00
|
|
|
$service.eventBus.$on('dragend', (args) => {
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
let itemdragend: IDrag = {
|
|
|
|
|
// newIndex: this.getElementIndex(args.el),
|
|
|
|
|
// oldIndex: this.getElementOldIndex(args.el)
|
|
|
|
|
category: this.categoryAtt,
|
2019-02-20 11:53:56 +01:00
|
|
|
newIndex: this.getElementIndex(args.el),
|
|
|
|
|
oldIndex: this.getElementOldIndex(args.el)
|
|
|
|
|
}
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-20 11:53:56 +01:00
|
|
|
this.onEnd(itemdragend)
|
|
|
|
|
})
|
|
|
|
|
|
2019-02-20 20:59:18 +01:00
|
|
|
let mythis = this
|
|
|
|
|
|
|
|
|
|
$service.eventBus.$on('drag', function (el, source) {
|
2019-02-27 02:58:41 +01:00
|
|
|
// mythis.inddragging = mythis.getElementIndex(el)
|
|
|
|
|
console.log('+++ DRAG ind=', mythis.inddragging)
|
2019-02-20 20:59:18 +01:00
|
|
|
mythis.scrollable = false
|
|
|
|
|
})
|
|
|
|
|
$service.eventBus.$on('drop', function (el, source) {
|
|
|
|
|
console.log('+++ DROP')
|
|
|
|
|
mythis.scrollable = true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2019-02-20 11:53:56 +01:00
|
|
|
this.load()
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-20 20:59:18 +01:00
|
|
|
mounted() {
|
2019-02-27 02:58:41 +01:00
|
|
|
// console.log('*** MOUNTED ***')
|
|
|
|
|
|
|
|
|
|
this.categoryAtt = this.$route.params.category
|
2019-02-20 20:59:18 +01:00
|
|
|
|
|
|
|
|
let mythis = this
|
|
|
|
|
if (window) {
|
|
|
|
|
window.addEventListener('touchmove', function (e) {
|
2019-02-22 10:23:00 +01:00
|
|
|
// console.log('touchmove')
|
2019-02-20 20:59:18 +01:00
|
|
|
if (!mythis.scrollable) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
}
|
|
|
|
|
}, { passive: false })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
setarrPriority() {
|
|
|
|
|
this.arrPrior = []
|
2019-02-27 02:58:41 +01:00
|
|
|
const arr = tools.selectPriority[UserStore.state.lang]
|
2019-02-16 02:01:17 +01:00
|
|
|
if (arr) {
|
|
|
|
|
arr.forEach(rec => {
|
|
|
|
|
this.arrPrior.push(rec.value)
|
|
|
|
|
})
|
|
|
|
|
}
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('Array PRIOR:', this.arrPrior)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
async load() {
|
2019-03-04 17:28:29 +01:00
|
|
|
console.log('LOAD TODO....')
|
2019-02-27 02:58:41 +01:00
|
|
|
this.categoryAtt = this.$route.params.category
|
2019-02-03 02:40:24 +01:00
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
// Set last category selected
|
2019-02-27 02:58:41 +01:00
|
|
|
localStorage.setItem(tools.localStorage.categorySel, this.categoryAtt)
|
2019-01-30 01:05:31 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
for (let todosKey in tools.Todos) {
|
|
|
|
|
this.listPriorityLabel.push(tools.Todos[todosKey])
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('Priority:' + this.listPriorityLabel)
|
2019-01-27 19:09:48 +01:00
|
|
|
this.setarrPriority()
|
|
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
this.loadDone = true
|
2019-02-04 04:17:50 +01:00
|
|
|
|
|
|
|
|
this.checkUpdate_everytime()
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 04:17:50 +01:00
|
|
|
// Call to check if need to refresh
|
|
|
|
|
checkUpdate_everytime() {
|
|
|
|
|
this.polling = setInterval(() => {
|
|
|
|
|
this.checkUpdate()
|
2019-02-22 10:23:00 +01:00
|
|
|
}, 60000)
|
2019-02-04 04:17:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
beforedestroy() {
|
|
|
|
|
clearInterval(this.polling)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getPriorityByInd(index) {
|
2019-02-16 02:01:17 +01:00
|
|
|
// console.log('LANG in PRIOR', UserStore.state.lang)
|
|
|
|
|
try {
|
2019-02-27 02:58:41 +01:00
|
|
|
const arr = tools.selectPriority[UserStore.state.lang]
|
2019-02-16 02:01:17 +01:00
|
|
|
for (let rec of arr) {
|
|
|
|
|
if (rec.value === index)
|
|
|
|
|
return rec.label
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
return ''
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-07 00:53:10 +01:00
|
|
|
isRegistered() {
|
2019-02-27 02:58:41 +01:00
|
|
|
return localStorage.getItem(tools.localStorage.userId) !== ''
|
2019-02-07 00:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
mydeleteItem(idobj: string) {
|
2019-03-04 17:28:29 +01:00
|
|
|
console.log('mydeleteItem', idobj)
|
2019-02-27 02:58:41 +01:00
|
|
|
return Todos.actions.deleteItem({ cat: this.categoryAtt, idobj })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertTodo(atfirst: boolean = false) {
|
2019-02-20 17:54:48 +01:00
|
|
|
let descr = this.todobottom.trim()
|
|
|
|
|
if (atfirst)
|
|
|
|
|
descr = this.todotop.trim()
|
|
|
|
|
|
|
|
|
|
if (descr === '')
|
2019-01-28 03:13:04 +01:00
|
|
|
return
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
if (UserStore.state.userId === undefined) {
|
|
|
|
|
this.$q.notify(this.$t('todo.usernotdefined'))
|
2019-02-07 00:53:10 +01:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
if (!this.isRegistered()) {
|
|
|
|
|
// Not logged
|
|
|
|
|
this.$q.notify(this.$t('user.notregistered'))
|
2019-01-31 13:52:52 +01:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
let myobj: ITodo = {
|
|
|
|
|
descr: descr,
|
|
|
|
|
category: this.categoryAtt
|
2019-02-09 18:04:49 +01:00
|
|
|
}
|
2019-02-03 19:28:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
return Todos.actions.insertTodo({ myobj, atfirst })
|
|
|
|
|
.then((data) => {
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
console.log('data', data)
|
|
|
|
|
if (data !== null)
|
|
|
|
|
this.$q.notify(data)
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
// empty the field
|
|
|
|
|
if (atfirst)
|
|
|
|
|
this.todotop = ''
|
|
|
|
|
else
|
|
|
|
|
this.todobottom = ''
|
2019-02-08 17:10:25 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
|
2019-02-15 01:25:44 +01:00
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
})
|
2019-02-02 20:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-03 00:51:58 +01:00
|
|
|
/*
|
|
|
|
|
sendMessageToSW(recdata, method) {
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-03 00:51:58 +01:00
|
|
|
navigator.serviceWorker.controller.postMessage({
|
|
|
|
|
type: 'sync',
|
|
|
|
|
recdata,
|
|
|
|
|
method,
|
|
|
|
|
cmd: 'sync-new-todos',
|
|
|
|
|
token: UserStore.state.idToken,
|
|
|
|
|
lang: UserStore.state.lang
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
*/
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
async updateitem({ myitem, field }) {
|
|
|
|
|
console.log('calling MODIFY updateitem', myitem, field)
|
|
|
|
|
// Update the others components...
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
const itemdragend: IDrag = {
|
|
|
|
|
category: this.categoryAtt,
|
|
|
|
|
field,
|
|
|
|
|
idelemtochange: myitem._id,
|
|
|
|
|
prioritychosen: myitem.priority,
|
|
|
|
|
atfirst: false
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
await Todos.actions.swapElems(itemdragend)
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-02-27 02:58:41 +01:00
|
|
|
await Todos.actions.modify({ myitem, field })
|
2019-02-22 10:23:00 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
deselectAllRows(item: ITodo, check, onlythis: boolean = false) {
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('deselectAllRows : ', item)
|
2019-01-27 19:09:48 +01:00
|
|
|
|
|
|
|
|
for (let i = 0; i < this.$refs.single.length; i++) {
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-28 03:13:04 +01:00
|
|
|
let contr = <SingleTodo>this.$refs.single[i]
|
|
|
|
|
// @ts-ignore
|
2019-02-01 04:10:31 +01:00
|
|
|
let id = contr.itemtodo._id
|
2019-01-28 03:13:04 +01:00
|
|
|
// Don't deselect the actual clicked!
|
2019-01-28 13:31:41 +01:00
|
|
|
let des = false
|
|
|
|
|
if (onlythis) {
|
2019-02-01 04:10:31 +01:00
|
|
|
des = item._id === id
|
|
|
|
|
} else {
|
|
|
|
|
des = ((check && (item._id !== id)) || (!check))
|
2019-01-28 13:31:41 +01:00
|
|
|
}
|
|
|
|
|
if (des) {
|
2019-01-28 03:13:04 +01:00
|
|
|
// @ts-ignore
|
|
|
|
|
contr.deselectAndExitEdit()
|
|
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 17:10:25 +01:00
|
|
|
checkUpdate() {
|
2019-02-04 03:09:15 +01:00
|
|
|
Todos.actions.waitAndcheckPendingMsg()
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 17:54:48 +01:00
|
|
|
loadMoreTodo(index, done) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.actualMaxPosition += 15
|
|
|
|
|
done()
|
|
|
|
|
}, 100)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 18:44:48 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|