diff --git a/src-pwa/custom-service-worker.js b/src-pwa/custom-service-worker.js index f192e0e..bd05761 100644 --- a/src-pwa/custom-service-worker.js +++ b/src-pwa/custom-service-worker.js @@ -113,9 +113,11 @@ if (workbox) { return clonedRes.json(); }) .then(function (data) { - console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos) - for (let key in data.todos) { - writeData('todos', data.todos[key]) + if (data.todos) { + console.log('Records TODOS Received from Server [', data.todos.length, 'record]', data.todos) + for (let key in data.todos) { + writeData('todos', data.todos[key]) + } } }); return res @@ -278,7 +280,11 @@ self.addEventListener('sync', function (event) { if (myrecs) { for (let rec of myrecs) { //console.log('syncing', table, '', rec.descr) - let link = cfgenv.serverweb + '/todos/' + rec._id + let link = cfgenv.serverweb + '/todos' + + if (method !== 'POST') + link += '/' + rec._id + console.log('++++++++++++++++++ SYNCING !!!! ', rec.descr, table, 'FETCH: ', method, link, 'data:') // Insert/Delete/Update table to the server @@ -289,7 +295,7 @@ self.addEventListener('sync', function (event) { body: JSON.stringify(rec) }) .then(function (resData) { - console.log('Result CALL ', method, ' OK? =', resData.ok); + // console.log('Result CALL ', method, ' OK? =', resData.ok); // 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 ... diff --git a/src/components/todos/todo/todo.ts b/src/components/todos/todo/todo.ts index dee9d90..3b9e4b9 100644 --- a/src/components/todos/todo/todo.ts +++ b/src/components/todos/todo/todo.ts @@ -85,11 +85,11 @@ export default class Todo extends Vue { @Watch('reload_fromServer', { immediate: true }) reload_fromServer_changed(value: string, oldValue: string) { console.log('reload_fromServer_changed!', value, oldValue) - if (value) { + // if (value) { Todos.actions.dbLoadTodo(false) Todos.actions.updateArrayInMemory() - } + // } } @@ -397,10 +397,20 @@ export default class Todo extends Vue { return '' } + isRegistered() { + return localStorage.getItem(rescodes.localStorage.userId) !== '' + } + async insertTodo() { if (this.todo.trim() === '') return + if (!this.isRegistered()) { + // Not logged + this.$q.notify(this.$t('user.notregistered')) + return + } + const objtodo = this.initcat() console.log('insertTodo ', UserStore.state.userId) diff --git a/src/model/UserStore.ts b/src/model/UserStore.ts index ed4b2a9..d859a11 100644 --- a/src/model/UserStore.ts +++ b/src/model/UserStore.ts @@ -28,4 +28,5 @@ export interface IUserState { servercode?: number x_auth_token?: string + isLogged?: boolean } diff --git a/src/statics/i18n.js b/src/statics/i18n.js index 98990af..19c9d03 100644 --- a/src/statics/i18n.js +++ b/src/statics/i18n.js @@ -52,6 +52,9 @@ const messages = { errore_generico: 'Errore Generico', errore_server: 'Impossibile accedere al Server. Riprovare Grazie', }, + user: { + notregistered: 'Devi registrarti al servizio prima di porter memorizzare i dati' + }, reg: { incorso: 'Registrazione in corso...', richiesto: 'Campo Richiesto', @@ -173,6 +176,9 @@ const messages = { errore_generico: 'Generic Error', errore_server: 'Unable to access to the Server. Retry. Thank you.', }, + user: { + notregistered: 'You need first to SignUp before storing data' + }, reg: { incorso: 'Registration please wait...', richiesto: 'Field Required', diff --git a/src/store/Api/index.ts b/src/store/Api/index.ts index b956965..4998894 100644 --- a/src/store/Api/index.ts +++ b/src/store/Api/index.ts @@ -79,19 +79,17 @@ export namespace ApiTool { } return reject(e) } - - return res.json() - .then((body) => { - return resolve({res, body}) - }) - .catch(e => { - UserStore.mutations.setServerCode(rescodes.ERR_GENERICO) - return reject(e) - }) - - } else { - return resolve({res, body: res.body}) } + + return res.json() + .then((body) => { + return resolve({ res, body }) + }) + .catch(e => { + UserStore.mutations.setServerCode(rescodes.ERR_GENERICO) + return reject(e) + }) + }) .catch(error => { if (process.env.DEV) { diff --git a/src/store/Modules/Todos.ts b/src/store/Modules/Todos.ts index 3150bd0..97ec034 100644 --- a/src/store/Modules/Todos.ts +++ b/src/store/Modules/Todos.ts @@ -80,12 +80,12 @@ namespace Actions { globalroutines(null, 'readall', 'swmsg') .then(function (arr_recmsg) { - let recclone = [...arr_recmsg] + // let recclone = [...arr_recmsg] if (arr_recmsg.length > 0) { console.log(' TROVATI MSG PENDENTI ! ORA LI MANDO: ', arr_recmsg) - console.log('---------------------- 2) navigator (2) .serviceWorker.ready') + // console.log('---------------------- 2) navigator (2) .serviceWorker.ready') something = true for (let rec of arr_recmsg) { diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index 6ed84a2..8181863 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -27,7 +27,7 @@ const state: IUserState = { verifiedEmail: false, categorySel: 'personal', servercode: 0, - x_auth_token: '' + x_auth_token: '', } @@ -76,8 +76,7 @@ namespace Getters { }, get getServerCode() { return getServerCode() - } - + }, } @@ -334,6 +333,7 @@ namespace Actions { localStorage.setItem(rescodes.localStorage.token, x_auth_token) localStorage.setItem(rescodes.localStorage.expirationDate, expirationDate.toString()) localStorage.setItem(rescodes.localStorage.verifiedEmail, '0') + state.isLogged = true // dispatch('storeUser', authData); // dispatch('setLogoutTimer', myres.data.expiresIn); @@ -476,6 +476,7 @@ namespace Actions { } function setGlobal() { + state.isLogged = true GlobalStore.mutations.setleftDrawerOpen(localStorage.getItem(rescodes.localStorage.leftDrawerOpen) === 'true') GlobalStore.mutations.setCategorySel(localStorage.getItem(rescodes.localStorage.categorySel)) @@ -506,6 +507,7 @@ namespace Actions { let expirationDate = new Date(String(expirationDateStr)) const now = new Date() if (now >= expirationDate) { + console.log('!!! Login Expired') return false } const userId = String(localStorage.getItem(rescodes.localStorage.userId)) diff --git a/src/store/Modules/serv_constants.ts b/src/store/Modules/serv_constants.ts index d3fd1b6..0a8ab56 100644 --- a/src/store/Modules/serv_constants.ts +++ b/src/store/Modules/serv_constants.ts @@ -1,11 +1,14 @@ export const serv_constants = { + RIS_CODE_TODO_CREATING_NOTMYUSER: -1001, + RIS_CODE_ERR: -99, RIS_CODE_EMAIL_ALREADY_VERIFIED: -5, RIS_CODE_EMAIL_VERIFIED: 1, - RIS_CODE_OK: 1, RIS_CODE_LOGIN_ERR_GENERIC: -20, RIS_CODE_LOGIN_ERR: -10, + RIS_CODE_OK: 1, + RIS_CODE_LOGIN_OK: 1