Add to the Circuit

Remove to the Circuit
Revoke request
Users Admins
This commit is contained in:
paoloar77
2022-09-02 02:25:17 +02:00
parent 1f414e19ea
commit 037ce99485
27 changed files with 438 additions and 206 deletions

View File

@@ -192,7 +192,7 @@ export const costanti = {
MANAGE_GROUPS: 31,
ADMIN_GROUPS: 40,
FIND_CIRCUIT: 50,
MY_USERACCOUNTS: 51,
MY_CIRCUITS: 51,
CREATE_CIRCUIT: 52,
MANAGE_CIRCUITS: 53,
ADMIN_CIRCUITS: 54,
@@ -207,10 +207,11 @@ export const costanti = {
REQ_ADD_USER_TO_GROUP: 100,
REQ_REMOVE_USER_TO_GROUP: 101,
REQ_ADD_USER_TO_CIRCUIT: 110,
REQ_REMOVE_USER_TO_CIRCUIT: 111,
FILTER_NESSUNO: 0,
FILTER_TUTTI: -100,
TABLES_ARRAY: ['mygroups'],
TABLES_ARRAY: ['mygroups', 'circuits'],
TABLES_USERNAME_DATE: ['friends', 'friendsandme'],
TABLES_IMG_USERNAME: ['friends', 'friendsandme'],

View File

@@ -594,7 +594,7 @@ export const colmyUserGroup = [
}),*/
AddCol({
name: 'admins',
label_trans: 'groups.admins',
label_trans: 'shared.admins',
fieldtype: costanti.FieldType.multiselect,
jointable: 'friendsandme',
field_outtype: costanti.FieldType.object,
@@ -2382,15 +2382,17 @@ export const colTableSubCashCategory = [
export const colTableCircuitComplete = [
AddCol({ name: 'Num', label_trans: 'circuit.num', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'groupnameId', label_trans: 'circuit.groupnameId' }), // da togliere poi
AddCol({ name: 'name', label_trans: 'circuit.name' }),
AddCol({ name: 'groupnameId', label_trans: 'circuit.groupnameId', fieldtype: costanti.FieldType.select, jointable: 'mygroups' }), // da togliere poi
AddCol({ name: 'name', label_trans: 'circuit.name',
maxlength: 40,
showWhen: costanti.showWhen.NewRec + costanti.showWhen.InPage }),
AddCol({ name: 'path', label_trans: 'circuit.path' }),
AddCol({ name: 'subname', label_trans: 'circuit.subname' }),
AddCol({ name: 'longdescr', label_trans: 'circuit.descr', fieldtype: costanti.FieldType.html }),
AddCol({ name: 'regulation', label_trans: 'circuit.regulation', fieldtype: costanti.FieldType.html }),
AddCol({ name: 'systemUserDescr', label_trans: 'circuit.systemUserDescr' }),
AddCol({ name: 'systemUserId', label_trans: 'circuit.systemUserId', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'founderUserId', label_trans: 'circuit.founderUserId', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'createdBy', label_trans: 'circuit.founder', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'totCircolante', label_trans: 'circuit.totCircolante', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'totTransato', label_trans: 'circuit.totTransato', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'nome_valuta', label_trans: 'circuit.nome_valuta' }),
@@ -2412,7 +2414,7 @@ export const colTableCircuitComplete = [
AddCol({ name: 'img_logo', label_trans: 'circuit.img_logo' }),
AddCol({
name: 'admins',
label_trans: 'groups.admins',
label_trans: 'shared.admins',
fieldtype: costanti.FieldType.multiselect,
jointable: 'friendsandme',
field_outtype: costanti.FieldType.object,
@@ -2437,13 +2439,29 @@ export const colTableCircuitComplete = [
]
export const colTableCircuit = [
AddCol({ name: 'groupnameId', label_trans: 'circuit.groupnameId' }), // da togliere poi
AddCol({ name: 'name', label_trans: 'circuit.name' }),
AddCol({ name: 'groupnameId', label_trans: 'circuit.groupnameId', fieldtype: costanti.FieldType.select, jointable: 'mygroups' }), // da togliere poi
AddCol({ name: 'name', label_trans: 'circuit.name',
maxlength: 40,
showWhen: costanti.showWhen.NewRec + costanti.showWhen.InPage }),
AddCol({ name: 'path', label_trans: 'circuit.path' }),
AddCol({ name: 'subname', label_trans: 'circuit.subname' }),
AddCol({ name: 'longdescr', label_trans: 'circuit.descr', fieldtype: costanti.FieldType.html }),
AddCol({ name: 'systemUserId', label_trans: 'circuit.systemUserId', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'founderUserId', label_trans: 'circuit.founderUserId', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({ name: 'createdBy', label_trans: 'circuit.founder', fieldtype: costanti.FieldType.select, jointable: 'users', }),
AddCol({
name: 'date_created', label_trans: 'reg.pub_created', fieldtype: costanti.FieldType.onlydate,
required: false,
visible: false,
sortable: true,
showWhen: 0
}),
AddCol({
name: 'date_updated', label_trans: 'reg.pub_updated', fieldtype: costanti.FieldType.onlydate,
required: false,
visible: false,
sortable: true,
showWhen: 0
}),
AddCol({ name: 'nome_valuta', label_trans: 'circuit.nome_valuta' }),
AddCol({ name: 'symbol', label_trans: 'circuit.symbol' }),
AddCol({ name: 'data_costituz', label_trans: 'circuit.data_costituz', fieldtype: costanti.FieldType.date }),
@@ -2459,6 +2477,7 @@ export const colmyUserCircuit = [
AddCol({ name: 'deperibile', label_trans: 'account.deperibile', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'importo_iniziale', label_trans: 'account.importo_iniziale', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'saldo', label_trans: 'account.saldo', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'deleted', label_trans: 'reg.deleted', fieldtype: costanti.FieldType.boolean }),
AddCol(DeleteRec),
AddCol(DuplicateRec),
]

View File

@@ -12,7 +12,7 @@ import {
ITodo,
IUserFields,
Privacy,
TipoVisu, IGroup, IMySkill, IMyBacheca, IImgGallery, IMsgGlobParam, IUserExport, ISpecialField, IAccount,
TipoVisu, IGroup, IMySkill, IMyBacheca, IImgGallery, IMsgGlobParam, IUserExport, ISpecialField, IAccount, IMyCircuit,
} from '@model'
import { addToDate } from '@quasar/quasar-ui-qcalendar'
@@ -4734,26 +4734,26 @@ export const tools = {
},
addToMyCircuits($q: any, username: string, name: string) {
addToMyCircuits($q: any, username: string, circuitname: string) {
const userStore = useUserStore()
const notifStore = useNotifStore()
$q.dialog({
message: t('db.domanda_addtocircuit', { username, name }),
message: t('db.domanda_addtocircuit', { username, circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, name, shared_consts.CIRCUITCMD.SET, true)
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.SET, true)
.then((res: any) => {
if (res) {
notifStore.updateNotification = true
if (userStore.my.profile.listUserAccounts)
userStore.my.profile.listUserAccounts = [...userStore.my.profile.listUserAccounts, res]
if (userStore.my.profile.mycircuits)
userStore.my.profile.mycircuits = [...userStore.my.profile.mycircuits, res]
else
userStore.my.profile.listUserAccounts = [res]
tools.showPositiveNotif($q, t('db.addedcircuit', { name }))
userStore.my.profile.mycircuits = [res]
tools.showPositiveNotif($q, t('db.addedcircuit', { circuitname }))
}
})
})
@@ -4798,7 +4798,9 @@ export const tools = {
userStore.setGroupsCmd($q, t, username, groupnameDest, shared_consts.GROUPSCMD.REFUSE_REQ_GROUP, null).then((res) => {
if (res) {
notifStore.updateNotification = true
userStore.my.profile.asked_groups = userStore.my.profile.asked_groups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
if (username === userStore.my.username) {
userStore.my.profile.asked_groups = userStore.my.profile.asked_groups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
}
tools.showPositiveNotif($q, t('db.refusedgroup', { username }))
}
})
@@ -4836,9 +4838,11 @@ export const tools = {
userStore.setGroupsCmd($q, t, username, groupnameDest, shared_consts.GROUPSCMD.REMOVE_FROM_MYGROUP, null).then((res) => {
if (res) {
if (userStore.my.profile.mygroups) {
userStore.my.profile.mygroups = userStore.my.profile.mygroups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
tools.showPositiveNotif($q, t('db.removedgroup'))
if (username === userStore.my.username) {
userStore.my.profile.mygroups = userStore.my.profile.mygroups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
}
}
tools.showPositiveNotif($q, t('db.removedgroup'))
}
})
})
@@ -5025,7 +5029,9 @@ export const tools = {
userStore.setGroupsCmd($q, t, username, groupnameDest, shared_consts.GROUPSCMD.CANCEL_REQ_GROUP, null).then((res) => {
if (res) {
userStore.my.profile.asked_groups = userStore.my.profile.asked_groups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
if (username === userStore.my.username) {
userStore.my.profile.asked_groups = userStore.my.profile.asked_groups.filter((rec: IMyGroup) => rec.groupname !== groupnameDest)
}
tools.showPositiveNotif($q, t('db.cancel_req_group'))
}
})
@@ -5187,15 +5193,15 @@ export const tools = {
return risultato
},
setRequestCircuit($q: any, username: string, name: string, value: boolean) {
setRequestCircuit($q: any, username: string, circuitname: string, value: boolean) {
const userStore = useUserStore()
let msg = ''
if (value) {
msg = t('circuit.domanda_ask', { name })
msg = t('circuit.domanda_ask', { circuitname })
} else {
msg = t('circuit.domanda_revoke', { name })
msg = t('circuit.domanda_revoke', { circuitname })
}
$q.dialog({
@@ -5210,17 +5216,17 @@ export const tools = {
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, name, shared_consts.CIRCUITCMD.REQ, value)
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.REQ, value)
.then((res: any) => {
if (res) {
if (value) {
// ADD to req
userStore.my.profile.asked_circuits.push(res)
tools.showPositiveNotif($q, t('circuit.askedto', { name }))
tools.showPositiveNotif($q, t('circuit.askedto', { circuitname }))
} else {
// REMOVE to req
userStore.my.profile.asked_circuits = userStore.my.profile.asked_circuits.filter((rec: ICircuit) => rec.name !== name)
tools.showPositiveNotif($q, t('circuit.revoketo', { name }))
userStore.my.profile.asked_circuits = userStore.my.profile.asked_circuits.filter((rec: ICircuit) => rec.name !== circuitname)
tools.showPositiveNotif($q, t('circuit.revoketo', { circuitname }))
}
} else {
@@ -5230,7 +5236,50 @@ export const tools = {
})
},
removeFromMyCircuits($q: any, username: string, name: string, domanda: any = '') {
cancelReqCircuit($q: any, username: string, circuitname: string) {
const userStore = useUserStore()
$q.dialog({
message: t('circuit.domanda_cancel_req', { username, circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.CANCEL_REQ, null).then((res) => {
if (res) {
if (username === userStore.my.username) {
userStore.my.profile.asked_circuits = userStore.my.profile.asked_circuits.filter((rec: ICircuit) => rec.name !== circuitname)
}
tools.showPositiveNotif($q, t('db.cancel_req_group'))
}
})
})
},
refuseReqCircuit($q: any, username: string, circuitname: string) {
const userStore = useUserStore()
const notifStore = useNotifStore()
$q.dialog({
message: t('circuit.domanda_refuse_circuit', { username, circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.REFUSE_REQ, null).then((res) => {
if (res) {
notifStore.updateNotification = true
if (username === userStore.my.username) {
userStore.my.profile.asked_circuits = userStore.my.profile.asked_circuits.filter((rec: ICircuit) => rec.name !== circuitname)
}
tools.showPositiveNotif($q, t('db.refusedcircuit', { username }))
}
})
})
},
removeFromMyCircuits($q: any, username: string, circuitname: string, domanda: any = '') {
const userStore = useUserStore()
$q.dialog({
@@ -5240,32 +5289,80 @@ export const tools = {
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, name, shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST, null).then((res) => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST, null).then((res) => {
if (res) {
if (userStore.my.profile.listUserAccounts) {
userStore.my.profile.listUserAccounts = userStore.my.profile.listUserAccounts.filter((rec: IAccount) => rec.name !== name)
tools.showPositiveNotif($q, t('circuit.removed'))
if (userStore.my.profile.mycircuits && username === userStore.my.username) {
userStore.my.profile.mycircuits = userStore.my.profile.mycircuits.filter((rec: IMyCircuit) => rec.circuitname !== circuitname)
}
tools.showPositiveNotif($q, t('circuit.removed'))
}
})
})
},
addtoAdminOfCircuit($q: any, username: string, circuitname: string, domanda: any = '') {
const userStore = useUserStore()
$q.dialog({
message: domanda ? domanda : t('db.domanda_addadminofcircuit', { username, circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.ADDADMIN, null).then((res) => {
if (res) {
const mycircuit = userStore.my.profile.manage_mycircuits.find((rec: ICircuit) => rec.name === circuitname)
console.log('mycircuit', mycircuit)
if (mycircuit && mycircuit.admins) {
mycircuit.admins = [...mycircuit.admins, {username, date: new Date}]
console.log('mycircuit.admins', mycircuit.admins)
tools.showPositiveNotif($q, t('db.addedtoadmin', { username }))
}
}
})
})
},
DeleteCircuit($q: any, username: string, name: string, domanda: any = '') {
removeAdminOfCircuit($q: any, username: string, circuitname: string, domanda: any = '') {
const userStore = useUserStore()
$q.dialog({
message: domanda ? domanda : t('db.domanda_removerecord', { name }),
message: domanda ? domanda : t('db.domanda_removeadminofcircuit', { username, circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, name, shared_consts.CIRCUITCMD.DELETE, null).then((res) => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.REMOVEADMIN, null).then((res) => {
if (res) {
const mygrp = userStore.my.profile.manage_mycircuits.find((rec: ICircuit) => rec.name === circuitname)
console.log('mygrp', mygrp)
if (mygrp && mygrp.admins) {
mygrp.admins = mygrp.admins.filter((rec: any) => rec.username !== username)
console.log('mygrp.admins', mygrp.admins)
tools.showPositiveNotif($q, t('db.removedtoadmin', { username }))
}
}
})
})
},
DeleteCircuit($q: any, username: string, circuitname: string, domanda: any = '') {
const userStore = useUserStore()
$q.dialog({
message: domanda ? domanda : t('db.domanda_removerecord', { circuitname }),
ok: { label: t('dialog.yes'), push: true },
cancel: { label: t('dialog.cancel') },
title: t('db.domanda')
}).onOk(() => {
userStore.setCircuitCmd($q, t, username, circuitname, shared_consts.CIRCUITCMD.DELETE, null).then((res) => {
if (res) {
if (userStore.my.profile.manage_mycircuits) {
userStore.my.profile.manage_mycircuits = userStore.my.profile.manage_mycircuits.filter((rec: ICircuit) => rec.name !== name)
tools.showPositiveNotif($q, t('circuit.deleted', { name } ))
userStore.my.profile.manage_mycircuits = userStore.my.profile.manage_mycircuits.filter((rec: ICircuit) => rec.name !== circuitname)
tools.showPositiveNotif($q, t('circuit.deleted', { circuitname } ))
}
}
})
@@ -5274,6 +5371,7 @@ export const tools = {
iCanShowCircuitsMember(circuit: ICircuit) {
// ++Todo: Posso vedere i membri dei Circuiti ???
/* if (grp && grp.visibility!.includes(shared_consts.Visibility_Group.PRIVATE)) {
// Only if I am part of this group
@@ -5284,14 +5382,14 @@ export const tools = {
},
iAmAdminCircuit(name: string) {
iAmAdminCircuit(circuitname: string) {
const userStore = useUserStore()
let risultato = false
if (userStore.my.profile.manage_mycircuits) {
const ris = userStore.my.profile.manage_mycircuits.find((circuit: ICircuit) => {
if (circuit.name === name) {
if (circuit.name === circuitname) {
return true
}
})
@@ -5405,7 +5503,7 @@ export const tools = {
},
isUserTheCreatorOfThCircuit(name: string, username: string) {
isUserTheCreatorOfTheCircuit(name: string, username: string) {
const userStore = useUserStore()
let risultato = false
@@ -5941,11 +6039,12 @@ export const tools = {
circuitStore.listcircuits = ris.listcircuits ? ris.listcircuits : []
// to Refresh Data User Accounts:
userStore.my.profile.listUserAccounts = ris.listUserAccounts ? ris.listUserAccounts : []
userStore.my.profile.mycircuits = ris.mycircuits ? ris.mycircuits : []
// Others not loaded at the beginning:
userStore.my.profile.asked_circuits = ris.listSentRequestCircuits ? ris.listSentRequestCircuits : []
userStore.my.profile.refused_circuits = ris.listRefusedCircuits ? ris.listRefusedCircuits : []
userStore.my.profile.asked_circuits = ris.asked_circuits ? ris.asked_circuits : []
userStore.my.profile.refused_circuits = ris.refused_circuits ? ris.refused_circuits : []
return [{ userId: userStore.my._id }]
}
})

View File

@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import {
ICircuit,
ICircuit, IMyCircuit,
IFriends, IMsgGlobParam,
ISigninOptions,
ISignupOptions, IUserFields, IUserNotifType, IUserProfile, IUserState,
@@ -54,6 +54,7 @@ export const DefaultUser: IUserFields = {
friends: [],
req_friends: [],
mygroups: [],
mycircuits: [],
manage_mygroups: [],
asked_friends: [],
asked_groups: [],
@@ -66,7 +67,6 @@ export const DefaultUser: IUserFields = {
notif_sector_goods: [],
asked_circuits: [],
refused_circuits: [],
listUserAccounts: [],
manage_mycircuits: [],
},
cart: {
@@ -110,6 +110,7 @@ export const DefaultProfile: IUserProfile = {
friends: [],
req_friends: [],
mygroups: [],
mycircuits: [],
manage_mygroups: [],
asked_friends: [],
asked_groups: [],
@@ -123,7 +124,6 @@ export const DefaultProfile: IUserProfile = {
asked_circuits: [],
refused_circuits: [],
listUserAccounts: [],
manage_mycircuits: [],
}
@@ -288,26 +288,26 @@ export const useUserStore = defineStore('UserStore', {
},
IsAskedCircuitByName(groupname: string): boolean {
IsAskedCircuitByName(name: string): boolean {
if (this.my.profile.asked_circuits)
return this.my.profile.asked_circuits.findIndex((rec: IMyGroup) => rec.groupname === groupname) >= 0
return this.my.profile.asked_circuits.findIndex((rec: ICircuit) => rec.name === name) >= 0
else
return false
},
IsMyCircuitByName(name: string): boolean {
IsMyCircuitByName(circuitname: string): boolean {
if (this.my.profile.manage_mycircuits)
return this.my.profile.manage_mycircuits.findIndex((rec: ICircuit) => rec.name === name) >= 0
if (this.my.profile.mycircuits)
return this.my.profile.mycircuits.findIndex((rec: IMyCircuit) => rec.circuitname === circuitname) >= 0
else
return false
},
IsRefusedCircuitByName(name: string): boolean {
IsRefusedCircuitByName(circuitname: string): boolean {
if (this.my.profile.refused_circuits)
return this.my.profile.refused_circuits.findIndex((rec: ICircuit) => rec.name === name) >= 0
return this.my.profile.refused_circuits.findIndex((rec: ICircuit) => rec.name === circuitname) >= 0
else
return false
},
@@ -1108,7 +1108,7 @@ export const useUserStore = defineStore('UserStore', {
},
async loadCIrcuit(path: string, idnotif: string) {
async loadCircuit(path: string, idnotif: string) {
const data = {
path,
idnotif,
@@ -1210,8 +1210,8 @@ export const useUserStore = defineStore('UserStore', {
},
async setCircuitCmd($q: any, t: any, usernameOrig: string, name: string, cmd: number, value: any) {
return Api.SendReq('/users/circuits/cmd', 'POST', { usernameOrig, name, cmd, value })
async setCircuitCmd($q: any, t: any, usernameOrig: string, circuitname: string, cmd: number, value: any) {
return Api.SendReq('/users/circuits/cmd', 'POST', { usernameOrig, circuitname, cmd, value })
.then((res) => {
this.updateTables = true
return res.data