From fb099322d49cfd05c5e7b1713caeee788d193fc0 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Mon, 4 Feb 2019 04:17:50 +0100 Subject: [PATCH] - fix: check if need refresh.. part 1 - keytab in todo... --- src-pwa/custom-service-worker.js | 9 +++-- src/components/todos/SingleTodo/SingleTodo.ts | 34 ++++++++++++++++--- src/components/todos/todo/todo.ts | 15 ++++++++ src/globalroutines/index.js | 2 +- src/store/Modules/Todos.ts | 8 ++--- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src-pwa/custom-service-worker.js b/src-pwa/custom-service-worker.js index dbac57d..34672c1 100644 --- a/src-pwa/custom-service-worker.js +++ b/src-pwa/custom-service-worker.js @@ -277,9 +277,12 @@ self.addEventListener('sync', function (event) { }) .then(function (resData) { console.log('Result CALL ', method, ' OK? =', resData.ok); - if (resData.ok) { - deleteItemFromData(table, rec._id); - } + + // Anyway Delete this, otherwise in some cases will return error, but it's not a problem. + // for example if I change a record and then I deleted ... + // if (resData.ok) { + deleteItemFromData(table, rec._id); + // } console.log('DELETE: ', mystrparam) deleteItemFromData('swmsg', mystrparam) diff --git a/src/components/todos/SingleTodo/SingleTodo.ts b/src/components/todos/SingleTodo/SingleTodo.ts index 70c7ba8..84d6b48 100644 --- a/src/components/todos/SingleTodo/SingleTodo.ts +++ b/src/components/todos/SingleTodo/SingleTodo.ts @@ -61,7 +61,7 @@ export default class SingleTodo extends Vue { } - @Watch('itemtodo.descr',) valueChanged5() { + @Watch('itemtodo.descr') valueChanged5() { this.precDescr = this.itemtodo.descr } @@ -234,6 +234,8 @@ export default class SingleTodo extends Vue { exitEdit(singola: boolean = false) { if (this.inEdit) { + if (this.precDescr !== this.itemtodo.descr) + this.updateTodo() // console.log('exitEdit') this.inEdit = false this.updateClasses @@ -243,11 +245,30 @@ export default class SingleTodo extends Vue { keyDownArea(e) { - if (e.key === 'Enter' && !e.shiftKey) { - e.preventDefault() +/* + if ((e.key === 'ArrowUp') && !e.shiftKey) { + e.key = 'Tab' + e.shiftKey = true + } + + if ((e.key === 'ArrowDown') && !e.shiftKey) { + let nextInput = inputs.get(inputs.index(this) + 1) + if (nextInput) { + nextInput.focus() + } + } +*/ + + if (((e.key === 'Enter') || (e.key === 'Tab')) && !e.shiftKey) { this.updateTodo() - this.deselectRiga() - this.faiFocus('insertTask', true) + + if ((e.key === 'Tab') && !e.shiftKey) { + + } else { + e.preventDefault() + this.deselectRiga() + this.faiFocus('insertTask', true) + } } // console.log('keyDownArea', e) @@ -261,6 +282,9 @@ export default class SingleTodo extends Vue { } updateTodo() { + if (this.itemtodo.descr === this.precDescr) + return + this.itemtodo.descr = this.precDescr console.log('updateTodo', this.precDescr, this.itemtodo.descr) this.watchupdate() diff --git a/src/components/todos/todo/todo.ts b/src/components/todos/todo/todo.ts index 93ef05c..dee9d90 100644 --- a/src/components/todos/todo/todo.ts +++ b/src/components/todos/todo/todo.ts @@ -41,6 +41,7 @@ export default class Todo extends Vue { itemDragStart: any = null itemDragEnd: any = null selrowid: number = 0 + polling = null fieldtochange: String [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'id_next', 'pos', 'enableExpiring', 'progress'] @@ -307,6 +308,10 @@ export default class Todo extends Vue { // console.log('Array PRIOR:', this.arrPrior) } + beforedestroy() { + clearInterval(this.polling) + } + async load() { this.todos_arr = [...Todos.state.todos] @@ -323,6 +328,9 @@ export default class Todo extends Vue { await this.updatetable() + + this.checkUpdate_everytime() + /* this.todos_arr.forEach((elem, index) => { this.logelem('LOAD ' + index, elem) @@ -331,6 +339,13 @@ export default class Todo extends Vue { } + // Call to check if need to refresh + checkUpdate_everytime() { + this.polling = setInterval(() => { + this.checkUpdate() + }, 10000) + } + copy(o) { let output, v, key output = Array.isArray(o) ? [] : {} diff --git a/src/globalroutines/index.js b/src/globalroutines/index.js index 9545b66..bcde872 100644 --- a/src/globalroutines/index.js +++ b/src/globalroutines/index.js @@ -2,6 +2,6 @@ import indexdb from './indexdb' export default async (context, cmd, table, data = null, id = '') => { const descr = data !== null ? data.descr : '' - console.log('globalroutines', cmd, table, descr, id) + // console.log('globalroutines', cmd, table, descr, id) return await indexdb(context, cmd, table, data, id) } diff --git a/src/store/Modules/Todos.ts b/src/store/Modules/Todos.ts index b103211..8f94248 100644 --- a/src/store/Modules/Todos.ts +++ b/src/store/Modules/Todos.ts @@ -105,12 +105,12 @@ namespace Actions { await aspettansec(1000) - console.log('waitAndcheckPendingMsg') + // console.log('waitAndcheckPendingMsg') return await checkPendingMsg(context) .then(ris => { - console.log('ris = ', ris) if (ris) { + console.log('ris = ', ris) const result = sendSwMsgIfAvailable() .then(something => { if (something) { @@ -132,7 +132,7 @@ namespace Actions { } async function checkPendingMsg(context) { - console.log('checkPendingMsg') + // console.log('checkPendingMsg') return new Promise(function (resolve, reject) { @@ -145,8 +145,8 @@ namespace Actions { // Check if there is something globalroutines(null, 'count', 'swmsg') .then(function (count) { - console.log('count = ', count) if (count > 0) { + console.log('count = ', count) return resolve(true) } else { return resolve(false)