rework schema loading when url changes

This commit is contained in:
Joel Wetzell
2026-03-21 16:21:18 -05:00
parent 9d068ae2b6
commit a806ae56b3
+34 -32
View File
@@ -1,5 +1,5 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { computed, effect, Injectable, signal } from '@angular/core'; import { computed, effect, inject, Injectable, signal } from '@angular/core';
import { import {
AbstractControl, AbstractControl,
FormControl, FormControl,
@@ -14,6 +14,7 @@ import { sortBy } from 'lodash-es';
import { Config, ModuleConfig, ProcessorConfig, RouteConfig } from '../models/config.models'; import { Config, ModuleConfig, ProcessorConfig, RouteConfig } from '../models/config.models';
import { ObjectInfo, ParamsFormInfo } from '../models/form.model'; import { ObjectInfo, ParamsFormInfo } from '../models/form.model';
import { SettingsService } from './settings.service'; import { SettingsService } from './settings.service';
import { EventsService } from './events.service';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -40,31 +41,37 @@ export class SchemaService {
errorPaths: string[] = []; errorPaths: string[] = [];
constructor( private settingsService = inject(SettingsService);
private http: HttpClient, private http = inject(HttpClient);
private settingsService: SettingsService, private eventsService = inject(EventsService);
) {
effect(() => {
if (this.settingsService.configSchemaUrl()) {
this.loadConfigSchema();
}
});
constructor() {
effect(() => { effect(() => {
if (this.settingsService.modulesSchemaUrl()) { switch (this.eventsService.status()) {
this.loadModulesSchema(); case 'open':
} if (this.settingsService.configSchemaUrl()) {
}); this.loadConfigSchema();
}
effect(() => { if (this.settingsService.modulesSchemaUrl()) {
if (this.settingsService.routesSchemaUrl()) { this.loadModulesSchema();
this.loadRoutesSchema(); }
} if (this.settingsService.routesSchemaUrl()) {
}); this.loadRoutesSchema();
}
effect(() => { if (this.settingsService.processorsSchemaUrl()) {
if (this.settingsService.processorsSchemaUrl()) { this.loadProcessorsSchema();
this.loadProcessorsSchema(); }
break;
case 'closed':
this.ajv.removeSchema(this.configSchema()!);
this.ajv.removeSchema(this.modulesSchema()!);
this.ajv.removeSchema(this.routesSchema()!);
this.ajv.removeSchema(this.processorsSchema()!);
this.configSchema.set(undefined);
this.modulesSchema.set(undefined);
this.routesSchema.set(undefined);
this.processorsSchema.set(undefined);
break;
} }
}); });
@@ -88,9 +95,7 @@ export class SchemaService {
loadModulesSchema() { loadModulesSchema() {
this.http this.http
.get< .get<JSONSchemaType<ModuleConfig[]>>(this.settingsService.modulesSchemaUrl().toString())
JSONSchemaType<ModuleConfig[]>
>(this.settingsService.modulesSchemaUrl().toString())
.subscribe((schema) => { .subscribe((schema) => {
this.setModulesSchema(schema); this.setModulesSchema(schema);
}); });
@@ -106,9 +111,7 @@ export class SchemaService {
loadProcessorsSchema() { loadProcessorsSchema() {
this.http this.http
.get< .get<JSONSchemaType<ProcessorConfig[]>>(this.settingsService.processorsSchemaUrl().toString())
JSONSchemaType<ProcessorConfig[]>
>(this.settingsService.processorsSchemaUrl().toString())
.subscribe((schema) => { .subscribe((schema) => {
this.setProcessorsSchema(schema); this.setProcessorsSchema(schema);
}); });
@@ -328,7 +331,6 @@ export class SchemaService {
} }
} }
paramsFormInfo.paramsInfo[paramKey] = { paramsFormInfo.paramsInfo[paramKey] = {
key: paramKey, key: paramKey,
display: paramSchema.title ? paramSchema.title : paramKey, display: paramSchema.title ? paramSchema.title : paramKey,
@@ -337,7 +339,7 @@ export class SchemaService {
isConst: !!paramSchema.const, isConst: !!paramSchema.const,
schema: paramSchema, schema: paramSchema,
placeholder: '', placeholder: '',
default: paramSchema.default ? paramSchema.default : undefined default: paramSchema.default ? paramSchema.default : undefined,
}; };
if (paramSchema.examples && paramSchema.examples.length > 0) { if (paramSchema.examples && paramSchema.examples.length > 0) {