Supabase Removals Frontend
This commit is contained in:
@@ -60,7 +60,6 @@ const router = useRouter()
|
|||||||
const createddocuments = ref([])
|
const createddocuments = ref([])
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
//createddocuments.value = (await useSupabaseSelect("createddocuments")).filter(i => !i.archived)
|
|
||||||
createddocuments.value = (await useEntities("createddocuments").select()).filter(i => !i.archived)
|
createddocuments.value = (await useEntities("createddocuments").select()).filter(i => !i.archived)
|
||||||
}
|
}
|
||||||
setup()
|
setup()
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const profileStore = useProfileStore()
|
|
||||||
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -28,8 +25,6 @@ const statementallocations = ref([])
|
|||||||
const incominginvoices = ref([])
|
const incominginvoices = ref([])
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
//statementallocations.value = (await supabase.from("statementallocations").select("*, bs_id(*)").eq("account", route.params.id).eq("tenant",profileStore.currentTenant).order("created_at",{ascending: true})).data
|
|
||||||
//incominginvoices.value = (await useSupabaseSelect("incominginvoices", "*, vendor(*)")).filter(i => i.accounts.find(x => x.account == route.params.id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ const emit = defineEmits(["updateNeeded"]);
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const profileStore = useProfileStore()
|
const profileStore = useProfileStore()
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
const renderedPhases = computed(() => {
|
const renderedPhases = computed(() => {
|
||||||
if(props.topLevelType === "projects" && props.item.phases) {
|
if(props.topLevelType === "projects" && props.item.phases) {
|
||||||
@@ -77,17 +76,6 @@ const changeActivePhase = async (key) => {
|
|||||||
|
|
||||||
const res = await useEntities("projects").update(item.id, {phases:item.phases,active_phase: item.phases.find(i => i.active).label})
|
const res = await useEntities("projects").update(item.id, {phases:item.phases,active_phase: item.phases.find(i => i.active).label})
|
||||||
|
|
||||||
//const {error:updateError} = await supabase.from("projects").update({phases: item.phases}).eq("id",item.id)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*const {error} = await supabase.from("historyitems").insert({
|
|
||||||
createdBy: profileStore.activeProfile.id,
|
|
||||||
tenant: profileStore.currentTenant,
|
|
||||||
text: `Aktive Phase zu "${phaseLabel}" gewechselt`,
|
|
||||||
project: item.id
|
|
||||||
})*/
|
|
||||||
|
|
||||||
emit("updateNeeded")
|
emit("updateNeeded")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
const profileStore = useProfileStore()
|
|
||||||
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
queryStringData: {
|
queryStringData: {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
const selectedItem = ref(0)
|
const selectedItem = ref(0)
|
||||||
const sort = ref({
|
const sort = ref({
|
||||||
column: dataType.supabaseSortColumn || "date",
|
column: dataType.sortColumn || "date",
|
||||||
direction: 'desc'
|
direction: 'desc'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const profileStore = useProfileStore()
|
const profileStore = useProfileStore()
|
||||||
|
|
||||||
const globalMessages = ref([])
|
const globalMessages = ref([])
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
let {data} = await supabase.from("globalmessages").select("*, profiles(id)")
|
let data = []
|
||||||
|
try {
|
||||||
|
data = await useNuxtApp().$api("/api/resource/globalmessages")
|
||||||
|
} catch (e) {
|
||||||
|
data = []
|
||||||
|
}
|
||||||
|
|
||||||
data = data.filter((message) => message.profiles.length === 0)
|
data = (data || []).filter((message) => !message.profiles || message.profiles.length === 0)
|
||||||
|
|
||||||
globalMessages.value = data
|
globalMessages.value = data
|
||||||
|
|
||||||
@@ -29,10 +32,17 @@ const showMessage = (message) => {
|
|||||||
showMessageModal.value = true
|
showMessageModal.value = true
|
||||||
}
|
}
|
||||||
const markMessageAsRead = async () => {
|
const markMessageAsRead = async () => {
|
||||||
await supabase.from("globalmessagesseen").insert({
|
try {
|
||||||
profile: profileStore.activeProfile.id,
|
await useNuxtApp().$api("/api/resource/globalmessagesseen", {
|
||||||
message: messageToShow.value.id,
|
method: "POST",
|
||||||
})
|
body: {
|
||||||
|
profile: profileStore.activeProfile.id,
|
||||||
|
message: messageToShow.value.id,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// noop: endpoint optional in newer backend versions
|
||||||
|
}
|
||||||
showMessageModal.value = false
|
showMessageModal.value = false
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ const { isHelpSlideoverOpen } = useDashboard()
|
|||||||
const { metaSymbol } = useShortcuts()
|
const { metaSymbol } = useShortcuts()
|
||||||
|
|
||||||
const shortcuts = ref(false)
|
const shortcuts = ref(false)
|
||||||
const dataStore = useDataStore()
|
|
||||||
const profileStore = useProfileStore()
|
|
||||||
const query = ref('')
|
const query = ref('')
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import {formatTimeAgo} from '@vueuse/core'
|
import {formatTimeAgo} from '@vueuse/core'
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
|
|
||||||
const { isNotificationsSlideoverOpen } = useDashboard()
|
const { isNotificationsSlideoverOpen } = useDashboard()
|
||||||
|
|
||||||
watch(isNotificationsSlideoverOpen, async (newVal,oldVal) => {
|
watch(isNotificationsSlideoverOpen, async (newVal,oldVal) => {
|
||||||
@@ -15,18 +12,24 @@ watch(isNotificationsSlideoverOpen, async (newVal,oldVal) => {
|
|||||||
const notifications = ref([])
|
const notifications = ref([])
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
notifications.value = (await supabase.from("notifications").select()).data
|
try {
|
||||||
|
notifications.value = await useNuxtApp().$api("/api/resource/notifications_items")
|
||||||
|
} catch (e) {
|
||||||
|
notifications.value = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
const setNotificationAsRead = async (notification) => {
|
const setNotificationAsRead = async (notification) => {
|
||||||
console.log(notification)
|
try {
|
||||||
|
await useNuxtApp().$api(`/api/resource/notifications_items/${notification.id}`, {
|
||||||
const {data,error} = await supabase.from("notifications").update({read: true}).eq("id", notification.id)
|
method: "PUT",
|
||||||
|
body: { readAt: new Date() }
|
||||||
console.log(error)
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// noop: endpoint optional in older/newer backend variants
|
||||||
|
}
|
||||||
setup()
|
setup()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,7 +44,7 @@ const setNotificationAsRead = async (notification) => {
|
|||||||
class="p-3 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800/50 cursor-pointer flex items-center gap-3 relative"
|
class="p-3 rounded-md hover:bg-gray-50 dark:hover:bg-gray-800/50 cursor-pointer flex items-center gap-3 relative"
|
||||||
@click="setNotificationAsRead(notification)"
|
@click="setNotificationAsRead(notification)"
|
||||||
>
|
>
|
||||||
<UChip color="primary" :show="!notification.read" inset>
|
<UChip color="primary" :show="!notification.read && !notification.readAt" inset>
|
||||||
<UAvatar alt="FEDEO" size="md" />
|
<UAvatar alt="FEDEO" size="md" />
|
||||||
</UChip>
|
</UChip>
|
||||||
|
|
||||||
@@ -49,7 +52,7 @@ const setNotificationAsRead = async (notification) => {
|
|||||||
<p class="flex items-center justify-between">
|
<p class="flex items-center justify-between">
|
||||||
<span class="text-gray-900 dark:text-white font-medium">{{notification.title}}</span>
|
<span class="text-gray-900 dark:text-white font-medium">{{notification.title}}</span>
|
||||||
|
|
||||||
<time :datetime="notification.date" class="text-gray-500 dark:text-gray-400 text-xs" v-text="formatTimeAgo(new Date(notification.created_at))" />
|
<time :datetime="notification.date || notification.createdAt || notification.created_at" class="text-gray-500 dark:text-gray-400 text-xs" v-text="formatTimeAgo(new Date(notification.createdAt || notification.created_at))" />
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-500 dark:text-gray-400">
|
<p class="text-gray-500 dark:text-gray-400">
|
||||||
{{ notification.message }}
|
{{ notification.message }}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const modal = useModal()
|
const modal = useModal()
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
type: {
|
type: {
|
||||||
@@ -35,11 +34,10 @@ const item = ref({})
|
|||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
if(props.mode === "show") {
|
if(props.mode === "show") {
|
||||||
//Load Data for Show
|
//Load Data for Show
|
||||||
item.value = await useEntities(props.type).selectSingle(props.id, dataType.supabaseSelectWithInformation || "*")
|
item.value = await useEntities(props.type).selectSingle(props.id, dataType.selectWithInformation || "*")
|
||||||
} else if(props.mode === "edit") {
|
} else if(props.mode === "edit") {
|
||||||
//Load Data for Edit
|
//Load Data for Edit
|
||||||
const data = JSON.stringify(await useEntities(props.type).selectSingle(props.id)/*(await supabase.from(props.type).select().eq("id", props.id).single()).data*/)
|
const data = JSON.stringify(await useEntities(props.type).selectSingle(props.id))
|
||||||
//await useSupabaseSelectSingle(type, route.params.id)
|
|
||||||
item.value = data
|
item.value = data
|
||||||
|
|
||||||
} else if(props.mode === "create") {
|
} else if(props.mode === "create") {
|
||||||
@@ -48,7 +46,7 @@ const setupPage = async () => {
|
|||||||
|
|
||||||
} else if(props.mode === "list") {
|
} else if(props.mode === "list") {
|
||||||
//Load Data for List
|
//Load Data for List
|
||||||
items.value = await useEntities(props.type).select(dataType.supabaseSelectWithInformation || "*", dataType.supabaseSortColumn,dataType.supabaseSortAscending || false)
|
items.value = await useEntities(props.type).select(dataType.selectWithInformation || "*", dataType.sortColumn,dataType.sortAscending || false)
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded.value = true
|
loaded.value = true
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
const { isHelpSlideoverOpen } = useDashboard()
|
const { isHelpSlideoverOpen } = useDashboard()
|
||||||
const { isDashboardSearchModalOpen } = useUIState()
|
const { isDashboardSearchModalOpen } = useUIState()
|
||||||
const { metaSymbol } = useShortcuts()
|
const { metaSymbol } = useShortcuts()
|
||||||
const user = useSupabaseUser()
|
|
||||||
const dataStore = useDataStore()
|
|
||||||
const profileStore = useProfileStore()
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const router = useRouter()
|
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
|
|
||||||
const items = computed(() => [
|
const items = computed(() => [
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
|
|
||||||
let inventoryitemgroups = await Promise.all(props.row.inventoryitemgroups.map(async (i) => {
|
let inventoryitemgroups = await Promise.all(props.row.inventoryitemgroups.map(async (i) => {
|
||||||
return (await supabase.from("inventoryitemgroups").select("id,name").eq("id",i).single()).data.name
|
const group = await useEntities("inventoryitemgroups").selectSingle(i)
|
||||||
|
return group?.name
|
||||||
}))
|
}))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
|
|
||||||
let inventoryitems = await Promise.all(props.row.inventoryitems.map(async (i) => {
|
let inventoryitems = await Promise.all(props.row.inventoryitems.map(async (i) => {
|
||||||
return (await supabase.from("inventoryitems").select("id,name").eq("id",i).single()).data.name
|
const item = await useEntities("inventoryitems").selectSingle(i)
|
||||||
|
return item?.name
|
||||||
}))
|
}))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ const props = defineProps({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
|
|
||||||
let vehicles = await Promise.all(props.row.vehicles.map(async (i) => {
|
let vehicles = await Promise.all(props.row.vehicles.map(async (i) => {
|
||||||
return (await supabase.from("vehicles").select("id,licensePlate").eq("id",i).single()).data.licensePlate
|
const vehicle = await useEntities("vehicles").selectSingle(i)
|
||||||
|
return vehicle?.licensePlate
|
||||||
}))
|
}))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const profileStore = useProfileStore()
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
item: {
|
item: {
|
||||||
required: true,
|
required: true,
|
||||||
|
|||||||
@@ -8,15 +8,12 @@ let incomeData = ref({})
|
|||||||
let expenseData = ref({})
|
let expenseData = ref({})
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
//let incomeRawData = (await supabase.from("createddocuments").select().eq("tenant",profileStore.currentTenant).eq("state","Gebucht").in('type',['invoices','advanceInvoices','cancellationInvoices'])).data
|
|
||||||
let incomeRawData = (await useEntities("createddocuments").select()).filter(i => i.state === "Gebucht" && ['invoices','advanceInvoices','cancellationInvoices'].includes(i.type))
|
let incomeRawData = (await useEntities("createddocuments").select()).filter(i => i.state === "Gebucht" && ['invoices','advanceInvoices','cancellationInvoices'].includes(i.type))
|
||||||
|
|
||||||
let incomeRawFilteredData = incomeRawData.filter(x => x.state === 'Gebucht' && incomeRawData.find(i => i.linkedDocument && i.linkedDocument.id === x.id && i.type === 'cancellationInvoices') && ['invoices','advanceInvoices'].includes(row.type))
|
let incomeRawFilteredData = incomeRawData.filter(x => x.state === 'Gebucht' && incomeRawData.find(i => i.linkedDocument && i.linkedDocument.id === x.id && i.type === 'cancellationInvoices') && ['invoices','advanceInvoices'].includes(row.type))
|
||||||
|
|
||||||
|
|
||||||
//let expenseRawData =(await supabase.from("incominginvoices").select().eq("tenant",profileStore.currentTenant)).data
|
|
||||||
let expenseRawData =(await useEntities("incominginvoices").select())
|
let expenseRawData =(await useEntities("incominginvoices").select())
|
||||||
//let withoutInvoiceRawData = (await supabase.from("statementallocations").select().eq("tenant",profileStore.currentTenant).not("account","is",null)).data
|
|
||||||
let withoutInvoiceRawData = (await useEntities("statementallocations").select()).filter(i => i.account)
|
let withoutInvoiceRawData = (await useEntities("statementallocations").select()).filter(i => i.account)
|
||||||
|
|
||||||
let withoutInvoiceRawDataExpenses = []
|
let withoutInvoiceRawDataExpenses = []
|
||||||
|
|||||||
@@ -32,15 +32,7 @@ const default_data = {
|
|||||||
const newProjectDescription = ref(data|| default_data.value);
|
const newProjectDescription = ref(data|| default_data.value);
|
||||||
|
|
||||||
const saveProjectDescription = async () => {
|
const saveProjectDescription = async () => {
|
||||||
//Update Project Description
|
|
||||||
/*const {data:updateData,error:updateError} = await supabase
|
|
||||||
.from("projects")
|
|
||||||
.update({description: newProjectDescription.value})
|
|
||||||
.eq('id',currentProject.id)
|
|
||||||
.select()
|
|
||||||
|
|
||||||
console.log(updateData)
|
|
||||||
console.log(updateError)*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const profileStore = useProfileStore()
|
const profileStore = useProfileStore()
|
||||||
|
|
||||||
const workingtimes = ref([])
|
const workingtimes = ref([])
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
workingtimes.value = (await supabase.from("workingtimes").select().eq("tenant",profileStore.currentTenant).is("endDate",null)).data
|
const profiles = profileStore.profiles || []
|
||||||
|
const checks = await Promise.all(profiles.map(async (profile) => {
|
||||||
|
try {
|
||||||
|
const spans = await useNuxtApp().$api(`/api/staff/time/spans?targetUserId=${profile.user_id || profile.id}`)
|
||||||
|
const openSpan = (spans || []).find((s) => !s.endedAt && s.type === "work")
|
||||||
|
if (openSpan) return { profile: profile.id }
|
||||||
|
} catch (e) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}))
|
||||||
|
workingtimes.value = checks.filter(Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupPage()
|
setupPage()
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
|
|
||||||
export const useSum = () => {
|
export const useSum = () => {
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
|
|
||||||
const getIncomingInvoiceSum = (invoice) => {
|
const getIncomingInvoiceSum = (invoice) => {
|
||||||
let sum = 0
|
let sum = 0
|
||||||
invoice.accounts.forEach(account => {
|
invoice.accounts.forEach(account => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default defineNuxtConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
modules: ['@vite-pwa/nuxt','@pinia/nuxt', '@nuxt/ui', '@nuxtjs/supabase', "nuxt-editorjs", '@nuxtjs/fontaine', 'nuxt-viewport', '@nuxtjs/leaflet', '@vueuse/nuxt'],
|
modules: ['@vite-pwa/nuxt','@pinia/nuxt', '@nuxt/ui', "nuxt-editorjs", '@nuxtjs/fontaine', 'nuxt-viewport', '@nuxtjs/leaflet', '@vueuse/nuxt'],
|
||||||
|
|
||||||
ssr: false,
|
ssr: false,
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const showDocument = ref(false)
|
|||||||
const uri = ref("")
|
const uri = ref("")
|
||||||
|
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
letterheads.value = await useSupabaseSelect("letterheads","*")
|
letterheads.value = await useEntities("letterheads").select("*")
|
||||||
|
|
||||||
preloadedContent.value = `<p></p><p></p><p></p>`
|
preloadedContent.value = `<p></p><p></p><p></p>`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ defineShortcuts({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -38,7 +37,7 @@ const openTab = ref(0)
|
|||||||
//Functions
|
//Functions
|
||||||
const setupPage = async () => {
|
const setupPage = async () => {
|
||||||
if(mode.value === "show" || mode.value === "edit"){
|
if(mode.value === "show" || mode.value === "edit"){
|
||||||
itemInfo.value = await useSupabaseSelectSingle("roles",route.params.id,"*")
|
itemInfo.value = await useEntities("roles").selectSingle(route.params.id,"*")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
const items = ref([])
|
const items = ref([])
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
items.value = await useSupabaseSelect("roles","*")
|
items.value = await useEntities("roles").select("*")
|
||||||
}
|
}
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import axios from "axios"
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const dataStore = useDataStore()
|
|
||||||
const profileStore = useProfileStore()
|
|
||||||
|
|
||||||
const createEMailAddress = ref("")
|
const createEMailAddress = ref("")
|
||||||
const createEMailType = ref("imap")
|
const createEMailType = ref("imap")
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ const setupPage = async (sort_column = null, sort_direction = null) => {
|
|||||||
console.log(item.value)
|
console.log(item.value)
|
||||||
} else if (mode.value === "list") {
|
} else if (mode.value === "list") {
|
||||||
//Load Data for List
|
//Load Data for List
|
||||||
//items.value = await useEntities(type).select(dataType.supabaseSelectWithInformation, sort_column || dataType.supabaseSortColumn, sort_direction === "asc", true)
|
|
||||||
items.value = await useEntities(type).select({
|
items.value = await useEntities(type).select({
|
||||||
filters: {},
|
filters: {},
|
||||||
sort: [],
|
sort: [],
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const pageLimit = ref(15)
|
|||||||
const page = ref(tempStore.pages[type] || 1)
|
const page = ref(tempStore.pages[type] || 1)
|
||||||
|
|
||||||
const sort = ref({
|
const sort = ref({
|
||||||
column: dataType.supabaseSortColumn || "created_at",
|
column: dataType.sortColumn || "created_at",
|
||||||
direction: 'desc'
|
direction: 'desc'
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ const setupPage = async () => {
|
|||||||
|
|
||||||
|
|
||||||
const {data,meta} = await useEntities(type).selectPaginated({
|
const {data,meta} = await useEntities(type).selectPaginated({
|
||||||
select: dataType.supabaseSelectWithInformation || "*",
|
select: dataType.selectWithInformation || "*",
|
||||||
filters: filters,
|
filters: filters,
|
||||||
sort: [{field: sort.value.column, direction: sort.value.direction}],
|
sort: [{field: sort.value.column, direction: sort.value.direction}],
|
||||||
page: page.value,
|
page: page.value,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
import {useFunctions} from "~/composables/useFunctions.js";
|
import {useFunctions} from "~/composables/useFunctions.js";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const profileStore = useProfileStore()
|
const profileStore = useProfileStore()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const auth = useAuthStore()
|
const auth = useAuthStore()
|
||||||
|
|||||||
@@ -10,15 +10,6 @@ const showClosedTickets = ref(false)
|
|||||||
const selectedTenant = ref(null)
|
const selectedTenant = ref(null)
|
||||||
|
|
||||||
const setup = async () => {
|
const setup = async () => {
|
||||||
/*if(profileStore.currentTenant === 5) {
|
|
||||||
tickets.value = (await supabase.from("tickets").select("*,created_by(*), ticketmessages(*), tenant(*)").order("created_at", {ascending: false})).data
|
|
||||||
} else {
|
|
||||||
tickets.value = (await supabase.from("tickets").select("*,created_by(*), ticketmessages(*)").eq("tenant",profileStore.currentTenant).order("created_at", {ascending: false})).data
|
|
||||||
}
|
|
||||||
|
|
||||||
if(profileStore.currentTenant === 5) {
|
|
||||||
tenants.value = (await supabase.from("tenants").select().order("id")).data
|
|
||||||
}*/
|
|
||||||
tickets.value = await useEntities("tickets").select("*,created_by(*), ticketmessages(*)", "created_at", false)
|
tickets.value = await useEntities("tickets").select("*,created_by(*), ticketmessages(*)", "created_at", false)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,152 +1,117 @@
|
|||||||
import {defineStore} from 'pinia'
|
import { defineStore } from "pinia"
|
||||||
import OneSignal from "onesignal-cordova-plugin";
|
import OneSignal from "onesignal-cordova-plugin"
|
||||||
import {Capacitor} from "@capacitor/core";
|
import { Capacitor } from "@capacitor/core"
|
||||||
// @ts-ignore
|
|
||||||
export const useProfileStore = defineStore('profile', () => {
|
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
export const useProfileStore = defineStore("profile", () => {
|
||||||
|
const auth = useAuthStore()
|
||||||
const dataStore = useDataStore()
|
const dataStore = useDataStore()
|
||||||
const user = useSupabaseUser()
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const router = useRouter()
|
const tempStore = useTempStore()
|
||||||
|
|
||||||
const loaded = ref(false)
|
const loaded = ref(false)
|
||||||
const showProfileSelection = ref(false)
|
const showProfileSelection = ref(false)
|
||||||
|
|
||||||
const ownTenant = ref({
|
const ownTenant = ref({
|
||||||
calendarConfig: {
|
calendarConfig: { eventTypes: [] },
|
||||||
eventTypes: []
|
timeConfig: { timeTypes: [] },
|
||||||
},
|
tags: { documents: [], products: [] },
|
||||||
timeConfig: {
|
|
||||||
timeTypes: []
|
|
||||||
},
|
|
||||||
tags: {
|
|
||||||
documents: [] ,
|
|
||||||
products: []
|
|
||||||
},
|
|
||||||
measures: []
|
measures: []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const profiles = ref([])
|
const profiles = ref([])
|
||||||
const ownProfiles = ref([])
|
const ownProfiles = ref([])
|
||||||
const activeProfile = ref([])
|
const activeProfile = ref(null)
|
||||||
const tenants = ref([])
|
const tenants = ref([])
|
||||||
const currentTenant = ref(null)
|
const currentTenant = ref(null)
|
||||||
|
|
||||||
|
const syncFromAuth = () => {
|
||||||
|
currentTenant.value = auth.activeTenant || null
|
||||||
|
activeProfile.value = auth.profile || null
|
||||||
|
tenants.value = auth.tenants || []
|
||||||
|
}
|
||||||
|
|
||||||
async function initializeData (userId) {
|
async function initializeData() {
|
||||||
|
await auth.fetchMe()
|
||||||
let profileconnections = (await supabase.from("profileconnections").select()).data
|
syncFromAuth()
|
||||||
let profiles = (await supabase.from("profiles").select("*, role(*)")).data
|
|
||||||
let activeProfileConnection = profileconnections.find(i => i.active)
|
|
||||||
if(activeProfileConnection) {
|
|
||||||
if(!false) {
|
|
||||||
toast.add({title: 'Aktives Profil ausgewählt'})
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Active Profile selected")
|
|
||||||
activeProfile.value = profiles.find(i => i.id === activeProfileConnection.profile_id)
|
|
||||||
currentTenant.value = activeProfile.value.tenant
|
|
||||||
|
|
||||||
if(Capacitor.getPlatform() === "ios") {
|
|
||||||
OneSignal.initialize("1295d5ff-28f8-46a6-9c62-fe5d090016d7");
|
|
||||||
OneSignal.Location.setShared(false)
|
|
||||||
OneSignal.Notifications.requestPermission();
|
|
||||||
OneSignal.login(activeProfileConnection.user_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (activeProfile.value?.temp_config) {
|
||||||
|
tempStore.setStoredTempConfig(activeProfile.value.temp_config)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentTenant.value) {
|
||||||
await fetchData()
|
await fetchData()
|
||||||
await dataStore.fetchData()
|
await dataStore.fetchData()
|
||||||
|
|
||||||
|
if (Capacitor.getPlatform() === "ios" && activeProfile.value?.user_id) {
|
||||||
|
OneSignal.initialize("1295d5ff-28f8-46a6-9c62-fe5d090016d7")
|
||||||
|
OneSignal.Location.setShared(false)
|
||||||
|
OneSignal.Notifications.requestPermission()
|
||||||
|
OneSignal.login(activeProfile.value.user_id)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toast.add({title: 'Kein aktives Profil', color: 'orange'})
|
toast.add({ title: "Kein aktiver Tenant", color: "orange" })
|
||||||
await fetchOwnProfiles()
|
|
||||||
await fetchTenants()
|
|
||||||
showProfileSelection.value = true
|
showProfileSelection.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeProfile(newActiveProfileId) {
|
async function changeProfile(newActiveTenantId) {
|
||||||
loaded.value = false
|
loaded.value = false
|
||||||
|
await auth.switchTenant(String(newActiveTenantId))
|
||||||
let profileconnections = (await supabase.from("profileconnections").select()).data
|
|
||||||
|
|
||||||
let oldActiveProfileConnection = profileconnections.find(i => i.active)
|
|
||||||
|
|
||||||
const {error} = await supabase.from("profileconnections").update({active: true}).eq("profile_id", newActiveProfileId)
|
|
||||||
|
|
||||||
if(error) {
|
|
||||||
console.log(error)
|
|
||||||
} else {
|
|
||||||
if(oldActiveProfileConnection){
|
|
||||||
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileConnection.profile_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadNuxtApp({
|
|
||||||
path:"/",
|
|
||||||
ttl: 10000
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData () {
|
async function fetchData() {
|
||||||
await fetchOwnProfiles()
|
await fetchOwnProfiles()
|
||||||
await fetchProfiles()
|
await fetchProfiles()
|
||||||
|
|
||||||
await fetchTenants()
|
await fetchTenants()
|
||||||
await fetchOwnTenant()
|
await fetchOwnTenant()
|
||||||
|
|
||||||
loaded.value = true
|
loaded.value = true
|
||||||
console.log("Finished Loading")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearStore () {
|
function clearStore() {
|
||||||
loaded.value = false
|
loaded.value = false
|
||||||
ownTenant.value = {}
|
ownTenant.value = {}
|
||||||
profiles.value = []
|
profiles.value = []
|
||||||
ownProfiles.value = []
|
ownProfiles.value = []
|
||||||
tenants.value = []
|
tenants.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchOwnTenant () {
|
async function fetchOwnTenant() {
|
||||||
ownTenant.value = (await supabase.from("tenants").select().eq('id', currentTenant.value).single()).data
|
syncFromAuth()
|
||||||
|
ownTenant.value = auth.activeTenantData || ownTenant.value
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchProfiles () {
|
async function fetchProfiles() {
|
||||||
profiles.value = (await supabase.from("profiles").select().eq("tenant",currentTenant.value).order("lastName")).data
|
try {
|
||||||
|
const res = await useNuxtApp().$api("/api/tenant/profiles")
|
||||||
|
profiles.value = res?.data || []
|
||||||
|
} catch (e) {
|
||||||
|
profiles.value = activeProfile.value ? [activeProfile.value] : []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchOwnProfiles () {
|
async function fetchOwnProfiles() {
|
||||||
let profiles = (await supabase.from("profiles").select().order("tenant")).data
|
ownProfiles.value = profiles.value
|
||||||
let conns = (await supabase.from("profileconnections").select()).data.map(i => i.profile_id)
|
|
||||||
ownProfiles.value = profiles.filter(i => conns.includes(i.id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchTenants () {
|
async function fetchTenants() {
|
||||||
tenants.value = (await supabase.from("tenants").select().order("id",{ascending: true})).data
|
syncFromAuth()
|
||||||
}
|
}
|
||||||
|
|
||||||
const getOwnProfile = computed(() => {
|
const getOwnProfile = computed(() => {
|
||||||
return profiles.value.find(i => i.id === user.value.id)
|
return activeProfile.value
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const getProfileById = computed(() => (itemId) => {
|
const getProfileById = computed(() => (itemId) => {
|
||||||
return profiles.value.find(item => item.id === itemId)
|
return profiles.value.find((item) => item.id === itemId || item.user_id === itemId)
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
//General
|
|
||||||
currentTenant,
|
currentTenant,
|
||||||
loaded,
|
loaded,
|
||||||
showProfileSelection,
|
showProfileSelection,
|
||||||
ownTenant,
|
ownTenant,
|
||||||
initializeData,
|
initializeData,
|
||||||
changeProfile,
|
changeProfile,
|
||||||
|
|
||||||
//Data
|
|
||||||
profiles,
|
profiles,
|
||||||
ownProfiles,
|
ownProfiles,
|
||||||
activeProfile,
|
activeProfile,
|
||||||
@@ -157,6 +122,4 @@ export const useProfileStore = defineStore('profile', () => {
|
|||||||
getOwnProfile,
|
getOwnProfile,
|
||||||
getProfileById
|
getProfileById
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user