other components... (2)
This commit is contained in:
18
src/components/CShareWithUs/CShareWithUs.scss
Executable file
18
src/components/CShareWithUs/CShareWithUs.scss
Executable file
@@ -0,0 +1,18 @@
|
||||
.zoom_data{
|
||||
font-size:1rem;
|
||||
font-weight: bold;
|
||||
text-shadow: .05rem .05rem .05rem #3d3d3d;
|
||||
color: green;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.id_conf{
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.note{
|
||||
font-style: italic;
|
||||
}
|
||||
262
src/components/CShareWithUs/CShareWithUs.ts
Executable file
262
src/components/CShareWithUs/CShareWithUs.ts
Executable file
@@ -0,0 +1,262 @@
|
||||
import { IParamsQuery, IShareWithUs } from 'model'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { CTitleBanner } from '@components'
|
||||
import { CCardState } from '../CCardState'
|
||||
import { CCopyBtn } from '../CCopyBtn'
|
||||
|
||||
import { computed, defineComponent, ref } from 'vue'
|
||||
import { useI18n } from '@src/boot/i18n'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { toolsext } from '@store/Modules/toolsext'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CShareWithUs',
|
||||
props: {
|
||||
mystr: {
|
||||
type: String,
|
||||
required: true,
|
||||
default: '',
|
||||
},
|
||||
myval: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
mybool: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
components: { CTitleBanner, CCardState, CCopyBtn },
|
||||
setup(props, { emit }) {
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n()
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const mydescrtext = ref('')
|
||||
|
||||
const listasharewithus = computed(() => {
|
||||
|
||||
const myarr = globalStore.sharewithus
|
||||
|
||||
return myarr.sort((a: any, b: any) => b.numshared! - a.numshared!)
|
||||
})
|
||||
|
||||
function listamyshare() {
|
||||
return userStore.my.profile.myshares
|
||||
}
|
||||
|
||||
function myload() {
|
||||
const sortBy = 'numshared'
|
||||
const descending = 1
|
||||
const myobj: any = {}
|
||||
if (descending)
|
||||
myobj[sortBy] = -1
|
||||
else
|
||||
myobj[sortBy] = 1
|
||||
|
||||
const params: IParamsQuery = {
|
||||
table: 'sharewithus',
|
||||
startRow: 0,
|
||||
endRow: 10000,
|
||||
filter: '',
|
||||
filterand: '',
|
||||
sortBy: myobj,
|
||||
descending,
|
||||
userId: userStore.my._id
|
||||
}
|
||||
|
||||
console.log('myload', params)
|
||||
|
||||
globalStore.loadTable(params).then((data) => {
|
||||
globalStore.sharewithus = data.rows
|
||||
})
|
||||
}
|
||||
|
||||
function recsharenow(mydescr: string): IShareWithUs {
|
||||
return {
|
||||
idapp: process.env.APP_ID,
|
||||
description: mydescr,
|
||||
userId: userStore.my._id,
|
||||
numshared: 0,
|
||||
rating: 0
|
||||
}
|
||||
}
|
||||
|
||||
function add_newshare(mydescr: string) {
|
||||
if (!mydescr)
|
||||
return false
|
||||
if (userStore.my.profile.myshares) {
|
||||
const recfound = userStore.my.profile.myshares.find((rec: IShareWithUs) => rec.description.toLowerCase() === mydescr.toLowerCase())
|
||||
if (!!recfound) {
|
||||
tools.showNegativeNotif($q, '"' + mydescr + '" è già presente!')
|
||||
return false
|
||||
}
|
||||
userStore.my.profile.myshares.push({ description: mydescr, rating: 5 })
|
||||
|
||||
const mydata = {
|
||||
'profile.myshares': userStore.my.profile.myshares
|
||||
}
|
||||
tools.saveFieldToServer($q, 'users', userStore.my._id, mydata)
|
||||
|
||||
const myrec = recsharenow(mydescr)
|
||||
|
||||
const updatedexistingrec = updaterecnow(mydescr, true)
|
||||
if (!updatedexistingrec) {
|
||||
tools.createNewRecord($q, 'sharewithus', myrec, false).then((myrecris) => {
|
||||
globalStore.sharewithus.push(myrecris)
|
||||
myload()
|
||||
mydescrtext.value = ''
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function updaterecnow(mydescr: string, add: boolean) {
|
||||
const recesistente = globalStore.sharewithus.find((rec) => rec.description.toLowerCase() === mydescr.toLowerCase())
|
||||
const indrec = globalStore.sharewithus.findIndex((rec) => rec.description.toLowerCase() === mydescr.toLowerCase())
|
||||
console.log('recesistente', recesistente)
|
||||
if (recesistente) {
|
||||
const mydatatosave = {
|
||||
id: recesistente._id,
|
||||
table: toolsext.TABSHAREWITHUS,
|
||||
fieldsvalue: recesistente
|
||||
}
|
||||
|
||||
if (recesistente.numshared) {
|
||||
if (add)
|
||||
recesistente.numshared++
|
||||
else {
|
||||
if (recesistente.numshared <= 0)
|
||||
return false
|
||||
else
|
||||
recesistente.numshared--
|
||||
}
|
||||
}
|
||||
|
||||
globalStore.saveFieldValue(mydatatosave).then((myrecris) => {
|
||||
if (myrecris) {
|
||||
globalStore.sharewithus[indrec] = recesistente
|
||||
myload()
|
||||
}
|
||||
mydescr = ''
|
||||
})
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function selected(value: any, shared: IShareWithUs) {
|
||||
shared.numshared!++
|
||||
tools.saveFieldToServer($q, 'sharewithus', shared._id, { numshared: shared.numshared })
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
function checkifICanRemove(shared: IShareWithUs) {
|
||||
// Controlla se questo è stato aggiunto da me
|
||||
const recfound = globalStore.sharewithus.find((rec) => rec.description.toLowerCase() === shared.description.toLowerCase())
|
||||
if (!!recfound)
|
||||
return recfound.userId === userStore.my._id
|
||||
else
|
||||
return true
|
||||
}
|
||||
|
||||
function removeShared(shared: IShareWithUs) {
|
||||
$q.dialog({
|
||||
message: 'Vuoi cancellare "' + shared.description + '" dalla tua lista ?',
|
||||
ok: {
|
||||
label: t('dialog.yes'),
|
||||
push: true
|
||||
},
|
||||
cancel: {
|
||||
label: t('dialog.cancel')
|
||||
},
|
||||
title: t('pages.sharedwithus')
|
||||
}).onOk(async () => {
|
||||
|
||||
const descr = shared.description
|
||||
|
||||
// Aggiorna Record Personale
|
||||
userStore.my.profile.myshares = userStore.my.profile.myshares.filter((rec) => rec.description !== descr)
|
||||
|
||||
const mydata = {
|
||||
'profile.myshares': userStore.my.profile.myshares
|
||||
}
|
||||
tools.saveFieldToServer($q, 'users', userStore.my._id, mydata)
|
||||
|
||||
const updatedexistingrec = updaterecnow(shared.description, false)
|
||||
if (!updatedexistingrec) {
|
||||
if (checkifICanRemove(shared)) {
|
||||
const myrec = globalStore.sharewithus.find((rec) => rec.description.toLowerCase() === descr.toLowerCase())
|
||||
if (!!myrec) {
|
||||
await globalStore.DeleteRec({ table: toolsext.TABSHAREWITHUS, id: myrec._id })
|
||||
.then((ris) => {
|
||||
console.log('DELETEREC ris=', ris)
|
||||
if (ris) {
|
||||
|
||||
// Aggiorna Array Globale
|
||||
globalStore.sharewithus = globalStore.sharewithus.filter((rec) => rec.description !== descr)
|
||||
myload()
|
||||
|
||||
console.log('globalStore.sharewithus', globalStore.sharewithus)
|
||||
tools.showPositiveNotif($q, t('db.deletedrecord'))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function findrec(descr: string) {
|
||||
if (userStore.my.profile.myshares) {
|
||||
if (userStore.my.profile.myshares.length === 0)
|
||||
return false
|
||||
return userStore.my.profile.myshares.find((rec) => rec.description.toLowerCase() === descr.toLowerCase())
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function mycolorbtn(shared: IShareWithUs) {
|
||||
if (findrec(shared.description)) {
|
||||
return 'positive'
|
||||
} else {
|
||||
return 'primary'
|
||||
}
|
||||
}
|
||||
|
||||
function geticon(shared: IShareWithUs) {
|
||||
if (findrec(shared.description))
|
||||
return undefined
|
||||
else
|
||||
return 'fas fa-plus'
|
||||
}
|
||||
|
||||
function getifdisable(shared: IShareWithUs) {
|
||||
return findrec(shared.description)
|
||||
}
|
||||
|
||||
myload()
|
||||
|
||||
return {
|
||||
listasharewithus,
|
||||
listamyshare,
|
||||
removeShared,
|
||||
mycolorbtn,
|
||||
geticon,
|
||||
getifdisable,
|
||||
mydescrtext,
|
||||
add_newshare,
|
||||
}
|
||||
}
|
||||
})
|
||||
103
src/components/CShareWithUs/CShareWithUs.vue
Executable file
103
src/components/CShareWithUs/CShareWithUs.vue
Executable file
@@ -0,0 +1,103 @@
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<CTitleBanner
|
||||
v-if="listasharewithus && listasharewithus.length > 0" class="q-pa-xs"
|
||||
:title="$t('pages.sharewithus')"
|
||||
bgcolor="bg-white" clcolor="text-blue"
|
||||
mystyle="" myclass="myshad" canopen="true">
|
||||
|
||||
|
||||
<div class="flex flex-center">
|
||||
|
||||
<div class="row animazione justify-center q-gutter-xs">
|
||||
|
||||
<q-item
|
||||
v-for="(shared) in listamyshare" :key="shared._id"
|
||||
class="q-mb-xs animated clBorderShare q-pa-sm" v-ripple>
|
||||
|
||||
<transition
|
||||
name="fade" mode="out-in"
|
||||
appear
|
||||
enter-active-class="animazione fadeIn"
|
||||
leave-active-class="animazione fadeOut">
|
||||
|
||||
<div class="row">
|
||||
<q-item-section class="text-center">
|
||||
<q-item-label class="title">{{ shared.description }}</q-item-label>
|
||||
<!--<q-item-label class="title">Condiviso: {{ shared.numshared }}</q-item-label>
|
||||
<q-item-label class="title">Rating: {{ shared.rating }}</q-item-label>-->
|
||||
</q-item-section>
|
||||
<!--<q-rating v-model="shared.rating" :max="5" size="16px" @input="change_rating(shared.rating, shared)"/>-->
|
||||
|
||||
|
||||
</div>
|
||||
</transition>
|
||||
<q-btn
|
||||
class="q-ml-sm" round icon="fas fa-times" color="white" text-color="grey" size="sm"
|
||||
@click="removeShared(shared)"></q-btn>
|
||||
|
||||
</q-item>
|
||||
</div>
|
||||
</div>
|
||||
</CTitleBanner>
|
||||
Scrivi cosa vorresti fare con noi:<br>
|
||||
<div class="row no-wrap justify-between q-pa-md q-gutter-sm">
|
||||
|
||||
<q-input v-model="mydescrtext" label="Cosa vorresti fare?" class="full-width">
|
||||
</q-input>
|
||||
<q-btn
|
||||
rounded label="Aggiungi" color="positive" @click="add_newshare(mydescrtext)"
|
||||
:disable="mydescrtext === ''"></q-btn>
|
||||
</div>
|
||||
|
||||
<CTitleBanner
|
||||
v-if="listasharewithus() && listasharewithus().length > 0" class="q-pa-xs"
|
||||
title="Graduatoria Attuale"
|
||||
bgcolor="bg-white" clcolor="text-blue"
|
||||
mystyle="" myclass="myshad" canopen="true">
|
||||
|
||||
|
||||
<div class="flex flex-center text-center">
|
||||
|
||||
<div class="animazione justify-center q-gutter-xs">
|
||||
|
||||
<q-item
|
||||
v-for="(shared) in listasharewithus" :key="shared._id"
|
||||
class="animated" style="padding: 4px;" v-ripple>
|
||||
|
||||
<transition
|
||||
name="fade" mode="out-in"
|
||||
appear
|
||||
enter-active-class="animazione fadeIn"
|
||||
leave-active-class="animazione fadeOut">
|
||||
|
||||
<div class="row no-wrap">
|
||||
|
||||
<q-btn
|
||||
dense size="md" :color="mycolorbtn(shared)" rounded :icon="geticon(shared)"
|
||||
:label="shared.description + ` (` + (shared.numshared + 1) + `)`"
|
||||
@click="add_newshare(shared.description)"></q-btn>
|
||||
<!--<q-item-label class="title">Condiviso: {{ shared.numshared }}</q-item-label>
|
||||
<q-item-label class="title">Rating: {{ shared.rating }}</q-item-label>-->
|
||||
<!--<q-rating v-model="shared.rating" :max="5" size="16px" @input="change_rating(shared.rating, shared)"/>-->
|
||||
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
</q-item>
|
||||
</div>
|
||||
</div>
|
||||
</CTitleBanner>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" src="./CShareWithUs.ts">
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './CShareWithUs.scss';
|
||||
</style>
|
||||
1
src/components/CShareWithUs/index.ts
Executable file
1
src/components/CShareWithUs/index.ts
Executable file
@@ -0,0 +1 @@
|
||||
export {default as CShareWithUs} from './CShareWithUs.vue'
|
||||
Reference in New Issue
Block a user