refs #4797 feat(workerNotification): add cards
gitea/salix-front/pipeline/head There was a failure building this commit
Details
gitea/salix-front/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
cc13e3935e
commit
4de39452ca
|
@ -5,6 +5,8 @@ import { computed, onMounted, onUpdated, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
|
import CrudModel from 'components/CrudModel.vue';
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
id: {
|
id: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -14,75 +16,60 @@ const $props = defineProps({
|
||||||
});
|
});
|
||||||
const entityId = computed(() => $props.id || route.params.id);
|
const entityId = computed(() => $props.id || route.params.id);
|
||||||
|
|
||||||
onMounted(() => fetch());
|
|
||||||
onUpdated(() => console.log('updated'));
|
onUpdated(() => console.log('updated'));
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const quasar = useQuasar();
|
const quasar = useQuasar();
|
||||||
|
|
||||||
const notifications = ref([]);
|
|
||||||
|
|
||||||
async function fetch() {
|
|
||||||
try {
|
|
||||||
await axios
|
|
||||||
.get(`NotificationSubscriptions/${entityId.value}/getList`)
|
|
||||||
.then(async (res) => {
|
|
||||||
if (res.data) {
|
|
||||||
notifications.value = res.data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function disableNotification(notification) {
|
|
||||||
await axios
|
|
||||||
.delete(`NotificationSubscriptions/${notification.id}`)
|
|
||||||
.catch(() => (notification.active = true))
|
|
||||||
.then((res) => {
|
|
||||||
if (res.data) {
|
|
||||||
notification.id = null;
|
|
||||||
notification.active = false;
|
|
||||||
quasar.notify({
|
|
||||||
type: 'positive',
|
|
||||||
message: t('worker.notificationsManager.unsubscribed'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function toggleNotification(notification) {
|
async function toggleNotification(notification) {
|
||||||
if (!notification.active) {
|
if (notification.active) {
|
||||||
await disableNotification(notification);
|
await axios.delete(`NotificationSubscriptions/${notification.id}`);
|
||||||
} else {
|
notification.id = null;
|
||||||
await axios
|
notification.active = false;
|
||||||
.post(`NotificationSubscriptions`, {
|
return quasar.notify({
|
||||||
notificationFk: notification.notificationFk,
|
type: 'positive',
|
||||||
userFk: entityId.value,
|
message: t('worker.notificationsManager.unsubscribed'),
|
||||||
})
|
});
|
||||||
.catch(() => (notification.active = false))
|
|
||||||
.then((res) => {
|
|
||||||
if (res.data) {
|
|
||||||
notification.id = res.data.id;
|
|
||||||
quasar.notify({
|
|
||||||
type: 'positive',
|
|
||||||
message: t('worker.notificationsManager.subscribed'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.post(`NotificationSubscriptions`, {
|
||||||
|
notificationFk: notification.notificationFk,
|
||||||
|
userFk: entityId.value,
|
||||||
|
});
|
||||||
|
|
||||||
|
notification.id = data.id;
|
||||||
|
quasar.notify({
|
||||||
|
type: 'positive',
|
||||||
|
message: t('worker.notificationsManager.subscribed'),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<CrudModel auto-load :url="`NotificationSubscriptions/${entityId}/getList`">
|
<CrudModel
|
||||||
|
auto-load
|
||||||
|
data-key="NotificationSubscriptions"
|
||||||
|
:url="`NotificationSubscriptions/${entityId}/getList`"
|
||||||
|
:default-remove="false"
|
||||||
|
>
|
||||||
<template #body="{ rows }">
|
<template #body="{ rows }">
|
||||||
<QList v-for="row in rows" :key="row.id">
|
<QList class="notificationList">
|
||||||
<QCard>
|
<QCard v-for="row in rows" :key="row.id" class="q-pa-md">
|
||||||
<QCardSection horizontal>
|
<QItem>
|
||||||
{{ row }}
|
<QItemSection avatar>
|
||||||
</QCardSection>
|
<QBtn
|
||||||
|
round
|
||||||
|
icon="mail"
|
||||||
|
:color="row.active ? 'green' : 'orange'"
|
||||||
|
@click="toggleNotification(row)"
|
||||||
|
/>
|
||||||
|
</QItemSection>
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>{{ row.name }}</QItemLabel>
|
||||||
|
<QItemLabel caption> {{ row.description }} </QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
|
</QItem>
|
||||||
</QCard>
|
</QCard>
|
||||||
</QList>
|
</QList>
|
||||||
</template>
|
</template>
|
||||||
|
@ -151,3 +138,11 @@ async function toggleNotification(notification) {
|
||||||
</QCard>
|
</QCard>
|
||||||
</QPage> -->
|
</QPage> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.notificationList {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(4, 1fr);
|
||||||
|
grid-gap: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue