diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 11e4357..a670e2f 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,10 +1,7 @@ import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; -import { provideRouter } from '@angular/router'; -import { appRoutes } from './app.routes'; export const appConfig: ApplicationConfig = { providers: [ provideBrowserGlobalErrorListeners(), - provideRouter(appRoutes), ], }; diff --git a/src/app/app.html b/src/app/app.html index fdf26e0..e233e1a 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -1,48 +1,48 @@
- - @if(eventsService.status() === 'open') { -
- } @else if (eventsService.status() === 'closed') { -
- } @else if (eventsService.status() === 'error') { -
- } - showbridge -
- - -
- - - @if (configService.pendingConfigIsValid()) { - - } @else { -
- error +
+ + @if(eventsService.status() === 'open') { +
+ } @else if (eventsService.status() === 'closed') { +
+ } @else if (eventsService.status() === 'error') { +
+ } + showbridge +
+ +
- } -
-
- - + + @if (configService.pendingConfigIsValid()) { + + } @else { +
+ error +
+ } +
+ @if (schemaService.schemasLoaded()) { +
+
+ + +
+
+ +
+
+ }
diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts deleted file mode 100644 index 5891326..0000000 --- a/src/app/app.routes.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Routes } from '@angular/router'; - -export const appRoutes: Routes = [ - { - path: '', - redirectTo: 'config', - pathMatch: 'full', - }, - { - path: 'config', - loadComponent: () => import('./components/config/config.component').then((m) => m.ConfigComponent), - }, -]; diff --git a/src/app/app.ts b/src/app/app.ts index 2dfb3f5..a4f02d0 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,4 +1,4 @@ -import { Component, effect, inject } from '@angular/core'; +import { Component, computed, effect, inject } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MatMenuModule } from '@angular/material/menu'; @@ -7,12 +7,15 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { MatToolbarModule } from '@angular/material/toolbar'; import { RouterOutlet } from '@angular/router'; import * as yaml from 'js-yaml'; -import { Config } from './models/config.models'; +import { Config, ModuleConfig, RouteConfig } from './models/config.models'; import { ConfigService } from './services/config.service'; import { EventsService } from './services/events.service'; import { SchemaService } from './services/schema.service'; import { SettingsService } from './services/settings.service'; import { MatTooltipModule } from '@angular/material/tooltip'; +import { ModuleListComponent } from './components/module-list/module-list.component'; +import { RouteListComponent } from './components/route-list/route-list.component'; +import { ConfigPreviewComponent } from './components/config-preview/config-preview.component'; @Component({ selector: 'app-root', @@ -23,12 +26,28 @@ import { MatTooltipModule } from '@angular/material/tooltip'; MatMenuModule, MatButtonModule, MatTooltipModule, - RouterOutlet + ModuleListComponent, + RouteListComponent, + ConfigPreviewComponent ], templateUrl: './app.html', styleUrl: './app.css', }) export class App { + + config = computed(() => this.configService.currentlyShownConfig()); + + modules = computed(() => this.config()?.modules ?? []); + routes = computed(() => this.config()?.routes ?? []); + + moduleIds = computed(() => { + const config = this.config(); + if (config !== undefined && config.modules !== undefined) { + return config.modules.map((module) => module.id!) ?? []; + } + return []; + }); + public schemaService = inject(SchemaService); public configService = inject(ConfigService); @@ -57,46 +76,35 @@ export class App { this.configService.updateCurrentlyShownConfig(config); } - downloadConfig() { - const config = this.configService.currentlyShownConfig(); - if (config) { - this.downloadYAML(config, 'config.yaml'); - } else { - this.snackBar.open('No config to download.', 'Dismiss', { - duration: 3000, - }); + modulesUpdated(modules: ModuleConfig[] | undefined) { + if (modules === undefined) { + console.error('modules is undefined, not updating'); + return; } + this.configService.currentlyShownConfig.update((config) => { + if (config) { + return { + ...config, + modules: modules, + }; + } + return config; + }); } - downloadJSON(data: object, filename: string) { - const content = JSON.stringify(data, null, 2); - const dataUri = URL.createObjectURL( - new Blob([content], { - type: 'application/json;charset=utf-8', - }), - ); - const dummyLink = document.createElement('a'); - dummyLink.href = dataUri; - dummyLink.download = filename; - - document.body.appendChild(dummyLink); - dummyLink.click(); - document.body.removeChild(dummyLink); - } - - downloadYAML(data: object, filename: string) { - const content = yaml.dump(data); - const dataUri = URL.createObjectURL( - new Blob([content], { - type: 'application/yaml;charset=utf-8', - }), - ); - const dummyLink = document.createElement('a'); - dummyLink.href = dataUri; - dummyLink.download = filename; - - document.body.appendChild(dummyLink); - dummyLink.click(); - document.body.removeChild(dummyLink); + routesUpdated(routes: RouteConfig[] | undefined) { + if (routes === undefined) { + console.error('routes is undefined, not updating'); + return; + } + this.configService.currentlyShownConfig.update((config) => { + if (config) { + return { + ...config, + routes: routes, + }; + } + return config; + }); } } diff --git a/src/app/components/config/config.component.css b/src/app/components/config-preview/config-preview.component.css similarity index 100% rename from src/app/components/config/config.component.css rename to src/app/components/config-preview/config-preview.component.css diff --git a/src/app/components/config-preview/config-preview.component.html b/src/app/components/config-preview/config-preview.component.html new file mode 100644 index 0000000..734ee2f --- /dev/null +++ b/src/app/components/config-preview/config-preview.component.html @@ -0,0 +1,14 @@ +
+
+
Config Preview
+
+
+ +
+
+
+
{{ yamlString() }}
+
+
diff --git a/src/app/components/config-preview/config-preview.component.ts b/src/app/components/config-preview/config-preview.component.ts new file mode 100644 index 0000000..4347027 --- /dev/null +++ b/src/app/components/config-preview/config-preview.component.ts @@ -0,0 +1,67 @@ +import { JsonPipe } from '@angular/common'; +import { Component, computed, input } from '@angular/core'; +import * as yaml from 'js-yaml'; +import { Config } from '../../models/config.models'; +import { MatIcon, MatIconModule } from "@angular/material/icon"; +import { MatButtonModule } from '@angular/material/button'; +import { MatTooltipModule } from '@angular/material/tooltip'; + +@Component({ + selector: 'app-config-preview', + imports: [ + MatIconModule, + MatButtonModule, + MatTooltipModule +], + templateUrl: './config-preview.component.html', + styleUrl: './config-preview.component.css', +}) +export class ConfigPreviewComponent { + config = input(); + + yamlString = computed(() => { + if (this.config() === undefined) { + return ''; + } + return yaml.dump(this.config()); + }); + + downloadConfig() { + const config = this.config(); + if (config) { + this.downloadYAML(config, 'config.yaml'); + } + } + + downloadJSON(data: object, filename: string) { + const content = JSON.stringify(data, null, 2); + const dataUri = URL.createObjectURL( + new Blob([content], { + type: 'application/json;charset=utf-8', + }), + ); + const dummyLink = document.createElement('a'); + dummyLink.href = dataUri; + dummyLink.download = filename; + + document.body.appendChild(dummyLink); + dummyLink.click(); + document.body.removeChild(dummyLink); + } + + downloadYAML(data: object, filename: string) { + const content = yaml.dump(data); + const dataUri = URL.createObjectURL( + new Blob([content], { + type: 'application/yaml;charset=utf-8', + }), + ); + const dummyLink = document.createElement('a'); + dummyLink.href = dataUri; + dummyLink.download = filename; + + document.body.appendChild(dummyLink); + dummyLink.click(); + document.body.removeChild(dummyLink); + } +} diff --git a/src/app/components/config/config.component.html b/src/app/components/config/config.component.html deleted file mode 100644 index a24b9d7..0000000 --- a/src/app/components/config/config.component.html +++ /dev/null @@ -1,4 +0,0 @@ -@if (config() && schemaService.schemasLoaded()) { - - -} \ No newline at end of file diff --git a/src/app/components/config/config.component.ts b/src/app/components/config/config.component.ts deleted file mode 100644 index b4e0448..0000000 --- a/src/app/components/config/config.component.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { Component, computed, inject } from '@angular/core'; -import { MatButtonModule } from '@angular/material/button'; -import { MatIconModule } from '@angular/material/icon'; -import { MatMenuModule } from '@angular/material/menu'; -import { MatTooltipModule } from '@angular/material/tooltip'; -import { Config, ModuleConfig, RouteConfig } from '../../models/config.models'; -import { ConfigService } from '../../services/config.service'; -import { SchemaService } from '../../services/schema.service'; -import { ModuleListComponent } from '../module-list/module-list.component'; -import { RouteListComponent } from '../route-list.component/route-list.component'; -import { EventsService } from '../../services/events.service'; - -@Component({ - selector: 'app-config', - imports: [ - MatMenuModule, - MatIconModule, - MatButtonModule, - MatTooltipModule, - ModuleListComponent, - RouteListComponent, - ], - templateUrl: './config.component.html', - styleUrl: './config.component.css', -}) -export class ConfigComponent { - config = computed(() => this.configService.currentlyShownConfig()); - - modules = computed(() => this.config()?.modules ?? []); - routes = computed(() => this.config()?.routes ?? []); - - moduleIds = computed(() => { - const config = this.config(); - if (config !== undefined && config.modules !== undefined) { - return config.modules.map((module) => module.id!) ?? []; - } - return []; - }); - - public configService = inject(ConfigService); - public schemaService = inject(SchemaService); - - public eventsService = inject(EventsService); - - modulesUpdated(modules: ModuleConfig[] | undefined) { - if (modules === undefined) { - console.error('modules is undefined, not updating'); - return; - } - this.configService.currentlyShownConfig.update((config) => { - if (config) { - return { - ...config, - modules: modules, - }; - } - return config; - }); - } - - routesUpdated(routes: RouteConfig[] | undefined) { - if (routes === undefined) { - console.error('routes is undefined, not updating'); - return; - } - this.configService.currentlyShownConfig.update((config) => { - if (config) { - return { - ...config, - routes: routes, - }; - } - return config; - }); - } -} diff --git a/src/app/components/module/module.component.html b/src/app/components/module/module.component.html index 6b6661a..0addb57 100644 --- a/src/app/components/module/module.component.html +++ b/src/app/components/module/module.component.html @@ -13,7 +13,7 @@ {{ schema().title || module()?.type }}
-
+
close
diff --git a/src/app/components/processor/processor.component.html b/src/app/components/processor/processor.component.html index 3c1ce86..61fdaf5 100644 --- a/src/app/components/processor/processor.component.html +++ b/src/app/components/processor/processor.component.html @@ -9,7 +9,7 @@
{{ schema()?.title || processor()?.type }}
-
+
close
diff --git a/src/app/components/route-list.component/route-list.component.css b/src/app/components/route-list/route-list.component.css similarity index 100% rename from src/app/components/route-list.component/route-list.component.css rename to src/app/components/route-list/route-list.component.css diff --git a/src/app/components/route-list.component/route-list.component.html b/src/app/components/route-list/route-list.component.html similarity index 97% rename from src/app/components/route-list.component/route-list.component.html rename to src/app/components/route-list/route-list.component.html index 728f11c..6d7cc13 100644 --- a/src/app/components/route-list.component/route-list.component.html +++ b/src/app/components/route-list/route-list.component.html @@ -12,7 +12,7 @@
@for (route of routes(); track route; let i = $index) {
-
chevron_right
Route {{ index() }}
-
+
close