improve: Drag & Drop (work in progress)
fix: - Axios: login error msg
This commit is contained in:
@@ -37,7 +37,6 @@
|
||||
"graphql": "^0.13.2",
|
||||
"graphql-tag": "^2.8.0",
|
||||
"gsap": "^2.0.2",
|
||||
"immortal-db": "^1.0.2",
|
||||
"jquery": "^3.3.1",
|
||||
"js-cookie": "^2.2.0",
|
||||
"localforage": "^1.7.3",
|
||||
@@ -56,7 +55,6 @@
|
||||
"vue-router": "^3.0.1",
|
||||
"vue-svgicon": "^3.1.0",
|
||||
"vue2-dragula": "^2.5.4",
|
||||
"vuedraggable": "^2.17.0",
|
||||
"vuelidate": "^0.7.4",
|
||||
"vuex": "^3.0.1",
|
||||
"vuex-class": "^0.3.1",
|
||||
|
||||
@@ -59,7 +59,7 @@ module.exports = function (ctx) {
|
||||
store: 'src/store/index.ts'
|
||||
},
|
||||
// app plugins (/src/plugins)
|
||||
plugins: ['i18n', 'axios', 'vee-validate', 'myconfig', 'local-storage', 'error-handler', 'globalroutines', 'vue-idb', 'vue2-dragula'],
|
||||
plugins: ['i18n', 'axios', 'vee-validate', 'myconfig', 'local-storage', 'error-handler', 'globalroutines', 'vue-idb', 'dragula'],
|
||||
css: [
|
||||
'app.styl'
|
||||
],
|
||||
|
||||
@@ -53,9 +53,11 @@ export default class App extends Vue {
|
||||
.then((loadstorage) => {
|
||||
if (loadstorage) {
|
||||
|
||||
if (UserStore.state.lang !== null) {
|
||||
if (UserStore.state.lang !== '') {
|
||||
console.log('SETLOCALE :', this.$i18n.locale)
|
||||
this.$i18n.locale = UserStore.state.lang // Set Lang
|
||||
} else {
|
||||
UserStore.mutations.setlang(this.$i18n.locale)
|
||||
}
|
||||
console.log('lang CARICATO:', this.$i18n.locale)
|
||||
|
||||
|
||||
@@ -240,8 +240,8 @@
|
||||
let my = this.getLangAtt()
|
||||
// this.$q.notify('prima: ' + String(my))
|
||||
|
||||
let mylang = localStorage.getItem(rescodes.localStorage.lang)
|
||||
if (mylang === null)
|
||||
let mylang = rescodes.getItemLS(rescodes.localStorage.lang)
|
||||
if (mylang === '')
|
||||
{
|
||||
if (navigator) {
|
||||
mylang = navigator.language
|
||||
@@ -252,7 +252,7 @@
|
||||
|
||||
console.log('IMPOSTA LANGMY', mylang)
|
||||
}
|
||||
if (mylang !== null) {
|
||||
if (mylang !== '') {
|
||||
if (mylang.toLowerCase() === 'enus')
|
||||
mylang = 'enUs'
|
||||
if ((mylang.toLowerCase() === 'eses') || (mylang.toLowerCase() === 'es-es'))
|
||||
|
||||
@@ -151,6 +151,7 @@ export default class SingleTodo extends Vue {
|
||||
// console.log('classDescrEdit = ', this.classDescrEdit)
|
||||
// console.log('classDescr', this.classDescr)
|
||||
|
||||
// console.log('UserStore.state.lang', UserStore.state.lang)
|
||||
if (this.isTodo())
|
||||
this.menuPopupTodo = rescodes.menuPopupTodo[UserStore.state.lang]
|
||||
else {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div :class="getClassRow()" @click="clickRow">
|
||||
<!--<div v-if="isTodo()" class="flex-item counter-item">{{itemtodo.counter}}</div>-->
|
||||
<div v-if="isTodo()" class="flex-item counter-item">{{itemtodo.pos}}</div>
|
||||
<!--<div v-if="isFirst">-->
|
||||
<!--<q-context-menu ref="contextMenu">-->
|
||||
<!--<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>-->
|
||||
|
||||
@@ -13,11 +13,10 @@ import objectId from '../../../js/objectId.js'
|
||||
|
||||
import _ from 'lodash'
|
||||
|
||||
import draggable from 'vuedraggable'
|
||||
|
||||
import VueIdb from 'vue-idb'
|
||||
// _.cloneDeep( Per clonare un oggetto
|
||||
|
||||
// import 'statics/css/dragula.css'
|
||||
import '../../../statics/css/dragula.css'
|
||||
|
||||
import globalroutines from '../../../globalroutines/index'
|
||||
|
||||
@@ -26,7 +25,7 @@ import Api from '@api'
|
||||
|
||||
@Component({
|
||||
|
||||
components: { SingleTodo, draggable }
|
||||
components: { SingleTodo }
|
||||
})
|
||||
export default class Todo extends Vue {
|
||||
$q: any
|
||||
@@ -50,6 +49,7 @@ export default class Todo extends Vue {
|
||||
loadDone: boolean = false
|
||||
public dragging: number
|
||||
public itemdrag: any = {}
|
||||
public service: any
|
||||
|
||||
fieldtochange: String [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'id_next', 'pos', 'enableExpiring', 'progress']
|
||||
|
||||
@@ -205,7 +205,7 @@ export default class Todo extends Vue {
|
||||
this.itemDragStart = null
|
||||
}
|
||||
|
||||
updateLinkedList(init: boolean, arr: ITodo[] = this.todos_arr) {
|
||||
updateLinkedList(drag: boolean, init: boolean, arr: ITodo[] = this.todos_arr) {
|
||||
|
||||
// console.log('updateLinkedList', this.todos_arr)
|
||||
|
||||
@@ -232,15 +232,17 @@ export default class Todo extends Vue {
|
||||
|
||||
// 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)
|
||||
|
||||
elem.id_prev = idprev
|
||||
elem.id_next = idnext
|
||||
if (elem.pos !== pos) {
|
||||
if ((elem.pos !== pos) || (drag && (elem.order !== elem.pos))) {
|
||||
elem.modified = true
|
||||
elem.pos = pos
|
||||
}
|
||||
|
||||
// if (elem.modified)
|
||||
// console.log('MODIFICATO QUIIIIIIIIIIIIIIIIIIII', elem.id_prev, idprev, elem.id_next, idnext, elem.pos, pos)
|
||||
|
||||
if (init) {
|
||||
elem.modified = false
|
||||
}
|
||||
@@ -336,7 +338,7 @@ export default class Todo extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
this.updateLinkedList(false)
|
||||
this.updateLinkedList(false, false)
|
||||
|
||||
// Updated only elements modified
|
||||
await this.updateModifyRecords(true)
|
||||
@@ -363,9 +365,42 @@ export default class Todo extends Vue {
|
||||
return await this.updatetable(refresh, 'updateModifyRecords')
|
||||
}
|
||||
|
||||
async updateAll(drag?: boolean) {
|
||||
this.updateLinkedList(drag, false)
|
||||
|
||||
async created() {
|
||||
await this.load()
|
||||
// Updated only elements modified
|
||||
await this.updateModifyRecords(true)
|
||||
|
||||
await this.updatetable(false, 'onEnd')
|
||||
|
||||
}
|
||||
|
||||
private getElementIndex(el: any) {
|
||||
return [].slice.call(el.parentElement.children).indexOf(el)
|
||||
}
|
||||
|
||||
private getElementOldIndex(el: any) {
|
||||
return el.attributes['index'].value
|
||||
}
|
||||
|
||||
created() {
|
||||
const $service = this.$dragula.$service
|
||||
$service.options('todos_arr', { direction: 'vertical' })
|
||||
$service.eventBus.$on('dragend', (args) => {
|
||||
|
||||
let itemdragend = {
|
||||
newIndex: this.getElementIndex(args.el),
|
||||
oldIndex: this.getElementOldIndex(args.el)
|
||||
}
|
||||
// console.log('args', args)
|
||||
|
||||
// console.log('newIndex', itemdragend.newIndex)
|
||||
// console.log('oldIndex', itemdragend.oldIndex)
|
||||
|
||||
this.onEnd(itemdragend)
|
||||
})
|
||||
|
||||
this.load()
|
||||
}
|
||||
|
||||
setarrPriority() {
|
||||
@@ -688,6 +723,10 @@ export default class Todo extends Vue {
|
||||
|
||||
this.prevRecords = [...this.todos_arr]
|
||||
|
||||
// To cloning an array...
|
||||
// this.prevRecords = _.cloneDeep(this.todos_arr)
|
||||
|
||||
|
||||
return await Todos.actions.getTodosByCategory(this.getCategory())
|
||||
.then(arrris => {
|
||||
|
||||
@@ -697,7 +736,7 @@ export default class Todo extends Vue {
|
||||
|
||||
arrtemp = _.orderBy(arrtemp, ['completed', 'priority', 'pos'], ['asc', 'desc', 'asc'])
|
||||
|
||||
this.updateLinkedList(true, arrtemp)
|
||||
this.updateLinkedList(false, true, arrtemp)
|
||||
|
||||
// If changed the position, then set modified
|
||||
arrtemp.forEach(itemNew => {
|
||||
@@ -874,7 +913,7 @@ export default class Todo extends Vue {
|
||||
|
||||
|
||||
if (miorec.modified) {
|
||||
console.log('Todo MODIFICATO! ', miorec.descr, 'SALVALO SULLA IndexedDB todos')
|
||||
// console.log('Todo MODIFICATO! ', miorec.descr, 'SALVALO SULLA IndexedDB todos')
|
||||
miorec.modify_at = new Date().getDate()
|
||||
miorec.modified = false
|
||||
|
||||
@@ -920,47 +959,50 @@ export default class Todo extends Vue {
|
||||
Todos.actions.waitAndcheckPendingMsg()
|
||||
}
|
||||
|
||||
dragStart(which, ev) {
|
||||
this.itemdrag.indTemp = which
|
||||
console.log('1) DRAG INIZIO: ', which)
|
||||
this.itemdrag.oldIndex = which
|
||||
this.dragging = which
|
||||
}
|
||||
|
||||
public randomHexColor() {
|
||||
return Math.random().toString(16).slice(2, 8)
|
||||
}
|
||||
|
||||
dragEnter(index, ev) {
|
||||
if (this.itemdrag.indTemp !== index) {
|
||||
console.log(`[${index}] DRAG ENTER`)
|
||||
this.itemdrag.indTemp = index
|
||||
|
||||
this.getItemDrag(index).addClass('draggato2').removeClass('non-draggato')
|
||||
/*
|
||||
dragStart(which, ev) {
|
||||
this.itemdrag.indTemp = which
|
||||
console.log('1) DRAG INIZIO: ', which)
|
||||
this.itemdrag.oldIndex = which
|
||||
this.dragging = which
|
||||
}
|
||||
}
|
||||
|
||||
getItemDrag(index) {
|
||||
return $('div[name=REF' + index + ']')
|
||||
}
|
||||
|
||||
dragLeave(index, ev) {
|
||||
if (this.itemdrag.indTemp !== index) {
|
||||
this.getItemDrag(index).addClass('non-draggato').removeClass('draggato')
|
||||
public randomHexColor() {
|
||||
return Math.random().toString(16).slice(2, 8)
|
||||
}
|
||||
}
|
||||
|
||||
dragEnd(ev) {
|
||||
this.dragging = -1
|
||||
}
|
||||
dragEnter(index, ev) {
|
||||
if (this.itemdrag.indTemp !== index) {
|
||||
console.log(`[${index}] DRAG ENTER`)
|
||||
this.itemdrag.indTemp = index
|
||||
|
||||
dragFinish(to, ev) {
|
||||
this.itemdrag.indTemp = -1
|
||||
this.getItemDrag(to).addClass('non-draggato').removeClass('draggato')
|
||||
console.log('2) DRAG FINE: ', to)
|
||||
this.itemdrag.newIndex = to
|
||||
this.onEnd(this.itemdrag)
|
||||
this.getItemDrag(index).addClass('draggato2').removeClass('non-draggato')
|
||||
}
|
||||
}
|
||||
|
||||
getItemDrag(index) {
|
||||
return $('div[name=REF' + index + ']')
|
||||
}
|
||||
|
||||
dragLeave(index, ev) {
|
||||
if (this.itemdrag.indTemp !== index) {
|
||||
this.getItemDrag(index).addClass('non-draggato').removeClass('draggato')
|
||||
}
|
||||
}
|
||||
|
||||
dragEnd(ev) {
|
||||
this.dragging = -1
|
||||
}
|
||||
|
||||
dragFinish(to, ev) {
|
||||
this.itemdrag.indTemp = -1
|
||||
this.getItemDrag(to).addClass('non-draggato').removeClass('draggato')
|
||||
console.log('2) DRAG FINE: ', to)
|
||||
this.itemdrag.newIndex = to
|
||||
this.onEnd(this.itemdrag)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
<div class="drag">
|
||||
<!--<draggable v-model="todos_arr" :options="{draggable:'.myitemdrag'}"-->
|
||||
<!--@start="onStart" @end="onEnd" class="dragArea">-->
|
||||
<transition-group :name="mytypetransgroup">
|
||||
<div :id="getmyid(mytodo._id)" v-for="(mytodo, index) in todos_arr" :key="mytodo._id" class="myitemdrag"
|
||||
draggable="true" @dragstart="dragStart(index, $event)" @dragover.prevent @dragenter="dragEnter(index)"
|
||||
@dragleave="dragLeave(index)" @dragend="dragEnd" @drop="dragFinish(index, $event)" >
|
||||
<!--<transition-group :name="mytypetransgroup">-->
|
||||
<!--<div :id="getmyid(mytodo._id)" v-for="(mytodo, index) in todos_arr" :key="mytodo._id" class="myitemdrag"-->
|
||||
<!--draggable="true" @dragstart="dragStart(index, $event)" @dragover.prevent @dragenter="dragEnter(index)"-->
|
||||
<!--@dragleave="dragLeave(index)" @dragend="dragEnd" @drop="dragFinish(index, $event)" >-->
|
||||
<div class="container" v-dragula="todos_arr" drake="first">
|
||||
<div :id="getmyid(mytodo._id)" :index="index" v-for="(mytodo, index) in todos_arr" :key="mytodo._id" class="myitemdrag">
|
||||
|
||||
|
||||
<div v-if="(prior !== mytodo.priority) && !mytodo.completed" :class="getTitlePriority(mytodo.priority)">
|
||||
<label>{{getPriorityByInd(mytodo.priority)}}</label>
|
||||
@@ -28,11 +31,12 @@
|
||||
@deselectAllRows="deselectAllRows" @onEnd="onEnd"
|
||||
:itemtodo='mytodo' />
|
||||
|
||||
<div :name="`REF${index}`" class="divdrag non-draggato"></div>
|
||||
<!--<div :name="`REF${index}`" class="divdrag non-draggato"></div>-->
|
||||
|
||||
<div style="display: none">{{ prior = mytodo.priority, priorcomplet = mytodo.completed }}</div>
|
||||
</div>
|
||||
</transition-group>
|
||||
</div>
|
||||
<!--</transition-group>-->
|
||||
<!--</draggable>-->
|
||||
</div>
|
||||
|
||||
|
||||
@@ -8,9 +8,14 @@ function translate(params) {
|
||||
let stringa = messages[lang]
|
||||
|
||||
let ris = stringa
|
||||
msg.forEach(param => {
|
||||
ris = ris[param]
|
||||
})
|
||||
if (ris !== undefined) {
|
||||
msg.forEach(param => {
|
||||
ris = ris[param]
|
||||
})
|
||||
} else {
|
||||
console.log('ERRORE IN TRANSLATE! ', params, ' NON ESISTE!')
|
||||
return params
|
||||
}
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<link rel="icon" href="/statics/icons/favicon.ico" type="image/x-icon">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/statics/icons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/statics/icons/favicon-16x16.png">
|
||||
<link rel="stylesheet" type="text/css" href="/statics/css/dragula.css">
|
||||
<script defer src="/statics/js/material.min.js"></script>
|
||||
<script src="/statics/js/promise.js"></script>
|
||||
<script src="/statics/js/fetch.js"></script>
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface ITodo {
|
||||
id_next?: string,
|
||||
modified?: boolean,
|
||||
pos?: number,
|
||||
order?: number,
|
||||
progress?: number
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import Vue from 'vue'
|
||||
import { Vue2Dragula } from 'vue2-dragula'
|
||||
|
||||
Vue.use(Vue2Dragula, {
|
||||
logging: {
|
||||
service: true // to only log methods in service (DragulaService)
|
||||
}
|
||||
});
|
||||
export default ({ Vue }) => {
|
||||
Vue.use(Vue2Dragula, {
|
||||
logging: {
|
||||
service: false // to only log methods in service (DragulaService)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,20 +6,22 @@ import { rescodes } from "../store/Modules/rescodes";
|
||||
export default ({ app, store, Vue }) => {
|
||||
Vue.use(VueI18n);
|
||||
// Vue.config.lang = process.env.LANG_DEFAULT;
|
||||
let mylang = localStorage.getItem(rescodes.localStorage.lang)
|
||||
|
||||
if ((navigator) && (mylang === null)) {
|
||||
let mylang = rescodes.getItemLS(rescodes.localStorage.lang)
|
||||
|
||||
if ((navigator) && (mylang === '')) {
|
||||
mylang = navigator.language
|
||||
console.log(`LANG NAVIGATOR ${mylang}`)
|
||||
}
|
||||
|
||||
if (mylang === '') {
|
||||
if (mylang === '')
|
||||
mylang = process.env.LANG_DEFAULT;
|
||||
}
|
||||
|
||||
if (mylang.toLowerCase() === 'es-es')
|
||||
mylang = 'esEs'
|
||||
|
||||
console.log('MYLANG=', mylang)
|
||||
console.log('MYLANG2=', mylang)
|
||||
console.log('process.env.LANG_DEFAULT=', process.env.LANG_DEFAULT)
|
||||
Vue.config.lang = mylang
|
||||
|
||||
// console.log("PLUGINS INIT....");
|
||||
|
||||
@@ -13,14 +13,16 @@ export class AxiosSuccess {
|
||||
|
||||
export class AxiosError {
|
||||
public success: boolean = false
|
||||
public status: number
|
||||
public status: number = 0
|
||||
public data: any
|
||||
public code: any
|
||||
public code: any = 0
|
||||
public msgerr: string = ''
|
||||
|
||||
constructor(status: number, data?: any, code?: any) {
|
||||
constructor(status: number, data?: any, code?: any, msgerr?: string) {
|
||||
this.status = status
|
||||
this.data = data
|
||||
this.code = code
|
||||
this.msgerr = msgerr
|
||||
if (status !== 401) {
|
||||
// if (status == 0) message = 'Vérifiez votre connexion Internet';
|
||||
// NotificationsStore.actions.addNotification({ type: 'warning', message: message })
|
||||
@@ -31,6 +33,22 @@ export class AxiosError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getMsgError() {
|
||||
if (this.data && this.data.error)
|
||||
return this.data.error.message
|
||||
|
||||
return this.msgerr
|
||||
}
|
||||
public getCode() {
|
||||
if (this.code === 0) {
|
||||
if (this.data.code) {
|
||||
return this.data.code
|
||||
}
|
||||
}
|
||||
|
||||
return this.code
|
||||
}
|
||||
}
|
||||
|
||||
// export class ApiResponse {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
|
||||
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||
import router from '@router'
|
||||
import {clone} from 'lodash'
|
||||
import { clone } from 'lodash'
|
||||
import * as Types from './ApiTypes'
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import { rescodes } from '@src/store/Modules/rescodes'
|
||||
@@ -21,8 +21,10 @@ axiosInstance.interceptors.response.use(
|
||||
return response
|
||||
},
|
||||
(error) => {
|
||||
console.log(error.response.status)
|
||||
console.log('Request Error: ', error.response)
|
||||
if (error.response) {
|
||||
console.log(error.response.status)
|
||||
console.log('Request Error: ', error.response)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
@@ -48,11 +50,12 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
})
|
||||
ricevuto = true
|
||||
console.log('response', response)
|
||||
// console.log(new Types.AxiosSuccess(response.data, response.status))
|
||||
|
||||
const setAuthToken = (path === '/updatepwd')
|
||||
|
||||
if (response.status === 200) {
|
||||
if (response && (response.status === 200)) {
|
||||
let x_auth_token = ''
|
||||
try {
|
||||
if (setAuthToken || (path === '/users/login')) {
|
||||
@@ -87,7 +90,8 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
// @ts-ignore
|
||||
response = await axiosInstance[type](path, {
|
||||
params: payload,
|
||||
headers: {'Content-Type': 'application/json',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth': UserStore.state.x_auth_token
|
||||
}
|
||||
})
|
||||
@@ -104,18 +108,28 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
|
||||
}
|
||||
catch (error) {
|
||||
if (process.env.DEV) {
|
||||
console.log('ERROR using', path, error, 'ricevuto=', ricevuto)
|
||||
console.log('ERROR using', path)
|
||||
// console.log('Error received: ', error)
|
||||
// console.log('ricevuto=', ricevuto)
|
||||
console.log('error.response=', error.response)
|
||||
}
|
||||
let mycode = 0
|
||||
if (!ricevuto) {
|
||||
mycode = rescodes.ERR_SERVERFETCH
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
|
||||
} else {
|
||||
mycode = rescodes.ERR_GENERICO
|
||||
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data))
|
||||
if (error.response.data && error.response.data.code) {
|
||||
mycode = error.response.data.code
|
||||
UserStore.mutations.setServerCode(mycode)
|
||||
}
|
||||
return Promise.reject(new Types.AxiosError(error.response.status, error.response.data, error.response.data.code))
|
||||
} else {
|
||||
return Promise.reject(new Types.AxiosError(0))
|
||||
return Promise.reject(new Types.AxiosError(0, null, mycode, error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ namespace Actions {
|
||||
return res
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('error=', error)
|
||||
console.log('error dbLoadTodo', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return error
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import { GlobalStore, UserStore, Todos } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
import translate from './../../globalroutines/util'
|
||||
import * as Types from "@src/store/Api/ApiTypes"
|
||||
|
||||
const bcrypt = require('bcryptjs')
|
||||
|
||||
@@ -150,11 +151,11 @@ namespace Mutations {
|
||||
}
|
||||
|
||||
|
||||
function setErrorCatch(state: IUserState, err: number) {
|
||||
function setErrorCatch(state: IUserState, axerr: Types.AxiosError) {
|
||||
if (state.servercode !== rescodes.ERR_SERVERFETCH) {
|
||||
state.servercode = err
|
||||
state.servercode = axerr.getCode()
|
||||
}
|
||||
console.log('Err catch: (servercode:', err, ')')
|
||||
console.log('Err catch: (servercode:', axerr.getCode(), axerr.getMsgError(), ')')
|
||||
}
|
||||
|
||||
function getMsgError(state: IUserState, err: number) {
|
||||
@@ -224,9 +225,9 @@ namespace Actions {
|
||||
.then(res => {
|
||||
return { code: res.data.code, msg: res.data.msg }
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch((error: Types.AxiosError) => {
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return { code: UserStore.getters.getServerCode, msg: error }
|
||||
return { code: UserStore.getters.getServerCode, msg: error.getMsgError() }
|
||||
})
|
||||
|
||||
}
|
||||
@@ -351,9 +352,9 @@ namespace Actions {
|
||||
}
|
||||
|
||||
async function signin(context, authData: ISigninOptions) {
|
||||
console.log('LOGIN ')
|
||||
console.log('LOGIN signin')
|
||||
|
||||
console.log('MYLANG = ' + state.lang)
|
||||
// console.log('MYLANG = ' + state.lang)
|
||||
|
||||
let sub = null
|
||||
|
||||
@@ -361,6 +362,7 @@ namespace Actions {
|
||||
if ('serviceWorker' in navigator) {
|
||||
sub = await navigator.serviceWorker.ready
|
||||
.then(function (swreg) {
|
||||
console.log('swreg')
|
||||
let sub = swreg.pushManager.getSubscription()
|
||||
return sub
|
||||
})
|
||||
@@ -388,19 +390,19 @@ namespace Actions {
|
||||
options
|
||||
}
|
||||
|
||||
// console.log('PASSO 4')
|
||||
|
||||
console.log(usertosend)
|
||||
|
||||
Mutations.mutations.setServerCode(rescodes.CALLING)
|
||||
|
||||
let myres: any
|
||||
|
||||
console.log('Api.SendReq')
|
||||
|
||||
return Api.SendReq('/users/login', 'POST', usertosend, true)
|
||||
.then(res => {
|
||||
myres = res
|
||||
if (myres.data.code === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
Mutations.mutations.setServerCode(myres.data.code)
|
||||
return myres
|
||||
}
|
||||
|
||||
if (myres.status !== 200) {
|
||||
return Promise.reject(rescodes.ERR_GENERICO)
|
||||
@@ -512,7 +514,7 @@ namespace Actions {
|
||||
// console.log('*** autologin_FromLocalStorage ***')
|
||||
// INIT
|
||||
|
||||
UserStore.state.lang = localStorage.getItem(rescodes.localStorage.lang)
|
||||
UserStore.state.lang = rescodes.getItemLS(rescodes.localStorage.lang)
|
||||
|
||||
const token = localStorage.getItem(rescodes.localStorage.token)
|
||||
if (!token) {
|
||||
|
||||
@@ -21,7 +21,7 @@ export const rescodes = {
|
||||
userId: 'uid',
|
||||
token: 'tk',
|
||||
username: 'uname',
|
||||
lang:'lg'
|
||||
lang: 'lg'
|
||||
},
|
||||
|
||||
Todos: {
|
||||
@@ -247,6 +247,14 @@ export const rescodes = {
|
||||
|
||||
jsonCopy(src) {
|
||||
return JSON.parse(JSON.stringify(src))
|
||||
},
|
||||
|
||||
getItemLS(item) {
|
||||
let ris = localStorage.getItem(item)
|
||||
if ((ris == null) || (ris === '') || (ris === 'null'))
|
||||
ris = ''
|
||||
|
||||
return ris
|
||||
}
|
||||
|
||||
|
||||
|
||||
8
src/typings/libs/dragula.d.ts
vendored
Normal file
8
src/typings/libs/dragula.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { dragula } from 'vue2-dragula'
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$dragula: dragula
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export default class Signin extends Vue {
|
||||
public $q
|
||||
loading: boolean
|
||||
$t: any
|
||||
public iswaitingforRes: boolean = false
|
||||
|
||||
public signin: ISigninOptions = {
|
||||
username: process.env.TEST_USERNAME || '',
|
||||
@@ -75,31 +76,46 @@ export default class Signin extends Vue {
|
||||
}
|
||||
|
||||
checkErrors(riscode) {
|
||||
// console.log("RIS = " + riscode);
|
||||
if (riscode === rescodes.OK) {
|
||||
this.showNotif({ type: 'positive', message: this.$t('login.completato') })
|
||||
this.$router.push('/')
|
||||
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
// console.log('checkErrors: ', riscode)
|
||||
try {
|
||||
if (riscode === rescodes.OK) {
|
||||
this.showNotif({ type: 'positive', message: this.$t('login.completato') })
|
||||
this.$router.push('/')
|
||||
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
|
||||
// Wait N seconds to avoid calling many times...
|
||||
return new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
resolve('anything')
|
||||
}, 1000)
|
||||
}).then(() => {
|
||||
this.showNotif(this.$t('login.errato'))
|
||||
this.$router.push('/signin')
|
||||
})
|
||||
// Wait N seconds to avoid calling many times...
|
||||
return new Promise(function (resolve, reject) {
|
||||
setTimeout(function () {
|
||||
resolve('anything')
|
||||
}, 3000)
|
||||
}).then(() => {
|
||||
setTimeout( () => {
|
||||
this.$q.loading.hide()
|
||||
}, 200)
|
||||
this.showNotif(this.$t('login.errato'))
|
||||
this.iswaitingforRes = false
|
||||
this.$router.push('/signin')
|
||||
})
|
||||
|
||||
} else if (riscode === rescodes.ERR_SERVERFETCH) {
|
||||
this.showNotif(this.$t('fetch.errore_server'))
|
||||
} else if (riscode === rescodes.ERR_GENERICO) {
|
||||
let msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
|
||||
this.showNotif(msg)
|
||||
} else {
|
||||
this.showNotif('Errore num ' + riscode)
|
||||
}
|
||||
|
||||
if (riscode !== serv_constants.RIS_CODE_LOGIN_ERR) {
|
||||
this.iswaitingforRes = false
|
||||
setTimeout( () => {
|
||||
this.$q.loading.hide()
|
||||
}, 200)
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
} else if (riscode === rescodes.ERR_SERVERFETCH) {
|
||||
this.showNotif(this.$t('fetch.errore_server'))
|
||||
} else if (riscode === rescodes.ERR_GENERICO) {
|
||||
let msg = this.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
|
||||
this.showNotif(msg)
|
||||
} else {
|
||||
this.showNotif('Errore num ' + riscode)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
redirect(response) {
|
||||
@@ -132,17 +148,24 @@ export default class Signin extends Vue {
|
||||
}
|
||||
|
||||
this.$q.loading.show({ message: this.$t('login.incorso') })
|
||||
// disable Button Login:
|
||||
this.iswaitingforRes = true
|
||||
|
||||
console.log(this.signin)
|
||||
UserStore.actions.signin(this.signin)
|
||||
.then((riscode) => {
|
||||
console.log('signin FINITO CALL: riscode=', riscode)
|
||||
// console.log('signin FINITO CALL: riscode=', riscode)
|
||||
if (riscode === rescodes.OK) {
|
||||
router.push('/signin')
|
||||
}
|
||||
return riscode
|
||||
}).then((riscode) => {
|
||||
this.$i18n.locale = UserStore.state.lang // Set Lang
|
||||
if (UserStore.state.lang !== '')
|
||||
this.$i18n.locale = UserStore.state.lang // Set Lang
|
||||
else
|
||||
UserStore.mutations.setlang(this.$i18n.locale) // Set Lang
|
||||
|
||||
// console.log('LANG ORA=', UserStore.state.lang)
|
||||
|
||||
globalroutines(this, 'loadapp', '')
|
||||
return riscode
|
||||
@@ -150,22 +173,21 @@ export default class Signin extends Vue {
|
||||
.then((riscode) => {
|
||||
if (riscode === rescodes.OK) {
|
||||
GlobalStore.actions.createPushSubscription()
|
||||
.then(ris => {
|
||||
.then(rissub => {
|
||||
|
||||
})
|
||||
.catch(e => {
|
||||
console.log('ERROR = ' + e)
|
||||
})
|
||||
.then(() => {
|
||||
this.checkErrors(riscode)
|
||||
this.$q.loading.hide()
|
||||
console.log('ERROR Subscription = ' + e)
|
||||
})
|
||||
}
|
||||
|
||||
this.checkErrors(riscode)
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('ERROR SIGNIN = ' + error)
|
||||
|
||||
this.checkErrors(error)
|
||||
this.$q.loading.hide()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
</q-card-main>
|
||||
|
||||
<div align="center">
|
||||
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error">{{$t('login.enter')}}
|
||||
<q-btn rounded size="lg" color="primary" @click="submit" :disable="$v.$error || iswaitingforRes">{{$t('login.enter')}}
|
||||
</q-btn>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user