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-01-14 22:40:30 +01:00
|
|
|
import { ITodo } from '@src/model'
|
|
|
|
|
|
|
|
|
|
import { rescodes } from '../../../store/Modules/rescodes'
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
import { 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-03 03:44:25 +01:00
|
|
|
import objectId from '../../../js/objectId.js'
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
import _ from 'lodash'
|
|
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
import VueIdb from 'vue-idb'
|
|
|
|
|
|
|
|
|
|
import globalroutines from '../../../globalroutines/index'
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
import $ from 'jquery'
|
2019-02-14 18:38:23 +01:00
|
|
|
import Api from '@api'
|
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-01-16 02:26:43 +01:00
|
|
|
components: { SingleTodo, draggable }
|
2019-01-14 22:40:30 +01:00
|
|
|
})
|
|
|
|
|
export default class Todo extends Vue {
|
|
|
|
|
$q: any
|
|
|
|
|
|
|
|
|
|
filter: boolean = false
|
|
|
|
|
title: string = ''
|
|
|
|
|
todo: string = ''
|
2019-01-27 19:09:48 +01:00
|
|
|
todos_arr: ITodo[] = []
|
2019-02-03 19:28:06 +01:00
|
|
|
prevRecords: ITodo[] = []
|
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[] = []
|
|
|
|
|
prioritySel: number = 0
|
|
|
|
|
itemDragStart: any = null
|
|
|
|
|
itemDragEnd: any = null
|
|
|
|
|
selrowid: number = 0
|
2019-02-04 04:17:50 +01:00
|
|
|
polling = null
|
2019-02-14 18:38:23 +01:00
|
|
|
mytypetransgroup: string = 'flip-list'
|
|
|
|
|
tmpstrTodos: string = ''
|
|
|
|
|
loadDone: boolean = false
|
2019-02-03 19:28:06 +01:00
|
|
|
|
|
|
|
|
fieldtochange: String [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'id_next', 'pos', 'enableExpiring', 'progress']
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
// @Prop({ required: false }) category: string
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
$refs: {
|
|
|
|
|
single: SingleTodo[]
|
|
|
|
|
}
|
2019-01-16 02:26:43 +01:00
|
|
|
|
|
|
|
|
@Watch('drag') changedrag() {
|
|
|
|
|
console.log('drag = ' + this.drag)
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-03 14:40:20 +01:00
|
|
|
@Watch('$route', { immediate: true, deep: true })
|
|
|
|
|
onUrlChange(newVal: any) {
|
|
|
|
|
// Some action
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-01-29 03:12:18 +01:00
|
|
|
@Watch('$route.params.category') changecat() {
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('changecat')
|
2019-02-12 19:09:43 +01:00
|
|
|
this.mytypetransgroup = 'nessuno'
|
2019-02-14 18:38:23 +01:00
|
|
|
this.updatetable(false, '$route.params.category').then(() => {
|
2019-02-12 19:09:43 +01:00
|
|
|
this.mytypetransgroup = 'crossfade'
|
|
|
|
|
})
|
2019-01-29 03:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 14:40:20 +01:00
|
|
|
get todos_changed() {
|
|
|
|
|
return Todos.state.todos_changed
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 03:09:15 +01:00
|
|
|
get reload_fromServer() {
|
|
|
|
|
return Todos.state.reload_fromServer
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
set reload_fromServer(value: number) {
|
|
|
|
|
Todos.state.reload_fromServer = value
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 03:09:15 +01:00
|
|
|
|
2019-02-08 17:10:25 +01:00
|
|
|
@Watch('todos_changed', { immediate: true, deep: true })
|
2019-02-14 18:38:23 +01:00
|
|
|
changetodos_changed(value: number, oldValue: number) {
|
2019-02-08 17:10:25 +01:00
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
// this.$q.notify('Changed...')
|
2019-02-08 17:10:25 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
if ((value > 1) && (this.loadDone)) {
|
|
|
|
|
// console.log('Todos.state.todos_changed CHANGED!', value, oldValue)
|
|
|
|
|
this.updatetable(true, 'todos_changed')
|
|
|
|
|
}
|
2019-02-03 14:40:20 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 03:09:15 +01:00
|
|
|
@Watch('reload_fromServer', { immediate: true })
|
2019-02-14 18:38:23 +01:00
|
|
|
reload_fromServer_changed(value: number, oldValue: number) {
|
|
|
|
|
if (value > 0) {
|
|
|
|
|
// console.log('reload_fromServer_changed!', value, oldValue)
|
|
|
|
|
// if (value) {
|
|
|
|
|
Todos.actions.dbLoadTodo(false)
|
2019-02-14 20:08:22 +01:00
|
|
|
.then(() => {
|
|
|
|
|
return Todos.actions.updateArrayInMemory()
|
|
|
|
|
})
|
2019-02-14 18:38:23 +01:00
|
|
|
}
|
2019-02-07 00:53:10 +01:00
|
|
|
// }
|
2019-02-04 03:09:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-03 14:40:20 +01:00
|
|
|
get testPao() {
|
|
|
|
|
return Todos.state.testpao
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Watch('testPao', { immediate: true, deep: true })
|
|
|
|
|
changedTestpao(value: string, oldValue: string) {
|
2019-02-04 03:09:15 +01:00
|
|
|
// console.log('testpao CHANGED', value, oldValue)
|
2019-02-14 18:38:23 +01:00
|
|
|
// this.updatetable(true, 'testPao')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getArrTodos() {
|
|
|
|
|
|
|
|
|
|
let mystr = ''
|
|
|
|
|
let mythis = this
|
|
|
|
|
|
|
|
|
|
mythis.tmpstrTodos = ''
|
2019-02-14 20:08:22 +01:00
|
|
|
return globalroutines(null, 'readall', 'todos', null)
|
2019-02-14 18:38:23 +01:00
|
|
|
.then(function (alldata) {
|
|
|
|
|
const myrecs = [...alldata]
|
|
|
|
|
|
|
|
|
|
myrecs.forEach(rec => {
|
|
|
|
|
mystr = mystr + rec.descr + '] ['
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
mythis.tmpstrTodos = 'TODOS: ' + mystr
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArrTodos() {
|
|
|
|
|
|
|
|
|
|
let mystr = ''
|
|
|
|
|
let mythis = this
|
|
|
|
|
|
|
|
|
|
mythis.tmpstrTodos = ''
|
2019-02-14 20:08:22 +01:00
|
|
|
return globalroutines(null, 'write', 'todos', this.todos_arr[0])
|
2019-02-14 18:38:23 +01:00
|
|
|
.then(function (alldata) {
|
|
|
|
|
mythis.getArrTodos()
|
|
|
|
|
})
|
2019-02-03 02:40:24 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-29 03:12:18 +01:00
|
|
|
getCategory() {
|
|
|
|
|
return this.$route.params.category
|
2019-01-30 01:05:31 +01:00
|
|
|
// return this.category
|
2019-01-29 03:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
change(param) {
|
|
|
|
|
console.log('Change... ' + param)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getmyid(id) {
|
|
|
|
|
return 'row' + id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getrefbyid(id) {
|
|
|
|
|
return 'single' + id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getelem(indelem, arr: ITodo[] = this.todos_arr) {
|
|
|
|
|
return (indelem >= 0) && (indelem < arr.length) ? arr[indelem] : null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getLastElem() {
|
|
|
|
|
if (this.todos_arr.length > 0)
|
|
|
|
|
return this.todos_arr[this.todos_arr.length - 1]
|
|
|
|
|
else
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getFirstelem() {
|
|
|
|
|
return this.todos_arr[this.todos_arr.length - 1]
|
|
|
|
|
}
|
|
|
|
|
|
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-02-14 20:08:22 +01:00
|
|
|
updateLinkedList(init: boolean, arr: ITodo[] = this.todos_arr) {
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('updateLinkedList', this.todos_arr)
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
let idprev = ''
|
|
|
|
|
let idnext = ''
|
2019-01-27 19:09:48 +01:00
|
|
|
let pos = 1
|
|
|
|
|
if (arr.length > 0) {
|
|
|
|
|
idprev = arr[0].id_prev
|
|
|
|
|
idnext = arr[0].id_next
|
|
|
|
|
}
|
2019-02-14 20:08:22 +01:00
|
|
|
arr.forEach((elem, index) => {
|
2019-01-27 19:09:48 +01:00
|
|
|
if (index === 0) {
|
|
|
|
|
idprev = rescodes.LIST_START
|
|
|
|
|
} else {
|
|
|
|
|
const elemprev = this.getelem(index - 1, arr)
|
2019-02-01 04:10:31 +01:00
|
|
|
idprev = elemprev._id
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
if (index === arr.length - 1) {
|
|
|
|
|
idnext = rescodes.LIST_END
|
|
|
|
|
} else {
|
|
|
|
|
const elemnext = this.getelem(index + 1, arr)
|
2019-02-01 04:10:31 +01:00
|
|
|
idnext = elemnext._id
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
// elem.modified = ((elem.id_prev !== idprev) || (elem.id_next !== idnext) || (elem.pos !== pos)) ? true : elem.modified
|
|
|
|
|
// elem.modified = elem.pos !== pos ? true : elem.modified
|
|
|
|
|
// if (elem.modified)
|
|
|
|
|
// console.log('MODIFICATO QUIIIIIIIIIIIIIIIIIIII', elem.id_prev, idprev, elem.id_next, idnext, elem.pos, pos)
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
elem.id_prev = idprev
|
|
|
|
|
elem.id_next = idnext
|
2019-02-03 19:28:06 +01:00
|
|
|
if (elem.pos !== pos) {
|
|
|
|
|
elem.modified = true
|
|
|
|
|
elem.pos = pos
|
|
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
if (init) {
|
|
|
|
|
elem.modified = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos++
|
|
|
|
|
|
2019-01-31 13:52:52 +01:00
|
|
|
// this.logelem('updateLinked', elem)
|
2019-01-27 19:09:48 +01:00
|
|
|
|
|
|
|
|
})
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
logelem(mystr, elem) {
|
2019-02-01 04:10:31 +01:00
|
|
|
console.log(mystr, 'elem [', elem._id, '] ', elem.descr, ' Pr(', this.getPriorityByInd(elem.priority), ') [', elem.id_prev, '-', elem.id_next, '] modif=', elem.modified)
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 21:49:10 +01:00
|
|
|
getPriorityToSet(ind1, ind2) {
|
2019-01-27 19:09:48 +01:00
|
|
|
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
|
|
|
|
|
}
|
2019-01-16 02:26:43 +01:00
|
|
|
} else {
|
2019-01-27 19:09:48 +01:00
|
|
|
return (elem1 != null) ? elem1.priority : ((elem2 != null) ? elem2.priority : null)
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
2019-01-27 21:49:10 +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) {
|
2019-01-28 03:13:04 +01:00
|
|
|
return elem1.completed
|
2019-01-27 21:49:10 +01:00
|
|
|
} 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 = ''
|
|
|
|
|
|
|
|
|
|
if (priority === rescodes.Todos.PRIORITY_HIGH)
|
|
|
|
|
cl = 'high_priority'
|
|
|
|
|
else if (priority === rescodes.Todos.PRIORITY_NORMAL)
|
|
|
|
|
cl = 'medium_priority'
|
|
|
|
|
else if (priority === rescodes.Todos.PRIORITY_LOW)
|
|
|
|
|
cl = 'low_priority'
|
|
|
|
|
|
|
|
|
|
return cl + ' titlePriority'
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async onEnd(itemdragend) {
|
|
|
|
|
console.log('newindex=', itemdragend.newIndex, 'oldindex=', itemdragend.oldIndex)
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 21:49:10 +01:00
|
|
|
if (itemdragend.newIndex === itemdragend.oldIndex)
|
|
|
|
|
return // If nothing change, exit
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
let myobj = this.getelem(itemdragend.newIndex)
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
const indini = itemdragend.newIndex - 1
|
|
|
|
|
const indfine = itemdragend.newIndex + 1
|
|
|
|
|
console.log('indini', indini, 'indfine', indfine)
|
|
|
|
|
// If the newIndex is between another priority, then change priority
|
2019-01-27 21:49:10 +01:00
|
|
|
|
|
|
|
|
let completed = this.getCompleted(indini, indfine)
|
|
|
|
|
let changecompleted = false
|
2019-01-28 03:13:04 +01:00
|
|
|
if (completed != null) {
|
2019-01-27 21:49:10 +01:00
|
|
|
myobj.modified = (myobj.completed !== completed) ? true : myobj.modified
|
|
|
|
|
myobj.completed = completed
|
|
|
|
|
changecompleted = true
|
2019-02-03 19:28:06 +01:00
|
|
|
console.log('Newcompleted: ', completed, 'modif', myobj.modified)
|
2019-01-27 21:49:10 +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-01-16 02:26:43 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
this.updateLinkedList(false)
|
2019-01-27 19:09:48 +01:00
|
|
|
|
|
|
|
|
// Updated only elements modified
|
|
|
|
|
await this.updateModifyRecords(true)
|
|
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.updatetable(false, 'onEnd')
|
2019-02-03 19:28:06 +01:00
|
|
|
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
async updateModifyRecords(refresh: boolean = false) {
|
|
|
|
|
let update = false
|
2019-02-14 20:08:22 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
await this.todos_arr.forEach((elem: ITodo) => {
|
|
|
|
|
if (elem.modified) {
|
2019-02-12 12:06:01 +01:00
|
|
|
console.log('calling MODIFY 3')
|
2019-02-14 20:08:22 +01:00
|
|
|
return this.modify(elem, false)
|
|
|
|
|
.then(() => {
|
|
|
|
|
update = true
|
|
|
|
|
elem.modified = false
|
|
|
|
|
})
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
})
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
if (update)
|
2019-02-14 20:08:22 +01:00
|
|
|
return await this.updatetable(refresh, 'updateModifyRecords')
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
async created() {
|
|
|
|
|
await this.load()
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setarrPriority() {
|
|
|
|
|
this.arrPrior = []
|
|
|
|
|
const arr = rescodes.selectPriority[UserStore.state.lang]
|
|
|
|
|
arr.forEach(rec => {
|
|
|
|
|
this.arrPrior.push(rec.value)
|
2019-01-14 22:40:30 +01:00
|
|
|
})
|
2019-01-31 13:52:52 +01:00
|
|
|
// console.log('Array PRIOR:', this.arrPrior)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 04:17:50 +01:00
|
|
|
beforedestroy() {
|
|
|
|
|
clearInterval(this.polling)
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
async load() {
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
|
2019-02-14 19:01:32 +01:00
|
|
|
// this.todos_arr = [...Todos.state.todos]
|
2019-02-03 02:40:24 +01:00
|
|
|
|
2019-01-30 01:05:31 +01:00
|
|
|
// Set last category selected
|
|
|
|
|
localStorage.setItem(rescodes.localStorage.categorySel, this.getCategory())
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
for (let todosKey in rescodes.Todos) {
|
|
|
|
|
this.listPriorityLabel.push(rescodes.Todos[todosKey])
|
|
|
|
|
}
|
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 18:38:23 +01:00
|
|
|
await this.updatetable(false, 'load')
|
2019-01-27 19:09:48 +01:00
|
|
|
|
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-08 17:10:25 +01:00
|
|
|
}, 10000)
|
2019-02-04 04:17:50 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
initcat() {
|
|
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
let tomorrow = new Date()
|
2019-02-14 18:38:23 +01:00
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
2019-02-03 02:40:24 +01:00
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
const objtodo: ITodo = {
|
2019-02-03 03:44:25 +01:00
|
|
|
// _id: new Date().toISOString(), // Create NEW
|
|
|
|
|
_id: objectId(),
|
2019-01-14 22:40:30 +01:00
|
|
|
userId: UserStore.state.userId,
|
|
|
|
|
descr: '',
|
|
|
|
|
priority: rescodes.Todos.PRIORITY_NORMAL,
|
|
|
|
|
completed: false,
|
2019-02-11 02:58:53 +01:00
|
|
|
created_at: new Date(),
|
|
|
|
|
modify_at: new Date(),
|
|
|
|
|
completed_at: new Date(),
|
2019-01-31 13:52:52 +01:00
|
|
|
category: '',
|
2019-02-11 02:58:53 +01:00
|
|
|
expiring_at: tomorrow,
|
2019-01-28 03:13:04 +01:00
|
|
|
enableExpiring: false,
|
2019-02-02 20:13:06 +01:00
|
|
|
id_prev: '',
|
|
|
|
|
id_next: '',
|
2019-01-27 19:09:48 +01:00
|
|
|
pos: 0,
|
2019-02-03 19:28:06 +01:00
|
|
|
modified: false,
|
2019-01-29 00:48:04 +01:00
|
|
|
progress: 0
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
2019-02-11 02:58:53 +01:00
|
|
|
// return this.copy(objtodo)
|
|
|
|
|
return objtodo
|
2019-01-14 22:40:30 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getPriorityByInd(index) {
|
|
|
|
|
const arr = rescodes.selectPriority[UserStore.state.lang]
|
|
|
|
|
for (let rec of arr) {
|
|
|
|
|
if (rec.value === index)
|
|
|
|
|
return rec.label
|
|
|
|
|
}
|
|
|
|
|
return ''
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-07 00:53:10 +01:00
|
|
|
isRegistered() {
|
|
|
|
|
return localStorage.getItem(rescodes.localStorage.userId) !== ''
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
async insertTodo() {
|
2019-01-28 03:13:04 +01:00
|
|
|
if (this.todo.trim() === '')
|
|
|
|
|
return
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-07 00:53:10 +01:00
|
|
|
if (!this.isRegistered()) {
|
|
|
|
|
// Not logged
|
|
|
|
|
this.$q.notify(this.$t('user.notregistered'))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
const objtodo = this.initcat()
|
|
|
|
|
|
|
|
|
|
objtodo.descr = this.todo
|
2019-01-29 03:12:18 +01:00
|
|
|
objtodo.category = this.getCategory()
|
2019-02-14 20:08:22 +01:00
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
const lastelem: ITodo = this.getLastList()
|
2019-02-01 04:10:31 +01:00
|
|
|
objtodo.id_prev = (lastelem !== null) ? lastelem._id : rescodes.LIST_START
|
2019-01-27 19:09:48 +01:00
|
|
|
objtodo.id_next = rescodes.LIST_END
|
|
|
|
|
objtodo.pos = (lastelem !== null) ? lastelem.pos + 1 : 1
|
2019-02-03 19:28:06 +01:00
|
|
|
objtodo.modified = false
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-31 13:52:52 +01:00
|
|
|
if (objtodo.userId === undefined) {
|
|
|
|
|
this.$q.notify(this.$t('todo.usernotdefined'))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
const id = await globalroutines(this, 'write', 'todos', objtodo)
|
|
|
|
|
// update also the last elem
|
|
|
|
|
if (lastelem !== null) {
|
|
|
|
|
lastelem.id_next = id
|
|
|
|
|
// lastelem.modified = true
|
|
|
|
|
// console.log('calling MODIFY 4', lastelem)
|
|
|
|
|
}
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.modify(lastelem, false)
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.saveItemToSyncAndDb(rescodes.DB.TABLE_SYNC_TODOS, 'POST', objtodo, true)
|
|
|
|
|
await this.updatetable(false, 'insertTodo')
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
// console.log('ESCO.........')
|
2019-01-14 22:40:30 +01:00
|
|
|
|
|
|
|
|
// empty the field
|
|
|
|
|
this.todo = ''
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
|
|
|
|
|
async cmdToSyncAndDb(cmd, table, method, item: ITodo, id, msg: String, update: boolean) {
|
2019-02-01 04:10:31 +01:00
|
|
|
// Send to Server to Sync
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
console.log('cmdToSyncAndDb', cmd, table, method, item.descr, id, msg)
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-02-04 03:09:15 +01:00
|
|
|
let cmdSw = cmd
|
|
|
|
|
if ((cmd === rescodes.DB.CMD_SYNC_NEW_TODOS) || (cmd === rescodes.DB.CMD_DELETE_TODOS)) {
|
|
|
|
|
cmdSw = rescodes.DB.CMD_SYNC_TODOS
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 12:06:01 +01:00
|
|
|
// if (process.env.DEV) {
|
|
|
|
|
// console.log('serviceWorker ', ('serviceWorker' in navigator) ? 'PRESENT!' : 'DOESN\'T EXIST!')
|
|
|
|
|
// console.log('SyncManager ', ('SyncManager' in window) ? 'PRESENT!' : 'DOESN\'T EXIST!')
|
|
|
|
|
// }
|
2019-02-08 17:10:25 +01:00
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
const mythis = this
|
2019-02-08 17:10:25 +01:00
|
|
|
if ('serviceWorker' in navigator) {
|
2019-02-14 20:08:22 +01:00
|
|
|
const ready = await navigator.serviceWorker.ready
|
2019-02-01 04:10:31 +01:00
|
|
|
.then(function (sw) {
|
|
|
|
|
// _id: new Date().toISOString(),
|
2019-02-12 12:06:01 +01:00
|
|
|
// console.log('---------------------- navigator.serviceWorker.ready')
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
return globalroutines(mythis, 'write', table, item, id)
|
2019-02-02 20:13:06 +01:00
|
|
|
.then(function (id) {
|
2019-02-03 19:28:06 +01:00
|
|
|
// console.log('id', id)
|
2019-02-14 20:08:22 +01:00
|
|
|
const sep = '|'
|
|
|
|
|
|
|
|
|
|
let multiparams = cmdSw + sep + table + sep + method + sep + UserStore.state.x_auth_token + sep + UserStore.state.lang
|
|
|
|
|
let mymsgkey = {
|
|
|
|
|
_id: multiparams,
|
|
|
|
|
value: multiparams
|
|
|
|
|
}
|
|
|
|
|
return globalroutines(mythis, 'write', 'swmsg', mymsgkey, multiparams)
|
|
|
|
|
.then(ris => {
|
|
|
|
|
// if ('SyncManager' in window) {
|
|
|
|
|
// console.log(' SENDING... sw.sync.register', multiparams)
|
|
|
|
|
// return sw.sync.register(multiparams)
|
|
|
|
|
// } else {
|
|
|
|
|
// #Todo ++ Alternative 2 to SyncManager
|
|
|
|
|
return Api.syncAlternative(multiparams)
|
|
|
|
|
// }
|
|
|
|
|
})
|
|
|
|
|
.then(function () {
|
|
|
|
|
let data = { message: msg, position: 'bottom', timeout: 3000 }
|
|
|
|
|
mythis.$q.notify(data)
|
|
|
|
|
})
|
|
|
|
|
.catch(function (err) {
|
|
|
|
|
console.error('Errore in globalroutines', table, err)
|
|
|
|
|
})
|
2019-02-01 04:10:31 +01:00
|
|
|
})
|
|
|
|
|
})
|
2019-02-03 19:28:06 +01:00
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
|
// // Update the array in memory, from todos table from IndexedDb
|
2019-02-14 20:08:22 +01:00
|
|
|
await Todos.actions.updateArrayInMemory()
|
2019-02-03 19:28:06 +01:00
|
|
|
.then((ris) => {
|
|
|
|
|
return ris
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
} else {
|
2019-02-04 03:09:15 +01:00
|
|
|
if (cmd === rescodes.DB.CMD_SYNC_NEW_TODOS) {
|
2019-02-03 00:51:58 +01:00
|
|
|
if (method === 'POST')
|
2019-02-14 20:08:22 +01:00
|
|
|
await Todos.actions.dbInsertTodo(item)
|
2019-02-03 00:51:58 +01:00
|
|
|
else if (method === 'PATCH')
|
2019-02-14 20:08:22 +01:00
|
|
|
await Todos.actions.dbSaveTodo(item)
|
2019-02-03 00:51:58 +01:00
|
|
|
} else if (cmd === rescodes.DB.CMD_DELETE_TODOS)
|
2019-02-14 20:08:22 +01:00
|
|
|
await Todos.actions.dbDeleteTodo(item)
|
2019-02-01 04:10:31 +01:00
|
|
|
}
|
2019-02-02 20:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
async saveItemToSyncAndDb(table: String, method, item: ITodo, update: boolean) {
|
2019-02-12 12:06:01 +01:00
|
|
|
return await this.cmdToSyncAndDb(rescodes.DB.CMD_SYNC_NEW_TODOS, table, method, item, 0, '', update)
|
2019-02-02 20:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
async deleteItemToSyncAndDb(table: String, item: ITodo, id, update: boolean) {
|
|
|
|
|
return await this.cmdToSyncAndDb(rescodes.DB.CMD_DELETE_TODOS, table, 'DELETE', item, id, '', update)
|
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-01-27 19:09:48 +01:00
|
|
|
getElemById(id, lista = this.todos_arr) {
|
|
|
|
|
let myobj: ITodo
|
|
|
|
|
for (myobj of lista) {
|
2019-02-01 04:10:31 +01:00
|
|
|
if (myobj._id === id) {
|
2019-01-27 19:09:48 +01:00
|
|
|
return myobj
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
return null
|
2019-01-16 02:26:43 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
async deleteitem(id) {
|
|
|
|
|
console.log('deleteitem: KEY = ', id)
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
let myobjtrov = this.getElemById(id)
|
2019-01-16 02:26:43 +01:00
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
if (myobjtrov !== null) {
|
2019-01-27 19:09:48 +01:00
|
|
|
let myobjprev = this.getElemById(myobjtrov.id_prev)
|
|
|
|
|
let myobjnext = this.getElemById(myobjtrov.id_next)
|
|
|
|
|
|
|
|
|
|
if (myobjprev !== null) {
|
|
|
|
|
myobjprev.id_next = myobjtrov.id_next
|
|
|
|
|
myobjprev.modified = true
|
2019-02-12 12:06:01 +01:00
|
|
|
console.log('calling MODIFY 2')
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.modify(myobjprev, false)
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (myobjnext !== null) {
|
|
|
|
|
myobjnext.id_prev = myobjtrov.id_prev
|
|
|
|
|
myobjnext.modified = true
|
2019-02-12 12:06:01 +01:00
|
|
|
console.log('calling MODIFY 1')
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.modify(myobjnext, false)
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
await this.deleteItemToSyncAndDb(rescodes.DB.TABLE_DELETE_TODOS, myobjtrov, id, true)
|
2019-02-02 20:13:06 +01:00
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
const mythis = this
|
2019-01-14 22:40:30 +01:00
|
|
|
// Delete item
|
2019-02-02 21:16:49 +01:00
|
|
|
await globalroutines(this, 'delete', 'todos', null, id)
|
2019-02-02 20:13:06 +01:00
|
|
|
.then((ris) => {
|
2019-02-14 18:38:23 +01:00
|
|
|
mythis.updatetable(false, 'deleteitem')
|
2019-01-27 19:09:48 +01:00
|
|
|
}).catch((error) => {
|
2019-02-03 00:51:58 +01:00
|
|
|
console.log('err: ', error)
|
|
|
|
|
})
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
2019-01-27 19:09:48 +01:00
|
|
|
|
2019-02-09 18:04:49 +01:00
|
|
|
// console.log('FINE deleteitem')
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
getElem(myarray: ITodo[], id) {
|
|
|
|
|
for (let i = 0; i < myarray.length - 1; i++) {
|
|
|
|
|
if (myarray[i]._id === id)
|
|
|
|
|
return myarray[i]
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isRecordModifPos(itemnew: ITodo, itemold: ITodo) {
|
|
|
|
|
return itemnew.pos !== itemold.pos
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 18:38:23 +01:00
|
|
|
async updatetable(refresh: boolean = false, strpos = '') {
|
|
|
|
|
console.log('updatetable', strpos)
|
2019-02-03 02:40:24 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
this.prevRecords = [...this.todos_arr]
|
|
|
|
|
|
2019-02-03 02:40:24 +01:00
|
|
|
return await Todos.actions.getTodosByCategory(this.getCategory())
|
2019-02-12 19:09:43 +01:00
|
|
|
.then(arrris => {
|
|
|
|
|
|
|
|
|
|
this.todos_arr = []
|
|
|
|
|
|
|
|
|
|
let arrtemp = [...arrris]
|
2019-02-03 02:40:24 +01:00
|
|
|
|
|
|
|
|
arrtemp = _.orderBy(arrtemp, ['completed', 'priority', 'pos'], ['asc', 'desc', 'asc'])
|
|
|
|
|
|
|
|
|
|
this.updateLinkedList(true, arrtemp)
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
// If changed the position, then set modified
|
|
|
|
|
arrtemp.forEach(itemNew => {
|
|
|
|
|
const itemOld = this.getElem(this.prevRecords, itemNew._id)
|
|
|
|
|
if (itemOld)
|
|
|
|
|
itemNew.modified = this.isRecordModifPos(itemNew, itemOld) ? true : false
|
|
|
|
|
})
|
|
|
|
|
|
2019-02-03 02:40:24 +01:00
|
|
|
this.todos_arr = [...arrtemp] // make copy
|
2019-02-03 19:28:06 +01:00
|
|
|
|
2019-02-12 19:09:43 +01:00
|
|
|
console.log('AGGIORNA todos_arr')
|
|
|
|
|
|
2019-02-03 02:40:24 +01:00
|
|
|
})
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearArr() {
|
2019-02-03 02:40:24 +01:00
|
|
|
// this.todos_arr = []
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
existArr(x) {
|
|
|
|
|
return x = (typeof x !== 'undefined' && x instanceof Array) ? x : []
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
getFirstList(arrlist) {
|
|
|
|
|
let elem: ITodo
|
|
|
|
|
for (elem of arrlist) {
|
|
|
|
|
if (elem.id_prev === rescodes.LIST_START) {
|
|
|
|
|
return elem
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getLastList(arrlist = this.todos_arr) {
|
|
|
|
|
let elem: ITodo
|
|
|
|
|
for (elem of arrlist) {
|
|
|
|
|
if (elem.id_next === rescodes.LIST_END) {
|
|
|
|
|
return elem
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setArrayFinale(arrris) {
|
|
|
|
|
|
|
|
|
|
// Sort List:
|
|
|
|
|
let myarr = []
|
|
|
|
|
|
|
|
|
|
let current = this.getFirstList(arrris)
|
|
|
|
|
let currentprec = current
|
|
|
|
|
|
|
|
|
|
if (current !== null)
|
|
|
|
|
myarr.push(current)
|
|
|
|
|
|
|
|
|
|
let index = -1
|
|
|
|
|
while (current !== null && current.id_next !== rescodes.LIST_END && index < arrris.length) {
|
|
|
|
|
this.logelem('current : ', current)
|
|
|
|
|
console.log('id_next', current.id_next)
|
|
|
|
|
// let changed = (prior !== elem.priority) ? true : false
|
|
|
|
|
current = this.getElemById(current.id_next, arrris)
|
|
|
|
|
if (current === null)
|
|
|
|
|
break
|
2019-02-01 04:10:31 +01:00
|
|
|
if (current._id === currentprec._id)
|
2019-01-27 19:09:48 +01:00
|
|
|
break
|
|
|
|
|
myarr.push(current)
|
|
|
|
|
currentprec = current
|
|
|
|
|
this.logelem('current AFTER : ', current)
|
|
|
|
|
index++
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return myarr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortarr(arr, field) {
|
|
|
|
|
|
2019-02-01 04:10:31 +01:00
|
|
|
return arr.slice().sort(function (a, b) {
|
2019-01-27 19:09:48 +01:00
|
|
|
return a[field] - b[field]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// let ind1 = -1
|
|
|
|
|
// let val1 = -1
|
|
|
|
|
// for (let x = 0; x <= arr.length; x++) {
|
|
|
|
|
// if (x[field] < ind1) {
|
|
|
|
|
// val11 = x[field]
|
|
|
|
|
// ind1 = x
|
|
|
|
|
// }
|
|
|
|
|
// for (let y: ITodo = null of arr) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
updateitem(myobj) {
|
2019-02-12 12:06:01 +01:00
|
|
|
console.log('calling MODIFY 4 updateitem')
|
2019-01-27 19:09:48 +01:00
|
|
|
this.modify(myobj, true)
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:09:48 +01:00
|
|
|
// inactiveAllButtons() {
|
|
|
|
|
// let divs = this.$children.filter(function (child) {
|
|
|
|
|
// return child.$attrs['component-type'] === 'my-custom-button'
|
|
|
|
|
// })
|
|
|
|
|
// divs.forEach(i => {
|
|
|
|
|
// divs[i].isActive = false
|
|
|
|
|
// })
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// updateRow(rec: ITodo) {
|
|
|
|
|
// let index = -1
|
|
|
|
|
// // get index
|
|
|
|
|
// this.$refs.single.forEach( (singletodo: SingleTodo) => {
|
2019-02-01 04:10:31 +01:00
|
|
|
// if (singletodo.itemtodo._id === rec._id)
|
2019-01-27 19:09:48 +01:00
|
|
|
// index = -1
|
|
|
|
|
// })
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
modifyField(recOut, recIn, field) {
|
2019-02-12 12:06:01 +01:00
|
|
|
if (String(recOut[field]) !== String(recIn[field])) {
|
|
|
|
|
console.log('*************** CAMPO ', field, 'MODIFICATO!')
|
|
|
|
|
console.log(recOut[field])
|
|
|
|
|
console.log(recIn[field])
|
2019-01-27 19:09:48 +01:00
|
|
|
recOut.modified = true
|
|
|
|
|
recOut[field] = recIn[field]
|
2019-02-03 19:28:06 +01:00
|
|
|
return true
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
2019-02-01 04:10:31 +01:00
|
|
|
return false
|
2019-01-27 19:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async modify(myobj: ITodo, update: boolean) {
|
2019-02-03 00:51:58 +01:00
|
|
|
if (myobj === null)
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
2019-02-14 20:08:22 +01:00
|
|
|
return await globalroutines(this, 'read', 'todos', null, myobj._id)
|
2019-02-02 20:13:06 +01:00
|
|
|
.then(miorec => {
|
|
|
|
|
if (miorec === undefined) {
|
2019-02-03 19:28:06 +01:00
|
|
|
console.log('~~~~~~~~~~~~~~~~~~~~ !!!!!!!!!!!!!!!!!! Record not Found !!!!!! id=', myobj._id)
|
2019-02-02 20:13:06 +01:00
|
|
|
return
|
|
|
|
|
}
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
if (this.modifyField(miorec, myobj, 'completed'))
|
2019-02-03 02:40:24 +01:00
|
|
|
miorec.completed_at = new Date().getDate()
|
2019-01-29 00:48:04 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
this.fieldtochange.forEach(field => {
|
|
|
|
|
this.modifyField(miorec, myobj, field)
|
|
|
|
|
})
|
2019-01-27 19:09:48 +01:00
|
|
|
|
|
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
if (miorec.modified) {
|
2019-02-03 19:28:06 +01:00
|
|
|
console.log('Todo MODIFICATO! ', miorec.descr, 'SALVALO SULLA IndexedDB todos')
|
2019-02-03 02:40:24 +01:00
|
|
|
miorec.modify_at = new Date().getDate()
|
2019-02-03 19:28:06 +01:00
|
|
|
miorec.modified = false
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-02 20:13:06 +01:00
|
|
|
// this.logelem('modify', miorec)
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
return globalroutines(this, 'write', 'todos', miorec)
|
2019-02-02 20:13:06 +01:00
|
|
|
.then(ris => {
|
2019-02-01 04:10:31 +01:00
|
|
|
|
2019-02-14 20:08:22 +01:00
|
|
|
return this.saveItemToSyncAndDb(rescodes.DB.TABLE_SYNC_TODOS_PATCH, 'PATCH', miorec, update)
|
2019-02-03 19:28:06 +01:00
|
|
|
.then(() => {
|
|
|
|
|
// console.log('SET MODIFIED FALSE')
|
|
|
|
|
|
|
|
|
|
if (update)
|
2019-02-14 20:08:22 +01:00
|
|
|
return this.updatetable(false, 'modify')
|
2019-01-14 22:40:30 +01:00
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
})
|
2019-02-02 20:13:06 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
clicktest() {
|
2019-02-03 02:40:24 +01:00
|
|
|
console.log('clicktest!')
|
|
|
|
|
|
|
|
|
|
const objtodo = this.initcat()
|
|
|
|
|
objtodo.descr = 'PROVA'
|
|
|
|
|
objtodo.category = this.getCategory()
|
|
|
|
|
Todos.state.todos.push(objtodo)
|
2019-02-08 17:10:25 +01:00
|
|
|
Todos.mutations.setTodos_changed()
|
2019-02-03 02:40:24 +01:00
|
|
|
|
|
|
|
|
console.log('Todos.state.todos', Todos.state.todos)
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-03 19:28:06 +01:00
|
|
|
clicktest2() {
|
2019-02-14 18:38:23 +01:00
|
|
|
this.updatetable(false, 'clicktest')
|
2019-02-03 02:40:24 +01:00
|
|
|
console.log('Todos.state.todos', Todos.state.todos)
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 17:10:25 +01:00
|
|
|
checkUpdate() {
|
2019-02-04 03:09:15 +01:00
|
|
|
Todos.actions.waitAndcheckPendingMsg()
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 22:40:30 +01:00
|
|
|
}
|