Added Phases to Projects
This commit is contained in:
@@ -87,6 +87,11 @@ export const useDataStore = defineStore('data', () => {
|
||||
incomingInvoices: {
|
||||
label: "Eingangsrechnungen",
|
||||
labelSingle: "Eingangsrechnung"
|
||||
},
|
||||
inventoryitems: {
|
||||
label: "Inventarartikel",
|
||||
labelSingle: "Inventarartikel",
|
||||
redirect: true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,12 +156,13 @@ export const useDataStore = defineStore('data', () => {
|
||||
const accounts = ref([])
|
||||
const taxTypes = ref([])
|
||||
const plants = ref([])
|
||||
const inventoryItems = ref([])
|
||||
const inventoryitems = ref([])
|
||||
const chats = ref([])
|
||||
const messages = ref([])
|
||||
const createddocuments = ref([])
|
||||
const workingtimes = ref([])
|
||||
const phasesTemplates = ref([])
|
||||
const emailAccounts = ref([])
|
||||
|
||||
|
||||
const rights = ref({
|
||||
@@ -217,13 +223,10 @@ export const useDataStore = defineStore('data', () => {
|
||||
}
|
||||
])
|
||||
|
||||
async function initializeData () {
|
||||
//console.log(user.value.id)
|
||||
let profile = (await supabase.from("profiles").select().eq("id",user.value.id).single()).data
|
||||
async function initializeData (userId) {
|
||||
let profile = (await supabase.from("profiles").select().eq("id",userId).single()).data
|
||||
|
||||
//console.log(profile)
|
||||
|
||||
currentTenant.value = profile.tenant//profiles.value.find(i => i.id === user.value.id).tenants[0].id
|
||||
currentTenant.value = profile.tenant
|
||||
|
||||
await fetchData()
|
||||
|
||||
@@ -273,6 +276,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
await fetchCreatedDocuments()
|
||||
await fetchWorkingTimes()
|
||||
await fetchPhasesTemplates()
|
||||
await fetchEmailAccounts()
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
@@ -280,7 +284,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
console.log("Clear")
|
||||
loaded.value = false
|
||||
ownTenant.value = {}
|
||||
profiles.value= []
|
||||
profiles.value = []
|
||||
events.value= []
|
||||
customers.value= []
|
||||
tasks.value= []
|
||||
@@ -307,12 +311,13 @@ export const useDataStore = defineStore('data', () => {
|
||||
accounts.value = []
|
||||
taxTypes.value = []
|
||||
plants.value = []
|
||||
inventoryItems.value = []
|
||||
inventoryitems.value = []
|
||||
chats.value = []
|
||||
messages.value = []
|
||||
createddocuments.value = []
|
||||
workingtimes.value = []
|
||||
phasesTemplates.value = []
|
||||
emailAccounts.value = []
|
||||
}
|
||||
|
||||
function hasRight (right) {
|
||||
@@ -338,13 +343,13 @@ export const useDataStore = defineStore('data', () => {
|
||||
(payload) => {
|
||||
//console.log(payload)
|
||||
|
||||
if(payload.eventType === 'INSERT') {
|
||||
/*if(payload.eventType === 'INSERT') {
|
||||
const c = payload.table + '.value.push(' + JSON.stringify(payload.new) + ')'
|
||||
eval(c)
|
||||
} else if(payload.eventType === 'UPDATE'){
|
||||
const c = payload.table + '.value[' + payload.table + '.value.findIndex(i => i.id === ' + JSON.stringify(payload.old.id) + ')] = ' + JSON.stringify(payload.new)
|
||||
eval(c)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
)
|
||||
.subscribe()
|
||||
@@ -371,7 +376,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
if(supabaseError) {
|
||||
console.log(supabaseError)
|
||||
} else if (supabaseData) {
|
||||
//await eval( dataType + '.value.push(' + JSON.stringify(...supabaseData) + ')')
|
||||
await eval( dataType + '.value.push(' + JSON.stringify(...supabaseData) + ')')
|
||||
toast.add({title: `${dataTypes[dataType].labelSingle} hinzugefügt`})
|
||||
if(dataTypes[dataType].redirect) await router.push(`/${dataType}/show/${supabaseData[0].id}`)
|
||||
return supabaseData
|
||||
@@ -396,7 +401,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
}
|
||||
|
||||
const uploadFiles = async (formData, files, upsert) => {
|
||||
|
||||
console.log(files)
|
||||
let documentsToInsert = []
|
||||
|
||||
const uploadSingleFile = async (file) => {
|
||||
@@ -436,11 +441,13 @@ export const useDataStore = defineStore('data', () => {
|
||||
} else if( files.length > 1) {
|
||||
|
||||
for(let i = 0; i < files.length; i++){
|
||||
uploadSingleFile(files[i])
|
||||
await uploadSingleFile(files[i])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.log(documentsToInsert)
|
||||
|
||||
const {data, error} = await supabase
|
||||
.from("documents")
|
||||
.insert(documentsToInsert)
|
||||
@@ -464,7 +471,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
}
|
||||
|
||||
async function fetchProfiles () {
|
||||
profiles.value = (await supabase.from("profiles").select('* , tenants (id, name)')).data
|
||||
profiles.value = (await supabase.from("profiles").select('* , tenants (id, name)')/*.eq("tenant", currentTenant.value)*/.order("fullName")).data
|
||||
}
|
||||
async function fetchBankAccounts () {
|
||||
bankAccounts.value = (await supabase.from("bankaccounts").select().eq('tenant', currentTenant.value)).data
|
||||
@@ -543,7 +550,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
plants.value = (await supabase.from("plants").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchInventoryItems () {
|
||||
inventoryItems.value = (await supabase.from("inventoryitems").select().eq('tenant', currentTenant.value)).data
|
||||
inventoryitems.value = (await supabase.from("inventoryitems").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
async function fetchChats() {
|
||||
chats.value = (await supabase.from("chats").select()).data
|
||||
@@ -563,25 +570,35 @@ export const useDataStore = defineStore('data', () => {
|
||||
phasesTemplates.value = (await supabase.from("phasesTemplates").select().eq('tenant', currentTenant.value).order('created_at', {ascending:true})).data
|
||||
}
|
||||
|
||||
async function fetchEmailAccounts() {
|
||||
emailAccounts.value = (await supabase.from("emailAccounts").select().eq('tenant', currentTenant.value)).data
|
||||
}
|
||||
|
||||
async function fetchDocuments () {
|
||||
let tempDocuments = (await supabase.from("documents").select().eq('tenant', currentTenant.value)).data
|
||||
|
||||
let paths = []
|
||||
tempDocuments.forEach(doc => {
|
||||
paths.push(doc.path)
|
||||
})
|
||||
if(tempDocuments.length > 0){
|
||||
let paths = []
|
||||
tempDocuments.forEach(doc => {
|
||||
paths.push(doc.path)
|
||||
})
|
||||
|
||||
const {data,error} = await supabase.storage.from('files').createSignedUrls(paths,3600)
|
||||
const {data,error} = await supabase.storage.from('files').createSignedUrls(paths,3600)
|
||||
|
||||
tempDocuments = tempDocuments.map((doc,index) => {
|
||||
tempDocuments = tempDocuments.map((doc,index) => {
|
||||
|
||||
return {
|
||||
...doc,
|
||||
url: data[index].signedUrl
|
||||
}
|
||||
})
|
||||
|
||||
documents.value = tempDocuments
|
||||
} else {
|
||||
documents.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
...doc,
|
||||
url: data[index].signedUrl
|
||||
}
|
||||
})
|
||||
|
||||
documents.value = tempDocuments
|
||||
}
|
||||
|
||||
async function addHistoryItem(text, user, elementId, resourceType) {
|
||||
@@ -615,7 +632,8 @@ export const useDataStore = defineStore('data', () => {
|
||||
})
|
||||
|
||||
const getOwnProfile = computed(() => {
|
||||
return profiles.value.find(profile => profile.id === user.value.id)
|
||||
return profiles.value.find(i => i.id === user.value.id)
|
||||
|
||||
})
|
||||
|
||||
const getMovementsBySpace = computed(() => (spaceId) => {
|
||||
@@ -626,6 +644,18 @@ export const useDataStore = defineStore('data', () => {
|
||||
return contacts.value.filter(item => item.customer === customerId)
|
||||
})
|
||||
|
||||
const getProjectsByCustomerId = computed(() => (customerId) => {
|
||||
return projects.value.filter(item => item.customer === customerId)
|
||||
})
|
||||
|
||||
const getPlantsByCustomerId = computed(() => (customerId) => {
|
||||
return plants.value.filter(item => item.customer === customerId)
|
||||
})
|
||||
|
||||
const getContractsByCustomerId = computed(() => (customerId) => {
|
||||
return contracts.value.filter(item => item.customer === customerId)
|
||||
})
|
||||
|
||||
const getContactsByVendorId = computed(() => (vendorId) => {
|
||||
return contacts.value.filter(item => item.vendor === vendorId)
|
||||
})
|
||||
@@ -646,6 +676,10 @@ export const useDataStore = defineStore('data', () => {
|
||||
return documents.value.filter(item => item.vehicle === itemId && !item.tags.includes("Archiviert"))
|
||||
})
|
||||
|
||||
const getDocumentsByProductId = computed(() => (itemId) => {
|
||||
return documents.value.filter(item => item.product === itemId && !item.tags.includes("Archiviert"))
|
||||
})
|
||||
|
||||
const getEventsByProjectId = computed(() => (projectId) => {
|
||||
return events.value.filter(item => item.project === projectId)
|
||||
})
|
||||
@@ -722,7 +756,7 @@ export const useDataStore = defineStore('data', () => {
|
||||
id: `F-${vehicle.id}`
|
||||
}
|
||||
}),
|
||||
...inventoryItems.value.filter(i=> i.usePlanning).map(item => {
|
||||
...inventoryitems.value.filter(i=> i.usePlanning).map(item => {
|
||||
return {
|
||||
type: 'Inventar',
|
||||
title: item.name,
|
||||
@@ -903,6 +937,10 @@ export const useDataStore = defineStore('data', () => {
|
||||
return createddocuments.value.find(item => item.id === documentId)
|
||||
})
|
||||
|
||||
const getInventoryItemById = computed(() => (itemId) => {
|
||||
return inventoryitems.value.find(item => item.id === itemId)
|
||||
})
|
||||
|
||||
const getProjectById = computed(() => (itemId) => {
|
||||
if(projects.value.find(i => i.id === itemId)) {
|
||||
let project = projects.value.find(project => project.id === itemId)
|
||||
@@ -961,13 +999,15 @@ export const useDataStore = defineStore('data', () => {
|
||||
accounts,
|
||||
taxTypes,
|
||||
plants,
|
||||
inventoryItems,
|
||||
inventoryitems,
|
||||
chats,
|
||||
messages,
|
||||
createddocuments,
|
||||
workingtimes,
|
||||
phasesTemplates,
|
||||
emailAccounts,
|
||||
documentTypesForCreation,
|
||||
|
||||
//Functions
|
||||
createNewItem,
|
||||
updateItem,
|
||||
@@ -1008,11 +1048,15 @@ export const useDataStore = defineStore('data', () => {
|
||||
getOwnProfile,
|
||||
getMovementsBySpace,
|
||||
getContactsByCustomerId,
|
||||
getProjectsByCustomerId,
|
||||
getPlantsByCustomerId,
|
||||
getContractsByCustomerId,
|
||||
getContactsByVendorId,
|
||||
getDocumentsByProjectId,
|
||||
getDocumentsByPlantId,
|
||||
getDocumentsByContractId,
|
||||
getDocumentsByVehicleId,
|
||||
getDocumentsByProductId,
|
||||
getEventsByProjectId,
|
||||
getTimesByProjectId,
|
||||
getTasksByProjectId,
|
||||
@@ -1045,7 +1089,8 @@ export const useDataStore = defineStore('data', () => {
|
||||
getProfileById,
|
||||
getAccountById,
|
||||
getPlantById,
|
||||
getCreatedDocumentById
|
||||
getCreatedDocumentById,
|
||||
getInventoryItemById,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user