From 393373cc1509d8e4b0056b42c2ab9397571072fe Mon Sep 17 00:00:00 2001 From: Bill Erickson <berickxx@gmail.com> Date: Wed, 11 Dec 2019 16:44:29 -0500 Subject: [PATCH] LP1852782 Tag menu static additions Adds support for add 006/007/008, delete fields and optionally add new field before and after actions to the context menus displayed for control field and data field tags. Signed-off-by: Bill Erickson <berickxx@gmail.com> Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu> --- .../context-menu-container.component.html | 17 ++++--- .../app/share/context-menu/context-menu.service.ts | 5 +- .../marc-edit/editable-content.component.html | 11 ++++ .../share/marc-edit/editable-content.component.ts | 59 ++++++++++++++++++++-- 4 files changed, 81 insertions(+), 11 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/context-menu/context-menu-container.component.html b/Open-ILS/src/eg2/src/app/share/context-menu/context-menu-container.component.html index 9a302883f7..b25f2cf356 100644 --- a/Open-ILS/src/eg2/src/app/share/context-menu/context-menu-container.component.html +++ b/Open-ILS/src/eg2/src/app/share/context-menu/context-menu-container.component.html @@ -1,10 +1,15 @@ <ng-template #menuTemplate> - <!-- apply (click) to div so user can click anywhere in the row --> - <div *ngFor="let entry of menuEntries; first as isFirst" - class="menu-entry {{entryClasses}}"> - <button (click)="entryClicked(entry)" class="btn p-0 m-0"> - {{entry.label}} - </button> + + <div *ngFor="let entry of menuEntries" class="menu-entry {{entryClasses}}"> + + <div *ngIf="entry.divider" class="dropdown-divider"></div> + + <ng-container *ngIf="!entry.divider"> + <button (click)="entryClicked(entry)" class="btn p-0 m-0"> + {{entry.label}} + </button> + </ng-container> + </div> </ng-template> diff --git a/Open-ILS/src/eg2/src/app/share/context-menu/context-menu.service.ts b/Open-ILS/src/eg2/src/app/share/context-menu/context-menu.service.ts index 838274b388..cd9470015b 100644 --- a/Open-ILS/src/eg2/src/app/share/context-menu/context-menu.service.ts +++ b/Open-ILS/src/eg2/src/app/share/context-menu/context-menu.service.ts @@ -5,8 +5,9 @@ import {tap} from 'rxjs/operators'; * template container component */ export interface ContextMenuEntry { - value: string; - label: string; + value?: string; + label?: string; + divider?: boolean; } export class ContextMenu { diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html index 5dd8c2996c..07b67767a6 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html @@ -1,4 +1,15 @@ +<!-- +Some context menus have additional static options. +Track their labels here. +--> +<eg-string #add006 text="Add 006" i18n-text></eg-string> +<eg-string #add007 text="Add 007" i18n-text></eg-string> +<eg-string #add008 text="Add/Replace 008" i18n-text></eg-string> +<eg-string #insertBefore text="Insert Field Before" i18n-text></eg-string> +<eg-string #insertAfter text="Insert Field After" i18n-text></eg-string> +<eg-string #deleteField text="Delete Field" i18n-text></eg-string> + <ng-container *ngIf="bigText"> <div contenteditable id='{{randId}}' diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts index 03acd76b18..312f7b1b67 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts @@ -1,5 +1,5 @@ import {ElementRef, Component, Input, Output, OnInit, OnDestroy, - EventEmitter, AfterViewInit, Renderer2} from '@angular/core'; + ViewChild, EventEmitter, AfterViewInit, Renderer2} from '@angular/core'; import {Subscription} from 'rxjs'; import {filter} from 'rxjs/operators'; import {MarcRecord, MarcField, MarcSubfield} from './marcrecord'; @@ -7,6 +7,7 @@ import {MarcEditContext, FieldFocusRequest, MARC_EDITABLE_FIELD_TYPE, TextUndoRedoAction} from './editor-context'; import {ContextMenuEntry} from '@eg/share/context-menu/context-menu.service'; import {TagTableService} from './tagtable.service'; +import {StringComponent} from '@eg/share/string/string.component'; /** * MARC Editable Content Component @@ -57,11 +58,21 @@ export class EditableContentComponent // Cache of fixed field menu options ffValues: ContextMenuEntry[] = []; + // Cache of tag context menu entries + tagMenuEntries: ContextMenuEntry[] = []; + // Track the fixed field value locally since extracting the value // in real time from the record, which adds padding to the text, // causes usability problems. ffValue: string; + @ViewChild('add006', {static: false}) add006Str: StringComponent; + @ViewChild('add007', {static: false}) add007Str: StringComponent; + @ViewChild('add008', {static: false}) add008Str: StringComponent; + @ViewChild('insertBefore', {static: false}) insertBeforeStr: StringComponent; + @ViewChild('insertAfter', {static: false}) insertAfterStr: StringComponent; + @ViewChild('deleteField', {static: false}) deleteFieldStr: StringComponent; + constructor( private renderer: Renderer2, private tagTable: TagTableService) {} @@ -198,11 +209,11 @@ export class EditableContentComponent // These are served dynamically to handle cases where a tag or // subfield is modified in place. contextMenuEntries(): ContextMenuEntry[] { - if (this.isLeader) { return; } + if (!this.field) { return; } switch (this.fieldType) { case 'tag': - return this.tagTable.getFieldTags(); + return this.tagContextMenuEntries(); case 'sfc': return this.tagTable.getSubfieldCodes(this.field.tag); @@ -224,6 +235,36 @@ export class EditableContentComponent return null; } + tagContextMenuEntries(): ContextMenuEntry[] { + + // string components may not yet be loaded. + if (this.tagMenuEntries.length > 0 || !this.add006Str) { + return this.tagMenuEntries; + } + + this.tagMenuEntries.push( + {label: this.add006Str.text, value: '_add006'}, + {label: this.add007Str.text, value: '_add007'}, + {label: this.add008Str.text, value: '_add008'} + ); + + if (!this.field.isCtrlField) { + this.tagMenuEntries.push( + {label: this.insertAfterStr.text, value: '_insertAfter'}, + {label: this.insertBeforeStr.text, value: '_insertBefore'} + ); + } + + this.tagMenuEntries.push( + {label: this.deleteFieldStr.text, value: '_deleteField'}, + {divider: true} + ); + + this.tagTable.getFieldTags().forEach(e => this.tagMenuEntries.push(e)); + + return this.tagMenuEntries; + } + getContent(): string { if (this.fieldText) { return this.fieldText; } // read-only @@ -538,6 +579,18 @@ export class EditableContentComponent } contextMenuChange(value: string) { + + switch (value) { + case '_add006': return this.context.add00X('006'); + case '_add007': return this.context.add00X('007'); + case '_add008': return this.context.insertReplace008(); + case '_insertBefore': + return this.context.insertStubField(this.field, true); + case '_insertAfter': + return this.context.insertStubField(this.field); + case '_deleteField': return this.context.deleteField(this.field); + } + this.setContent(value, true); // Context menus can steal focus. -- 2.11.0