LP1852782 Tag menu static additions
authorBill Erickson <berickxx@gmail.com>
Wed, 11 Dec 2019 21:44:29 +0000 (16:44 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 21 Feb 2020 16:44:38 +0000 (11:44 -0500)
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>
Open-ILS/src/eg2/src/app/share/context-menu/context-menu-container.component.html
Open-ILS/src/eg2/src/app/share/context-menu/context-menu.service.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts

index 9a30288..b25f2cf 100644 (file)
@@ -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>
index 838274b..cd94700 100644 (file)
@@ -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 {
index 5dd8c29..07b6776 100644 (file)
@@ -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}}' 
index 03acd76..312f7b1 100644 (file)
@@ -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.