123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <script setup lang="ts">
- import { defineAsyncComponent, ref } from "vue";
- import Toast from "toasters";
- import { useModalsStore } from "@/stores/modals";
- import { TableColumn, TableFilter } from "@/types/advancedTable";
- import { useNewsModelStore } from "@/stores/models/news";
- const AdvancedTable = defineAsyncComponent(
- () => import("@/components/AdvancedTable.vue")
- );
- const QuickConfirm = defineAsyncComponent(
- () => import("@/components/QuickConfirm.vue")
- );
- const UserLink = defineAsyncComponent(
- () => import("@/components/UserLink.vue")
- );
- const columnDefault = ref<TableColumn>({
- sortable: true,
- hidable: true,
- defaultVisibility: "shown",
- draggable: true,
- resizable: true,
- minWidth: 150,
- maxWidth: 600
- });
- const columns = ref<TableColumn[]>([
- {
- name: "options",
- displayName: "Options",
- properties: ["_id"],
- sortable: false,
- hidable: false,
- resizable: false,
- minWidth: 85,
- defaultWidth: 85
- },
- {
- name: "status",
- displayName: "Status",
- properties: ["status"],
- sortProperty: "status",
- defaultWidth: 150
- },
- {
- name: "showToNewUsers",
- displayName: "Show to new users",
- properties: ["showToNewUsers"],
- sortProperty: "showToNewUsers",
- defaultWidth: 180
- },
- {
- name: "title",
- displayName: "Title",
- properties: ["title"],
- sortProperty: "title"
- },
- {
- name: "createdBy",
- displayName: "Created By",
- properties: ["createdBy"],
- sortProperty: "createdBy",
- defaultWidth: 150
- },
- {
- name: "markdown",
- displayName: "Markdown",
- properties: ["markdown"],
- sortProperty: "markdown"
- }
- ]);
- const filters = ref<TableFilter[]>([
- {
- name: "status",
- displayName: "Status",
- property: "status",
- filterTypes: ["contains", "exact", "regex"],
- defaultFilterType: "contains"
- },
- {
- name: "showToNewUsers",
- displayName: "Show to new users",
- property: "showToNewUsers",
- filterTypes: ["boolean"],
- defaultFilterType: "boolean"
- },
- {
- name: "title",
- displayName: "Title",
- property: "title",
- filterTypes: ["contains", "exact", "regex"],
- defaultFilterType: "contains"
- },
- {
- name: "createdBy",
- displayName: "Created By",
- property: "createdBy",
- filterTypes: ["contains", "exact", "regex"],
- defaultFilterType: "contains"
- },
- {
- name: "markdown",
- displayName: "Markdown",
- property: "markdown",
- filterTypes: ["contains", "exact", "regex"],
- defaultFilterType: "contains"
- }
- ]);
- const { openModal } = useModalsStore();
- const { deleteById, hasPermission } = useNewsModelStore();
- const remove = async (_id: string) => {
- const res = await deleteById(_id);
- new Toast(res.message);
- };
- </script>
- <template>
- <div class="admin-tab container">
- <page-metadata title="Admin | News" />
- <div class="card tab-info">
- <div class="info-row">
- <h1>News</h1>
- <p>Create and update news items</p>
- </div>
- <div class="button-row">
- <button
- v-if="hasPermission('data.news.create')"
- class="is-primary button"
- @click="
- openModal({
- modal: 'editNews',
- props: { createNews: true }
- })
- "
- >
- Create News Item
- </button>
- </div>
- </div>
- <advanced-table
- :column-default="columnDefault"
- :columns="columns"
- :filters="filters"
- model="news"
- :max-width="1200"
- >
- <template #column-options="slotProps">
- <div class="row-options">
- <button
- v-if="
- hasPermission(
- 'data.news.updateById',
- slotProps.item._id
- )
- "
- class="button is-primary icon-with-button material-icons"
- @click="
- openModal({
- modal: 'editNews',
- props: { newsId: slotProps.item._id }
- })
- "
- content="Edit News"
- v-tippy
- >
- edit
- </button>
- <quick-confirm
- v-if="
- hasPermission(
- 'data.news.deleteById',
- slotProps.item._id
- )
- "
- @confirm="remove(slotProps.item._id)"
- :disabled="slotProps.item.removed"
- >
- <button
- class="button is-danger icon-with-button material-icons"
- content="Remove News"
- v-tippy
- >
- delete_forever
- </button>
- </quick-confirm>
- </div>
- </template>
- <template #column-status="slotProps">
- <span :title="slotProps.item.status">{{
- slotProps.item.status
- }}</span>
- </template>
- <template #column-showToNewUsers="slotProps">
- <span :title="slotProps.item.showToNewUsers">{{
- slotProps.item.showToNewUsers
- }}</span>
- </template>
- <template #column-title="slotProps">
- <span :title="slotProps.item.title">{{
- slotProps.item.title
- }}</span>
- </template>
- <template #column-createdBy="slotProps">
- <user-link
- :user-id="slotProps.item.createdBy"
- :alt="slotProps.item.createdBy"
- />
- </template>
- <template #column-markdown="slotProps">
- <span :title="slotProps.item.markdown">{{
- slotProps.item.markdown
- }}</span>
- </template>
- </advanced-table>
- </div>
- </template>
|