Add Movement !
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import {
|
||||
ICircuit,
|
||||
ICircuit, ICircuitState, IGlobalState,
|
||||
} from '@src/model'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import translate from '@src/globalroutines/util'
|
||||
@@ -20,7 +20,7 @@ import { costanti } from '@costanti'
|
||||
import globalroutines from '../globalroutines/index'
|
||||
|
||||
export const useCircuitStore = defineStore('CircuitStore', {
|
||||
state: () => ({
|
||||
state: (): ICircuitState => ({
|
||||
listcircuits: []
|
||||
}),
|
||||
|
||||
@@ -29,6 +29,7 @@ export const useCircuitStore = defineStore('CircuitStore', {
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
getImgByCircuit(circ: ICircuit): string {
|
||||
|
||||
try {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
ITodo,
|
||||
IUserFields,
|
||||
Privacy,
|
||||
TipoVisu, IGroup, IMySkill, IMyBacheca, IImgGallery, IMsgGlobParam, IUserExport, ISpecialField, IAccount, IMyCircuit,
|
||||
TipoVisu, IGroup, IMySkill, IMyBacheca, IImgGallery, IMsgGlobParam, IUserExport, ISpecialField, IAccount, IMyCircuit, ISendCoin,
|
||||
} from '@model'
|
||||
|
||||
import { addToDate } from '@quasar/quasar-ui-qcalendar'
|
||||
@@ -4784,6 +4784,29 @@ export const tools = {
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
acceptCoins($q: any, username: string, recsendcoin: ISendCoin) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
userStore.setCircuitCmd($q, t, username, recsendcoin.circuitname, shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT, 0, recsendcoin)
|
||||
.then((res: any) => {
|
||||
if (res) {
|
||||
tools.showPositiveNotif($q, t('circuit.coins_accepted'))
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
refuseCoins($q: any, username: string, recsendcoin: ISendCoin) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
userStore.setCircuitCmd($q, t, username, recsendcoin.circuitname, shared_consts.CIRCUITCMD.SENDCOINS_REFUSE, recsendcoin)
|
||||
.then((res: any) => {
|
||||
if (res) {
|
||||
tools.showPositiveNotif($q, t('circuit.coins_refused'))
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
refuseReqGroup($q: any, username: string, groupnameDest: string) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
@@ -4863,7 +4886,7 @@ export const tools = {
|
||||
const mygrp = userStore.my.profile.manage_mygroups.find((rec: IMyGroup) => rec.groupname === groupnameDest)
|
||||
console.log('mygrp', mygrp)
|
||||
if (mygrp && mygrp.admins) {
|
||||
mygrp.admins = [...mygrp.admins, {username, date: new Date}]
|
||||
mygrp.admins = [...mygrp.admins, { username, date: new Date }]
|
||||
console.log('mygrp.admins', mygrp.admins)
|
||||
tools.showPositiveNotif($q, t('db.addedtoadmin', { username }))
|
||||
}
|
||||
@@ -5236,6 +5259,39 @@ export const tools = {
|
||||
})
|
||||
},
|
||||
|
||||
sendCoinsByCircuit($q: any, circuit: ICircuit, sendcoinrec: ISendCoin) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const username = userStore.my.username
|
||||
|
||||
let msg = ''
|
||||
msg = t('circuit.question_sendcoinsto', { coin: circuit.symbol, dest: sendcoinrec.dest, qty: sendcoinrec.qty })
|
||||
|
||||
$q.dialog({
|
||||
message: msg,
|
||||
ok: {
|
||||
label: t('dialog.yes'),
|
||||
push: true
|
||||
},
|
||||
cancel: {
|
||||
label: t('dialog.cancel')
|
||||
},
|
||||
title: t('db.domanda')
|
||||
}).onOk(() => {
|
||||
|
||||
userStore.setCircuitCmd($q, t, username, sendcoinrec.circuitname, shared_consts.CIRCUITCMD.SENDCOINS_REQ, true, sendcoinrec)
|
||||
.then((res: any) => {
|
||||
if (res) {
|
||||
tools.showPositiveNotif($q, t('circuit.coins_sendrequest_sent'))
|
||||
|
||||
} else {
|
||||
tools.showNegativeNotif($q, t('db.coins_sendrequest_failed'))
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
cancelReqCircuit($q: any, username: string, circuitname: string) {
|
||||
const userStore = useUserStore()
|
||||
$q.dialog({
|
||||
@@ -5315,7 +5371,7 @@ export const tools = {
|
||||
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}]
|
||||
mycircuit.admins = [...mycircuit.admins, { username, date: new Date }]
|
||||
console.log('mycircuit.admins', mycircuit.admins)
|
||||
tools.showPositiveNotif($q, t('db.addedtoadmin', { username }))
|
||||
}
|
||||
@@ -5362,7 +5418,7 @@ export const tools = {
|
||||
if (res) {
|
||||
if (userStore.my.profile.manage_mycircuits) {
|
||||
userStore.my.profile.manage_mycircuits = userStore.my.profile.manage_mycircuits.filter((rec: ICircuit) => rec.name !== circuitname)
|
||||
tools.showPositiveNotif($q, t('circuit.deleted', { circuitname } ))
|
||||
tools.showPositiveNotif($q, t('circuit.deleted', { circuitname }))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -6151,7 +6207,7 @@ export const tools = {
|
||||
VUE_APP_BACKEND_API_URL: window?.appConfig?.VUE_APP_BACKEND_API_URL || process.env.VUE_APP_BACKEND_API_URL
|
||||
}
|
||||
|
||||
return config[name];
|
||||
return config[name]
|
||||
},
|
||||
|
||||
getArrSector(table: string, rec: any) {
|
||||
@@ -6160,7 +6216,7 @@ export const tools = {
|
||||
else if ((table === toolsext.TABMYBACHECAS) || (table === toolsext.TABMYSKILLS))
|
||||
return rec.sector
|
||||
else if (table === toolsext.TABMYGROUPS)
|
||||
return [{descr: rec.sector}]
|
||||
return [{ descr: rec.sector }]
|
||||
else if (table === toolsext.TABMYHOSPS)
|
||||
return []
|
||||
|
||||
@@ -6178,8 +6234,35 @@ export const tools = {
|
||||
return []
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
findCommonElements(arr1: any, arr2: any) {
|
||||
return arr1.some((item: any) => arr2.includes(item))
|
||||
},
|
||||
|
||||
// Function to return commonElements
|
||||
getCommon(arr1: any, arr2: any, field: string): any[] {
|
||||
arr1.sort((a: any, b: any) => b[field] - a[field]) // Sort both the arrays
|
||||
arr2.sort((a: any, b: any) => b[field] - a[field])
|
||||
let common = [] // Array to contain common elements
|
||||
let i = 0, j = 0 // i points to arr1 and j to arr2
|
||||
// Break if one of them runs out
|
||||
while (i < arr1.length && j < arr2.length) {
|
||||
|
||||
if (arr1[i][field] == arr2[j][field]) { // If both are same, add it to result
|
||||
common.push(arr1[i][field])
|
||||
i++
|
||||
j++
|
||||
} else if (arr1[i][field] < arr2[j][field]) { // Increment the smaller value so that
|
||||
i++ // it could be matched with the larger
|
||||
} // element
|
||||
else {
|
||||
j++
|
||||
}
|
||||
}
|
||||
|
||||
return common
|
||||
},
|
||||
// getLocale() {
|
||||
// if (navigator.languages && navigator.languages.length > 0) {
|
||||
// return navigator.languages[0]
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
ICircuit, IMyCircuit,
|
||||
IFriends, IMsgGlobParam,
|
||||
ISigninOptions,
|
||||
ISignupOptions, IUserFields, IUserNotifType, IUserProfile, IUserState,
|
||||
ISignupOptions, IUserFields, IUserNotifType, IUserProfile, IUserState, IAccount,
|
||||
} from '@src/model'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import translate from '@src/globalroutines/util'
|
||||
@@ -68,6 +68,7 @@ export const DefaultUser: IUserFields = {
|
||||
asked_circuits: [],
|
||||
refused_circuits: [],
|
||||
manage_mycircuits: [],
|
||||
useraccounts: [],
|
||||
},
|
||||
cart: {
|
||||
userId: '',
|
||||
@@ -125,6 +126,7 @@ export const DefaultProfile: IUserProfile = {
|
||||
asked_circuits: [],
|
||||
refused_circuits: [],
|
||||
manage_mycircuits: [],
|
||||
useraccounts: [],
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore('UserStore', {
|
||||
@@ -305,6 +307,16 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
},
|
||||
|
||||
IsMyCircuitByUser(user: IUserFields): any[] {
|
||||
|
||||
return tools.getCommon(this.my.profile.mycircuits, user.profile.mycircuits, 'circuitname')
|
||||
},
|
||||
|
||||
|
||||
getAccountByCircuitName(circuitname: string): any {
|
||||
return this.my.profile.useraccounts.find((rec: IAccount) => rec.circuit.name === circuitname)
|
||||
},
|
||||
|
||||
IsRefusedCircuitByName(circuitname: string): boolean {
|
||||
if (this.my.profile.refused_circuits)
|
||||
return this.my.profile.refused_circuits.findIndex((rec: ICircuit) => rec.name === circuitname) >= 0
|
||||
@@ -1210,8 +1222,8 @@ export const useUserStore = defineStore('UserStore', {
|
||||
|
||||
},
|
||||
|
||||
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 })
|
||||
async setCircuitCmd($q: any, t: any, usernameOrig: string, circuitname: string, cmd: number, value: any, extrarec?: any) {
|
||||
return Api.SendReq('/users/circuits/cmd', 'POST', { usernameOrig, circuitname, cmd, value, extrarec })
|
||||
.then((res) => {
|
||||
this.updateTables = true
|
||||
return res.data
|
||||
|
||||
@@ -31,6 +31,7 @@ import translate from '@src/globalroutines/util'
|
||||
import { useTodoStore } from '@store/Todos'
|
||||
import { useMessageStore } from './MessageStore'
|
||||
import { useNotifStore } from '@store/NotifStore'
|
||||
import { useCircuitStore } from '@store/CircuitStore'
|
||||
|
||||
|
||||
const stateConnDefault = 'online'
|
||||
@@ -1311,6 +1312,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
async loadSite() {
|
||||
const userStore = useUserStore()
|
||||
const calendarStore = useCalendarStore()
|
||||
const circuitStore = useCircuitStore()
|
||||
// console.log('calendarStore: loadAfterLogin')
|
||||
// Load local data
|
||||
const showall = userStore.isAdmin || userStore.isManager ? '1' : '0'
|
||||
@@ -1332,6 +1334,8 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
calendarStore.wheres = (res.data.wheres) ? res.data.wheres : []
|
||||
calendarStore.contribtype = (res.data.contribtype) ? res.data.contribtype : []
|
||||
|
||||
circuitStore.listcircuits = (res.data.listcircuits) ? res.data.listcircuits : []
|
||||
|
||||
this.settings = (res.data.settings) ? [...res.data.settings] : []
|
||||
this.disciplines = (res.data.disciplines) ? [...res.data.disciplines] : []
|
||||
this.paymenttypes = (res.data.paymenttypes) ? [...res.data.paymenttypes] : []
|
||||
@@ -1356,6 +1360,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
this.mygroups = (res.data.mygroups) ? [...res.data.mygroups] : []
|
||||
this.adtypes = (res.data.adtypes) ? [...res.data.adtypes] : []
|
||||
this.adtypegoods = (res.data.adtypegoods) ? [...res.data.adtypegoods] : []
|
||||
circuitStore.listcircuits = (res.data.listcircuits) ? [...res.data.listcircuits] : []
|
||||
|
||||
// console.log('res.data.cart', res.data.cart)
|
||||
|
||||
@@ -1670,7 +1675,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
myserv = window.location.host
|
||||
|
||||
if (process.env.DEBUGGING) {
|
||||
myserv = 'http://192.168.1.54:3000'
|
||||
myserv = ' http://192.168.1.102:3000'; // 'http://192.168.1.54:3000'
|
||||
}
|
||||
|
||||
if (!myserv) {
|
||||
|
||||
Reference in New Issue
Block a user