import { defineComponent, onMounted, ref } from 'vue' import { computed } from 'vue' import { CMyPage } from '@src/components/CMyPage' import { CCopyBtn } from '@src/components/CCopyBtn' import { CKeyAndValue } from '@src/components/CKeyAndValue' import { CGridTableRec } from '@src/components/CGridTableRec' import { tools } from '@tools' import { static_data } from '@src/db/static_data' import { fieldsTable } from '@src/store/Modules/fieldsTable' import { shared_consts } from '@src/common/shared_vuejs' import { DefaultProfile, useUserStore } from '@store/UserStore' import { costanti } from '@costanti' import { useQuasar } from 'quasar' import { useNotifStore } from '@store/NotifStore' import type { INotif } from 'model' import type { IUserFields } from '@model/UserStore' import { useI18n } from 'vue-i18n' import MixinUsers from '@src/mixins/mixin-users' export default defineComponent({ name: 'userPanel', components: { CMyPage, CKeyAndValue, CCopyBtn }, setup() { const arrfilterand: any = ref([]) const $q = useQuasar() const search = ref('') const colVisib = ref('') const mycolumns = ref([]) const myuser = ref({ _id: '', username: '', name: '', surname: '', profile: DefaultProfile }) const risultato = ref('') const mynotif = ref('') const title = ref('') const notifdirtype = ref(1) const notifidtype = ref(1) const notifdirtypeTest = ref(1) const notifidtypeTest = ref(1) const listnotif = ref([]) const listnotiftype = ref([]) const listnotiftypeTest = ref([]) const { t } = useI18n(); const listnotifid = computed(() => { if (notifdirtype.value) { const mylist: any = shared_consts.TypeNotifs_Arr.find((rec: any) => rec.value === notifdirtype.value) if (mylist) { for (const rec of mylist.list) { rec.label = t(rec.labeltrans) } } return mylist.list } return [] }) const listnotifidTest = computed(() => { if (notifdirtypeTest.value) { const mylist: any = shared_consts.TypeNotifs_Test.find((rec: any) => rec.value === notifdirtypeTest.value) if (mylist) { for (const rec of mylist.list) { rec.label = t(rec.labeltrans) } } return mylist.list } return [] }) const userStore = useUserStore() const notifStore = useNotifStore() const { getMyUsername } = MixinUsers() async function mounted() { // search.value = tools.getCookie(tools.COOK_SEARCH + 'searchpanel') await refresh() listnotif.value = shared_consts.UsersNotif_Adv_List for (const rec of listnotif.value) { rec.label = t(rec.labeltrans) } listnotiftype.value = shared_consts.TypeNotifs_Arr for (const rec of listnotiftype.value) { rec.label = t(rec.labeltrans) } listnotiftypeTest.value = shared_consts.TypeNotifs_Test for (const rec of listnotiftypeTest.value) { rec.label = t(rec.labeltrans) } } function changeCol(newval: any) { // } async function refresh() { if (search.value) myuser.value = await userStore.loadUserPanel(search.value) else myuser.value = { _id: '', username: '', name: '', surname: '', profile: DefaultProfile } } function db_fieldsTable() { return fieldsTable } async function doSearch() { tools.setCookie(tools.COOK_SEARCH + 'searchpanel', search.value) await refresh() } async function exportListaEmail() { risultato.value = await tools.exportListaEmail() tools.copyStringToClipboard($q, risultato.value, false) } async function sendNotifToUser() { if (myuser.value) { const notif: INotif = { typedir: notifdirtype.value, typeid: notifidtype.value, sender: userStore.my.username, dest: myuser.value.username, descr: mynotif.value, title: title.value, } await notifStore.SendNotifEvent(notif) } } async function sendNotifToUserTest() { if (myuser.value) { const notif: INotif = { typedir: notifdirtypeTest.value, typeid: notifidtypeTest.value, sender: userStore.my.username, dest: myuser.value.username, descr: mynotif.value, title: title.value, } await notifStore.SendNotifEvent(notif) } } onMounted(mounted) return { arrfilterand, fieldsTable, search, tools, shared_consts, doSearch, changeCol, myuser, refresh, mycolumns, colVisib, exportListaEmail, sendNotifToUser, sendNotifToUserTest, risultato, mynotif, title, notifdirtype, notifidtype, notifdirtypeTest, notifidtypeTest, listnotif, listnotiftype, listnotiftypeTest, listnotifid, listnotifidTest, getMyUsername, t, userStore, } } })