- fix: Date problems... (it was a bad "copy" function, the object date was not valid...
- fix: error fetch on loading... (offline appeared)
This commit is contained in:
@@ -69,6 +69,11 @@ export default class SingleTodo extends Vue {
|
||||
this.updateClasses()
|
||||
}
|
||||
|
||||
dateToYYYYMMDD(date) {
|
||||
// may have timezone caveats https://stackoverflow.com/a/29774197/1850609
|
||||
return date && date.toISOString().split('T')[0]
|
||||
}
|
||||
|
||||
isTodo() {
|
||||
return this.isTodoByElem(this.itemtodo)
|
||||
}
|
||||
|
||||
@@ -49,9 +49,13 @@
|
||||
<div v-if="itemtodo.enableExpiring">
|
||||
<div :class="classExpiring">
|
||||
<q-datetime
|
||||
type="date"
|
||||
:class="classExpiringEx"
|
||||
v-model="itemtodo.expiring_at"
|
||||
class="myexpired">
|
||||
class="myexpired"
|
||||
format="DD/MM/YY"
|
||||
@change="val => { model = val }" >
|
||||
|
||||
</q-datetime>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -350,24 +350,11 @@ export default class Todo extends Vue {
|
||||
}, 10000)
|
||||
}
|
||||
|
||||
copy(o) {
|
||||
let output, v, key
|
||||
output = Array.isArray(o) ? [] : {}
|
||||
for (key in o) {
|
||||
v = o[key]
|
||||
output[key] = (typeof v === 'object') ? this.copy(v) : v
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
|
||||
initcat() {
|
||||
|
||||
var tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
|
||||
let mydatenow = new Date().getDate()
|
||||
let mydateexp = new Date().getDate() + 10
|
||||
|
||||
// console.log('User:' + UserStore.state.userId)
|
||||
|
||||
const objtodo: ITodo = {
|
||||
// _id: new Date().toISOString(), // Create NEW
|
||||
@@ -376,11 +363,11 @@ export default class Todo extends Vue {
|
||||
descr: '',
|
||||
priority: rescodes.Todos.PRIORITY_NORMAL,
|
||||
completed: false,
|
||||
created_at: mydatenow,
|
||||
modify_at: mydatenow,
|
||||
completed_at: 0,
|
||||
created_at: new Date(),
|
||||
modify_at: new Date(),
|
||||
completed_at: new Date(),
|
||||
category: '',
|
||||
expiring_at: mydateexp,
|
||||
expiring_at: tomorrow,
|
||||
enableExpiring: false,
|
||||
id_prev: '',
|
||||
id_next: '',
|
||||
@@ -388,7 +375,8 @@ export default class Todo extends Vue {
|
||||
modified: false,
|
||||
progress: 0
|
||||
}
|
||||
return this.copy(objtodo)
|
||||
// return this.copy(objtodo)
|
||||
return objtodo
|
||||
|
||||
}
|
||||
|
||||
@@ -417,8 +405,6 @@ export default class Todo extends Vue {
|
||||
|
||||
const objtodo = this.initcat()
|
||||
|
||||
console.log('insertTodo ', UserStore.state.userId)
|
||||
|
||||
objtodo.descr = this.todo
|
||||
objtodo.category = this.getCategory()
|
||||
const lastelem: ITodo = this.getLastList()
|
||||
@@ -766,7 +752,7 @@ export default class Todo extends Vue {
|
||||
|
||||
modifyField(recOut, recIn, field) {
|
||||
if (recOut[field] !== recIn[field]) {
|
||||
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
|
||||
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field])
|
||||
recOut.modified = true
|
||||
recOut[field] = recIn[field]
|
||||
return true
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export let idbKeyval = (() => {
|
||||
let db;
|
||||
const fieldsData = ['completed_at', 'created_at', 'expiring_at', 'modify_at']
|
||||
|
||||
function getDB() {
|
||||
if (!db) {
|
||||
@@ -29,7 +30,7 @@ export let idbKeyval = (() => {
|
||||
return db;
|
||||
}
|
||||
|
||||
async function withStore(type, table, callback, ) {
|
||||
async function withStore(type, table, callback,) {
|
||||
const db = await getDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const transaction = db.transaction(table, type);
|
||||
@@ -47,14 +48,18 @@ export let idbKeyval = (() => {
|
||||
});
|
||||
return req.result;
|
||||
},
|
||||
jsonCopy(src) {
|
||||
return JSON.parse(JSON.stringify(src));
|
||||
},
|
||||
|
||||
async getdata(table, key) {
|
||||
let req;
|
||||
|
||||
await withStore('readonly', table, store => {
|
||||
console.log('store', store, 'key', key)
|
||||
// console.log('store', store, 'key', key)
|
||||
req = store.get(key);
|
||||
});
|
||||
// console.log('RISFINALE!', req.result)
|
||||
|
||||
return req.result;
|
||||
},
|
||||
async getalldata(table) {
|
||||
@@ -80,9 +85,8 @@ export let idbKeyval = (() => {
|
||||
},
|
||||
async setdata(table, value) {
|
||||
let req;
|
||||
// console.log('setdata', table, value)
|
||||
|
||||
await withStore('readwrite', table, store => {
|
||||
await withStore('readwrite', table, store => {
|
||||
req = store.put(value);
|
||||
});
|
||||
return req.result;
|
||||
|
||||
@@ -5,10 +5,10 @@ export interface ITodo {
|
||||
descr?: string,
|
||||
priority: number,
|
||||
completed: boolean,
|
||||
created_at: any,
|
||||
modify_at: any,
|
||||
completed_at: any,
|
||||
expiring_at: any,
|
||||
created_at: Date,
|
||||
modify_at: Date,
|
||||
completed_at: Date,
|
||||
expiring_at: Date,
|
||||
enableExpiring?: boolean,
|
||||
id_prev?: string,
|
||||
id_next?: string,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export interface IToken {
|
||||
access: string
|
||||
token: string
|
||||
data_login: Date
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,14 +47,28 @@ let idbKeyval = (() => {
|
||||
});
|
||||
return req.result;
|
||||
},
|
||||
|
||||
// jsonCopy(src) {
|
||||
// return JSON.parse(JSON.stringify(src));
|
||||
// },
|
||||
|
||||
// contains(a, b) {
|
||||
// // array matches
|
||||
// if (Array.isArray(b)) {
|
||||
// return b.some(x => a.indexOf(x) > -1);
|
||||
// }
|
||||
// // string match
|
||||
// return a.indexOf(b) > -1;
|
||||
// },
|
||||
|
||||
async getdata(table, key) {
|
||||
let req;
|
||||
|
||||
await withStore('readonly', table, store => {
|
||||
console.log('store', store, 'key', key)
|
||||
// console.log('store', store, 'key', key)
|
||||
req = store.get(key);
|
||||
});
|
||||
// console.log('RISFINALE!', req.result)
|
||||
|
||||
return req.result;
|
||||
},
|
||||
async getalldata(table) {
|
||||
@@ -73,7 +87,7 @@ let idbKeyval = (() => {
|
||||
},
|
||||
async setdata(table, value) {
|
||||
let req;
|
||||
console.log('setdata', table, value)
|
||||
// console.log('setdata', table, value)
|
||||
|
||||
await withStore('readwrite', table, store => {
|
||||
req = store.put(value);
|
||||
|
||||
@@ -31,9 +31,12 @@ async function sendRequest(url: string, lang: string, mytok: string, method: str
|
||||
method: method,
|
||||
cache: 'no-cache',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(mydata),
|
||||
headers: authHeader
|
||||
}
|
||||
|
||||
if (mydata !== null)
|
||||
configInit.body = JSON.stringify(mydata)
|
||||
|
||||
}
|
||||
|
||||
const request: Promise<Response> = fetch(url, configInit)
|
||||
|
||||
@@ -107,8 +107,10 @@ export namespace ApiTool {
|
||||
return resolve({ res, body })
|
||||
})
|
||||
.catch(e => {
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
return reject({ code: rescodes.ERR_GENERICO, status: res.status })
|
||||
return resolve({ res, body: {} })
|
||||
// Array not found...
|
||||
// UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
// return reject({ code: rescodes.ERR_GENERICO, status: res.status })
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
@@ -278,6 +278,8 @@ namespace Actions {
|
||||
|
||||
const token = UserStore.state.idToken
|
||||
|
||||
console.log('TODO TO SAVE: ', itemtodo)
|
||||
|
||||
let res = await Api.SendReq(call, UserStore.state.lang, token, method, itemtodo)
|
||||
.then(({ res, newItem }) => {
|
||||
console.log('dbInsertSaveTodo RIS =', newItem)
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Mutations {
|
||||
state.category = data.categorySel
|
||||
// @ts-ignore
|
||||
state.tokens = [
|
||||
{ access: 'auth', token: data.idToken }
|
||||
{ access: 'auth ' + navigator.userAgent, token: data.idToken, date_login: new Date() }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Mutations {
|
||||
if (!state.tokens) {
|
||||
state.tokens = []
|
||||
}
|
||||
state.tokens.push({ access: 'auth', token: data.idToken })
|
||||
state.tokens.push({ access: 'auth ' + navigator.userAgent, token: data.idToken, data_login: new Date() })
|
||||
}
|
||||
|
||||
function setServerCode(state: IUserState, num: number) {
|
||||
@@ -143,6 +143,7 @@ namespace Mutations {
|
||||
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
||||
state.servercode = err
|
||||
}
|
||||
console.log('Err catch: (servercode:', err, ')')
|
||||
}
|
||||
|
||||
function getMsgError(state: IUserState, err: number) {
|
||||
|
||||
Reference in New Issue
Block a user