From 5433deb76cd42e7adbae4319cd008413f827fe07 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 29 Jan 2019 11:15:38 -0500 Subject: [PATCH] LP1813647 Angular page title component & sandbox example Adds a new component which may be used to pass strings to the native Angular Title service. Each title may have a prefix and/or a suffix. If both are defined, they are separated by a "-" (by default / en-US) and the prefix is tructed to 12 characters, consistent with AngularJS strings.setPageTitle() function. Signed-off-by: Bill Erickson --- .../eg2/src/app/share/title/title.component.html | 19 ++++++++ .../src/eg2/src/app/share/title/title.component.ts | 55 ++++++++++++++++++++++ Open-ILS/src/eg2/src/app/staff/common.module.ts | 3 ++ .../src/app/staff/sandbox/sandbox.component.html | 14 +++++- .../eg2/src/app/staff/sandbox/sandbox.component.ts | 3 +- 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/title/title.component.html create mode 100644 Open-ILS/src/eg2/src/app/share/title/title.component.ts diff --git a/Open-ILS/src/eg2/src/app/share/title/title.component.html b/Open-ILS/src/eg2/src/app/share/title/title.component.html new file mode 100644 index 0000000000..a72eef7024 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/title/title.component.html @@ -0,0 +1,19 @@ + + + + + + + {{pfx | slice:0:12}} - + + {{pfx}} + + + {{sfx}} + + + Evergreen + + + + diff --git a/Open-ILS/src/eg2/src/app/share/title/title.component.ts b/Open-ILS/src/eg2/src/app/share/title/title.component.ts new file mode 100644 index 0000000000..8dc18718e9 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/title/title.component.ts @@ -0,0 +1,55 @@ +import {Component, Input, AfterViewInit, ViewChild} from '@angular/core'; +import {Title} from '@angular/platform-browser'; +import {StringComponent} from '@eg/share/string/string.component'; + +/* + + + + Tab title shows (in en-US): "Patron #123 - Staff Client" +*/ + +@Component({ + selector: 'eg-title', + templateUrl: 'title.component.html' +}) + +export class TitleComponent implements AfterViewInit { + + initDone: boolean; + + pfx: string; + @Input() set prefix(p: string) { + this.pfx = p; + this.setTitle(); + } + + sfx: string; + @Input() set suffix(s: string) { + this.sfx = s; + this.setTitle(); + } + + @ViewChild('titleString') titleString: StringComponent; + + constructor(private title: Title) {} + + ngAfterViewInit() { + this.initDone = true; + this.setTitle(); + } + + setTitle() { + + // Avoid setting the title while the page is still loading + if (!this.initDone) { return; } + + setTimeout(() => { + this.titleString.current({pfx: this.pfx, sfx: this.sfx}) + .then(txt => this.title.setTitle(txt)); + }); + } +} + diff --git a/Open-ILS/src/eg2/src/app/staff/common.module.ts b/Open-ILS/src/eg2/src/app/staff/common.module.ts index e83143c9a3..5a83f8ac29 100644 --- a/Open-ILS/src/eg2/src/app/staff/common.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/common.module.ts @@ -14,6 +14,7 @@ import {ToastService} from '@eg/share/toast/toast.service'; import {ToastComponent} from '@eg/share/toast/toast.component'; import {StringComponent} from '@eg/share/string/string.component'; import {StringService} from '@eg/share/string/string.service'; +import {TitleComponent} from '@eg/share/title/title.component'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; import {DateSelectComponent} from '@eg/share/date-select/date-select.component'; import {RecordBucketDialogComponent} from '@eg/staff/share/buckets/record-bucket-dialog.component'; @@ -35,6 +36,7 @@ import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.componen AccessKeyInfoComponent, ToastComponent, StringComponent, + TitleComponent, OpChangeComponent, FmRecordEditorComponent, DateSelectComponent, @@ -58,6 +60,7 @@ import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.componen AccessKeyInfoComponent, ToastComponent, StringComponent, + TitleComponent, OpChangeComponent, FmRecordEditorComponent, DateSelectComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 8249335155..00c2ee7397 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -2,6 +2,19 @@ + + + +
+
Modify Page Title:
+
+ +
+
+
Hello, {{context.world}}!

-HERasdfE
diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index a36af85f8a..ed2c496257 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -53,6 +53,8 @@ export class SandboxComponent implements OnInit { name = 'Jane'; + dynamicTitleText: string; + complimentEvergreen: (rows: IdlObject[]) => void; notOneSelectedRow: (rows: IdlObject[]) => boolean; @@ -112,7 +114,6 @@ export class SandboxComponent implements OnInit { this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!'); this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1); - } btGridRowClassCallback(row: any): string { -- 2.11.0