diff --git a/src/app/mods/system.ts b/src/app/mods/system.ts index 7ac9b7460..29011be01 100644 --- a/src/app/mods/system.ts +++ b/src/app/mods/system.ts @@ -1,3 +1,5 @@ +import { FormlyFieldConfig } from '@ngx-formly/core'; +import { Schema } from 'jtd'; import * as moment from 'moment'; import { Plugin } from '../model/plugin'; import { Mod } from '../model/tag'; @@ -20,8 +22,155 @@ const systemPlugin: Plugin = { }, }; +const systemUsagePlugin: Plugin = { + tag: '_plugin/system/usage', + name: $localize`📟️ System Usage`, + config: { + mod: $localize`📟️ System`, + generated: 'Generated by jasper-ui ' + moment().toISOString(), + submitChild: $localize`📊️ usage`, + description: $localize`View system usage and limits.`, + // language=CSS + css: ` + ._plugin-system.ui > .md { + display: inline-block; + padding: 10px; + border-radius: 8px; + background-color: var(--bg-accent); + backdrop-filter: blur(1px); + box-shadow: 0 0 4px 2px rgba(0, 0, 0, 0.1); + } + `, + // language=Handlebars + ui: ` + ### Usage + | | | Used | Limit | + |--|:--:|--:|--:| + | Ref | | {{usage.ref}} | {{usage.limit.ref}} | + | Ext | | {{usage.ext}} | {{usage.limit.ext}} | + | User | | {{usage.user}} | {{usage.limit.user}} | + | Plugin | | {{usage.plugin}} | {{usage.limit.plugin}} | + | Template | | {{usage.template}} | {{usage.limit.template}} | + + ### Size + | | | Used | Limit | + |--|:--:|--:|--:| + | Ref | | {{size.ref}} | {{size.limit.ref}} | + | Ext | | {{size.ext}} | {{size.limit.ext}} | + | User | | {{size.user}} | {{size.limit.user}} | + | Plugin | | {{size.plugin}} | {{size.limit.plugin}} | + | Template | | {{size.template}} | {{size.limit.template}} | + `, + form: [{ + key: 'usage', + props: { + label: $localize`Usage`, + }, + fieldGroup: quotaForm(), + }, { + key: 'size', + props: { + label: $localize`Size`, + }, + fieldGroup: quotaForm(), + }], + }, + schema: { + optionalProperties: { + usage: quotaSchema(), + size: quotaSchema(), + } + } +}; + +function quotaSchema(): Schema { + return { + optionalProperties: { + ref: {type: 'uint32'}, + ext: {type: 'uint32'}, + user: {type: 'uint32'}, + plugin: {type: 'uint32'}, + template: {type: 'uint32'}, + limit: { + optionalProperties: { + ref: {type: 'uint32'}, + ext: {type: 'uint32'}, + user: {type: 'uint32'}, + plugin: {type: 'uint32'}, + template: {type: 'uint32'}, + }, + }, + }, + }; +} + +function quotaForm(): FormlyFieldConfig[] { + return [{ + key: 'ref', + type: 'number', + props: { + label: $localize`Refs:`, + } + }, { + key: 'limit.ref', + type: 'number', + props: { + label: $localize`Limit:`, + } + }, { + key: 'ext', + type: 'number', + props: { + label: $localize`Exts:`, + } + }, { + key: 'limit.ext', + type: 'number', + props: { + label: $localize`Limit:`, + } + }, { + key: 'user', + type: 'number', + props: { + label: $localize`Users:`, + } + }, { + key: 'limit.user', + type: 'number', + props: { + label: $localize`Limit:`, + } + }, { + key: 'plugin', + type: 'number', + props: { + label: $localize`Plugins:`, + } + }, { + key: 'limit.plugin', + type: 'number', + props: { + label: $localize`Limit:`, + } + }, { + key: 'template', + type: 'number', + props: { + label: $localize`Templates:`, + } + }, { + key: 'limit.template', + type: 'number', + props: { + label: $localize`Limit:`, + } + }]; +} + export const systemMod: Mod = { plugins: { system: systemPlugin, + systemUsagePlugin: systemUsagePlugin, }, }