Introduced EntityList.vue and implemented it in projects
This commit is contained in:
179
components/EntityList.vue
Normal file
179
components/EntityList.vue
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
type: {
|
||||||
|
required: true,
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
items: {
|
||||||
|
required: true,
|
||||||
|
type: Array
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const {type} = props
|
||||||
|
|
||||||
|
defineShortcuts({
|
||||||
|
'/': () => {
|
||||||
|
//console.log(searchinput)
|
||||||
|
//searchinput.value.focus()
|
||||||
|
document.getElementById("searchinput").focus()
|
||||||
|
},
|
||||||
|
'+': () => {
|
||||||
|
router.push(`/${type}/create`)
|
||||||
|
},
|
||||||
|
'Enter': {
|
||||||
|
usingInput: true,
|
||||||
|
handler: () => {
|
||||||
|
router.push(`/${type}/show/${filteredRows.value[selectedItem.value].id}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'arrowdown': () => {
|
||||||
|
if(selectedItem.value < filteredRows.value.length - 1) {
|
||||||
|
selectedItem.value += 1
|
||||||
|
} else {
|
||||||
|
selectedItem.value = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'arrowup': () => {
|
||||||
|
if(selectedItem.value === 0) {
|
||||||
|
selectedItem.value = filteredRows.value.length - 1
|
||||||
|
} else {
|
||||||
|
selectedItem.value -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const dataStore = useDataStore()
|
||||||
|
|
||||||
|
const dataType = dataStore.dataTypes[type]
|
||||||
|
|
||||||
|
//Old
|
||||||
|
|
||||||
|
const selectedItem = ref(0)
|
||||||
|
|
||||||
|
|
||||||
|
const selectedColumns = ref(dataType.templateColumns)
|
||||||
|
const columns = computed(() => dataType.templateColumns.filter((column) => selectedColumns.value.includes(column)))
|
||||||
|
|
||||||
|
const searchString = ref('')
|
||||||
|
|
||||||
|
const selectableFilters = ref(dataType.filters.map(i => i.name))
|
||||||
|
const selectedFilters = ref(dataType.filters.filter(i => i.default).map(i => i.name) || [])
|
||||||
|
console.log(selectableFilters)
|
||||||
|
console.log(selectedFilters)
|
||||||
|
|
||||||
|
const filteredRows = computed(() => {
|
||||||
|
|
||||||
|
let tempItems = props.items
|
||||||
|
|
||||||
|
if(selectedFilters.value.length > 0) {
|
||||||
|
selectedFilters.value.forEach(filterName => {
|
||||||
|
let filter = dataType.filters.find(i => i.name === filterName)
|
||||||
|
|
||||||
|
tempItems = tempItems.filter(filter.filterFunction)
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return useSearch(searchString.value, tempItems)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<UDashboardNavbar :title="dataType.label" :badge="filteredRows.length">
|
||||||
|
<template #right>
|
||||||
|
<UInput
|
||||||
|
id="searchinput"
|
||||||
|
v-model="searchString"
|
||||||
|
icon="i-heroicons-funnel"
|
||||||
|
autocomplete="off"
|
||||||
|
placeholder="Suche..."
|
||||||
|
class="hidden lg:block"
|
||||||
|
@keydown.esc="$event.target.blur()"
|
||||||
|
>
|
||||||
|
<template #trailing>
|
||||||
|
<UKbd value="/" />
|
||||||
|
</template>
|
||||||
|
</UInput>
|
||||||
|
|
||||||
|
<UButton v-if="useRole().checkRight(`${type}-create`)" @click="router.push(`/${type}/create`)">+ {{dataType.labelSingle}}</UButton>
|
||||||
|
</template>
|
||||||
|
</UDashboardNavbar>
|
||||||
|
|
||||||
|
<UDashboardToolbar>
|
||||||
|
<template #left v-if="$slots['left-toolbar']">
|
||||||
|
<slot name="left-toolbar"/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #right>
|
||||||
|
<USelectMenu
|
||||||
|
v-model="selectedColumns"
|
||||||
|
icon="i-heroicons-adjustments-horizontal-solid"
|
||||||
|
:options="dataType.templateColumns"
|
||||||
|
multiple
|
||||||
|
class="hidden lg:block"
|
||||||
|
by="key"
|
||||||
|
>
|
||||||
|
<template #label>
|
||||||
|
Spalten
|
||||||
|
</template>
|
||||||
|
</USelectMenu>
|
||||||
|
<USelectMenu
|
||||||
|
icon="i-heroicons-adjustments-horizontal-solid"
|
||||||
|
multiple
|
||||||
|
v-model="selectedFilters"
|
||||||
|
:options="selectableFilters"
|
||||||
|
>
|
||||||
|
<template #label>
|
||||||
|
Filter
|
||||||
|
</template>
|
||||||
|
</USelectMenu>
|
||||||
|
</template>
|
||||||
|
</UDashboardToolbar>
|
||||||
|
|
||||||
|
<UTable
|
||||||
|
:rows="filteredRows"
|
||||||
|
:columns="columns"
|
||||||
|
class="w-full"
|
||||||
|
:ui="{ divide: 'divide-gray-200 dark:divide-gray-800' }"
|
||||||
|
@select="(i) => router.push(`/projects/show/${i.id}`) "
|
||||||
|
:empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: `Keine ${dataType.label} anzuzeigen` }"
|
||||||
|
>
|
||||||
|
<template
|
||||||
|
v-for="column in dataType.templateColumns"
|
||||||
|
v-slot:[`${column.key}-data`]="{row}">
|
||||||
|
<component v-if="column.component" :is="column.component" :row="row"></component>
|
||||||
|
<span v-else>{{row[column.key]}}</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <template #name-data="{row}">
|
||||||
|
<span class="text-primary-500 font-bold" v-if="row === filteredRows[selectedItem]">{{row.name}}</span>
|
||||||
|
<span v-else>{{row.name}}</span>
|
||||||
|
</template>
|
||||||
|
<template #projecttype-data="{row}">
|
||||||
|
{{row.projecttype ? row.projecttype.name : ""}}
|
||||||
|
</template>
|
||||||
|
<template #phase-data="{row}">
|
||||||
|
{{getActivePhaseLabel(row)}}
|
||||||
|
</template>
|
||||||
|
<template #customer-data="{row}">
|
||||||
|
{{row.customer ? row.customer.name : ""}}
|
||||||
|
</template>
|
||||||
|
<template #plant-data="{row}">
|
||||||
|
{{row.plant ? row.plant.name : ""}}
|
||||||
|
</template>
|
||||||
|
<template #users-data="{row}">
|
||||||
|
{{row.users.map(i => dataStore.getProfileById(i).fullName).join(", ")}}
|
||||||
|
</template>-->
|
||||||
|
</UTable>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
13
components/columnRenderings/customer.vue
Normal file
13
components/columnRenderings/customer.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
row: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span>{{props.row.customer ? props.row.customer.name : ''}}</span>
|
||||||
|
</template>
|
||||||
13
components/columnRenderings/plant.vue
Normal file
13
components/columnRenderings/plant.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
row: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span>{{props.row.plant ? props.row.plant.name : ''}}</span>
|
||||||
|
</template>
|
||||||
13
components/columnRenderings/projecttype.vue
Normal file
13
components/columnRenderings/projecttype.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<script setup>
|
||||||
|
const props = defineProps({
|
||||||
|
row: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<span>{{props.row.projecttype ? props.row.projecttype.name : ''}}</span>
|
||||||
|
</template>
|
||||||
@@ -1,194 +1,36 @@
|
|||||||
<template>
|
<template>
|
||||||
<UDashboardNavbar title="Projekte" :badge="filteredRows.length">
|
<EntityList
|
||||||
<template #right>
|
type="projects"
|
||||||
<UInput
|
:items="items"
|
||||||
id="searchinput"
|
:filters="filters"
|
||||||
v-model="searchString"
|
></EntityList>
|
||||||
icon="i-heroicons-funnel"
|
|
||||||
autocomplete="off"
|
|
||||||
placeholder="Suche..."
|
|
||||||
class="hidden lg:block"
|
|
||||||
@keydown.esc="$event.target.blur()"
|
|
||||||
>
|
|
||||||
<template #trailing>
|
|
||||||
<UKbd value="/" />
|
|
||||||
</template>
|
|
||||||
</UInput>
|
|
||||||
|
|
||||||
<UButton @click="router.push(`/projects/create`)">+ Projekt</UButton>
|
|
||||||
</template>
|
|
||||||
</UDashboardNavbar>
|
|
||||||
|
|
||||||
<UDashboardToolbar>
|
|
||||||
<template #left>
|
|
||||||
|
|
||||||
|
|
||||||
<UCheckbox
|
|
||||||
label="Abgeschlossene anzeigen"
|
|
||||||
v-model="showFinished"
|
|
||||||
class="mt-1"
|
|
||||||
/>
|
|
||||||
<USelectMenu
|
|
||||||
class="ml-3 w-36"
|
|
||||||
v-model="selectedTypes"
|
|
||||||
:options="projecttypes"
|
|
||||||
value-attribute="id"
|
|
||||||
option-attribute="name"
|
|
||||||
multiple
|
|
||||||
>
|
|
||||||
<template #label>
|
|
||||||
Typen
|
|
||||||
</template>
|
|
||||||
</USelectMenu>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #right>
|
|
||||||
<USelectMenu
|
|
||||||
v-model="selectedColumns"
|
|
||||||
icon="i-heroicons-adjustments-horizontal-solid"
|
|
||||||
:options="templateColumns"
|
|
||||||
multiple
|
|
||||||
class="hidden lg:block"
|
|
||||||
by="key"
|
|
||||||
>
|
|
||||||
<template #label>
|
|
||||||
Spalten
|
|
||||||
</template>
|
|
||||||
</USelectMenu>
|
|
||||||
</template>
|
|
||||||
</UDashboardToolbar>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<UTable
|
|
||||||
:rows="filteredRows"
|
|
||||||
:columns="columns"
|
|
||||||
class="w-full"
|
|
||||||
:ui="{ divide: 'divide-gray-200 dark:divide-gray-800' }"
|
|
||||||
@select="(i) => router.push(`/projects/show/${i.id}`) "
|
|
||||||
:empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: 'Keine Projekte anzuzeigen' }"
|
|
||||||
>
|
|
||||||
<template #name-data="{row}">
|
|
||||||
<span class="text-primary-500 font-bold" v-if="row === filteredRows[selectedItem]">{{row.name}}</span>
|
|
||||||
<span v-else>{{row.name}}</span>
|
|
||||||
</template>
|
|
||||||
<template #projecttype-data="{row}">
|
|
||||||
{{row.projecttype ? row.projecttype.name : ""}}
|
|
||||||
</template>
|
|
||||||
<template #phase-data="{row}">
|
|
||||||
{{getActivePhaseLabel(row)}}
|
|
||||||
</template>
|
|
||||||
<template #customer-data="{row}">
|
|
||||||
{{row.customer ? row.customer.name : ""}}
|
|
||||||
</template>
|
|
||||||
<template #plant-data="{row}">
|
|
||||||
{{row.plant ? row.plant.name : ""}}
|
|
||||||
</template>
|
|
||||||
<template #users-data="{row}">
|
|
||||||
{{row.users.map(i => dataStore.getProfileById(i).fullName).join(", ")}}
|
|
||||||
</template>
|
|
||||||
</UTable>
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import EntityList from "~/components/EntityList.vue";
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: "auth"
|
middleware: "auth"
|
||||||
})
|
})
|
||||||
|
|
||||||
defineShortcuts({
|
|
||||||
'/': () => {
|
|
||||||
//console.log(searchinput)
|
|
||||||
//searchinput.value.focus()
|
|
||||||
document.getElementById("searchinput").focus()
|
|
||||||
},
|
|
||||||
'+': () => {
|
|
||||||
router.push("/projects/create")
|
|
||||||
},
|
|
||||||
'Enter': {
|
|
||||||
usingInput: true,
|
|
||||||
handler: () => {
|
|
||||||
router.push(`/projects/show/${filteredRows.value[selectedItem.value].id}`)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'arrowdown': () => {
|
|
||||||
if(selectedItem.value < filteredRows.value.length - 1) {
|
|
||||||
selectedItem.value += 1
|
|
||||||
} else {
|
|
||||||
selectedItem.value = 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'arrowup': () => {
|
|
||||||
if(selectedItem.value === 0) {
|
|
||||||
selectedItem.value = filteredRows.value.length - 1
|
|
||||||
} else {
|
|
||||||
selectedItem.value -= 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const items = ref([])
|
const items = ref([])
|
||||||
const selectedItem = ref(0)
|
|
||||||
const projecttypes = ref([])
|
|
||||||
const selectedTypes = ref([])
|
|
||||||
|
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
items.value = await useSupabaseSelect("projects","*, customer (name), plant(name), projecttype(name, id)","projectNumber")
|
let profiles = (await useSupabaseSelect("profiles"))
|
||||||
projecttypes.value = await useSupabaseSelect("projecttypes","*")
|
items.value = (await useSupabaseSelect("projects","*, customer (name), plant(name), projecttype(name, id)","projectNumber")).map(project => {
|
||||||
selectedTypes.value = projecttypes.value.map(i => i.id)
|
return {
|
||||||
|
...project,
|
||||||
|
profiles: project.profiles.map(x => profiles.find(z => z.id === x).fullName).join(", "),
|
||||||
|
phase: getActivePhaseLabel(project)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setupPage()
|
|
||||||
|
|
||||||
const templateColumns = [
|
|
||||||
{
|
|
||||||
key: "projectNumber",
|
|
||||||
label: "Projektnummer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "projecttype",
|
|
||||||
label: "Typ"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "phase",
|
|
||||||
label: "Phase"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "measure",
|
|
||||||
label: "Gewerk"
|
|
||||||
},{
|
|
||||||
key: "name",
|
|
||||||
label: "Name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "customer",
|
|
||||||
label: "Kunde",
|
|
||||||
sortable: true
|
|
||||||
},/*
|
|
||||||
{
|
|
||||||
key: "notes",
|
|
||||||
label: "Notizen",
|
|
||||||
sortable: true
|
|
||||||
},*/
|
|
||||||
{
|
|
||||||
key: "plant",
|
|
||||||
label: "Objekt",
|
|
||||||
sortable: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "users",
|
|
||||||
label: "Benutzer",
|
|
||||||
sortable: true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const selectedColumns = ref(templateColumns)
|
|
||||||
const columns = computed(() => templateColumns.filter((column) => selectedColumns.value.includes(column)))
|
|
||||||
|
|
||||||
|
|
||||||
const getActivePhaseLabel = (item) => {
|
const getActivePhaseLabel = (item) => {
|
||||||
if(item.phases) {
|
if(item.phases) {
|
||||||
if(item.phases.length > 0) {
|
if(item.phases.length > 0) {
|
||||||
@@ -204,29 +46,6 @@ const getActivePhaseLabel = (item) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupPage()
|
||||||
|
|
||||||
const searchString = ref('')
|
|
||||||
const showFinished = ref(false)
|
|
||||||
|
|
||||||
const filteredRows = computed(() => {
|
|
||||||
let temp = items.value.map(item => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
phaseLabel: getActivePhaseLabel(item)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if(showFinished.value) {
|
|
||||||
temp = temp.filter(i => i.phaseLabel === "Abgeschlossen")
|
|
||||||
} else {
|
|
||||||
temp = temp.filter(i => i.phaseLabel !== "Abgeschlossen")
|
|
||||||
}
|
|
||||||
|
|
||||||
temp = temp.filter(i => !i.projecttype || selectedTypes.value.includes(i.projecttype.id))
|
|
||||||
|
|
||||||
if(!searchString.value) {
|
|
||||||
return temp
|
|
||||||
}
|
|
||||||
return useSearch(searchString.value, temp)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
@@ -5,6 +5,10 @@ import {useNumberRange} from "~/composables/useNumberRange.js";
|
|||||||
|
|
||||||
//const supabase = createClient('https://uwppvcxflrcsibuzsbil.supabase.co','eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA5MzgxOTQsImV4cCI6MjAxNjUxNDE5NH0.CkxYSQH0uLfwx9GVUlO6AYMU2FMLAxGMrwEKvyPv7Oo')
|
//const supabase = createClient('https://uwppvcxflrcsibuzsbil.supabase.co','eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDA5MzgxOTQsImV4cCI6MjAxNjUxNDE5NH0.CkxYSQH0uLfwx9GVUlO6AYMU2FMLAxGMrwEKvyPv7Oo')
|
||||||
|
|
||||||
|
import projecttype from "~/components/columnRenderings/projecttype.vue"
|
||||||
|
import customer from "~/components/columnRenderings/customer.vue"
|
||||||
|
import plant from "~/components/columnRenderings/plant.vue"
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const useDataStore = defineStore('data', () => {
|
export const useDataStore = defineStore('data', () => {
|
||||||
|
|
||||||
@@ -60,6 +64,54 @@ export const useDataStore = defineStore('data', () => {
|
|||||||
redirect:true,
|
redirect:true,
|
||||||
historyItemHolder: "project",
|
historyItemHolder: "project",
|
||||||
numberRangeHolder: "projectNumber",
|
numberRangeHolder: "projectNumber",
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: "Abgeschlossen",
|
||||||
|
default: true,
|
||||||
|
"filterFunction": function (row) {
|
||||||
|
if(row.phases && row.phases.length > 0) {
|
||||||
|
return row.phases.find(i => i.active).label !== "Abgeschlossen";
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
templateColumns: [
|
||||||
|
{
|
||||||
|
key: "projectNumber",
|
||||||
|
label: "Projektnummer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "projecttype",
|
||||||
|
label: "Typ",
|
||||||
|
component: projecttype
|
||||||
|
},{
|
||||||
|
key: "phase",
|
||||||
|
label: "Phase"
|
||||||
|
},{
|
||||||
|
key: "name",
|
||||||
|
label: "Name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "customer",
|
||||||
|
label: "Kunde",
|
||||||
|
component: customer
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "notes",
|
||||||
|
label: "Notizen",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "plant",
|
||||||
|
label: "Objekt",
|
||||||
|
component: plant
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "profiles",
|
||||||
|
label: "Benutzer"
|
||||||
|
}]
|
||||||
},
|
},
|
||||||
vehicles: {
|
vehicles: {
|
||||||
label: "Fahrzeuge",
|
label: "Fahrzeuge",
|
||||||
|
|||||||
Reference in New Issue
Block a user