Add ability to set home screens and fix issue with sorting screens
This commit is contained in:
parent
7bf25d9a7b
commit
893327cd9e
|
@ -225,6 +225,31 @@ export const getFrontendStore = () => {
|
|||
// Refresh routes
|
||||
await store.actions.routing.fetch()
|
||||
},
|
||||
updateHomeScreen: async (screen, makeHomeScreen = true) => {
|
||||
let promises = []
|
||||
|
||||
// Find any existing home screen for this role so we can remove it,
|
||||
// if we are setting this to be the new home screen
|
||||
if (makeHomeScreen) {
|
||||
const roleId = screen.routing.roleId
|
||||
let existingHomeScreen = get(store).screens.find(s => {
|
||||
return (
|
||||
s.routing.roleId === roleId &&
|
||||
s.routing.homeScreen &&
|
||||
s._id !== screen._id
|
||||
)
|
||||
})
|
||||
if (existingHomeScreen) {
|
||||
existingHomeScreen.routing.homeScreen = false
|
||||
promises.push(store.actions.screens.save(existingHomeScreen))
|
||||
}
|
||||
}
|
||||
|
||||
// Update the passed in screen
|
||||
screen.routing.homeScreen = makeHomeScreen
|
||||
promises.push(store.actions.screens.save(screen))
|
||||
return await Promise.all(promises)
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
saveSelected: async () => {
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
return roleA > roleB ? -1 : 1
|
||||
}
|
||||
// Then put home screens first
|
||||
const homeA = a.routing.homeScreen
|
||||
const homeB = b.routing.homeScreen
|
||||
const homeA = !!a.routing.homeScreen
|
||||
const homeB = !!b.routing.homeScreen
|
||||
if (homeA !== homeB) {
|
||||
return homeA ? -1 : 1
|
||||
}
|
||||
|
|
|
@ -61,6 +61,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Home screen changes need to be handled manually
|
||||
if (key === "routing.homeScreen") {
|
||||
store.actions.screens.updateHomeScreen(get(selectedScreen), value)
|
||||
return
|
||||
}
|
||||
|
||||
// Update screen object in store
|
||||
store.update(state => {
|
||||
setWith(get(selectedScreen), key.split("."), value, Object)
|
||||
|
|
Loading…
Reference in New Issue