improve: Drag & Drop (work in progress)

fix: - Axios: login error msg
This commit is contained in:
Paolo Arena
2019-02-20 11:53:56 +01:00
parent 1eca13c27f
commit 6a99f22bf3
21 changed files with 263 additions and 133 deletions

View File

@@ -37,7 +37,6 @@
"graphql": "^0.13.2", "graphql": "^0.13.2",
"graphql-tag": "^2.8.0", "graphql-tag": "^2.8.0",
"gsap": "^2.0.2", "gsap": "^2.0.2",
"immortal-db": "^1.0.2",
"jquery": "^3.3.1", "jquery": "^3.3.1",
"js-cookie": "^2.2.0", "js-cookie": "^2.2.0",
"localforage": "^1.7.3", "localforage": "^1.7.3",
@@ -56,7 +55,6 @@
"vue-router": "^3.0.1", "vue-router": "^3.0.1",
"vue-svgicon": "^3.1.0", "vue-svgicon": "^3.1.0",
"vue2-dragula": "^2.5.4", "vue2-dragula": "^2.5.4",
"vuedraggable": "^2.17.0",
"vuelidate": "^0.7.4", "vuelidate": "^0.7.4",
"vuex": "^3.0.1", "vuex": "^3.0.1",
"vuex-class": "^0.3.1", "vuex-class": "^0.3.1",

View File

@@ -59,7 +59,7 @@ module.exports = function (ctx) {
store: 'src/store/index.ts' store: 'src/store/index.ts'
}, },
// app plugins (/src/plugins) // 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: [ css: [
'app.styl' 'app.styl'
], ],

View File

@@ -53,9 +53,11 @@ export default class App extends Vue {
.then((loadstorage) => { .then((loadstorage) => {
if (loadstorage) { if (loadstorage) {
if (UserStore.state.lang !== null) { if (UserStore.state.lang !== '') {
console.log('SETLOCALE :', this.$i18n.locale) console.log('SETLOCALE :', this.$i18n.locale)
this.$i18n.locale = UserStore.state.lang // Set Lang this.$i18n.locale = UserStore.state.lang // Set Lang
} else {
UserStore.mutations.setlang(this.$i18n.locale)
} }
console.log('lang CARICATO:', this.$i18n.locale) console.log('lang CARICATO:', this.$i18n.locale)

View File

@@ -240,8 +240,8 @@
let my = this.getLangAtt() let my = this.getLangAtt()
// this.$q.notify('prima: ' + String(my)) // this.$q.notify('prima: ' + String(my))
let mylang = localStorage.getItem(rescodes.localStorage.lang) let mylang = rescodes.getItemLS(rescodes.localStorage.lang)
if (mylang === null) if (mylang === '')
{ {
if (navigator) { if (navigator) {
mylang = navigator.language mylang = navigator.language
@@ -252,7 +252,7 @@
console.log('IMPOSTA LANGMY', mylang) console.log('IMPOSTA LANGMY', mylang)
} }
if (mylang !== null) { if (mylang !== '') {
if (mylang.toLowerCase() === 'enus') if (mylang.toLowerCase() === 'enus')
mylang = 'enUs' mylang = 'enUs'
if ((mylang.toLowerCase() === 'eses') || (mylang.toLowerCase() === 'es-es')) if ((mylang.toLowerCase() === 'eses') || (mylang.toLowerCase() === 'es-es'))

View File

@@ -151,6 +151,7 @@ export default class SingleTodo extends Vue {
// console.log('classDescrEdit = ', this.classDescrEdit) // console.log('classDescrEdit = ', this.classDescrEdit)
// console.log('classDescr', this.classDescr) // console.log('classDescr', this.classDescr)
// console.log('UserStore.state.lang', UserStore.state.lang)
if (this.isTodo()) if (this.isTodo())
this.menuPopupTodo = rescodes.menuPopupTodo[UserStore.state.lang] this.menuPopupTodo = rescodes.menuPopupTodo[UserStore.state.lang]
else { else {

View File

@@ -1,6 +1,6 @@
<template> <template>
<div :class="getClassRow()" @click="clickRow"> <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">--> <!--<div v-if="isFirst">-->
<!--<q-context-menu ref="contextMenu">--> <!--<q-context-menu ref="contextMenu">-->
<!--<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>--> <!--<SubMenus :menuPopupTodo="menuPopupTodo" :itemtodo="itemtodo" @clickMenu="clickMenu" @setPriority="setPriority"></SubMenus>-->

View File

@@ -13,11 +13,10 @@ import objectId from '../../../js/objectId.js'
import _ from 'lodash' 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' import globalroutines from '../../../globalroutines/index'
@@ -26,7 +25,7 @@ import Api from '@api'
@Component({ @Component({
components: { SingleTodo, draggable } components: { SingleTodo }
}) })
export default class Todo extends Vue { export default class Todo extends Vue {
$q: any $q: any
@@ -50,6 +49,7 @@ export default class Todo extends Vue {
loadDone: boolean = false loadDone: boolean = false
public dragging: number public dragging: number
public itemdrag: any = {} public itemdrag: any = {}
public service: any
fieldtochange: String [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'id_next', 'pos', 'enableExpiring', 'progress'] 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 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) // 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.id_prev !== idprev) || (elem.id_next !== idnext) || (elem.pos !== pos)) ? true : elem.modified
// elem.modified = 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_prev = idprev
elem.id_next = idnext elem.id_next = idnext
if (elem.pos !== pos) { if ((elem.pos !== pos) || (drag && (elem.order !== elem.pos))) {
elem.modified = true elem.modified = true
elem.pos = pos elem.pos = pos
} }
// if (elem.modified)
// console.log('MODIFICATO QUIIIIIIIIIIIIIIIIIIII', elem.id_prev, idprev, elem.id_next, idnext, elem.pos, pos)
if (init) { if (init) {
elem.modified = false elem.modified = false
} }
@@ -336,7 +338,7 @@ export default class Todo extends Vue {
} }
} }
this.updateLinkedList(false) this.updateLinkedList(false, false)
// Updated only elements modified // Updated only elements modified
await this.updateModifyRecords(true) await this.updateModifyRecords(true)
@@ -363,9 +365,42 @@ export default class Todo extends Vue {
return await this.updatetable(refresh, 'updateModifyRecords') return await this.updatetable(refresh, 'updateModifyRecords')
} }
async updateAll(drag?: boolean) {
this.updateLinkedList(drag, false)
async created() { // Updated only elements modified
await this.load() 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() { setarrPriority() {
@@ -688,6 +723,10 @@ export default class Todo extends Vue {
this.prevRecords = [...this.todos_arr] this.prevRecords = [...this.todos_arr]
// To cloning an array...
// this.prevRecords = _.cloneDeep(this.todos_arr)
return await Todos.actions.getTodosByCategory(this.getCategory()) return await Todos.actions.getTodosByCategory(this.getCategory())
.then(arrris => { .then(arrris => {
@@ -697,7 +736,7 @@ export default class Todo extends Vue {
arrtemp = _.orderBy(arrtemp, ['completed', 'priority', 'pos'], ['asc', 'desc', 'asc']) 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 // If changed the position, then set modified
arrtemp.forEach(itemNew => { arrtemp.forEach(itemNew => {
@@ -874,7 +913,7 @@ export default class Todo extends Vue {
if (miorec.modified) { 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.modify_at = new Date().getDate()
miorec.modified = false miorec.modified = false
@@ -920,6 +959,7 @@ export default class Todo extends Vue {
Todos.actions.waitAndcheckPendingMsg() Todos.actions.waitAndcheckPendingMsg()
} }
/*
dragStart(which, ev) { dragStart(which, ev) {
this.itemdrag.indTemp = which this.itemdrag.indTemp = which
console.log('1) DRAG INIZIO: ', which) console.log('1) DRAG INIZIO: ', which)
@@ -962,5 +1002,7 @@ export default class Todo extends Vue {
this.onEnd(this.itemdrag) this.onEnd(this.itemdrag)
} }
*/
} }

View File

@@ -12,10 +12,13 @@
<div class="drag"> <div class="drag">
<!--<draggable v-model="todos_arr" :options="{draggable:'.myitemdrag'}"--> <!--<draggable v-model="todos_arr" :options="{draggable:'.myitemdrag'}"-->
<!--@start="onStart" @end="onEnd" class="dragArea">--> <!--@start="onStart" @end="onEnd" class="dragArea">-->
<transition-group :name="mytypetransgroup"> <!--<transition-group :name="mytypetransgroup">-->
<div :id="getmyid(mytodo._id)" v-for="(mytodo, index) in todos_arr" :key="mytodo._id" class="myitemdrag" <!--<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)" <!--draggable="true" @dragstart="dragStart(index, $event)" @dragover.prevent @dragenter="dragEnter(index)"-->
@dragleave="dragLeave(index)" @dragend="dragEnd" @drop="dragFinish(index, $event)" > <!--@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)"> <div v-if="(prior !== mytodo.priority) && !mytodo.completed" :class="getTitlePriority(mytodo.priority)">
<label>{{getPriorityByInd(mytodo.priority)}}</label> <label>{{getPriorityByInd(mytodo.priority)}}</label>
@@ -28,11 +31,12 @@
@deselectAllRows="deselectAllRows" @onEnd="onEnd" @deselectAllRows="deselectAllRows" @onEnd="onEnd"
:itemtodo='mytodo' /> :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 style="display: none">{{ prior = mytodo.priority, priorcomplet = mytodo.completed }}</div>
</div> </div>
</transition-group> </div>
<!--</transition-group>-->
<!--</draggable>--> <!--</draggable>-->
</div> </div>

View File

@@ -8,9 +8,14 @@ function translate(params) {
let stringa = messages[lang] let stringa = messages[lang]
let ris = stringa let ris = stringa
if (ris !== undefined) {
msg.forEach(param => { msg.forEach(param => {
ris = ris[param] ris = ris[param]
}) })
} else {
console.log('ERRORE IN TRANSLATE! ', params, ' NON ESISTE!')
return params
}
return ris return ris
} }

View File

@@ -13,6 +13,7 @@
<link rel="icon" href="/statics/icons/favicon.ico" type="image/x-icon"> <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="32x32" href="/statics/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/statics/icons/favicon-16x16.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 defer src="/statics/js/material.min.js"></script>
<script src="/statics/js/promise.js"></script> <script src="/statics/js/promise.js"></script>
<script src="/statics/js/fetch.js"></script> <script src="/statics/js/fetch.js"></script>

View File

@@ -14,6 +14,7 @@ export interface ITodo {
id_next?: string, id_next?: string,
modified?: boolean, modified?: boolean,
pos?: number, pos?: number,
order?: number,
progress?: number progress?: number
} }

View File

@@ -1,8 +1,10 @@
import Vue from 'vue' import Vue from 'vue'
import { Vue2Dragula } from 'vue2-dragula' import { Vue2Dragula } from 'vue2-dragula'
Vue.use(Vue2Dragula, { export default ({ Vue }) => {
Vue.use(Vue2Dragula, {
logging: { logging: {
service: true // to only log methods in service (DragulaService) service: false // to only log methods in service (DragulaService)
} }
}); })
}

View File

@@ -6,20 +6,22 @@ import { rescodes } from "../store/Modules/rescodes";
export default ({ app, store, Vue }) => { export default ({ app, store, Vue }) => {
Vue.use(VueI18n); Vue.use(VueI18n);
// Vue.config.lang = process.env.LANG_DEFAULT; // 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 mylang = navigator.language
console.log(`LANG NAVIGATOR ${mylang}`) console.log(`LANG NAVIGATOR ${mylang}`)
} }
if (mylang === '') { if (mylang === '')
mylang = process.env.LANG_DEFAULT; mylang = process.env.LANG_DEFAULT;
}
if (mylang.toLowerCase() === 'es-es') if (mylang.toLowerCase() === 'es-es')
mylang = 'esEs' mylang = 'esEs'
console.log('MYLANG=', mylang) console.log('MYLANG2=', mylang)
console.log('process.env.LANG_DEFAULT=', process.env.LANG_DEFAULT)
Vue.config.lang = mylang Vue.config.lang = mylang
// console.log("PLUGINS INIT...."); // console.log("PLUGINS INIT....");

View File

@@ -13,14 +13,16 @@ export class AxiosSuccess {
export class AxiosError { export class AxiosError {
public success: boolean = false public success: boolean = false
public status: number public status: number = 0
public data: any 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.status = status
this.data = data this.data = data
this.code = code this.code = code
this.msgerr = msgerr
if (status !== 401) { if (status !== 401) {
// if (status == 0) message = 'Vérifiez votre connexion Internet'; // if (status == 0) message = 'Vérifiez votre connexion Internet';
// NotificationsStore.actions.addNotification({ type: 'warning', message: message }) // 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 { // export class ApiResponse {

View File

@@ -1,7 +1,7 @@
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios' import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
// import LoginModule from '../Modules/Auth/LoginStore' // import LoginModule from '../Modules/Auth/LoginStore'
import router from '@router' import router from '@router'
import {clone} from 'lodash' import { clone } from 'lodash'
import * as Types from './ApiTypes' import * as Types from './ApiTypes'
import { GlobalStore, UserStore } from '@store' import { GlobalStore, UserStore } from '@store'
import { rescodes } from '@src/store/Modules/rescodes' import { rescodes } from '@src/store/Modules/rescodes'
@@ -21,8 +21,10 @@ axiosInstance.interceptors.response.use(
return response return response
}, },
(error) => { (error) => {
if (error.response) {
console.log(error.response.status) console.log(error.response.status)
console.log('Request Error: ', error.response) console.log('Request Error: ', error.response)
}
return Promise.reject(error) return Promise.reject(error)
} }
) )
@@ -48,11 +50,12 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
} }
}) })
ricevuto = true ricevuto = true
console.log('response', response)
// console.log(new Types.AxiosSuccess(response.data, response.status)) // console.log(new Types.AxiosSuccess(response.data, response.status))
const setAuthToken = (path === '/updatepwd') const setAuthToken = (path === '/updatepwd')
if (response.status === 200) { if (response && (response.status === 200)) {
let x_auth_token = '' let x_auth_token = ''
try { try {
if (setAuthToken || (path === '/users/login')) { if (setAuthToken || (path === '/users/login')) {
@@ -87,7 +90,8 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
// @ts-ignore // @ts-ignore
response = await axiosInstance[type](path, { response = await axiosInstance[type](path, {
params: payload, params: payload,
headers: {'Content-Type': 'application/json', headers: {
'Content-Type': 'application/json',
'x-auth': UserStore.state.x_auth_token 'x-auth': UserStore.state.x_auth_token
} }
}) })
@@ -104,18 +108,28 @@ async function Request(type: string, path: string, payload: any, setAuthToken?:
} }
catch (error) { catch (error) {
if (process.env.DEV) { 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) { if (!ricevuto) {
mycode = rescodes.ERR_SERVERFETCH
UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH) UserStore.mutations.setServerCode(rescodes.ERR_SERVERFETCH)
} else { } else {
mycode = rescodes.ERR_GENERICO
UserStore.mutations.setServerCode(rescodes.ERR_GENERICO) UserStore.mutations.setServerCode(rescodes.ERR_GENERICO)
} }
if (error.response) { 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 { } else {
return Promise.reject(new Types.AxiosError(0)) return Promise.reject(new Types.AxiosError(0, null, mycode, error))
} }
} }
} }

View File

@@ -247,7 +247,7 @@ namespace Actions {
return res return res
}) })
.catch(error => { .catch(error => {
console.log('error=', error) console.log('error dbLoadTodo', error)
UserStore.mutations.setErrorCatch(error) UserStore.mutations.setErrorCatch(error)
return error return error
}) })

View File

@@ -10,6 +10,7 @@ import { GlobalStore, UserStore, Todos } from '@store'
import globalroutines from './../../globalroutines/index' import globalroutines from './../../globalroutines/index'
import translate from './../../globalroutines/util' import translate from './../../globalroutines/util'
import * as Types from "@src/store/Api/ApiTypes"
const bcrypt = require('bcryptjs') 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) { 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) { function getMsgError(state: IUserState, err: number) {
@@ -224,9 +225,9 @@ namespace Actions {
.then(res => { .then(res => {
return { code: res.data.code, msg: res.data.msg } return { code: res.data.code, msg: res.data.msg }
}) })
.catch((error) => { .catch((error: Types.AxiosError) => {
UserStore.mutations.setErrorCatch(error) 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) { 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 let sub = null
@@ -361,6 +362,7 @@ namespace Actions {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
sub = await navigator.serviceWorker.ready sub = await navigator.serviceWorker.ready
.then(function (swreg) { .then(function (swreg) {
console.log('swreg')
let sub = swreg.pushManager.getSubscription() let sub = swreg.pushManager.getSubscription()
return sub return sub
}) })
@@ -388,19 +390,19 @@ namespace Actions {
options options
} }
// console.log('PASSO 4')
console.log(usertosend) console.log(usertosend)
Mutations.mutations.setServerCode(rescodes.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let myres: any let myres: any
console.log('Api.SendReq')
return Api.SendReq('/users/login', 'POST', usertosend, true) return Api.SendReq('/users/login', 'POST', usertosend, true)
.then(res => { .then(res => {
myres = 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) { if (myres.status !== 200) {
return Promise.reject(rescodes.ERR_GENERICO) return Promise.reject(rescodes.ERR_GENERICO)
@@ -512,7 +514,7 @@ namespace Actions {
// console.log('*** autologin_FromLocalStorage ***') // console.log('*** autologin_FromLocalStorage ***')
// INIT // INIT
UserStore.state.lang = localStorage.getItem(rescodes.localStorage.lang) UserStore.state.lang = rescodes.getItemLS(rescodes.localStorage.lang)
const token = localStorage.getItem(rescodes.localStorage.token) const token = localStorage.getItem(rescodes.localStorage.token)
if (!token) { if (!token) {

View File

@@ -21,7 +21,7 @@ export const rescodes = {
userId: 'uid', userId: 'uid',
token: 'tk', token: 'tk',
username: 'uname', username: 'uname',
lang:'lg' lang: 'lg'
}, },
Todos: { Todos: {
@@ -247,6 +247,14 @@ export const rescodes = {
jsonCopy(src) { jsonCopy(src) {
return JSON.parse(JSON.stringify(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
View File

@@ -0,0 +1,8 @@
import { dragula } from 'vue2-dragula'
declare module 'vue/types/vue' {
interface Vue {
$dragula: dragula
}
}

View File

@@ -30,6 +30,7 @@ export default class Signin extends Vue {
public $q public $q
loading: boolean loading: boolean
$t: any $t: any
public iswaitingforRes: boolean = false
public signin: ISigninOptions = { public signin: ISigninOptions = {
username: process.env.TEST_USERNAME || '', username: process.env.TEST_USERNAME || '',
@@ -75,7 +76,8 @@ export default class Signin extends Vue {
} }
checkErrors(riscode) { checkErrors(riscode) {
// console.log("RIS = " + riscode); // console.log('checkErrors: ', riscode)
try {
if (riscode === rescodes.OK) { if (riscode === rescodes.OK) {
this.showNotif({ type: 'positive', message: this.$t('login.completato') }) this.showNotif({ type: 'positive', message: this.$t('login.completato') })
this.$router.push('/') this.$router.push('/')
@@ -85,9 +87,13 @@ export default class Signin extends Vue {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
setTimeout(function () { setTimeout(function () {
resolve('anything') resolve('anything')
}, 1000) }, 3000)
}).then(() => { }).then(() => {
setTimeout( () => {
this.$q.loading.hide()
}, 200)
this.showNotif(this.$t('login.errato')) this.showNotif(this.$t('login.errato'))
this.iswaitingforRes = false
this.$router.push('/signin') this.$router.push('/signin')
}) })
@@ -100,6 +106,16 @@ export default class Signin extends Vue {
this.showNotif('Errore num ' + riscode) this.showNotif('Errore num ' + riscode)
} }
if (riscode !== serv_constants.RIS_CODE_LOGIN_ERR) {
this.iswaitingforRes = false
setTimeout( () => {
this.$q.loading.hide()
}, 200)
}
} finally {
}
} }
redirect(response) { redirect(response) {
@@ -132,17 +148,24 @@ export default class Signin extends Vue {
} }
this.$q.loading.show({ message: this.$t('login.incorso') }) this.$q.loading.show({ message: this.$t('login.incorso') })
// disable Button Login:
this.iswaitingforRes = true
console.log(this.signin) console.log(this.signin)
UserStore.actions.signin(this.signin) UserStore.actions.signin(this.signin)
.then((riscode) => { .then((riscode) => {
console.log('signin FINITO CALL: riscode=', riscode) // console.log('signin FINITO CALL: riscode=', riscode)
if (riscode === rescodes.OK) { if (riscode === rescodes.OK) {
router.push('/signin') router.push('/signin')
} }
return riscode return riscode
}).then((riscode) => { }).then((riscode) => {
if (UserStore.state.lang !== '')
this.$i18n.locale = UserStore.state.lang // Set 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', '') globalroutines(this, 'loadapp', '')
return riscode return riscode
@@ -150,22 +173,21 @@ export default class Signin extends Vue {
.then((riscode) => { .then((riscode) => {
if (riscode === rescodes.OK) { if (riscode === rescodes.OK) {
GlobalStore.actions.createPushSubscription() GlobalStore.actions.createPushSubscription()
.then(ris => { .then(rissub => {
}) })
.catch(e => { .catch(e => {
console.log('ERROR = ' + e) console.log('ERROR Subscription = ' + e)
})
.then(() => {
this.checkErrors(riscode)
this.$q.loading.hide()
}) })
} }
this.checkErrors(riscode)
}) })
.catch(error => { .catch(error => {
console.log('ERROR SIGNIN = ' + error) console.log('ERROR SIGNIN = ' + error)
this.checkErrors(error) this.checkErrors(error)
this.$q.loading.hide()
}) })
} }

View File

@@ -52,7 +52,7 @@
</q-card-main> </q-card-main>
<div align="center"> <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> </q-btn>
</div> </div>
</form> </form>