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'
|
|
|
|
|
import { tools } from '@store/Modules/tools'
|
|
|
|
|
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
|
|
|
|
|
import { useUserStore } from '@store/UserStore'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore'
|
|
|
|
|
import { useI18n } from '@/boot/i18n'
|
|
|
|
|
import { toolsext } from '@store/Modules/toolsext'
|
|
|
|
|
import { useQuasar } from 'quasar'
|
|
|
|
|
import { costanti } from '@costanti'
|
|
|
|
|
import { IUserFields, IUserProfile } from 'model'
|
2022-01-07 01:16:46 +01:00
|
|
|
import { shared_consts } from '@/common/shared_vuejs'
|
2022-01-05 19:11:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'myuser',
|
|
|
|
|
components: { CProfile, CTitleBanner, CMyFieldDb, CSkill, CDateTime },
|
|
|
|
|
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('')
|
|
|
|
|
const filter = ref(costanti.FRIENDS)
|
|
|
|
|
const listFriends = ref([])
|
|
|
|
|
const listTrusted = ref([])
|
|
|
|
|
|
|
|
|
|
const filtroutente = ref(<any[]>[])
|
|
|
|
|
|
|
|
|
|
const listfriendsfiltered = computed(() => {
|
|
|
|
|
let arr: any[] = []
|
|
|
|
|
if (filter.value === costanti.FRIENDS) {
|
|
|
|
|
arr = listFriends.value
|
|
|
|
|
}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-05 19:11:47 +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)
|
|
|
|
|
}else if (filter.value === costanti.REEJECTED) {
|
|
|
|
|
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 }]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mounted() {
|
|
|
|
|
username.value = userStore.my.username
|
|
|
|
|
loadFriends()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getImgUser(profile: IUserFields) {
|
|
|
|
|
return userStore.getImgByProfile(profile)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 01:16:46 +01:00
|
|
|
function setRequestTrust(usernameDest: string, value: any) {
|
|
|
|
|
userStore.setFriendsCmd($q, t, username.value, usernameDest, shared_consts.FRIENDSCMD.SETTRUST, value).then((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
const myuser: IUserFields|undefined = listTrusted.value.find((rec: IUserFields) => rec.username === usernameDest )
|
|
|
|
|
if (myuser) {
|
|
|
|
|
listFriends.value.push(myuser)
|
|
|
|
|
listTrusted.value = listTrusted.value.filter((rec: IUserFields) => rec.username !== usernameDest)
|
|
|
|
|
}
|
|
|
|
|
tools.showPositiveNotif($q, t('db.trusted'))
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
tools.showNegativeNotif($q, t('db.recfailed'))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeFromMyFriends(usernameDest: string) {
|
|
|
|
|
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'))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function blockUser(usernameDest: string) {
|
|
|
|
|
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.blockedfriend'))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function naviga(path: string) {
|
|
|
|
|
$router.push(path)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 19:11:47 +01:00
|
|
|
onMounted(mounted)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
listfriends: listFriends,
|
|
|
|
|
tools,
|
|
|
|
|
costanti,
|
|
|
|
|
getImgUser,
|
|
|
|
|
filtroutente,
|
|
|
|
|
filter,
|
|
|
|
|
listfriendsfiltered,
|
|
|
|
|
numFriends,
|
|
|
|
|
numAskTrust,
|
2022-01-07 01:16:46 +01:00
|
|
|
numTrusted,
|
|
|
|
|
numRejected,
|
|
|
|
|
setRequestTrust,
|
|
|
|
|
removeFromMyFriends,
|
|
|
|
|
blockUser,
|
|
|
|
|
naviga,
|
2022-01-05 19:11:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|