From b65aaba56b63134c242127cdcdf3a2c67c298b64 Mon Sep 17 00:00:00 2001 From: albaintor <118518828+albaintor@users.noreply.github.com> Date: Wed, 25 Sep 2024 09:46:44 +0200 Subject: [PATCH] Improved UI grid editor (grid size according to remote capabilities and grid constraints, UI page renaming) --- package.json | 2 +- server/app.js | 18 +++++++ server/package.json | 2 +- server/remote.js | 15 ++++++ .../activity-editor.component.ts | 2 +- .../activity-page-list.component.ts | 47 +++++++++++++++---- .../activity-viewer.component.css | 5 ++ .../activity-viewer.component.html | 31 +++++++++++- .../activity-viewer.component.ts | 45 +++++++++++++++--- src/app/helper.ts | 21 +++++++-- src/app/interfaces.ts | 18 +++++++ src/app/server.service.ts | 9 +++- 12 files changed, 191 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 2888335..8b73217 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucr-tool", - "version": "1.4.2", + "version": "1.4.3", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/server/app.js b/server/app.js index 95798f4..baacb88 100644 --- a/server/app.js +++ b/server/app.js @@ -667,6 +667,24 @@ app.get('/api/remote/:address/cfg/entity/commands', async (req, res, next) => { } }) +app.get('/api/remote/:address/cfg/device/screen_layout', async (req, res, next) => { + const address = req.params.address; + const configFile = getConfigFile(); + const remoteEntry = configFile?.remotes?.find(remote => remote.address === address); + if (!remoteEntry) + { + res.status(404).json(address); + return; + } + const remote = new Remote(remoteEntry.address, remoteEntry.port, remoteEntry.user, remoteEntry.token, remoteEntry.api_key); + try { + res.status(200).json(await remote.getConfigScreenLayout()); + } catch (error) + { + errorHandler(error, req, res, next); + } +}) + app.get('/api/remote/:address/macros', async (req, res, next) => { const address = req.params.address; diff --git a/server/package.json b/server/package.json index 693f2bd..e62509a 100644 --- a/server/package.json +++ b/server/package.json @@ -1,7 +1,7 @@ { "name": "server", "type": "module", - "version": "1.4.2", + "version": "1.4.3", "main": "app.js", "scripts": { "start": "node app.js" diff --git a/server/remote.js b/server/remote.js index 60a9c39..174fb87 100644 --- a/server/remote.js +++ b/server/remote.js @@ -388,6 +388,21 @@ export class Remote return JSON.parse(res.body); } + async getConfigScreenLayout() + { + const limit = 100; + const options = { + ...this.getOptions(), + searchParams: { + limit, + page: 1 + } + } + const url = this.getURL() + '/api/cfg/device/screen_layout'; + let res = await got.get(url, options); + return JSON.parse(res.body); + } + async getMacros() { const options = this.getOptions(); diff --git a/src/app/activity-editor/activity-editor.component.ts b/src/app/activity-editor/activity-editor.component.ts index 6d1e8c9..99f8139 100644 --- a/src/app/activity-editor/activity-editor.component.ts +++ b/src/app/activity-editor/activity-editor.component.ts @@ -188,7 +188,7 @@ export class ActivityEditorComponent implements OnInit, AfterViewInit { this.server.setEntities(this.entities); this.server.setActivities(this.activities); this.remoteOperations = this.buildData(); - this.cdr.detectChanges(); + // this.cdr.detectChanges(); } this.server.getRemoteModels().subscribe(remoteModels => { this.remoteModels = remoteModels; diff --git a/src/app/activity-viewer/activity-page-list/activity-page-list.component.ts b/src/app/activity-viewer/activity-page-list/activity-page-list.component.ts index f83479e..909bd5f 100644 --- a/src/app/activity-viewer/activity-page-list/activity-page-list.component.ts +++ b/src/app/activity-viewer/activity-page-list/activity-page-list.component.ts @@ -3,7 +3,7 @@ import { ChangeDetectorRef, Component, EventEmitter, - Input, + Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; @@ -15,9 +15,16 @@ import {NgIf} from "@angular/common"; import {OrderListModule} from "primeng/orderlist"; import {MessageService, PrimeTemplate} from "primeng/api"; import {TooltipModule} from "primeng/tooltip"; -import {Activity, Remote, UIPage} from "../../interfaces"; +import {Activity, Remote, ScreenLayout, UIPage} from "../../interfaces"; import {ServerService} from "../../server.service"; +export enum Operation { + ReorderPages, + AddPage, + DeletePage, + UpdatePage +} + @Component({ selector: 'app-activity-page-list', standalone: true, @@ -36,33 +43,57 @@ import {ServerService} from "../../server.service"; changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) -export class ActivityPageListComponent { +export class ActivityPageListComponent implements OnInit { + remote: Remote | undefined; + private screenLayout: ScreenLayout | undefined; + @Input("remote") set _remote(value: Remote | undefined) { + this.remote = value; + if (value) { + this.server.getConfigScreenLayout(value).subscribe(screenLayout => { + this.screenLayout = screenLayout; + this.cdr.detectChanges(); + }) + } + } @Input() activity: Activity | undefined; @Input() editable = true; - @Output() onReorder = new EventEmitter<{activity:Activity, page:UIPage}>(); + @Output() onReorder = new EventEmitter<{activity:Activity, page:UIPage, operation: Operation}>(); @Output() onSelectPage = new EventEmitter<{activity:Activity, page:UIPage}>(); - protected readonly Helper = Helper; + protected readonly Helper = Helper; constructor(private server:ServerService, private cdr:ChangeDetectorRef, private messageService: MessageService) { } + ngOnInit(): void { + if (this.remote) + this.server.getConfigScreenLayout(this.remote).subscribe(screenLayout => { + this.screenLayout = screenLayout; + this.cdr.detectChanges(); + }) + } + addPage($event: MouseEvent) { if (!this.activity) return; if (!this.activity.options) this.activity.options = {}; if (!this.activity.options.user_interface) this.activity.options.user_interface = { pages: []}; const newPage: UIPage = {name: "New page", items: [], grid: {width: 4, height: 6}}; + if (this.screenLayout) + { + newPage.grid.width = this.screenLayout.grid.default.width; + newPage.grid.height = this.screenLayout.grid.default.height; + } this.activity.options.user_interface.pages?.push(newPage); const activity = this.activity; this.activity = undefined; this.cdr.detectChanges(); this.activity = activity; this.cdr.detectChanges(); - this.onReorder.emit({activity: this.activity!, page: newPage}); + this.onReorder.emit({activity: this.activity!, page: newPage, operation: Operation.AddPage}); } updatePages($event: UIPage) { console.log("Reorder pages", $event); - this.onReorder.emit({activity: this.activity!, page: $event}); + this.onReorder.emit({activity: this.activity!, page: $event, operation: Operation.UpdatePage}); } selectPage(page: UIPage) { @@ -71,6 +102,6 @@ export class ActivityPageListComponent { deletePage(page: UIPage) { this.activity?.options?.user_interface?.pages?.splice(this.activity?.options?.user_interface?.pages.indexOf(page), 1); - this.onReorder.emit({activity: this.activity!, page: page}); + this.onReorder.emit({activity: this.activity!, page: page, operation: Operation.DeletePage}); } } diff --git a/src/app/activity-viewer/activity-viewer.component.css b/src/app/activity-viewer/activity-viewer.component.css index d58ed4b..bc841df 100644 --- a/src/app/activity-viewer/activity-viewer.component.css +++ b/src/app/activity-viewer/activity-viewer.component.css @@ -42,3 +42,8 @@ svg * { transition: all 2s; } + +.grid-size input +{ + width: 35px !important; +} diff --git a/src/app/activity-viewer/activity-viewer.component.html b/src/app/activity-viewer/activity-viewer.component.html index 0c135a9..63a3c25 100644 --- a/src/app/activity-viewer/activity-viewer.component.html +++ b/src/app/activity-viewer/activity-viewer.component.html @@ -183,7 +183,34 @@