- Added Delete Record to the CGridTableRec

This commit is contained in:
Paolo Arena
2019-10-15 20:40:23 +02:00
parent 0ee08f8430
commit 9fd858d33f
16 changed files with 210 additions and 53 deletions

View File

@@ -2,7 +2,8 @@ export const shared_consts = {
Permissions: {
Normal: 0,
Admin: 1
Admin: 1,
Manager: 2,
},
fieldsUserToChange() {

View File

@@ -0,0 +1,3 @@
.colmodif {
cursor: pointer;
}

View File

@@ -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)
}
}
}

View File

@@ -27,9 +27,9 @@
<q-td v-for="col in mycolumns" :key="col.name" :props="props">
<div v-if="col.action">
<q-btn flat round color="red" icon="fas fa-trash-alt"
@click="col.clickfunz"></q-btn>
@click="clickFunz(props.row, col)"></q-btn>
</div>
<div v-else>
<div v-else :class="getclassCol(col)">
{{ props.row[col.name] }}
<q-popup-edit v-model="props.row[col.name]" :disable="col.disable" :title="col.title" buttons
@save="SaveValue" @show="selItem(props.row, col.field)">

View File

@@ -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
}

View File

@@ -141,7 +141,7 @@
<q-btn class="absolute-top-right" style="margin-right: 10px; color: white;"
dense flat round icon="close" @click="right = !right">
</q-btn>
<div v-if="isLogged" class="text-weight-bold text-user">{{ Username }} - {{ myName }} <span v-if="isAdmin"> [Admin]</span></div>
<div v-if="isLogged" class="text-weight-bold text-user">{{ Username }} - {{ myName }} <span v-if="isAdmin"> [Admin]</span><span v-if="isManager"> [Manager]</span></div>
<div v-else class="text-user text-italic bg-red">
{{ $t('user.loggati') }}
</div>

View File

@@ -57,6 +57,14 @@
font-size: 1rem;
}
.isAdmin {
color: red;
}
.isManager {
color: green;
}
.my-menu-icon{
min-width: 26px;
font-size: 1rem;

View File

@@ -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
}
}

View File

@@ -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">
<q-expansion-item v-for="(child2, index) in myitemmenu.routes2"

View File

@@ -1,5 +1,6 @@
import { IAction } from '@src/model/Projects'
import { Component } from 'vue-router/types/router'
import { lists } from '@src/store/Modules/lists'
export interface IPost {
title: string
@@ -83,6 +84,7 @@ export interface IListRoutes {
infooter?: boolean
submenu?: boolean
onlyAdmin?: boolean
onlyManager?: boolean
meta?: any
idelem?: string
urlroute?: string
@@ -209,3 +211,17 @@ export interface IParamsQuery {
sortBy: any
descending: number
}
export interface IColGridTable {
name: string
required: boolean
label?: string
label_trans?: string
align?: string
field?: string
sortable?: boolean
disable?: boolean
titlepopupedit?: string
icon?: string
action?: any
}

View File

@@ -33,6 +33,7 @@ export interface IUserState {
x_auth_token?: string
isLogged?: boolean
isAdmin?: boolean
isManager?: boolean
usersList?: IUserList[]
countusers?: number
}

View File

@@ -9,6 +9,9 @@ const msgglobal = {
usereventlist: 'Prenotazioni Utenti',
userlist: 'Lista Utenti',
},
manage: {
menu: 'Gestione'
}
},
sendmsg: {
write: 'scrive'
@@ -33,7 +36,11 @@ const msgglobal = {
},
db: {
recupdated: 'Record Aggiornato',
recfailed: 'Errore durante aggiornamento Record'
recfailed: 'Errore durante aggiornamento Record',
deleterecord: 'Elimina Record',
deletetherecord: 'Eliminare il Record?',
deletedrecord: 'Record Cancellato',
recdelfailed: 'Errore durante la cancellazione del Record',
},
components: {
authentication: {
@@ -149,7 +156,7 @@ const msgglobal = {
titledenied: 'Permesso Notifiche Disabilitato!',
title_subscribed: 'Sottoscrizione a FreePlanet.app!',
subscribed: 'Ora potrai ricevere i messaggi e le notifiche.',
newVersionAvailable: 'Aggiorna'
newVersionAvailable: 'Aggiorna',
},
connection: 'Connessione',
proj: {
@@ -229,6 +236,9 @@ const msgglobal = {
usereventlist: 'Reserva Usuarios',
userlist: 'Lista de usuarios',
},
manage: {
menu: 'Gestionar'
}
},
sendmsg: {
write: 'escribe'
@@ -253,7 +263,11 @@ const msgglobal = {
},
db: {
recupdated: 'Registro Actualizado',
recfailed: 'Error durante el registro de actualización'
recfailed: 'Error durante el registro de actualización',
deleterecord: 'Eliminar registro',
deletetherecord: '¿Eliminar el registro?',
deletedrecord: 'Registro cancelado',
recdelfailed: 'Error durante la eliminación del registro',
},
components: {
authentication: {
@@ -362,7 +376,7 @@ const msgglobal = {
titledenied: 'Notificaciones permitidas deshabilitadas!',
title_subscribed: 'Suscripción a FreePlanet.app!',
subscribed: 'Ahora puedes recibir mensajes y notificaciones.',
newVersionAvailable: 'Actualiza'
newVersionAvailable: 'Actualiza',
},
connection: 'Connection',
proj: {
@@ -443,6 +457,9 @@ const msgglobal = {
usereventlist: 'Réservation Utilisateur',
userlist: 'Liste d\'utilisateurs',
},
manage: {
menu: 'Gérer'
}
},
sendmsg: {
write: 'écrit'
@@ -467,7 +484,11 @@ const msgglobal = {
},
db: {
recupdated: 'Enregistrement mis à jour',
recfailed: 'Erreur lors de la mise à jour'
recfailed: 'Erreur lors de la mise à jour',
deleterecord: 'Supprimer l\'enregistrement',
deletetherecord: 'Supprimer l\'enregistrement?',
deletedrecord: 'Enregistrement annulé',
recdelfailed: 'Erreur lors de la suppression de l\'enregistrement',
},
components: {
authentication: {
@@ -575,7 +596,7 @@ const msgglobal = {
titledenied: 'Notifications autorisées désactivées!',
title_subscribed: 'Abonnement au Site Web!',
subscribed: 'Maintenant, vous pouvez recevoir des messages et des notifications.',
newVersionAvailable: 'Mise à jour'
newVersionAvailable: 'Mise à jour',
},
connection: 'Connexion',
proj: {
@@ -656,6 +677,9 @@ const msgglobal = {
usereventlist: 'Users Booking',
userlist: 'Users List',
},
manage: {
menu: 'Manage'
}
},
sendmsg: {
write: 'write'
@@ -680,7 +704,11 @@ const msgglobal = {
},
db: {
recupdated: 'Record Updated',
recfailed: 'Error during update Record'
recfailed: 'Error during update Record',
deleterecord: 'Delete Record',
deletetherecord: 'Delete the Record?',
deletedrecord: 'Record Deleted',
recdelfailed: 'Error during deletion of the Record',
},
components: {
authentication: {
@@ -787,7 +815,7 @@ const msgglobal = {
titledenied: 'Notification Permission Denied!',
title_subscribed: 'Subscribed to FreePlanet.app!',
subscribed: 'You can now receive Notification and Messages.',
newVersionAvailable: 'Upgrade'
newVersionAvailable: 'Upgrade',
},
connection: 'Conexión',
proj: {
@@ -868,6 +896,9 @@ const msgglobal = {
usereventlist: 'Users Booking',
userlist: 'Users List',
},
manage: {
menu: 'Manage'
}
},
sendmsg: {
write: 'write'
@@ -892,7 +923,11 @@ const msgglobal = {
},
db: {
recupdated: 'Record Updated',
recfailed: 'Error during update Record'
recfailed: 'Error during update Record',
deleterecord: 'Delete Record',
deletetherecord: 'Delete the Record?',
deletedrecord: 'Record Deleted',
recdelfailed: 'Error during deletion of the Record',
},
components: {
authentication: {
@@ -1001,7 +1036,7 @@ const msgglobal = {
titledenied: 'Notification Permission Denied!',
title_subscribed: 'Subscribed to FreePlanet.app!',
subscribed: 'You can now receive Notification and Messages.',
newVersionAvailable: 'Upgrade'
newVersionAvailable: 'Upgrade',
},
connection: 'Conexión',
proj: {

View File

@@ -21,6 +21,8 @@ import globalroutines from './../../globalroutines/index'
import { cfgrouter } from '../../router/route-config'
import { static_data } from '@src/db/static_data'
import { IParamsQuery } from '@src/model/GlobalStore'
import { serv_constants } from '@src/store/Modules/serv_constants'
import { IUserState } from '@src/model'
// import { static_data } from '@src/db/static_data'
let stateConnDefault = 'online'
@@ -520,6 +522,40 @@ namespace Actions {
})
}
async function saveFieldValue(context, mydata: object) {
console.log('saveFieldValue', mydata)
return await Api.SendReq(`/chval`, 'PATCH', { data: mydata })
.then((res) => {
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)
}
}

View File

@@ -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)

View File

@@ -13,7 +13,9 @@ export const lists = {
EDIT: 160,
ADD_PROJECT: 200,
THEME: 210,
THEMEBG: 211
THEMEBG: 211,
DELETE_RECTABLE: 300,
},
selectTheme: [

View File

@@ -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)