Catalog set default tab WIP
authorBill Erickson <berickxx@gmail.com>
Mon, 3 Dec 2018 23:11:09 +0000 (18:11 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 3 Dec 2018 23:11:09 +0000 (18:11 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/record.component.ts

index 96c733e..d4dcd0d 100644 (file)
     </eg-bib-summary>
   </div>
   <div id='staff-catalog-bib-tabs-container' class='mt-3'>
+    <div class="row">
+      <div class="col-lg-12 text-right">
+        <button class="btn btn-secondary btn-sm" 
+            [disabled]="recordTab == defaultTab"
+            (click)="setDefaultTab()" i18n>Set Default View</button>
+      </div>
+    </div>
     <ngb-tabset #recordTabs [activeId]="recordTab" (tabChange)="onTabChange($event)">
       <ngb-tab title="Copy Table" i18n-title id="copy_table">
         <ng-template ngbTabContent>
@@ -28,7 +35,7 @@
       <!-- NOTE some tabs send the user over to the AngJS app -->
       <ngb-tab title="MARC Edit" i18n-title id="marc_edit">
       </ngb-tab>
-      <ngb-tab title="MARC View" i18n-title id="marc_view">
+      <ngb-tab title="MARC View" i18n-title id="marc_html">
         <ng-template ngbTabContent>
           <eg-marc-html [recordId]="recordId" recordType="bib"></eg-marc-html>
         </ng-template>
index 7dfaf2f..abcc24e 100644 (file)
@@ -8,6 +8,7 @@ import {CatalogService} from '@eg/share/catalog/catalog.service';
 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
 import {StaffCatalogService} from '../catalog.service';
 import {BibSummaryComponent} from '@eg/staff/share/bib-summary/bib-summary.component';
+import {StoreService} from '@eg/core/store.service';
 
 @Component({
   selector: 'eg-catalog-record',
@@ -20,6 +21,7 @@ export class RecordComponent implements OnInit {
     summary: BibRecordSummary;
     searchContext: CatalogSearchContext;
     @ViewChild('recordTabs') recordTabs: NgbTabset;
+    defaultTab: string; // eg.cat.default_record_tab
 
     constructor(
         private router: Router,
@@ -27,21 +29,39 @@ export class RecordComponent implements OnInit {
         private pcrud: PcrudService,
         private bib: BibRecordService,
         private cat: CatalogService,
-        private staffCat: StaffCatalogService
+        private staffCat: StaffCatalogService,
+        private store: StoreService
     ) {}
 
     ngOnInit() {
         this.searchContext = this.staffCat.searchContext;
 
+        this.defaultTab = 
+            this.store.getLocalItem('eg.cat.default_record_tab')
+            || 'copy_table';
+
+        // TODO: Implement default tab handling for tabs that require
+        // and AngJS redirect.
+
         // Watch for URL record ID changes
+        // This includes the initial route.
+        // When applying the default configured tab, no navigation occurs
+        // to apply the tab name to the URL, it displays as the default.
+        // This is done so no intermediate redirect is required, which
+        // messes with browser back/forward navigation.
         this.route.paramMap.subscribe((params: ParamMap) => {
-            this.recordTab = params.get('tab') || 'copy_table';
+            this.recordTab = params.get('tab') || this.defaultTab;
             this.recordId = +params.get('id');
             this.searchContext = this.staffCat.searchContext;
             this.loadRecord();
         });
     }
 
+    setDefaultTab() {
+        this.defaultTab = this.recordTab;
+        this.store.setLocalItem('eg.cat.default_record_tab', this.recordTab);
+    }
+
     // Changing a tab in the UI means changing the route.
     // Changing the route ultimately results in changing the tab.
     onTabChange(evt: NgbTabChangeEvent) {
@@ -63,10 +83,7 @@ export class RecordComponent implements OnInit {
                 return;
         }
 
-        let url = '/staff/catalog/record/' + this.recordId;
-        if (this.recordTab !== 'copy_table') {
-            url += '/' + this.recordTab;
-        }
+        const url = `/staff/catalog/record/${this.recordId}/${this.recordTab}`;
 
         // Retain search parameters
         this.router.navigate([url], {queryParamsHandling: 'merge'});