Skip to content

Commit

Permalink
cleanup toolbar implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Oct 15, 2023
1 parent 1bf3c2d commit 8cee2a5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 58 deletions.
2 changes: 1 addition & 1 deletion projects/aas-lib/src/test/download.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { EMPTY, first, of } from 'rxjs';
import { EMPTY } from 'rxjs';

import { DownloadService } from '../lib/download.service';

Expand Down
6 changes: 4 additions & 2 deletions projects/aas-portal/src/app/aas/aas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
public aasTree: lib.AASTree | null = null;

@ViewChild('aasToolbar', { read: TemplateRef })
public aasToolbar!: TemplateRef<undefined>;
public aasToolbar: TemplateRef<unknown> | null = null;

public document: AASDocument | null = null;

Expand Down Expand Up @@ -202,7 +202,9 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
this.subscription.add(this.aasTree.selectedElements.subscribe(values => this.selectedElements = values));
}

this.toolbar.set(this.aasToolbar);
if (this.aasToolbar) {
this.toolbar.set(this.aasToolbar);
}
}

public ngOnDestroy(): void {
Expand Down
10 changes: 6 additions & 4 deletions projects/aas-portal/src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ToolbarService } from '../toolbar.service';
})
export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
constructor(
private serverApi: ServerApiService,
private serverApi: ServerApiService,
private translate: TranslateService,
private toolbar: ToolbarService) {
this.author = pkg.author;
Expand All @@ -29,7 +29,7 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
}

@ViewChild('aasToolbar', { read: TemplateRef })
public aboutToolbar!: TemplateRef<undefined>;
public aboutToolbar: TemplateRef<unknown> | null = null;

public version = '';

Expand All @@ -46,15 +46,17 @@ export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
public ngOnInit(): void {

this.serverApi.getInfo().subscribe(info => {
this.serverVersion = info.version;
this.serverVersion = info.version;
this.libraries = info.libraries ?? [];
});

this.serverApi.getMessages().subscribe(messages => this.messages = messages);
}

public ngAfterViewInit(): void {
this.toolbar.set(this.aboutToolbar);
if (this.aboutToolbar) {
this.toolbar.set(this.aboutToolbar);
}
}

public ngOnDestroy(): void {
Expand Down
48 changes: 4 additions & 44 deletions projects/aas-portal/src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit, Aft
public chartContainers: QueryList<ElementRef<HTMLCanvasElement>> | null = null;

@ViewChild('dashboardToolbar', { read: TemplateRef })
public dashboardToolbar!: TemplateRef<undefined>;
public dashboardToolbar: TemplateRef<unknown> | null = null;

public get page(): DashboardPage {
return this._page;
Expand Down Expand Up @@ -193,7 +193,9 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit, Aft
}

public ngAfterViewInit(): void {
this.toolbar.set(this.dashboardToolbar);
if (this.dashboardToolbar) {
this.toolbar.set(this.dashboardToolbar);
}
}

public ngAfterViewChecked(): void {
Expand Down Expand Up @@ -837,46 +839,4 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit, Aft
private isChart(value?: DashboardItem | null): value is DashboardChart {
return value?.type === DashboardItemType.Chart;
}

// private createToolbar(): lib.Toolbar {
// const $editMode = this.store.select(selectEditMode);
// return {
// groups: [
// this.toolbar.createGroup(
// [
// this.toolbar.createSelect<string>(
// this.store.select(selectPages)
// .pipe(map(pages => pages.map(page => this.toolbar.createOption(
// page.name,
// page.name)))),
// this.store.select(selectName),
// (name) => this.setPage(name)),
// this.toolbar.createButton('bi bi-plus', () => this.addNew(), () => this.editMode),
// this.toolbar.createButton('bi bi-pen', () => this.rename(), () => this.editMode),
// this.toolbar.createButton('bi bi-trash', () => this.delete(), () => this.editMode)
// ]),
// this.toolbar.createGroup(
// [
// this.toolbar.createSwitch(
// 'Edit mode',
// $editMode,
// () => this.toggleEditMode())
// ]),
// this.toolbar.createGroup(
// [
// this.toolbar.createButton('bi bi-arrow-90deg-left', () => this.undo(), () => this.canUndo()),
// this.toolbar.createButton('bi bi-arrow-90deg-right', () => this.redo(), () => this.canRedo()),
// ],
// $editMode),
// this.toolbar.createGroup(
// [
// this.toolbar.createButton('bi bi-box-arrow-left', () => this.moveLeft(), () => this.canMoveLeft()),
// this.toolbar.createButton('bi bi-box-arrow-up', () => this.moveUp(), () => this.canMoveUp()),
// this.toolbar.createButton('bi bi-box-arrow-down', () => this.moveDown(), () => this.canMoveDown()),
// this.toolbar.createButton('bi bi-box-arrow-right', () => this.moveRight(), () => this.canMoveRight())
// ],
// $editMode),
// ]
// };
// }
}
6 changes: 4 additions & 2 deletions projects/aas-portal/src/app/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class StartComponent implements OnInit, OnDestroy, AfterViewInit {
public aasTable: lib.AASTable | null = null;

@ViewChild('startToolbar', { read: TemplateRef })
public startToolbar!: TemplateRef<unknown>;
public startToolbar: TemplateRef<unknown> | null = null;

public viewMode: lib.ViewMode = lib.ViewMode.List;

Expand Down Expand Up @@ -120,7 +120,9 @@ export class StartComponent implements OnInit, OnDestroy, AfterViewInit {
}

public ngAfterViewInit(): void {
this.toolbar.set(this.startToolbar);
if (this.startToolbar) {
this.toolbar.set(this.startToolbar);
}
}

public ngOnDestroy(): void {
Expand Down
4 changes: 3 additions & 1 deletion projects/aas-portal/src/app/view/view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

<fhg-digital-nameplate *ngIf="template === 'Nameplate'" [submodels]="submodels"></fhg-digital-nameplate>
<fhg-customer-feedback *ngIf="template === 'CustomerFeedback'" [submodels]="submodels"></fhg-customer-feedback>
<div *ngIf="!template" class="alert alert-info" role="alert">No well known submodel selected.</div>
<div *ngIf="!template" class="alert alert-info" role="alert">No well known submodel selected.</div>

<ng-template #viewToolbar></ng-template>
18 changes: 15 additions & 3 deletions projects/aas-portal/src/app/view/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { Component, OnDestroy, OnInit } from '@angular/core';
import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { EMPTY, from, mergeMap, of, Subscription, toArray, zip } from 'rxjs';
Expand All @@ -16,21 +16,23 @@ import { State } from './view.state';
import * as ViewActions from './view.actions';
import * as ViewSelectors from './view.selectors';
import { ProjectService } from '../project/project.service';
import { ToolbarService } from '../toolbar.service';

@Component({
selector: 'fhg-view',
templateUrl: './view.component.html',
styleUrls: ['./view.component.scss']
})
export class ViewComponent implements OnInit, OnDestroy {
export class ViewComponent implements OnInit, AfterViewInit, OnDestroy {
private readonly store: Store<State>;
private readonly subscription = new Subscription();

constructor(
store: Store,
private readonly route: ActivatedRoute,
private readonly project: ProjectService,
private readonly clipboard: lib.ClipboardService
private readonly clipboard: lib.ClipboardService,
private readonly toolbar: ToolbarService
) {
this.store = store as Store<State>;
this.subscription.add(this.store.select(ViewSelectors.selectSubmodels)
Expand All @@ -44,6 +46,9 @@ export class ViewComponent implements OnInit, OnDestroy {
}));
}

@ViewChild('viewToolbar', { read: TemplateRef })
public viewToolbar: TemplateRef<unknown> | null = null;

public template?: string;

public submodels: lib.DocumentSubmodelPair[] = [];
Expand Down Expand Up @@ -73,7 +78,14 @@ export class ViewComponent implements OnInit, OnDestroy {
}
}

public ngAfterViewInit(): void {
if (this.viewToolbar) {
this.toolbar.set(this.viewToolbar);
}
}

public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.toolbar.clear();
}
}
2 changes: 1 addition & 1 deletion projects/aas-portal/src/test/aas/aas.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Store, StoreModule } from '@ngrx/store';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { AASDocument, aas } from 'common';
import { Observable, first, noop, of } from 'rxjs';
import { Observable, noop, of } from 'rxjs';
import { AASTree, DownloadService, NotifyService, OnlineState } from 'projects/aas-lib/src/public-api';
import { CommonModule } from '@angular/common';

Expand Down

0 comments on commit 8cee2a5

Please sign in to comment.