Add CMyToogleList and CMyChipList to views Binary choice number 2, 4, 8... show the Values Selected (join with other table)

This commit is contained in:
Paolo Arena
2019-10-28 19:00:06 +01:00
parent 340c813a7c
commit 6c9f97c716
18 changed files with 320 additions and 80 deletions

View File

@@ -1,21 +1,20 @@
export const shared_consts = { export const shared_consts = {
Permissions: { Permissions: {
Normal: {
value: 0,
label: '[None]'
},
Admin: { Admin: {
value: 1, value: 1,
label: 'Admin' label: 'pages.Admin',
icon: 'fas fa-user-shield'
}, },
Manager: { Manager: {
value: 2, value: 2,
label: 'Manager' label: 'otherpages.manage.manager',
icon: 'fas fa-tools'
}, },
Teacher: { Teacher: {
value: 4, value: 4,
label: 'Teacher' label: 'event.teacher',
icon: 'fas fa-user-tie'
} }
}, },

View File

@@ -38,8 +38,12 @@ export default class CDateTime extends Vue {
this.valueprec = this.myvalue this.valueprec = this.myvalue
this.$emit('show') this.$emit('show')
} else { } else {
if (!this.saveit) if (!this.saveit) {
if (this.myvalue !== this.valueprec) {
this.myvalue = this.valueprec this.myvalue = this.valueprec
tools.showNeutralNotif(this.$q, this.$t('db.reccanceled'))
}
}
} }
} }
@@ -73,7 +77,7 @@ export default class CDateTime extends Vue {
} }
public changeval(newval) { public changeval(newval) {
console.log('changeval', newval) // console.log('changeval', newval)
this.$emit('update:value', newval) this.$emit('update:value', newval)
} }
} }

View File

@@ -12,9 +12,11 @@ import { lists } from '../../store/Modules/lists'
import { IParamsQuery } from '../../model/GlobalStore' import { IParamsQuery } from '../../model/GlobalStore'
import { fieldsTable } from '../../store/Modules/fieldsTable' import { fieldsTable } from '../../store/Modules/fieldsTable'
import { CDateTime } from '../CDateTime' import { CDateTime } from '../CDateTime'
import { CMyToggleList } from '../CMyToggleList'
import { CMyChipList } from '../CMyChipList'
@Component({ @Component({
components: { CDateTime } components: { CDateTime, CMyToggleList, CMyChipList }
}) })
export default class CGridTableRec extends Vue { export default class CGridTableRec extends Vue {
@Prop({ required: false }) public prop_mytable: string @Prop({ required: false }) public prop_mytable: string
@@ -81,9 +83,6 @@ export default class CGridTableRec extends Vue {
this.rowsel = item this.rowsel = item
this.idsel = item._id this.idsel = item._id
this.colsel = col this.colsel = col
this.updateValueExtra(col, this.rowsel[col.name])
// console.log('this.idsel', this.idsel)
} }
public undoVal() { public undoVal() {
@@ -363,7 +362,7 @@ export default class CGridTableRec extends Vue {
} }
} }
public visuValByType(col, val) { public visuValByType(col: IColGridTable, val) {
if (col.fieldtype === tools.FieldType.date) { if (col.fieldtype === tools.FieldType.date) {
if (val === undefined) { if (val === undefined) {
return '[]' return '[]'
@@ -374,9 +373,9 @@ export default class CGridTableRec extends Vue {
return (val) ? this.$t('dialog.yes') : this.$t('dialog.no') return (val) ? this.$t('dialog.yes') : this.$t('dialog.no')
} else if (col.fieldtype === tools.FieldType.binary) { } else if (col.fieldtype === tools.FieldType.binary) {
if (val === undefined) if (val === undefined)
return '[]' return '[---]'
else else
return val return fieldsTable.getArrStrByValueBinary(this, col, val)
} else { } else {
if (val === undefined) if (val === undefined)
return '[]' return '[]'
@@ -435,37 +434,4 @@ export default class CGridTableRec extends Vue {
this.refresh() this.refresh()
} }
public setResultJoin(col: IColGridTable, row) {
let myval = 0
const tabjoin = fieldsTable.getTableJoinByName(col.jointable)
col.resultjoin.forEach((mycol) => {
myval = tools.SetBit(myval, mycol)
})
row[col.name] = myval
console.log('col.resultjoin')
console.table(col.resultjoin)
console.log('row[col.name]', row[col.name])
}
public updateValueExtra(col: IColGridTable, myval) {
if (col.jointable) {
const tabjoin = fieldsTable.getTableJoinByName(col.jointable)
const arr = []
if (myval !== undefined && tabjoin !== undefined) {
tabjoin.forEach((mybit) => {
if (tools.isBitActive(myval, mybit.value))
arr.push(mybit)
})
}
col.resultjoin = arr
console.log('col', col.field, 'myval', myval, 'arr', arr)
console.log('resultjoin')
console.table(col.resultjoin)
}
}
} }

View File

@@ -119,29 +119,28 @@
</div> </div>
<div v-else-if="col.fieldtype === tools.FieldType.binary"> <div v-else-if="col.fieldtype === tools.FieldType.binary">
<div :class="getclassCol(col)"> <div :class="getclassCol(col)">
{{ visuValByType(col, props.row[col.name]) }}
<CMyChipList
:value="props.row[col.name]"
:options="db_fieldsTable.getTableJoinByName(col.jointable)"
:optval="db_fieldsTable.getKeyByTable(col.jointable)"
:optlab="db_fieldsTable.getLabelByTable(col.jointable)"
:opticon="db_fieldsTable.getIconByTable(col.jointable)"
></CMyChipList>
<q-popup-edit v-if="canEdit" v-model="props.row[col.name]" :disable="col.disable" <q-popup-edit v-if="canEdit" v-model="props.row[col.name]" :disable="col.disable"
:title="col.title" buttons :title="col.title" buttons
@save="SaveValue" @show="selItem(props.row, col)"> @save="SaveValue" @show="selItem(props.row, col)">
<q-select <CMyToggleList :label="col.title"
v-model="col.resultjoin"
multiple
borderless
dense
options-dense
display-value="Valori:"
emit-value
map-options
:options="db_fieldsTable.getTableJoinByName(col.jointable)" :options="db_fieldsTable.getTableJoinByName(col.jointable)"
@input="setResultJoin(col, props.row)" :value.sync="props.row[col.name]"
:option-value="db_fieldsTable.getKeyByTable(col.jointable)" :optval="db_fieldsTable.getKeyByTable(col.jointable)"
style="min-width: 150px"> :optlab="db_fieldsTable.getLabelByTable(col.jointable)"
</q-select> >
<q-input v-model="props.row[col.name]"/> </CMyToggleList>
{{ visuValByType(col, props.row[col.name]) }}
</q-popup-edit> </q-popup-edit>
</div> </div>

View File

@@ -0,0 +1,5 @@
.clchip{
display: flex;
//flex: 1;
//flex-direction: column;
}

View File

@@ -0,0 +1,57 @@
import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator'
import { tools } from '../../store/Modules/tools'
import { toolsext } from '@src/store/Modules/toolsext'
@Component({
name: 'CMyChipList'
})
export default class CMyChipList extends Vue {
public $t
@Prop({ required: true }) public options: []
@Prop({ required: true }) public value
@Prop({ required: true, default: '' }) public optlab
@Prop({ required: true, default: '' }) public optval
@Prop({ required: false, default: '' }) public myclass
@Prop({ required: false, default: '' }) public opticon
@Prop({ required: false, default: '' }) public optcolor
public myvalue = ''
public myarrvalues = []
get tools() {
return tools
}
public mounted() {
this.myarrvalues = []
console.table(this.options)
this.options.forEach((rec, index) => {
if (tools.isBitActive(this.value, rec[this.optval])) {
const mydata = {
label: this.$t(rec[this.optlab]),
value: rec[this.optval],
valbool: tools.isBitActive(this.value, rec[this.optval]),
icon: '',
color: tools.getColorByIndexBest(index)
}
if (this.opticon)
mydata.icon = rec[this.opticon]
if (this.optcolor)
mydata.color = rec[this.optcolor]
this.myarrvalues.push(mydata)
}
})
if (this.myarrvalues.length === 0)
this.myarrvalues.push({ label: this.$t('otherpages.manage.nessuno'), color: 'gray' })
console.log('arrvalues=', this.myarrvalues)
}
}

View File

@@ -0,0 +1,19 @@
<template>
<div class="clchip">
<div v-for="(rec, index) in myarrvalues">
<q-chip dense
:color="rec.color"
text-color="white"
:icon="rec.icon">
{{rec.label}}
</q-chip>
</div>
</div>
</template>
<script lang="ts" src="./CMyChipList.ts">
</script>
<style lang="scss" scoped>
@import './CMyChipList.scss';
</style>

View File

@@ -0,0 +1 @@
export {default as CMyChipList} from './CMyChipList.vue'

View File

@@ -31,7 +31,7 @@ export default class CMySelect extends Vue {
} }
public changeval(newval) { public changeval(newval) {
console.log('changeval', newval) // console.log('changeval', newval)
// const newvallab = newval[`${this.optval}`] // const newvallab = newval[`${this.optval}`]
// this.myvalue = newvallab // this.myvalue = newvallab
this.$emit('update:value', newval) this.$emit('update:value', newval)

View File

@@ -0,0 +1,5 @@
.cltoggle{
display: flex;
flex: 1;
flex-direction: column;
}

View File

@@ -0,0 +1,50 @@
import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator'
import { tools } from '../../store/Modules/tools'
import { toolsext } from '@src/store/Modules/toolsext'
@Component({
name: 'CMyToggleList'
})
export default class CMyToggleList extends Vue {
public $t
@Prop({ required: true }) public options: []
@Prop({ required: true }) public value
@Prop({ required: true, default: '' }) public label
@Prop({ required: false, default: '' }) public myclass
@Prop({ required: true, default: '' }) public optlab
@Prop({ required: true, default: '' }) public optval
public myvalue = ''
public myarrvalues = []
get tools() {
return tools
}
public changeval(newval) {
// Update value
const totale = this.myarrvalues.filter((rec) => rec.valbool).reduce((sum, rec) => sum + rec.value, 0)
this.myvalue = totale
// Refresh value
this.$emit('update:value', this.myvalue)
}
public mounted() {
this.myarrvalues = []
console.table(this.options)
this.options.forEach((rec) => {
const mydata = {
label: this.$t(rec[this.optlab]),
value: rec[this.optval],
valbool: tools.isBitActive(this.value, rec[this.optval])
}
this.myarrvalues.push(mydata)
})
}
}

View File

@@ -0,0 +1,20 @@
<template>
<div>
<div class="cltoggle" v-for="(rec, index) in myarrvalues">
<q-toggle
v-model="rec.valbool"
:label="rec.label"
:color="tools.getColorByIndexBest(index)"
keep-color
@input="changeval">
</q-toggle>
</div>
</div>
</template>
<script lang="ts" src="./CMyToggleList.ts">
</script>
<style lang="scss" scoped>
@import './CMyToggleList.scss';
</style>

View File

@@ -0,0 +1 @@
export {default as CMyToggleList} from './CMyToggleList.vue'

View File

@@ -7,6 +7,8 @@ export * from './CBook'
export * from './CMyPage' export * from './CMyPage'
export * from './CTitle' export * from './CTitle'
export * from './CMySelect' export * from './CMySelect'
export * from './CMyToggleList'
export * from './CMyChipList'
export * from './CMyEditor' export * from './CMyEditor'
export * from './CImgText' export * from './CImgText'
export * from './CImgTitle' export * from './CImgTitle'

View File

@@ -239,6 +239,8 @@ export interface ITableRec {
value: string value: string
columns: IColGridTable[] columns: IColGridTable[]
colkey: string colkey: string
collabel: string
colicon?: string
} }
export interface IDataPass { export interface IDataPass {

View File

@@ -18,7 +18,9 @@ const msgglobal = {
tableslist: 'Lista Tabelle', tableslist: 'Lista Tabelle',
}, },
manage: { manage: {
menu: 'Gestione' menu: 'Gestione',
manager: 'Gestore',
nessuno: 'Nessuno'
}, },
messages: { messages: {
menu: 'I tuoi Messaggi' menu: 'I tuoi Messaggi'
@@ -50,6 +52,7 @@ const msgglobal = {
db: { db: {
recupdated: 'Record Aggiornato', recupdated: 'Record Aggiornato',
recfailed: 'Errore durante aggiornamento Record', recfailed: 'Errore durante aggiornamento Record',
reccanceled: 'Annullato Aggiornamento. Ripristinato valore precendente',
deleterecord: 'Elimina Record', deleterecord: 'Elimina Record',
deletetherecord: 'Eliminare il Record?', deletetherecord: 'Eliminare il Record?',
deletedrecord: 'Record Cancellato', deletedrecord: 'Record Cancellato',
@@ -196,6 +199,10 @@ const msgglobal = {
themecolor: 'Tema Colore', themecolor: 'Tema Colore',
themebgcolor: 'Tema Colore Sfondo' themebgcolor: 'Tema Colore Sfondo'
}, },
where: {
code: 'Id',
whereicon: 'Icona',
},
cal: { cal: {
booked: 'Prenotato', booked: 'Prenotato',
booked_error: 'Prenotazione non avvenuta. Riprovare più tardi', booked_error: 'Prenotazione non avvenuta. Riprovare più tardi',
@@ -304,7 +311,9 @@ const msgglobal = {
tableslist: 'Listado de tablas', tableslist: 'Listado de tablas',
}, },
manage: { manage: {
menu: 'Gestionar' menu: 'Gestionar',
manager: 'Gerente',
nessuno: 'Nadie'
}, },
messages: { messages: {
menu: 'Tus mensajes' menu: 'Tus mensajes'
@@ -336,6 +345,7 @@ const msgglobal = {
db: { db: {
recupdated: 'Registro Actualizado', recupdated: 'Registro Actualizado',
recfailed: 'Error durante el registro de actualización', recfailed: 'Error durante el registro de actualización',
reccanceled: 'Actualización cancelada Restaurar valor anterior',
deleterecord: 'Eliminar registro', deleterecord: 'Eliminar registro',
deletetherecord: '¿Eliminar el registro?', deletetherecord: '¿Eliminar el registro?',
deletedrecord: 'Registro cancelado', deletedrecord: 'Registro cancelado',
@@ -476,6 +486,10 @@ const msgglobal = {
themecolor: 'Tema Colores', themecolor: 'Tema Colores',
themebgcolor: 'Tema Colores Fondo' themebgcolor: 'Tema Colores Fondo'
}, },
where: {
code: 'Id',
whereicon: 'Icono',
},
cal: { cal: {
booked: 'Reservado', booked: 'Reservado',
booked_error: 'Reserva fallida. Intenta nuevamente más tarde', booked_error: 'Reserva fallida. Intenta nuevamente más tarde',
@@ -581,7 +595,9 @@ const msgglobal = {
tableslist: 'Liste des tables', tableslist: 'Liste des tables',
}, },
manage: { manage: {
menu: 'Gérer' menu: 'Gérer',
manager: 'Directeur',
nessuno: 'Aucun'
}, },
messages: { messages: {
menu: 'Vos messages' menu: 'Vos messages'
@@ -613,6 +629,7 @@ const msgglobal = {
db: { db: {
recupdated: 'Enregistrement mis à jour', recupdated: 'Enregistrement mis à jour',
recfailed: 'Erreur lors de la mise à jour', recfailed: 'Erreur lors de la mise à jour',
reccanceled: 'Mise à jour annulée. Restaurer la valeur précédente',
deleterecord: 'Supprimer l\'enregistrement', deleterecord: 'Supprimer l\'enregistrement',
deletetherecord: 'Supprimer l\'enregistrement?', deletetherecord: 'Supprimer l\'enregistrement?',
deletedrecord: 'Enregistrement annulé', deletedrecord: 'Enregistrement annulé',
@@ -752,6 +769,10 @@ const msgglobal = {
themecolor: 'Tema Colores', themecolor: 'Tema Colores',
themebgcolor: 'Tema Colores Fondo' themebgcolor: 'Tema Colores Fondo'
}, },
where: {
code: 'Id',
whereicon: 'icône',
},
cal: { cal: {
booked: 'Réservé', booked: 'Réservé',
booked_error: 'La réservation a échoué. Réessayez plus tard', booked_error: 'La réservation a échoué. Réessayez plus tard',
@@ -857,7 +878,9 @@ const msgglobal = {
tableslist: 'List of tables', tableslist: 'List of tables',
}, },
manage: { manage: {
menu: 'Manage' menu: 'Manage',
manager: 'Manager',
nessuno: 'None'
}, },
messages: { messages: {
menu: 'Your Messages' menu: 'Your Messages'
@@ -889,6 +912,7 @@ const msgglobal = {
db: { db: {
recupdated: 'Record Updated', recupdated: 'Record Updated',
recfailed: 'Error during update Record', recfailed: 'Error during update Record',
reccanceled: 'Canceled Update. Restore previous value',
deleterecord: 'Delete Record', deleterecord: 'Delete Record',
deletetherecord: 'Delete the Record?', deletetherecord: 'Delete the Record?',
deletedrecord: 'Record Deleted', deletedrecord: 'Record Deleted',
@@ -1027,6 +1051,10 @@ const msgglobal = {
themecolor: 'Theme Color', themecolor: 'Theme Color',
themebgcolor: 'Theme Color Background' themebgcolor: 'Theme Color Background'
}, },
where: {
code: 'Id',
whereicon: 'Icon',
},
cal: { cal: {
booked: 'Booked', booked: 'Booked',
booked_error: 'Reservation failed. Try again later', booked_error: 'Reservation failed. Try again later',
@@ -1132,7 +1160,9 @@ const msgglobal = {
tableslist: 'List of tables', tableslist: 'List of tables',
}, },
manage: { manage: {
menu: 'Manage' menu: 'Manage',
manager: 'Manager',
nessuno: 'None'
}, },
messages: { messages: {
menu: 'Your Messages' menu: 'Your Messages'
@@ -1164,6 +1194,7 @@ const msgglobal = {
db: { db: {
recupdated: 'Record Updated', recupdated: 'Record Updated',
recfailed: 'Error during update Record', recfailed: 'Error during update Record',
reccanceled: 'Canceled Update. Restore previous value',
deleterecord: 'Delete Record', deleterecord: 'Delete Record',
deletetherecord: 'Delete the Record?', deletetherecord: 'Delete the Record?',
deletedrecord: 'Record Deleted', deletedrecord: 'Record Deleted',
@@ -1304,6 +1335,10 @@ const msgglobal = {
themecolor: 'Theme Color', themecolor: 'Theme Color',
themebgcolor: 'Theme Color Background' themebgcolor: 'Theme Color Background'
}, },
where: {
code: 'Id',
whereicon: 'Icon',
},
cal: { cal: {
booked: 'Booked', booked: 'Booked',
booked_error: 'Reservation failed. Try again later', booked_error: 'Reservation failed. Try again later',

View File

@@ -40,7 +40,7 @@ function AddCol(params: IColGridTable) {
const colTableWhere = [ const colTableWhere = [
AddCol({ name: 'code', label_trans: 'where.code' }), AddCol({ name: 'code', label_trans: 'where.code' }),
AddCol({ name: 'placename', label_trans: 'where.placename' }), AddCol({ name: 'placename', label_trans: 'cal.where' }),
AddCol({ name: 'whereicon', label_trans: 'where.whereicon' }), AddCol({ name: 'whereicon', label_trans: 'where.whereicon' }),
AddCol(DeleteRec) AddCol(DeleteRec)
] ]
@@ -111,6 +111,30 @@ const colTableEvents = [
] ]
export const fieldsTable = { export const fieldsTable = {
getArrStrByValueBinary(mythis, col: IColGridTable, val) {
const arr = this.getArrByValueBinary(mythis, col, val)
if (arr.length > 0)
return arr.join(' - ')
else
return '[---]'
},
getArrByValueBinary(mythis, col: IColGridTable, val) {
if (col.jointable) {
const mylist = this.getTableJoinByName(col.jointable)
const key = this.getKeyByTable(col.jointable)
const myres = []
mylist.forEach((myrec) => {
if (tools.isBitActive(val, myrec[key]))
myres.push(mythis.$t(myrec.label))
})
return myres
} else {
return []
}
},
getColByTable(table) { getColByTable(table) {
if (table === 'permissions') { if (table === 'permissions') {
return ['value', 'label'] return ['value', 'label']
@@ -118,7 +142,7 @@ export const fieldsTable = {
}, },
getTableJoinByName(table) { getTableJoinByName(table) {
if (table === 'permissions') { if (table === 'permissions') {
return [shared_consts.Permissions.Normal, shared_consts.Permissions.Admin, shared_consts.Permissions.Manager, shared_consts.Permissions.Teacher] return [shared_consts.Permissions.Admin, shared_consts.Permissions.Manager, shared_consts.Permissions.Teacher]
} }
}, },
getrecTableList(mytable) { getrecTableList(mytable) {
@@ -131,36 +155,56 @@ export const fieldsTable = {
else else
return '_id' return '_id'
}, },
getLabelByTable(mytable): string {
const myrec = this.getrecTableList(mytable)
if (myrec)
return ((myrec.collabel) ? myrec.collabel : 'label')
else
return 'label'
},
getIconByTable(mytable): string {
const myrec = this.getrecTableList(mytable)
if (myrec)
return ((myrec.icon) ? myrec.icon : '')
else
return ''
},
tablesList: [ tablesList: [
{ {
value: 'operators', value: 'operators',
label: 'Insegnanti', label: 'Insegnanti',
columns: colTableOperator, columns: colTableOperator,
colkey: '_id' colkey: '_id',
collabel: 'username'
}, },
{ {
value: 'wheres', value: 'wheres',
label: 'Luoghi', label: 'Luoghi',
columns: colTableWhere, columns: colTableWhere,
colkey: '_id' colkey: '_id',
collabel: 'placename'
}, },
{ {
value: tools.TABEVENTS, value: tools.TABEVENTS,
label: 'Eventi', label: 'Eventi',
columns: colTableEvents, columns: colTableEvents,
colkey: '_id' colkey: '_id',
collabel: 'title'
}, },
{ {
value: 'contribtype', value: 'contribtype',
label: 'Tipi di Contributi', label: 'Tipi di Contributi',
columns: colcontribtype, columns: colcontribtype,
colkey: '_id' colkey: '_id',
collabel: 'label'
}, },
{ {
value: 'permissions', value: 'permissions',
label: 'Permessi', label: 'Permessi',
columns: colTablePermission, columns: colTablePermission,
colkey: 'value' colkey: 'value',
collabel: 'label',
colicon: 'icon'
} }
], ],

View File

@@ -37,6 +37,23 @@ export interface INotify {
} }
export const tools = { export const tools = {
listBestColor: [
'blue',
'green',
'purple',
'deep-purple',
'indigo',
'light-blue',
'cyan',
'teal',
'lime',
'orange',
'deeporange',
'grey',
'blue-gray',
'yellow'
],
TABEVENTS: 'myevents', TABEVENTS: 'myevents',
MAX_CHARACTERS: 60, MAX_CHARACTERS: 60,
@@ -1405,6 +1422,10 @@ export const tools = {
tools.showNotif(q, msg, { color: 'negative', icon: 'notifications' }) tools.showNotif(q, msg, { color: 'negative', icon: 'notifications' })
}, },
showNeutralNotif(q: any, msg) {
tools.showNotif(q, msg, { color: 'warning', icon: 'notifications' })
},
showNotif(q: any, msg, data ?: INotify | null showNotif(q: any, msg, data ?: INotify | null
) { ) {
let myicon = data ? data.icon : 'ion-add' let myicon = data ? data.icon : 'ion-add'
@@ -2494,7 +2515,10 @@ export const tools = {
}, },
isBitActive(bit, whattofind) { isBitActive(bit, whattofind) {
if (whattofind > 0)
return ((bit & whattofind) === whattofind) return ((bit & whattofind) === whattofind)
else
return false
}, },
SetBit(myval, bit) { SetBit(myval, bit) {
@@ -2513,6 +2537,13 @@ export const tools = {
.filter(e => arr[e]).map(e => arr[e]) .filter(e => arr[e]).map(e => arr[e])
return unique return unique
},
getColorByIndexBest(index) {
if (index < this.listBestColor.length - 1)
return this.listBestColor[index]
else
return 'primary'
} }
// getLocale() { // getLocale() {