Ancora sistemazioni Typescript... getters, mutations, actions... "@" alias.

This commit is contained in:
paolo
2018-11-17 20:32:28 +01:00
parent 7c49a97217
commit 794e7088e7
22 changed files with 184 additions and 165 deletions

View File

@@ -44,6 +44,7 @@
"vuex": "^3.0.1", "vuex": "^3.0.1",
"vuex-class": "^0.3.1", "vuex-class": "^0.3.1",
"vuex-module-decorators": "^0.4.3", "vuex-module-decorators": "^0.4.3",
"vuex-router-sync": "^5.0.0",
"vuex-typex": "^3.0.1" "vuex-typex": "^3.0.1"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -9,7 +9,27 @@ const envparser = require('./config/envparser')
const extendTypescriptToWebpack = (config) => { const extendTypescriptToWebpack = (config) => {
config.resolve config.resolve
.extensions .extensions
.add('.ts'); .add('.ts', '.js', '.vue')
config.resolve
.alias
.set('@components', path.resolve(__dirname, 'src/components/index.ts'))
.set('@components', path.resolve(__dirname, 'src/components'))
.set('@views', path.resolve(__dirname, 'src/components/views/index.ts'))
.set('@views', path.resolve(__dirname, 'src/components/views'))
.set('@src', path.resolve(__dirname, 'src'))
.set('@icons', path.resolve(__dirname, 'src/assets/icons'))
.set('@images', path.resolve(__dirname, 'src/assets/images'))
.set('@classes', path.resolve(__dirname, 'src/classes/index.ts'))
.set('@utils', path.resolve(__dirname, 'src/utils/index.ts'))
.set('@utils', path.resolve(__dirname, 'src/utils/*'))
.set('@css', path.resolve(__dirname, 'src/styles/variables.scss'))
.set('@router', path.resolve(__dirname, 'src/router/index.ts'))
.set('@validators', path.resolve(__dirname, 'src/utils/validators.ts'))
.set('@api', path.resolve(__dirname, 'src/store/Api/index.ts'))
.set('@paths', path.resolve(__dirname, 'src/store/Api/ApiRoutes.ts'))
.set('@types', path.resolve(__dirname, 'src/typings/index.ts'))
.set('@store', path.resolve(__dirname, 'src/store/index.ts'))
.set('@modules', path.resolve(__dirname, 'src/store/Modules/index.ts'))
config.module config.module
.rule('typescript') .rule('typescript')
.test(/\.tsx?$/) .test(/\.tsx?$/)
@@ -68,7 +88,6 @@ module.exports = function (ctx) {
.alias .alias
.set('~', __dirname) .set('~', __dirname)
.set('@', path.resolve(__dirname, 'src')) .set('@', path.resolve(__dirname, 'src'))
.set('@classes', path.resolve(__dirname, 'src/classes/index.ts'));
config.module config.module
.rule('template-engine') .rule('template-engine')
.test(/\.pug$/) .test(/\.pug$/)

View File

@@ -15,26 +15,38 @@
</div> </div>
</template> </template>
<script type="ts"> <script lang="ts">
import Vue from "vue"
import { Store } from "vuex"
import { sync } from 'vuex-router-sync'
import { Component } from 'vue-property-decorator'
import { EventBus, RootState, storeBuilder, DebugMode } from '@store'
import router from "./router"
import { UserStore } from '@store'
import { Component, Vue} from 'vue-property-decorator' import $ from "jquery"
import { UserModule } from './store/Modules/user'
import Header from './components/Header.vue'; import Header from './components/Header.vue'
const store: Store<RootState> = storeBuilder.vuexStore({
strict: DebugMode
})
sync(store, router)
@Component({ @Component({
store: store,
components: { components: {
appHeader: Header, appHeader: Header,
} },
router
}) })
export default class App extends Vue { export default class App extends Vue {
backgroundColor = 'whitesmoke' backgroundColor = 'whitesmoke'
constructor () { created() {
super()
//this.title = 'My Vue and CosmosDB Heroes App' //this.title = 'My Vue and CosmosDB Heroes App'
console.info(process.env); console.info(process.env)
UserModule.autologin() UserStore.mutations.autologin()
} }
} }
</script> </script>

View File

@@ -1,46 +1,45 @@
import { AlertsStore, LoginStore } from '@store'; import {Forms} from './FormController'
import {Forms} from './FormController';
import Router from '@router'; import Router from '@router'
export namespace AlertsElement { export namespace AlertsElement {
type AlertType = "success" | "confirm" | "warning" | "error" | "info" | "form"; type AlertType = 'success' | 'confirm' | 'warning' | 'error' | 'info' | 'form'
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>; type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>
type formParam = { type formParam = {
form: Forms.Form, form: Forms.Form,
validations?: { validations?: {
[x:string]: any [x: string]: any
}, },
submit: { submit: {
params?: {[x:string]: any}, params?: {[x: string]: any},
trigger: Function trigger: Function
} }
} }
export class Alert{ export class Alert {
public type: AlertType; public type: AlertType
public title: string; public title: string
public message?: string; public message?: string
public strict?: boolean; public strict?: boolean
public actions: ActionsElements.Action[]; public actions: ActionsElements.Action[]
public formElement?: formParam; public formElement?: formParam
public onClose?: Function[] public onClose?: Function[]
constructor(fields?:{type: AlertType, title: string, message?: string, strict?: boolean, actions: ActionsElements.Action[], formElement?: formParam, onClose?: Function[]}) { constructor(fields?: {type: AlertType, title: string, message?: string, strict?: boolean, actions: ActionsElements.Action[], formElement?: formParam, onClose?: Function[]}) {
Object.assign(this, fields); Object.assign(this, fields)
AlertsStore.actions.addAlert(this); AlertsStore.actions.addAlert(this)
} }
async waitResponse() { async waitResponse() {
return AlertsStore.actions.addAlert(this); return AlertsStore.actions.addAlert(this)
} }
} }
export class WarningAlert extends Alert { export class WarningAlert extends Alert {
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) { constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
const actions = fields.actions || []; const actions = fields.actions || []
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({}) const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({})
console.log(fields.actions) console.log(fields.actions)
super({ super({
@@ -53,13 +52,13 @@ export namespace AlertsElement {
...actions, ...actions,
confirmAction confirmAction
] ]
}); })
} }
} }
export class SuccessAlert extends Alert { export class SuccessAlert extends Alert {
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) { constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
const actions = fields.actions || []; const actions = fields.actions || []
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({}) const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({})
console.log(fields.actions) console.log(fields.actions)
super({ super({
@@ -72,13 +71,13 @@ export namespace AlertsElement {
...actions, ...actions,
confirmAction confirmAction
] ]
}); })
} }
} }
export class ErrorAlert extends Alert { export class ErrorAlert extends Alert {
constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) { constructor(fields?: {title: string, message?: string, strict?: boolean, actions?: ActionsElements.Action[], onClose?: Function[]}) {
const actions = fields.actions || []; const actions = fields.actions || []
console.log(fields.actions) console.log(fields.actions)
const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({text: 'Fermer'}) const confirmAction = (fields.actions && fields.actions.find(m => m.type == 'confirm')) ? undefined : new ActionsElements.ConfirmAction({text: 'Fermer'})
super({ super({
@@ -91,12 +90,12 @@ export namespace AlertsElement {
...actions, ...actions,
confirmAction confirmAction
] ]
}); })
} }
} }
export class FormAlert extends Alert { export class FormAlert extends Alert {
constructor(fields?: {title: string, message?: string, strict?:boolean, formElement: formParam, onClose?: Function[]}) { constructor(fields?: {title: string, message?: string, strict?: boolean, formElement: formParam, onClose?: Function[]}) {
const confirmAction = new ActionsElements.ConfirmAction({ const confirmAction = new ActionsElements.ConfirmAction({
text: 'Valider', text: 'Valider',
triggers: [ triggers: [
@@ -115,7 +114,7 @@ export namespace AlertsElement {
confirmAction, confirmAction,
new ActionsElements.CancelAction() new ActionsElements.CancelAction()
] ]
}); })
} }
} }
} }
@@ -127,37 +126,37 @@ export namespace AlertsElement {
export namespace ActionsElements { export namespace ActionsElements {
type ActionType = "confirm" | "action" | "cancel" | "link"; type ActionType = 'confirm' | 'action' | 'cancel' | 'link'
export class Action { export class Action {
public type: ActionType; public type: ActionType
public text: string; public text: string
public to?: {path: string} | {name: string, params?: {[x: string]: any}}; public to?: {path: string} | {name: string, params?: {[x: string]: any}}
public trigger?: Function; public trigger?: Function
public triggers?: Function[]; public triggers?: Function[]
constructor({type, text, trigger, triggers, to}: Action) { constructor({type, text, trigger, triggers, to}: Action) {
this.text = text; this.text = text
this.type = type; this.type = type
this.trigger = trigger; this.trigger = trigger
this.triggers = triggers; this.triggers = triggers
this.to = to; this.to = to
} }
} }
export class ConfirmAction extends Action { export class ConfirmAction extends Action {
constructor({text, triggers}: {text?: string, triggers?: Function[]}) { constructor({text, triggers}: {text?: string, triggers?: Function[]}) {
super({ super({
text: text || "Ça marche!", text: text || 'Ça marche!',
type: "confirm", type: 'confirm'
}); })
if (triggers) { if (triggers) {
this.triggers = [ this.triggers = [
...triggers, ...triggers,
AlertsStore.mutations.confirmAlert, AlertsStore.mutations.confirmAlert
]; ]
} else { } else {
this.trigger = this.trigger = AlertsStore.mutations.confirmAlert; this.trigger = this.trigger = AlertsStore.mutations.confirmAlert
} }
} }
} }
@@ -167,30 +166,30 @@ export namespace ActionsElements {
super({ super({
text: text, text: text,
to: to, to: to,
type: "link", type: 'link'
}); })
} }
} }
export class LoginAction extends Action { export class LoginAction extends Action {
constructor() { constructor() {
super({ super({
text: "Se connecter", text: 'Se connecter',
type: "action", type: 'action',
triggers: [ triggers: [
LoginStore.mutations.showLogin, LoginStore.mutations.showLogin,
AlertsStore.actions.hideAlert AlertsStore.actions.hideAlert
] ]
}); })
} }
} }
export class CancelAction extends Action { export class CancelAction extends Action {
constructor() { constructor() {
super({ super({
text: "Annuler", text: 'Annuler',
type: "cancel", type: 'cancel',
trigger: AlertsStore.mutations.cancelAlert trigger: AlertsStore.mutations.cancelAlert
}); })
} }
} }

View File

@@ -32,8 +32,8 @@
import menuTwo from './menuTwo.vue' import menuTwo from './menuTwo.vue'
import { Component, Vue, Watch, Prop } from 'vue-property-decorator' import { Component, Vue, Watch, Prop } from 'vue-property-decorator'
import { GlobModule } from '../../store/Modules/glob' import { GlobalStore } from '@store'
import { UserModule } from '../../store/Modules/user'; import { UserStore } from '@store';
@Component({ @Component({
components: { components: {
@@ -74,14 +74,14 @@
} }
get MenuCollapse () { get MenuCollapse () {
return GlobModule.menuCollapse return GlobalStore.getters.menuCollapse
} }
get Username () { get Username () {
return UserModule.username return UserStore.getters.username
} }
get Verificato () { get Verificato () {
return UserModule.verifiedEmail return UserStore.getters.verifiedEmail
} }
logoutHandler() { logoutHandler() {

View File

@@ -1,5 +1,5 @@
export * from './user' export * from './UserStore'
export * from './glob' export * from './GlobalStore'
export * from './signup-option' export * from './signup-option'
export * from './key-value' export * from './key-value'
export * from './payload' export * from './payload'

View File

@@ -1,6 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import { Component, Watch, Prop } from 'vue-property-decorator' import { Component } from 'vue-property-decorator'
import { GlobModule } from '@/store/Modules/glob' import { GlobalStore } from '@store'
require('./home.scss') require('./home.scss')
@@ -29,12 +29,12 @@ export default class Home extends Vue {
} }
get conta() { get conta() {
return GlobModule.conta return GlobalStore.getters.getConta
} }
set conta(valore) { set conta(valore) {
GlobModule.setConta(valore) GlobalStore.actions.setConta(valore)
var my = this.$q.i18n.lang let my = this.$q.i18n.lang
this.showNotification(String(my)) this.showNotification(String(my))
} }

4
src/store/EventBus.ts Normal file
View File

@@ -0,0 +1,4 @@
import Vue from 'vue'
const EventBus = new Vue()
export default EventBus

View File

@@ -1,15 +1,6 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
import { IGlobalState } from '@types' import { IGlobalState } from '@types'
import { storeBuilder } from '@store' import { storeBuilder } from '@store'
Vue.use(Vuex)
const state: IGlobalState = { const state: IGlobalState = {
conta: 0, conta: 0,
isLoginPage: false, isLoginPage: false,
@@ -73,7 +64,7 @@ namespace Mutations {
} }
namespace Actions { namespace Actions {
async function setConta(num: number) { async function setConta(context, num: number) {
Mutations.mutations.setConta(num) Mutations.mutations.setConta(num)
} }

View File

@@ -1,36 +1,20 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
import {Route} from 'vue-router'
import Api from '@api' import Api from '@api'
import { ISignupOptions, IUserState } from 'model'
import { ILinkReg, IResult, IIdToken } from 'model/other'
import { storeBuilder } from '@store'
import router from '@router'
import { serv_constants } from '../Modules/serv_constants'
import { rescodes } from '../Modules/rescodes'
const bcrypt = require('bcryptjs') const bcrypt = require('bcryptjs')
import * as types from 'store/mutation-types'
import { serv_constants } from 'store/Modules/serv_constants'
import router from '@router' // State
const state: IUserState = {
import { storeBuilder } from '@store'
import { ISignupOptions, IUserState } from 'model'
import { ILinkReg, IResult, IIdToken } from 'model/other'
export const ErroriMongoDb = {
CALLING: 10,
OK: 20,
ERR_GENERICO: -1,
DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100
}
Vue.use(Vuex)
const initialState: IUserState = {
_id: '', _id: '',
email: '', email: '',
username: '', username: '',
@@ -44,8 +28,6 @@ const initialState: IUserState = {
verifiedEmail: false verifiedEmail: false
} }
// State
const state = {...initialState}
const b = storeBuilder.module<IUserState>('UserModule', state) const b = storeBuilder.module<IUserState>('UserModule', state)
const stateGetter = b.state() const stateGetter = b.state()
@@ -177,7 +159,7 @@ namespace Actions {
} }
async function resetpwd (paramquery: IUserState) { async function resetpwd (context, paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/updatepwd' let call = process.env.MONGODB_HOST + '/updatepwd'
console.log('CALL ' + call) console.log('CALL ' + call)
@@ -190,7 +172,7 @@ namespace Actions {
} }
console.log(usertosend) console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let myres let myres
@@ -204,8 +186,8 @@ namespace Actions {
if (myres.status === 200) { if (myres.status === 200) {
return myres.json() return myres.json()
} }
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true } return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
}) })
.then((body) => { .then((body) => {
@@ -215,13 +197,13 @@ namespace Actions {
return { code: body.code, msg: body.msg } return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err) console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' } return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
}) })
} }
async function requestpwd (paramquery: IUserState) { async function requestpwd (context, paramquery: IUserState) {
let call = process.env.MONGODB_HOST + '/requestnewpwd' let call = process.env.MONGODB_HOST + '/requestnewpwd'
console.log('CALL ' + call) console.log('CALL ' + call)
@@ -233,7 +215,7 @@ namespace Actions {
} }
console.log(usertosend) console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let myres let myres
@@ -244,21 +226,21 @@ namespace Actions {
if (myres.status === 200) { if (myres.status === 200) {
return myres.json() return myres.json()
} }
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true } return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status, resetpwd: true }
}) })
.then((body) => { .then((body) => {
return { code: body.code, msg: body.msg } return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err) console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' } return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
}) })
} }
async function vreg (paramquery: ILinkReg) { async function vreg (context, paramquery: ILinkReg) {
let call = process.env.MONGODB_HOST + '/vreg' let call = process.env.MONGODB_HOST + '/vreg'
console.log('CALL ' + call) console.log('CALL ' + call)
@@ -269,7 +251,7 @@ namespace Actions {
} }
console.log(usertosend) console.log(usertosend)
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let myres let myres
@@ -280,8 +262,8 @@ namespace Actions {
if (myres.status === 200) { if (myres.status === 200) {
return myres.json() return myres.json()
} }
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore: ' + myres.status } return { code: rescodes.ERR_GENERICO, msg: 'Errore: ' + myres.status }
}) })
.then((body) => { .then((body) => {
@@ -293,12 +275,12 @@ namespace Actions {
return { code: body.code, msg: body.msg } return { code: body.code, msg: body.msg }
}).catch((err) => { }).catch((err) => {
console.log('ERROR: ' + err) console.log('ERROR: ' + err)
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return { code: ErroriMongoDb.ERR_GENERICO, msg: 'Errore' } return { code: rescodes.ERR_GENERICO, msg: 'Errore' }
}) })
} }
async function signup (authData: ISignupOptions) { async function signup (context, authData: ISignupOptions) {
let call = process.env.MONGODB_HOST + '/users' let call = process.env.MONGODB_HOST + '/users'
console.log('CALL ' + call) console.log('CALL ' + call)
@@ -322,7 +304,7 @@ namespace Actions {
let myres: IResult let myres: IResult
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let x_auth_token: string = '' let x_auth_token: string = ''
@@ -333,7 +315,7 @@ namespace Actions {
if (x_auth_token) { if (x_auth_token) {
return res.json() return res.json()
} else { } else {
return { status: 400, code: ErroriMongoDb.ERR_GENERICO } return { status: 400, code: rescodes.ERR_GENERICO }
} }
}) })
.then((body) => { .then((body) => {
@@ -372,7 +354,7 @@ namespace Actions {
// dispatch('storeUser', authData); // dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn); // dispatch('setLogoutTimer', myres.data.expiresIn);
return ErroriMongoDb.OK return rescodes.OK
} else if (myres.status === 404) { } else if (myres.status === 404) {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code) console.log('CODE = ' + body.code)
@@ -390,13 +372,13 @@ namespace Actions {
console.log('ERROREEEEEEEEE') console.log('ERROREEEEEEEEE')
console.log(error) console.log(error)
} }
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return ErroriMongoDb.ERR_GENERICO return rescodes.ERR_GENERICO
}) })
}) })
} }
async function signin (authData: ISignupOptions) { async function signin (context, authData: ISignupOptions) {
let call = process.env.MONGODB_HOST + '/users/login' let call = process.env.MONGODB_HOST + '/users/login'
console.log('LOGIN ' + call) console.log('LOGIN ' + call)
@@ -414,7 +396,7 @@ namespace Actions {
let myres: IResult let myres: IResult
Mutations.mutations.setServerCode(ErroriMongoDb.CALLING) Mutations.mutations.setServerCode(rescodes.CALLING)
let x_auth_token: string = '' let x_auth_token: string = ''
@@ -427,7 +409,7 @@ namespace Actions {
if (x_auth_token || injson) { if (x_auth_token || injson) {
return injson return injson
} else { } else {
return { status: 400, code: ErroriMongoDb.ERR_GENERICO } return { status: 400, code: rescodes.ERR_GENERICO }
} }
}) })
.then((body) => { .then((body) => {
@@ -472,7 +454,7 @@ namespace Actions {
// dispatch('storeUser', authData); // dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn); // dispatch('setLogoutTimer', myres.data.expiresIn);
return ErroriMongoDb.OK return rescodes.OK
} else if (myres.status === 404) { } else if (myres.status === 404) {
if (process.env.DEV) { if (process.env.DEV) {
console.log('CODE = ' + body.code) console.log('CODE = ' + body.code)
@@ -490,12 +472,12 @@ namespace Actions {
console.log('ERROREEEEEEEEE') console.log('ERROREEEEEEEEE')
console.log(error) console.log(error)
} }
Mutations.mutations.setServerCode(ErroriMongoDb.ERR_GENERICO) Mutations.mutations.setServerCode(rescodes.ERR_GENERICO)
return ErroriMongoDb.ERR_GENERICO return rescodes.ERR_GENERICO
}) })
} }
async function logout () { async function logout (context) {
let call = process.env.MONGODB_HOST + '/users/me/token' let call = process.env.MONGODB_HOST + '/users/me/token'
console.log('CALL ' + call) console.log('CALL ' + call)

View File

@@ -1,2 +1,3 @@
export {storeBuilder} from './Store/Store' export {storeBuilder} from './Store/Store'
export {default as User} from './user' export {default as GlobalStore} from './GlobalStore'
export {default as UserStore} from './UserStore'

View File

@@ -0,0 +1,7 @@
export const rescodes = {
CALLING: 10,
OK: 20,
ERR_GENERICO: -1,
DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100
}

View File

@@ -7,4 +7,6 @@ export const serv_constants = {
RIS_CODE_LOGIN_ERR_GENERIC: -20, RIS_CODE_LOGIN_ERR_GENERIC: -20,
RIS_CODE_LOGIN_ERR: -10, RIS_CODE_LOGIN_ERR: -10,
RIS_CODE_LOGIN_OK: 1 RIS_CODE_LOGIN_OK: 1
} }

View File

@@ -1,22 +1,23 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { IUserState, IGlobState } from 'model' import { IUserState, IGlobState } from 'model'
import {Route} from 'vue-router' import {Route} from 'vue-router'
Vue.use(Vuex) Vue.use(Vuex)
export interface RootState { export interface RootState {
user: IUserState GlobalModule: IGlobState
glob: IGlobState
route: Route route: Route
} }
// const store = new Vuex.Store<IRootState>({}) export const DebugMode = true
// export default store
export * from './Modules' export * from './Modules'
// export {default as EventBus} from './EventBus'; export {default as EventBus} from './EventBus'
export {default as Api} from './Api' export {default as Api} from './Api'
export default new Vuex.Store<RootState>({
})

View File

@@ -50,7 +50,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
//import {ErroriMongoDb} from '../../store/Modules/user' import { rescodes } from '../../../store/Modules/rescodes'
import {serv_constants} from '../../store/Modules/serv_constants'; import {serv_constants} from '../../store/Modules/serv_constants';

View File

@@ -64,7 +64,7 @@
import {mapGetters, mapActions} from 'vuex' import {mapGetters, mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
//import {ErroriMongoDb} from '../../store/Modules/user' import { rescodes } from '../../../store/Modules/rescodes'
import {serv_constants} from "../../store/Modules/serv_constants"; import {serv_constants} from "../../store/Modules/serv_constants";
import axios from 'axios'; import axios from 'axios';
@@ -128,7 +128,7 @@
}, },
checkErrors(riscode) { checkErrors(riscode) {
//console.log("RIS = " + riscode); //console.log("RIS = " + riscode);
if (riscode === ErroriMongoDb.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('/');
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) { } else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {

View File

@@ -1,7 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator' import { Component, Prop, Watch } from 'vue-property-decorator'
import { User } from '@store' import { UserStore } from '@store'
import { ErroriMongoDb } from 'store/Modules/user' import { rescodes } from '../../../store/Modules/rescodes'
import { required, email, numeric, maxLength, maxValue, minValue, sameAs, minLength } from 'vuelidate/lib/validators' import { required, email, numeric, maxLength, maxValue, minValue, sameAs, minLength } from 'vuelidate/lib/validators'
import { ISignupOptions, IUserState } from 'model' import { ISignupOptions, IUserState } from 'model'
@@ -131,11 +131,11 @@ export default class Signup extends Vue {
checkErrors(riscode: number) { checkErrors(riscode: number) {
// console.log("RIS = " + riscode); // console.log("RIS = " + riscode);
if (riscode === ErroriMongoDb.DUPLICATE_EMAIL_ID) { if (riscode === rescodes.DUPLICATE_EMAIL_ID) {
this.showNotif(this.$t('reg.err.duplicate_email')) this.showNotif(this.$t('reg.err.duplicate_email'))
} else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) { } else if (riscode === rescodes.DUPLICATE_USERNAME_ID) {
this.showNotif(this.$t('reg.err.duplicate_username')) this.showNotif(this.$t('reg.err.duplicate_username'))
} else if (riscode === ErroriMongoDb.OK) { } else if (riscode === rescodes.OK) {
this.$router.push('/') this.$router.push('/')
} else { } else {
this.showNotif('Errore num ' + riscode) this.showNotif('Errore num ' + riscode)
@@ -162,7 +162,7 @@ export default class Signup extends Vue {
this.$q.loading.show({ message: this.$t('reg.incorso') }) this.$q.loading.show({ message: this.$t('reg.incorso') })
console.log(this.signup) console.log(this.signup)
User.actions.signup(this.signup) UserStore.actions.signup(this.signup)
.then((riscode) => { .then((riscode) => {
this.checkErrors(riscode) this.checkErrors(riscode)
this.$q.loading.hide() this.$q.loading.hide()

View File

@@ -24,7 +24,7 @@
<script lang="ts"> <script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator'; import { Component, Vue, Watch } from 'vue-property-decorator';
import { UserModule } from '../../store/Modules/user'; import { UserStore } from '@store';
@Component({}) @Component({})

View File

@@ -60,7 +60,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
//import {ErroriMongoDb} from '../../store/Modules/user' //import {rescodes} from '../../store/Modules/user'
import {serv_constants} from '../../store/Modules/serv_constants'; import {serv_constants} from '../../store/Modules/serv_constants';

View File

@@ -32,7 +32,7 @@
import {mapActions} from 'vuex' import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types' import * as types from '../../store/mutation-types'
//import {ErroriMongoDb} from '../../store/Modules/user' import { rescodes } from '../../../store/Modules/rescodes'
import {serv_constants} from '../../store/Modules/serv_constants'; import {serv_constants} from '../../store/Modules/serv_constants';