Files
myprojplanet_vite/src/components/CMyCircuit/CMyCircuit.ts

182 lines
4.8 KiB
TypeScript
Raw Normal View History

2025-03-01 14:14:43 +01:00
import type { PropType } from 'vue';
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
2022-08-26 03:32:50 +02:00
import { useUserStore } from '@store/UserStore'
2022-09-14 11:31:48 +02:00
import { useCircuitStore } from '@store/CircuitStore'
2025-03-01 14:14:43 +01:00
import type { ICircuit, IMyCircuit, IMyGroup } from 'model';
import { IImgGallery, IUserFields, IUserProfile, IFriends, IAccount } from 'model'
2022-08-26 03:32:50 +02:00
import { costanti } from '@costanti'
2025-03-01 14:14:43 +01:00
import { shared_consts } from '@src/common/shared_vuejs'
import { tools } from '@tools'
2022-08-26 03:32:50 +02:00
import { useQuasar } from 'quasar'
2025-03-01 14:14:43 +01:00
import { useI18n } from 'vue-i18n'
2022-08-26 03:32:50 +02:00
import { useRoute, useRouter } from 'vue-router'
2025-03-01 14:14:43 +01:00
import { CUserNonVerif } from '@src/components/CUserNonVerif'
import { CSaldo } from '@src/components/CSaldo'
import { CTitleBanner } from '@src/components/CTitleBanner'
2022-08-26 03:32:50 +02:00
import { toolsext } from '@store/Modules/toolsext'
2022-10-21 21:25:54 +02:00
import { useGlobalStore } from '@store/globalStore'
import { userPanel } from 'app/src/rootgen/admin/userPanel';
2022-08-26 03:32:50 +02:00
export default defineComponent({
name: 'CMyCircuit',
emits: ['setCmd'],
2025-03-01 14:14:43 +01:00
components: { CUserNonVerif, CSaldo, CTitleBanner },
2022-08-26 03:32:50 +02:00
props: {
mycircuit: {
type: Object as PropType<ICircuit | null>,
required: false,
default: null,
},
circuitname: {
type: String,
required: false,
default: null,
},
prop_groupnameSel: {
type: Object as PropType<IMyGroup | null>,
required: false,
default: null,
},
2022-08-26 03:32:50 +02:00
visu: {
type: Number,
required: true,
},
noaut: {
type: Boolean,
required: false,
default: false,
2023-04-12 16:29:30 +02:00
},
username: {
type: String,
required: false,
default: '',
},
myuser: {
type: Object as PropType<IUserFields | null>,
required: false,
default: null,
2022-08-26 03:32:50 +02:00
}
},
setup(props, { emit }) {
const userStore = useUserStore()
2022-09-14 11:31:48 +02:00
const circuitStore = useCircuitStore()
2022-08-26 03:32:50 +02:00
const $q = useQuasar()
const { t } = useI18n()
const $router = useRouter()
const $route = useRoute()
2022-10-21 21:25:54 +02:00
const globalStore = useGlobalStore()
const circuit = ref(<IMyCircuit | ICircuit | null>null)
2025-03-01 14:14:43 +01:00
const account = computed(() => circuit.value ? userStore.getAccountByCircuitId(circuit.value._id) : null)
2022-09-14 11:31:48 +02:00
const qtarem = computed(() => account.value ? circuitStore.getRemainingCoinsToSend(account.value) : 0)
const saldo_pend = computed(() => account.value ? account.value.saldo_pend : 0)
2022-09-14 11:31:48 +02:00
const saldo = computed(() => account.value ? account.value.saldo : 0)
2022-08-26 03:32:50 +02:00
const fidoConcessoUtente = computed(() => circuitStore.getFidoConcessoByUsername(props.myuser, circuit.value._id, props.username))
const table = ref(shared_consts.TABLES_CIRCUITS)
2022-08-26 03:32:50 +02:00
2022-10-21 21:25:54 +02:00
const showingtooltip = ref(false)
const showrules = ref(false)
const requestToEnterCircuit = ref(false)
const groupnameSel = ref(<IMyGroup | null>null)
2022-10-21 21:25:54 +02:00
2022-08-26 03:32:50 +02:00
watch(() => props.mycircuit, (newval, oldval) => {
mounted()
})
2025-03-01 14:14:43 +01:00
function getNameCircuit() {
if (circuit.value) {
if (tools.existProp(circuit.value, 'name')) {
return tools.getProp(circuit.value, 'name')
} else if (tools.existProp(circuit.value, 'circuitname')) {
return tools.getProp(circuit.value, 'circuitname')
}
}
return ''
}
2022-08-26 03:32:50 +02:00
function mounted() {
groupnameSel.value = props.prop_groupnameSel
2022-08-26 03:32:50 +02:00
if (!props.mycircuit) {
if (props.circuitname) {
circuit.value = null
}
} else {
if (props.mycircuit) {
circuit.value = props.mycircuit
}
}
2025-03-01 14:14:43 +01:00
if (circuit.value) {
const rectofind = circuitStore.listcircuits.find((circ: ICircuit) => circ.name === getNameCircuit())
if (rectofind) {
2023-01-06 15:51:58 +01:00
// console.log('rectofind', rectofind)
circuit.value = rectofind
}
}
2022-08-26 03:32:50 +02:00
}
function getImgCircuit(circuit: ICircuit) {
return userStore.getImgByCircuit(circuit)
}
function naviga(path: string) {
$router.push(path)
}
function setCmd(cmd: number, myusername: string, value: any = '') {
emit('setCmd', cmd, myusername, value)
}
function myusername() {
return userStore.my.username
}
2023-08-27 23:56:18 +02:00
function getRegulation(reg: string) {
2025-03-01 14:14:43 +01:00
const strreg = reg + ''
2023-08-27 23:56:18 +02:00
if (!reg) {
2025-03-01 14:14:43 +01:00
let name = getNameCircuit()
const mystringa = t('circuit.regolamento', { nomecircuito: name })
2023-08-27 23:56:18 +02:00
return mystringa
} else {
return reg
}
}
2022-08-26 03:32:50 +02:00
onMounted(mounted)
return {
circuit,
2023-08-27 23:56:18 +02:00
getRegulation,
2022-08-26 03:32:50 +02:00
costanti,
getImgCircuit,
naviga,
setCmd,
shared_consts,
userStore,
tools,
table,
myusername,
2022-09-14 11:31:48 +02:00
circuitStore,
t,
account,
qtarem,
saldo,
saldo_pend,
2022-10-21 21:25:54 +02:00
globalStore,
showingtooltip,
showrules,
requestToEnterCircuit,
groupnameSel,
fidoConcessoUtente,
2022-08-26 03:32:50 +02:00
}
},
})