feat: externalized tool configuration

This commit is contained in:
Corentin Thomasset 2021-05-28 19:44:27 +02:00
parent c3adfe30ec
commit 690bd099ef
No known key found for this signature in database
GPG key ID: DBD997E935996158
31 changed files with 387 additions and 300 deletions

View file

@ -0,0 +1,12 @@
import {Component, Vue} from 'nuxt-property-decorator'
import {ToolConfig} from '~/types/ToolConfig'
@Component
export class ToolConfigMixin extends Vue {
public $toolConfig!: ToolConfig;
beforeCreate() {
// @ts-ignore
this.$toolConfig = this.$options.__toolConfig
}
}

View file

@ -1,37 +0,0 @@
import {Component, Vue} from 'nuxt-property-decorator'
import {ToolRouteConfig} from '~/types/ToolConfig'
import {capitalise} from '~/utils/string'
@Component
export class ToolRoutesMixin extends Vue {
toolRoutesFlat : ToolRouteConfig[] = []
toolRoutesSections : {[key: string]: ToolRouteConfig[]} = {}
async created() {
const routes = this.$router.options.routes?.filter((r1, i, a) => r1.meta?.isTool && a.findIndex(r2 => r2.path.split('/').pop() === r1.path.split('/').pop()) === i) || []
const flat: ToolRouteConfig[] = []
const sections: { [key: string]: ToolRouteConfig[] } = {}
for (const route of routes) {
if ('component' in route) {
// @ts-ignore
const component = await route.component()
const routeConfig = {...route, config: component.options.methods.config()} as ToolRouteConfig
flat.push(routeConfig)
const sectionKey = capitalise(route.meta.section).replace(/_/g, ' ')
if (!(sectionKey in sections)) {
sections[sectionKey] = []
}
sections[sectionKey].push(routeConfig)
}
}
this.toolRoutesSections = sections
this.toolRoutesFlat = flat
}
}