2022-01-05 19:11:47 +01:00
|
|
|
import { CMyFieldDb } from '@/components/CMyFieldDb'
|
|
|
|
|
import { CTitleBanner } from '@/components/CTitleBanner'
|
|
|
|
|
import { CProfile } from '@/components/CProfile'
|
|
|
|
|
import { CSkill } from '@/components/CSkill'
|
|
|
|
|
import { CDateTime } from '@/components/CDateTime'
|
2022-01-12 00:38:31 +01:00
|
|
|
import { CGridTableRec } from '@/components/CGridTableRec'
|
|
|
|
|
import { CMyUser } from '@/components/CMyUser'
|
2022-01-05 19:11:47 +01:00
|
|
|
import { tools } from '@store/Modules/tools'
|
2022-01-12 00:38:31 +01:00
|
|
|
import { computed, defineComponent, onMounted, ref } from 'vue'
|
2022-01-05 19:11:47 +01:00
|
|
|
import { useUserStore } from '@store/UserStore'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
import { useI18n } from '@/boot/i18n'
|
|
|
|
|
import { useQuasar } from 'quasar'
|
|
|
|
|
import { costanti } from '@costanti'
|
2022-01-12 00:38:31 +01:00
|
|
|
import { ISearchList, IUserFields } from 'model'
|
2022-01-07 01:16:46 +01:00
|
|
|
import { shared_consts } from '@/common/shared_vuejs'
|
2022-01-12 00:38:31 +01:00
|
|
|
import { colmyUserPeople } from '@store/Modules/fieldsTable'
|
2022-01-05 19:11:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'myuser',
|
2022-01-12 00:38:31 +01:00
|
|
|
components: { CProfile, CTitleBanner, CMyFieldDb, CSkill, CDateTime, CGridTableRec, CMyUser},
|
2022-01-05 19:11:47 +01:00
|
|
|
props: {},
|
|
|
|
|
setup() {
|
|
|
|
|
const userStore = useUserStore()
|
2022-01-07 01:16:46 +01:00
|
|
|
const $router = useRouter()
|
2022-01-05 19:11:47 +01:00
|
|
|
const $route = useRoute()
|
2022-01-07 01:16:46 +01:00
|
|
|
const $q = useQuasar()
|
2022-01-05 19:11:47 +01:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
|
|
const username = ref('')
|
2022-01-12 00:38:31 +01:00
|
|
|
const filter = ref(costanti.FIND_PEOPLE)
|
|
|
|
|
const listFriends = ref(<IUserFields[]>[])
|
|
|
|
|
const listTrusted = ref(<IUserFields[]>[])
|
2022-01-05 19:11:47 +01:00
|
|
|
|
|
|
|
|
const filtroutente = ref(<any[]>[])
|
|
|
|
|
|
2022-01-12 00:38:31 +01:00
|
|
|
const arrfilterand: any = ref([])
|
|
|
|
|
const filtercustom: any = ref([])
|
|
|
|
|
const searchList = ref(<ISearchList[]>[])
|
|
|
|
|
|
2022-01-05 19:11:47 +01:00
|
|
|
const listfriendsfiltered = computed(() => {
|
|
|
|
|
let arr: any[] = []
|
|
|
|
|
if (filter.value === costanti.FRIENDS) {
|
|
|
|
|
arr = listFriends.value
|
2022-01-12 00:38:31 +01:00
|
|
|
} else if (filter.value === costanti.ASK_TRUST) {
|
2022-01-07 01:16:46 +01:00
|
|
|
arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador === undefined)
|
2022-01-12 00:38:31 +01:00
|
|
|
} else if (filter.value === costanti.TRUSTED) {
|
2022-01-07 01:16:46 +01:00
|
|
|
arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador)
|
2022-01-12 00:38:31 +01:00
|
|
|
} else if (filter.value === costanti.REEJECTED) {
|
2022-01-07 01:16:46 +01:00
|
|
|
arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador === false)
|
2022-01-05 19:11:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arr
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const numFriends = computed(() => {
|
|
|
|
|
const arr = listFriends.value
|
|
|
|
|
return (arr) ? arr.length : 0
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const numAskTrust = computed(() => {
|
2022-01-07 01:16:46 +01:00
|
|
|
const arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador === undefined)
|
2022-01-05 19:11:47 +01:00
|
|
|
return (arr) ? arr.length : 0
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-07 01:16:46 +01:00
|
|
|
const numTrusted = computed(() => {
|
2022-01-05 19:11:47 +01:00
|
|
|
const arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador)
|
|
|
|
|
return (arr) ? arr.length : 0
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-07 01:16:46 +01:00
|
|
|
const numRejected = computed(() => {
|
|
|
|
|
const arr = listTrusted.value.filter((user: IUserFields) => user.verified_by_aportador === false)
|
|
|
|
|
return (arr) ? arr.length : 0
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-05 19:11:47 +01:00
|
|
|
function loadFriends() {
|
|
|
|
|
// Carica il profilo di quest'utente
|
|
|
|
|
if (username.value) {
|
|
|
|
|
userStore.loadFriends(username.value).then((ris) => {
|
|
|
|
|
console.log('ris', ris)
|
|
|
|
|
if (ris) {
|
|
|
|
|
listFriends.value = ris.listFriends
|
|
|
|
|
listTrusted.value = ris.listTrusted
|
|
|
|
|
filtroutente.value = [{ userId: userStore.my._id }]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 01:16:46 +01:00
|
|
|
function setRequestTrust(usernameDest: string, value: any) {
|
2022-01-12 00:38:31 +01:00
|
|
|
let msg = ''
|
|
|
|
|
if (value) {
|
|
|
|
|
msg = t('db.domanda_trusted', { username: usernameDest })
|
|
|
|
|
} else {
|
|
|
|
|
msg = t('db.domanda_rejectedtrust', { username: usernameDest })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$q.dialog({
|
|
|
|
|
message: msg,
|
|
|
|
|
ok: {
|
|
|
|
|
label: t('dialog.yes'),
|
|
|
|
|
push: true
|
|
|
|
|
},
|
|
|
|
|
cancel: {
|
|
|
|
|
label: t('dialog.cancel')
|
|
|
|
|
},
|
|
|
|
|
title: t('db.domanda')
|
|
|
|
|
}).onOk(() => {
|
|
|
|
|
|
|
|
|
|
userStore.setFriendsCmd($q, t, username.value, usernameDest, shared_consts.FRIENDSCMD.SETTRUST, value).then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
const myuser: IUserFields = listTrusted.value.find((rec: IUserFields) => rec.username === usernameDest)!
|
|
|
|
|
if (myuser) {
|
|
|
|
|
myuser.verified_by_aportador = value
|
|
|
|
|
if (value) {
|
|
|
|
|
// ADD to Trusted
|
|
|
|
|
listFriends.value.push(myuser)
|
|
|
|
|
} else {
|
|
|
|
|
// REMOVE to Trusted and to Friends
|
|
|
|
|
listFriends.value = listFriends.value.filter((rec: IUserFields) => rec.username !== usernameDest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tools.showPositiveNotif($q, t('db.trusted'))
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
tools.showNegativeNotif($q, t('db.recfailed'))
|
2022-01-07 01:16:46 +01:00
|
|
|
}
|
2022-01-12 00:38:31 +01:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-01-07 01:16:46 +01:00
|
|
|
|
2022-01-12 00:38:31 +01:00
|
|
|
function addToMyFriends(usernameDest: string) {
|
|
|
|
|
$q.dialog({
|
|
|
|
|
message: t('db.domanda_addtofriend', { username: usernameDest }),
|
|
|
|
|
ok: { label: t('dialog.yes'), push: true },
|
|
|
|
|
cancel: { label: t('dialog.cancel') },
|
|
|
|
|
title: t('db.domanda')
|
|
|
|
|
}).onOk(() => {
|
|
|
|
|
|
|
|
|
|
userStore.setFriendsCmd($q, t, username.value, usernameDest, shared_consts.FRIENDSCMD.SETFRIEND, null)
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
console.log('res = ', res)
|
|
|
|
|
listFriends.value = [...listFriends.value, res]
|
|
|
|
|
tools.showPositiveNotif($q, t('db.addedfriend'))
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-01-07 01:16:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeFromMyFriends(usernameDest: string) {
|
2022-01-12 00:38:31 +01:00
|
|
|
$q.dialog({
|
|
|
|
|
message: t('db.domanda_removefriend', { username: usernameDest }),
|
|
|
|
|
ok: { label: t('dialog.yes'), push: true },
|
|
|
|
|
cancel: { label: t('dialog.cancel') },
|
|
|
|
|
title: t('db.domanda')
|
|
|
|
|
}).onOk(() => {
|
|
|
|
|
|
|
|
|
|
userStore.setFriendsCmd($q, t, username.value, usernameDest, shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS, null).then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
listFriends.value = listFriends.value.filter((rec: IUserFields) => rec.username !== usernameDest)
|
|
|
|
|
tools.showPositiveNotif($q, t('db.removedfriend'))
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-01-07 01:16:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blockUser(usernameDest: string) {
|
2022-01-12 00:38:31 +01:00
|
|
|
$q.dialog({
|
|
|
|
|
message: t('db.domanda_blockuser', { username: usernameDest }),
|
|
|
|
|
ok: { label: t('dialog.yes'), push: true },
|
|
|
|
|
cancel: { label: t('dialog.cancel') },
|
|
|
|
|
title: t('db.domanda')
|
|
|
|
|
}).onOk(() => {
|
|
|
|
|
userStore.setFriendsCmd($q, t, username.value, usernameDest, shared_consts.FRIENDSCMD.BLOCK_USER, null).then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
listFriends.value = listFriends.value.filter((rec: IUserFields) => rec.username !== usernameDest)
|
|
|
|
|
tools.showPositiveNotif($q, t('db.blockedfriend'))
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-01-07 01:16:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 00:38:31 +01:00
|
|
|
function setCmd(cmd: number, usernameDest: string, value: any = '') {
|
|
|
|
|
if (cmd === shared_consts.FRIENDSCMD.SETTRUST) {
|
|
|
|
|
setRequestTrust(usernameDest, value)
|
|
|
|
|
} else if (cmd === shared_consts.FRIENDSCMD.REMOVE_FROM_MYFRIENDS) {
|
|
|
|
|
removeFromMyFriends(usernameDest)
|
|
|
|
|
} else if (cmd === shared_consts.FRIENDSCMD.BLOCK_USER) {
|
|
|
|
|
blockUser(usernameDest)
|
|
|
|
|
} else if (cmd === shared_consts.FRIENDSCMD.SETFRIEND) {
|
|
|
|
|
addToMyFriends(usernameDest)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mounted() {
|
|
|
|
|
username.value = userStore.my.username
|
|
|
|
|
loadFriends()
|
|
|
|
|
|
|
|
|
|
searchList.value = []
|
|
|
|
|
filtercustom.value = []
|
|
|
|
|
arrfilterand.value = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function extraparams() {
|
|
|
|
|
let lk_tab = 'users'
|
|
|
|
|
let lk_LF = 'userId'
|
|
|
|
|
let lk_FF = '_id'
|
|
|
|
|
let lk_as = 'user'
|
|
|
|
|
let af_objId_tab = 'myId'
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
lookup1: {
|
|
|
|
|
lk_tab,
|
|
|
|
|
lk_LF,
|
|
|
|
|
lk_FF,
|
|
|
|
|
lk_as,
|
|
|
|
|
af_objId_tab,
|
|
|
|
|
lk_proj: {
|
|
|
|
|
username: 1,
|
|
|
|
|
name: 1,
|
|
|
|
|
'profile.img': 1,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-07 01:16:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-05 19:11:47 +01:00
|
|
|
onMounted(mounted)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
listfriends: listFriends,
|
|
|
|
|
tools,
|
|
|
|
|
costanti,
|
2022-01-12 00:38:31 +01:00
|
|
|
shared_consts,
|
2022-01-05 19:11:47 +01:00
|
|
|
filtroutente,
|
|
|
|
|
filter,
|
|
|
|
|
listfriendsfiltered,
|
|
|
|
|
numFriends,
|
|
|
|
|
numAskTrust,
|
2022-01-07 01:16:46 +01:00
|
|
|
numTrusted,
|
|
|
|
|
numRejected,
|
2022-01-12 00:38:31 +01:00
|
|
|
arrfilterand,
|
|
|
|
|
filtercustom,
|
|
|
|
|
searchList,
|
|
|
|
|
colmyUserPeople,
|
|
|
|
|
extraparams,
|
|
|
|
|
setCmd,
|
2022-01-05 19:11:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|