From 9fd858d33f1e1b1cf0573415eadfa070d383f267 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Tue, 15 Oct 2019 20:40:23 +0200 Subject: [PATCH] - Added Delete Record to the CGridTableRec --- src/common/shared_vuejs.ts | 3 +- .../CGridTableRec/CGridTableRec.scss | 3 + src/components/CGridTableRec/CGridTableRec.ts | 60 ++++++++++++++++--- .../CGridTableRec/CGridTableRec.vue | 4 +- src/components/Header/Header.ts | 4 ++ src/components/Header/Header.vue | 2 +- src/layouts/menuone/menuOne.scss | 8 +++ src/layouts/menuone/menuOne.ts | 14 ++++- src/layouts/menuone/menuOne.vue | 2 +- src/model/GlobalStore.ts | 16 +++++ src/model/UserStore.ts | 1 + src/statics/i18n.js | 55 +++++++++++++---- src/store/Modules/GlobalStore.ts | 40 ++++++++++++- src/store/Modules/UserStore.ts | 20 +------ src/store/Modules/lists.ts | 4 +- src/store/Modules/tools.ts | 27 ++++++--- 16 files changed, 210 insertions(+), 53 deletions(-) diff --git a/src/common/shared_vuejs.ts b/src/common/shared_vuejs.ts index c6c2531..dbe020d 100644 --- a/src/common/shared_vuejs.ts +++ b/src/common/shared_vuejs.ts @@ -2,7 +2,8 @@ export const shared_consts = { Permissions: { Normal: 0, - Admin: 1 + Admin: 1, + Manager: 2, }, fieldsUserToChange() { diff --git a/src/components/CGridTableRec/CGridTableRec.scss b/src/components/CGridTableRec/CGridTableRec.scss index e69de29..614fcef 100644 --- a/src/components/CGridTableRec/CGridTableRec.scss +++ b/src/components/CGridTableRec/CGridTableRec.scss @@ -0,0 +1,3 @@ +.colmodif { + cursor: pointer; +} diff --git a/src/components/CGridTableRec/CGridTableRec.ts b/src/components/CGridTableRec/CGridTableRec.ts index a5d0f86..7848c3d 100644 --- a/src/components/CGridTableRec/CGridTableRec.ts +++ b/src/components/CGridTableRec/CGridTableRec.ts @@ -5,15 +5,15 @@ import { GlobalStore, UserStore } from '../../store/Modules/index' import { tools } from '../../store/Modules/tools' import { shared_consts } from '../../common/shared_vuejs' -import { ICategory } from '../../model' +import { ICategory, IColGridTable } from '../../model' import { CTodo } from '../todos/CTodo' import { SingleProject } from '../projects/SingleProject' +import { lists } from '../../store/Modules/lists' @Component({}) export default class CGridTableRec extends Vue { @Prop({ required: true }) public mytable: string @Prop({ required: true }) public mytitle: string - @Prop({ required: true }) public mylist: any[] @Prop({ required: true }) public mycolumns: any[] @Prop({ required: true }) public colkey: string public $q @@ -67,20 +67,28 @@ export default class CGridTableRec extends Vue { public SaveValue(newVal, valinitial) { console.log('SaveValue', newVal, 'selected', this.selected) - const mydata = {} + const mydata = { + // colkey: this.colkey, + id: this.idsel, + table: this.mytable, + fieldsvalue: { - mydata[this.colsel] = newVal - mydata[this.colkey] = this.idsel - this.valPrec = valinitial + } + } + + mydata.fieldsvalue[this.colsel] = newVal - console.log('this.idsel', this.idsel, 'this.colsel', this.colsel) console.table(mydata) - this.$emit('save', mydata) + this.valPrec = valinitial + + // console.log('this.idsel', this.idsel, 'this.colsel', this.colsel) + // console.table(mydata) + + this.saveFieldValue(mydata) } public created() { - // this.serverData = this.mylist.slice() // [{ chiave: 'chiave1', valore: 'valore 1' }] } @@ -210,11 +218,45 @@ export default class CGridTableRec extends Vue { return this.returnedCount } + public getclassCol(col) { + return col.disable ? '' : 'colmodif' + } + + public saveFieldValue(mydata) { + console.log('saveFieldValue', mydata) + + // Save on Server + GlobalStore.actions.saveFieldValue(mydata).then((esito) => { + if (esito) + tools.showPositiveNotif(this.$q, this.$t('db.recupdated')) + else { + tools.showNegativeNotif(this.$q, this.$t('db.recfailed')) + this.undoVal() + } + }) + } + public mounted() { + this.mycolumns.forEach((rec: IColGridTable) => { + rec.label = this.$t(rec.label_trans) + }) + this.onRequest({ pagination: this.pagination, filter: undefined }) } + public clickFunz(item, col: IColGridTable) { + if (col.action) { + tools.ActionRecTable(this, col.action, this.mytable, item._id, item) + } + } + + public ActionAfterYes(action, item) { + if (action === lists.MenuAction.DELETE_RECTABLE) { + this.serverData.splice(this.serverData.indexOf(item), 1) + } + } + } diff --git a/src/components/CGridTableRec/CGridTableRec.vue b/src/components/CGridTableRec/CGridTableRec.vue index f9d20c4..4329fa2 100644 --- a/src/components/CGridTableRec/CGridTableRec.vue +++ b/src/components/CGridTableRec/CGridTableRec.vue @@ -27,9 +27,9 @@
+ @click="clickFunz(props.row, col)">
-
+
{{ props.row[col.name] }} diff --git a/src/components/Header/Header.ts b/src/components/Header/Header.ts index 6769281..fa3a853 100644 --- a/src/components/Header/Header.ts +++ b/src/components/Header/Header.ts @@ -60,6 +60,10 @@ export default class Header extends Vue { return UserStore.state.isAdmin } + get isManager() { + return UserStore.state.isManager + } + get conndata_changed() { return GlobalStore.state.connData } diff --git a/src/components/Header/Header.vue b/src/components/Header/Header.vue index 1ebc4e1..16a4539 100644 --- a/src/components/Header/Header.vue +++ b/src/components/Header/Header.vue @@ -141,7 +141,7 @@ -
{{ Username }} - {{ myName }} [Admin]
+
{{ Username }} - {{ myName }} [Admin] [Manager]
{{ $t('user.loggati') }}
diff --git a/src/layouts/menuone/menuOne.scss b/src/layouts/menuone/menuOne.scss index 4ff2ec9..baf8709 100644 --- a/src/layouts/menuone/menuOne.scss +++ b/src/layouts/menuone/menuOne.scss @@ -57,6 +57,14 @@ font-size: 1rem; } +.isAdmin { + color: red; +} + +.isManager { + color: green; +} + .my-menu-icon{ min-width: 26px; font-size: 1rem; diff --git a/src/layouts/menuone/menuOne.ts b/src/layouts/menuone/menuOne.ts index 8536b0e..e92c85e 100644 --- a/src/layouts/menuone/menuOne.ts +++ b/src/layouts/menuone/menuOne.ts @@ -33,7 +33,8 @@ export default class MenuOne extends Vue { } public visumenu(elem) { // : IListRoutes - return (elem.onlyAdmin && UserStore.state.isAdmin) || (!elem.onlyAdmin) + return (elem.onlyAdmin && UserStore.state.isAdmin) || (elem.onlyManager && UserStore.state.isManager) + || ((!elem.onlyAdmin) && (!elem.onlyManager)) } public setParentVisibilityBasedOnRoute(parent) { @@ -64,4 +65,15 @@ export default class MenuOne extends Vue { } } + + public getmymenuclass(elem: IListRoutes) { + let menu = 'my-menu' + + if (elem.onlyAdmin) + menu += ' isAdmin' + if (elem.onlyManager) + menu += ' isManager' + + return menu + } } diff --git a/src/layouts/menuone/menuOne.vue b/src/layouts/menuone/menuOne.vue index aba8b69..3eebf2c 100644 --- a/src/layouts/menuone/menuOne.vue +++ b/src/layouts/menuone/menuOne.vue @@ -11,7 +11,7 @@ :label="tools.getLabelByItem(myitemmenu, mythis)" :icon="myitemmenu.materialIcon" expand-icon-class="my-menu-separat" - header-class="my-menu" + :header-class="getmymenuclass(myitemmenu)" active-class="my-menu-active"> { + if (res) + return (res.data.code === serv_constants.RIS_CODE_OK) + else + return false + }) + .catch((error) => { + return false + }) + } + + async function DeleteRec(context, { table, id }) { + console.log('DeleteRec', id) + + return await Api.SendReq('/delrec/' + table + '/' + id, 'DELETE', null) + .then((res) => { + if (res.status === 200) { + if (res.data.code === serv_constants.RIS_CODE_OK) { + return true + } + } + return false + }) + .catch((error) => { + console.error(error) + return false + }) + } + + export const actions = { setConta: b.dispatch(setConta), createPushSubscription: b.dispatch(createPushSubscription), @@ -529,7 +565,9 @@ namespace Actions { prova: b.dispatch(prova), saveCfgServerKey: b.dispatch(saveCfgServerKey), checkUpdates: b.dispatch(checkUpdates), - loadTable: b.dispatch(loadTable) + saveFieldValue: b.dispatch(saveFieldValue), + loadTable: b.dispatch(loadTable), + DeleteRec: b.dispatch(DeleteRec) } } diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index f7050f4..27910fd 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -37,6 +37,7 @@ const state: IUserState = { x_auth_token: '', isLogged: false, isAdmin: false, + isManager: false, usersList: [], countusers: 0 } @@ -158,8 +159,9 @@ namespace Mutations { mystate.surname = data.surname mystate.perm = data.perm mystate.isAdmin = tools.isBitActive(mystate.perm, shared_consts.Permissions.Admin) + mystate.isManager = tools.isBitActive(mystate.perm, shared_consts.Permissions.Manager) - console.log('authUser', 'state.isAdmin', mystate.isAdmin) + // console.log('authUser', 'state.isAdmin', mystate.isAdmin) console.table(mystate) console.table(data) if (data.verified_email) { @@ -324,21 +326,6 @@ namespace Actions { } - async function saveUserChange(context, user: IUserState) { - console.log('saveUserChange', user) - - return await Api.SendReq(`/users/${user.userId}`, 'PATCH', { user }) - .then((res) => { - if (res) - return (res.data.code === serv_constants.RIS_CODE_OK) - else - return false - }) - .catch((error) => { - return false - }) - - } async function requestpwd(context, paramquery: IUserState) { @@ -717,7 +704,6 @@ namespace Actions { logout: b.dispatch(logout), requestpwd: b.dispatch(requestpwd), resetpwd: b.dispatch(resetpwd), - saveUserChange: b.dispatch(saveUserChange), signin: b.dispatch(signin), signup: b.dispatch(signup), vreg: b.dispatch(vreg) diff --git a/src/store/Modules/lists.ts b/src/store/Modules/lists.ts index 4631e55..6298e74 100644 --- a/src/store/Modules/lists.ts +++ b/src/store/Modules/lists.ts @@ -13,7 +13,9 @@ export const lists = { EDIT: 160, ADD_PROJECT: 200, THEME: 210, - THEMEBG: 211 + THEMEBG: 211, + + DELETE_RECTABLE: 300, }, selectTheme: [ diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 774a258..1c8f52a 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -1,4 +1,4 @@ -import { Todos, Projects, UserStore, CalendarStore } from '@store' +import { Todos, Projects, UserStore, CalendarStore, GlobalStore } from '@store' import globalroutines from './../../globalroutines/index' import { costanti } from './costanti' import { toolsext } from './toolsext' @@ -1314,7 +1314,7 @@ export const tools = { return result }, - executefunc(myself: any, func: number, par: IParamDialog) { + executefunc(myself: any, table, func: number, par: IParamDialog) { if (func === lists.MenuAction.DELETE) { console.log('param1', par.param1) CalendarStore.actions.CancelBookingEvent({ideventbook: par.param1, notify: par.param2 === true ? '1' : '0'}).then((ris) => { @@ -1325,10 +1325,19 @@ export const tools = { } else tools.showNegativeNotif(myself.$q, myself.$t('cal.cancelederrorbooking')) }) + } else if (func === lists.MenuAction.DELETE_RECTABLE) { + console.log('param1', par.param1) + GlobalStore.actions.DeleteRec({table, id: par.param1}).then((ris) => { + if (ris) { + myself.ActionAfterYes(func, par.param2) + tools.showPositiveNotif(myself.$q, myself.$t('db.deletedrecord')) + } else + tools.showNegativeNotif(myself.$q, myself.$t('db.recdelfailed')) + }) } }, - async askConfirm($q: any, mytitle, mytext, ok, cancel, myself: any, funcok: number, funccancel: number, par: IParamDialog) { + async askConfirm($q: any, mytitle, mytext, ok, cancel, myself: any, table, funcok: number, funccancel: number, par: IParamDialog) { return $q.dialog({ message: mytext, ok: { @@ -1340,11 +1349,11 @@ export const tools = { persistent: false }).onOk(() => { console.log('OK') - tools.executefunc(myself, funcok, par) + tools.executefunc(myself, table, funcok, par) return true }).onCancel(() => { console.log('CANCEL') - tools.executefunc(myself, funccancel, par) + tools.executefunc(myself, table, funccancel, par) return false }) }, @@ -2241,11 +2250,11 @@ export const tools = { }, CancelBookingEvent(mythis, eventparam: IEvents, bookeventid: string, notify: boolean) { console.log('CancelBookingEvent ', eventparam) - tools.askConfirm(mythis.$q, translate('cal.titlebooking'), translate('cal.cancelbooking') + ' ' + tools.gettextevent(eventparam) + '?', translate('dialog.yes'), translate('dialog.no'), mythis, lists.MenuAction.DELETE, 0, { param1: bookeventid, param2: notify }) + tools.askConfirm(mythis.$q, translate('cal.titlebooking'), translate('cal.cancelbooking') + ' ' + tools.gettextevent(eventparam) + '?', translate('dialog.yes'), translate('dialog.no'), mythis, '', lists.MenuAction.DELETE, 0, { param1: bookeventid, param2: notify }) }, - CancelUserRec(mythis, id) { - console.log('CancelUserRec', id) - tools.askConfirm(mythis.$q, translate('cal.titlebooking'), translate('cal.canceluser') + '?', translate('dialog.yes'), translate('dialog.no'), mythis, lists.MenuAction.DELETE, 0, { param1: id }) + ActionRecTable(mythis, action, table, id, item?) { + console.log('CancelRecTable', id) + return tools.askConfirm(mythis.$q, translate('db.deleterecord'), translate('db.deletetherecord'), translate('dialog.yes'), translate('dialog.no'), mythis, table, action, 0, { param1: id, param2: item }) }, isBitActive(bit, whattofind) { return ((bit & whattofind) === whattofind)