Flesh out Cobalt, LDAP groups, &c.

This commit is contained in:
garrettmills
2020-05-11 20:26:09 -05:00
parent c389e151b5
commit 6f621f5891
34 changed files with 1508 additions and 31 deletions

View File

@@ -1,10 +1,27 @@
import { location_service } from './Location.service.js'
import { resource_service } from './Resource.service.js'
class ActionService {
async perform({ text, action, ...args }) {
async perform({ text = '', action, ...args }) {
if ( action === 'redirect' ) {
if ( args.next ) {
return location_service.redirect(args.next, args.delay || 1500)
return location_service.redirect(args.next, args.delay || 0)
}
} else if ( action === 'back' ) {
return location_service.back()
} else if ( args.type === 'resource' ) {
const { resource } = args
if ( action === 'insert' ) {
return location_service.redirect(`/dash/c/form/${resource}`, 0)
} else if ( action === 'update' ) {
const { id } = args
return location_service.redirect(`/dash/c/form/${resource}?id=${id}`, 0)
} else if ( action === 'delete' ) {
const { id } = args
const rsc = await resource_service.get(resource)
await rsc.delete(id)
} else if ( action === 'list' ) {
return location_service.redirect(`/dash/c/listing/${resource}`, 0)
}
} else {
throw new TypeError(`Unknown action type: ${action}`)

View File

@@ -20,6 +20,13 @@ class LocationService {
}, delay)
})
}
set_query(query) {
if (history.pushState) {
const new_url = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + query;
window.history.pushState({path: new_url}, '', new_url);
}
}
}
const location_service = new LocationService()

View File

@@ -0,0 +1,18 @@
class ResourceService {
async get(name) {
const resource_mod = await import(`../resource/${name}.resource.js`)
if ( !resource_mod ) throw new Error(`Unable to fetch resource ${name}.`)
if ( !this.object_name(name) in resource_mod )
throw new Error(`Unable to retrieve resource from module (${this.object_name(name)}).`)
return resource_mod[this.object_name(name)]
}
object_name(name) {
return name.toLowerCase().replace(/\//g, '_')
}
}
const resource_service = new ResourceService()
export { resource_service }