Remodel of Profile System

Added isCompany to Customers
changes in workingtimes.vue
This commit is contained in:
2024-03-17 11:01:19 +01:00
parent 874ff01551
commit aef8cce755
16 changed files with 349 additions and 168 deletions

View File

@@ -143,6 +143,9 @@ export const useDataStore = defineStore('data', () => {
const profiles = ref([])
const ownProfiles = ref([])
const activeProfile = ref([])
const tenants = ref([])
const currentTenant = ref(null)
const events = ref([])
const customers = ref([])
@@ -180,6 +183,7 @@ export const useDataStore = defineStore('data', () => {
const texttemplates =ref([])
const services =ref([])
const serviceCategories =ref([])
const resources =ref([])
const rights = ref({
@@ -241,26 +245,54 @@ export const useDataStore = defineStore('data', () => {
])
async function initializeData (userId) {
let profile = (await supabase.from("profiles").select().eq("user",userId).single()).data
currentTenant.value = profile.tenant
let profileconnections = (await supabase.from("profileconnections").select()).data
let profiles = (await supabase.from("profiles").select()).data
let profileId = profileconnections.find(i => i.active).profile_id
activeProfile.value = profiles.find(i => i.id === profileId)
currentTenant.value = activeProfile.value.tenant
await fetchData()
}
async function changeTenant() {
async function changeProfile(newActiveProfileId) {
loaded.value = false
await clearStore()
await fetchData()
router.push("/")
loaded.value = true
let profileconnections = (await supabase.from("profileconnections").select()).data
let oldActiveProfileId = profileconnections.find(i => i.active).profile_id
const {error} = await supabase.from("profileconnections").update({active: true}).eq("profile_id", newActiveProfileId)
if(error) {
console.log(error)
} else {
const {error} = await supabase.from("profileconnections").update({active: false}).eq("profile_id", oldActiveProfileId)
if(error) {
} else {
reloadNuxtApp({
path:"/",
ttl: 10000
})
}
/*await clearStore()
await fetchData()
router.push("/")
loaded.value = true*/
}
}
async function fetchData () {
await fetchOwnProfiles()
await fetchProfiles()
await fetchDocuments()
await fetchTenants()
await fetchOwnTenant()
await fetchEvents()
await fetchTasks()
@@ -297,6 +329,7 @@ export const useDataStore = defineStore('data', () => {
await fetchTextTemplates()
await fetchServices()
await fetchServiceCategories()
await fetchResources()
loaded.value = true
}
@@ -305,6 +338,8 @@ export const useDataStore = defineStore('data', () => {
loaded.value = false
ownTenant.value = {}
profiles.value = []
ownProfiles.value = []
tenants.value = []
events.value= []
customers.value= []
tasks.value= []
@@ -341,6 +376,7 @@ export const useDataStore = defineStore('data', () => {
texttemplates.value = []
services.value = []
serviceCategories.value = []
resources.value = []
}
function hasRight (right) {
@@ -395,7 +431,7 @@ export const useDataStore = defineStore('data', () => {
if(dataTypes[dataType].numberRangeHolder) {
const numberRange = useNumberRange(dataType)
if(!dataTypes[dataType].numberRangeHolder) {
if(!data[dataTypes[dataType].numberRangeHolder]) {
data[dataTypes[dataType].numberRangeHolder] = await numberRange.useNextNumber()
}
@@ -517,12 +553,25 @@ export const useDataStore = defineStore('data', () => {
}
async function fetchOwnTenant () {
ownTenant.value = (await supabase.from("tenants").select().eq('id', currentTenant.value)).data[0]
ownTenant.value = (await supabase.from("tenants").select().eq('id', currentTenant.value).single()).data
}
async function fetchProfiles () {
profiles.value = (await supabase.from("profiles").select('* , tenants (id, name)').eq("tenant", currentTenant.value).order("fullName")).data
profiles.value = (await supabase.from("profiles").select().eq("tenant",currentTenant.value).order("fullName")).data
}
async function fetchOwnProfiles () {
let profiles = (await supabase.from("profiles").select().order("fullName")).data
let conns = (await supabase.from("profileconnections").select()).data.map(i => i.profile_id)
console.log(conns)
console.log(profiles.filter(i => conns.includes(i.id)))
ownProfiles.value = profiles.filter(i => conns.includes(i.id))
}
async function fetchTenants () {
tenants.value = (await supabase.from("tenants").select()).data
}
async function fetchBankAccounts () {
bankAccounts.value = (await supabase.from("bankaccounts").select().eq('tenant', currentTenant.value)).data
}
@@ -636,6 +685,10 @@ export const useDataStore = defineStore('data', () => {
serviceCategories.value = (await supabase.from("serviceCategories").select().eq('tenant', currentTenant.value)).data
}
async function fetchResources() {
resources.value = (await supabase.from("resources").select().eq('tenant', currentTenant.value)).data
}
async function fetchDocuments () {
let tempDocuments = (await supabase.from("documents").select().eq('tenant', currentTenant.value)).data
@@ -844,6 +897,32 @@ export const useDataStore = defineStore('data', () => {
]
})
const getResourcesList = computed(() => {
return [
...profiles.value.filter(i => i.tenant === currentTenant.value).map(profile => {
return {
type: 'Mitarbeiter',
title: profile.fullName,
id: profile.id
}
}),
...vehicles.value.map(vehicle => {
return {
type: 'Fahrzeug',
title: vehicle.licensePlate,
id: vehicle.id
}
}),
...inventoryitems.value.filter(i=> i.usePlanning).map(item => {
return {
type: 'Inventar',
title: item.name,
id: item.id
}
})
]
})
const getEvents = computed(() => {
return [
...events.value.map(event => {
@@ -880,6 +959,7 @@ export const useDataStore = defineStore('data', () => {
const getEventsByResource = computed(() => {
let tempEvents = []
events.value.forEach(event => {
console.log(event)
event.resources.forEach(resource => {
let eventColor = ownTenant.value.calendarConfig.eventTypes.find(type => type.label === event.type).color
@@ -894,8 +974,8 @@ export const useDataStore = defineStore('data', () => {
tempEvents.push({
...event,
resourceId: resource.type !== 'Mitarbeiter' ? `${resource.type[0]}-${resource.id}`: resource.id,
resourceType: resource.type,
resourceId: /*resource.type !== 'Mitarbeiter' ? `${resource.type[0]}-${resource.id}`:*/ resource.id,
resourceType: "Mitarbeiter",
title: title,
borderColor: eventColor,
textColor: eventColor,
@@ -1049,12 +1129,15 @@ export const useDataStore = defineStore('data', () => {
loaded,
ownTenant,
initializeData,
changeTenant,
changeProfile,
uploadFiles,
hasRight,
//Data
profiles,
ownProfiles,
activeProfile,
tenants,
events,
customers,
tasks,
@@ -1100,6 +1183,7 @@ export const useDataStore = defineStore('data', () => {
clearStore,
fetchOwnTenant,
fetchProfiles,
fetchOwnProfiles,
fetchBankAccounts,
fetchBankStatements,
fetchEvents,
@@ -1161,6 +1245,7 @@ export const useDataStore = defineStore('data', () => {
getDocumentTags,
getMeasures,
getResources,
getResourcesList,
getEvents,
getEventsByResource,
getCostCentresComposed,