From: Bill Erickson Date: Thu, 7 Dec 2017 16:46:41 +0000 (-0500) Subject: LP#626157 Ang2 experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e2b5e50ed2201ae68072081932d59b2d84921030;p=working%2FEvergreen.git LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/webby-src/src/app/share/catalog/catalog-url.service.ts b/Open-ILS/webby-src/src/app/share/catalog/catalog-url.service.ts index 009f86f839..68c33c5db4 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/catalog-url.service.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/catalog-url.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core'; import {ParamMap} from '@angular/router'; import {EgOrgService} from '@eg/core/org'; -import {CatalogSearchContext} from './search-context'; +import {CatalogSearchContext, FacetFilter} from './search-context'; import {CATALOG_CCVM_FILTERS} from './catalog.service'; @Injectable() @@ -111,7 +111,8 @@ export class EgCatalogUrlService { }); params.getAll('facets').forEach(blob => { - context.facetFilters.push(JSON.parse(blob)); + let facet: FacetFilter = JSON.parse(blob) + context.addFacet(facet); }); context.searchOrg = diff --git a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts index e88d12f4dc..7f3e376902 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts @@ -4,7 +4,7 @@ import {EgUnapiService} from '@eg/share/unapi'; import {EgIdlObject} from '@eg/core/idl'; import {EgNetService} from '@eg/core/net'; import {EgPcrudService} from '@eg/core/pcrud'; -import {CatalogSearchContext} from './search-context'; +import {CatalogSearchContext, CatalogSearchState} from './search-context'; export const CATALOG_CCVM_FILTERS = [ 'item_type', @@ -32,7 +32,7 @@ export class EgCatalogService { ) {} search(ctx: CatalogSearchContext): Promise { - ctx.searchInProgress = true; + ctx.searchState = CatalogSearchState.SEARCHING; var fullQuery = ctx.compileSearch(); @@ -52,7 +52,7 @@ export class EgCatalogService { ctx.result = result; ctx.result.records = []; ctx.pager.resultCount = result.count; - ctx.searchInProgress = false; + ctx.searchState = CatalogSearchState.COMPLETE; let promises = []; result.ids.forEach(blob => { diff --git a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts index d71b063122..0dea6274da 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts @@ -5,10 +5,30 @@ import {Params} from '@angular/router'; // Document and enforce facet filter entries. -interface FacetFilter { +export class FacetFilter { facetClass: string; facetName: string; facetValue: string; + + constructor(cls: string, name: string, value: string) { + this.facetClass = cls; + this.facetName = name; + this.facetValue = value; + } + + equals(filter: FacetFilter): boolean { + return ( + this.facetClass == filter.facetClass && + this.facetName == filter.facetName && + this.facetValue == filter.facetValue + ); + } +} + +export enum CatalogSearchState { + PENDING, + SEARCHING, + COMPLETE } // Not an angular service. @@ -16,8 +36,8 @@ interface FacetFilter { export class CatalogSearchContext { // Search options and filters - available: boolean; - global: boolean; + available: boolean = false; + global: boolean = false; sort: string; fieldClass: string[]; query: string[]; @@ -31,7 +51,7 @@ export class CatalogSearchContext { // Result from most recent search. result: any = {}; - searchInProgress: boolean = false; + searchState: CatalogSearchState = CatalogSearchState.PENDING; // Utility stuff pager: Pager; @@ -42,6 +62,10 @@ export class CatalogSearchContext { this.reset(); } + /** + * Reset search parameters. This does not reset global filters + * like limit-to-available and search-global. + */ reset(): void { this.pager.offset = 0, this.format = '', @@ -50,8 +74,6 @@ export class CatalogSearchContext { this.fieldClass = ['keyword']; this.matchOp = ['contains']; this.joinOp = ['']; - this.available = false; - this.global = false; this.ccvmFilters = {}; this.facetFilters = []; } @@ -59,7 +81,7 @@ export class CatalogSearchContext { compileSearch(): string { let str: string = ''; - if (this.available) str += ' #available'; + if (this.available) str += '#available'; if (this.sort) { // e.g. title, title.descending @@ -151,6 +173,31 @@ export class CatalogSearchContext { return str + query + ')'; } + + hasFacet(facet: FacetFilter): boolean { + return Boolean( + this.facetFilters.filter( + f => {return f.equals(facet)})[0] + ); + } + + removeFacet(facet: FacetFilter): void { + this.facetFilters = this.facetFilters.filter( + f => { return !f.equals(facet); }); + } + + addFacet(facet: FacetFilter): void { + if (!this.hasFacet(facet)) + this.facetFilters.push(facet); + } + + toggleFacet(facet: FacetFilter): void { + if (this.hasFacet(facet)) { + this.removeFacet(facet); + } else { + this.facetFilters.push(facet); + } + } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts b/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts index f4527aa946..e5d65f39e8 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts @@ -8,6 +8,7 @@ import {EgCatalogUrlService} from '@eg/share/catalog/catalog-url.service'; import {EgCatalogComponent} from './catalog.component'; import {SearchFormComponent} from './search-form.component'; import {ResultsComponent} from './result/results.component'; +import {RecordComponent} from './record/record.component'; import {ResultPaginationComponent} from './result/pagination.component'; import {ResultFacetsComponent} from './result/facets.component'; import {ResultRecordComponent} from './result/record.component'; @@ -17,6 +18,7 @@ import {StaffCatalogService} from './staff-catalog.service'; declarations: [ EgCatalogComponent, ResultsComponent, + RecordComponent, SearchFormComponent, ResultRecordComponent, ResultFacetsComponent, diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.css b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html new file mode 100644 index 0000000000..7b7485235c --- /dev/null +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html @@ -0,0 +1,5 @@ + +
+ RECORD {{recordId}} +
+ diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts new file mode 100644 index 0000000000..d3672305c9 --- /dev/null +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts @@ -0,0 +1,34 @@ +import {Component, OnInit, Input} from '@angular/core'; +import {ActivatedRoute, ParamMap} from '@angular/router'; +import {EgPcrudService} from '@eg/core/pcrud'; +import {EgIdlObject} from '@eg/core/idl'; +import {CatalogSearchContext, CatalogSearchState} + from '@eg/share/catalog/search-context'; +import {StaffCatalogService} from '../staff-catalog.service'; + +@Component({ + selector: 'eg-catalog-record', + styleUrls: ['record.component.css'], + templateUrl: 'record.component.html' +}) +export class RecordComponent implements OnInit { + + recordId: number; + searchContext: CatalogSearchContext; + + // Cache record creator/editor since this will likely be a + // reasonably small set of data w/ lots of repitition. + userCache: {[id:number] : EgIdlObject} = {}; + + constructor( + private route: ActivatedRoute, + private pcrud: EgPcrudService, + private staffCat: StaffCatalogService + ) {} + + ngOnInit() { + this.recordId = +this.route.snapshot.paramMap.get('id'); + } +} + + diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html index a951dc92aa..332b77c849 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.html @@ -24,13 +24,14 @@ *ngFor=" let value of searchContext.result.facetData[facetConf.facetClass][name].valueList | slice:0:facetConfig.displayCount">
- diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts index 6bfce97439..d6bc2cf91d 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/facets.component.ts @@ -1,17 +1,17 @@ import {Component, OnInit, Input} from '@angular/core'; import {EgCatalogService} from '@eg/share/catalog/catalog.service'; -import {CatalogSearchContext} from '@eg/share/catalog/search-context'; +import {CatalogSearchContext, FacetFilter} from '@eg/share/catalog/search-context'; import {StaffCatalogService} from '../staff-catalog.service'; export const FACET_CONFIG = { - display: [ - {facetClass : 'author', facetOrder : ['personal', 'corporate']}, - {facetClass : 'subject', facetOrder : ['topic']}, - {facetClass : 'identifier', facetOrder : ['genre']}, - {facetClass : 'series', facetOrder : ['seriestitle']}, - {facetClass : 'subject', facetOrder : ['name', 'geographic']} - ], - displayCount : 5 + display: [ + {facetClass : 'author', facetOrder : ['personal', 'corporate']}, + {facetClass : 'subject', facetOrder : ['topic']}, + {facetClass : 'identifier', facetOrder : ['genre']}, + {facetClass : 'series', facetOrder : ['seriestitle']}, + {facetClass : 'subject', facetOrder : ['name', 'geographic']} + ], + displayCount : 5 }; @Component({ @@ -29,20 +29,20 @@ export class ResultFacetsComponent implements OnInit { private staffCat: StaffCatalogService ) { this.facetConfig = FACET_CONFIG; - } + } ngOnInit() { this.searchContext = this.staffCat.searchContext; } - facetIsApplied(cls: string, name: string, value: string) { - return this.searchContext.facetFilters.filter(f => { - return ( - f.facetClass == cls && - f.facetName == name && - f.facetValue == value - ); - })[0]; + facetIsApplied(cls: string, name: string, value: string): boolean { + return this.searchContext.hasFacet(new FacetFilter(cls, name, value)); + } + + applyFacet(cls: string, name: string, value: string): void { + this.searchContext.toggleFacet(new FacetFilter(cls, name, value)); + this.searchContext.pager.offset = 0; + this.staffCat.search(); } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.css b/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.css index 8865836a25..8e2b849a72 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.css +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.css @@ -2,10 +2,3 @@ /* Bootstrap default is 20px */ .pagination {margin: 10px 0px 10px 0px} -/* style a's without hrefs - * TODO: consider moving this to a shared css file - * */ -.pagination a:hover { - cursor: pointer; -} - diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.html index 56c69b15ec..e5f7c5a52f 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/pagination.component.html @@ -1,18 +1,20 @@
  • -
  • - + {{page}} (current)
  • - diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html index 7c817ce677..98baa0acf3 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.html @@ -17,7 +17,7 @@
    @@ -25,7 +25,8 @@
    @@ -99,14 +100,14 @@
    diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.ts index 3484789dbd..b1bfde5f4e 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/record.component.ts @@ -47,6 +47,13 @@ export class ResultRecordComponent implements OnInit { alert('Adding to list for bib ' + this.bibSummary.id); } + searchAuthor(bibSummary: any) { + this.searchContext.reset(); + this.searchContext.fieldClass = ['author']; + this.searchContext.query = [bibSummary.author]; + this.staffCat.search(); + } + } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html index 796016c3ab..e16ad856ac 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.html @@ -1,5 +1,5 @@ -
    +
    Search Results ({{searchContext.result.count}})
    diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts index 290d358705..50ad129c67 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts @@ -4,7 +4,8 @@ import {map, switchMap, distinctUntilChanged} from 'rxjs/operators'; import {ActivatedRoute, ParamMap} from '@angular/router'; import {EgCatalogService} from '@eg/share/catalog/catalog.service'; import {EgCatalogUrlService} from '@eg/share/catalog/catalog-url.service'; -import {CatalogSearchContext} from '@eg/share/catalog/search-context'; +import {CatalogSearchContext, CatalogSearchState} + from '@eg/share/catalog/search-context'; import {EgPcrudService} from '@eg/core/pcrud'; import {StaffCatalogService} from '../staff-catalog.service'; import {EgIdlObject} from '@eg/core/idl'; @@ -96,8 +97,10 @@ export class ResultsComponent implements OnInit { }); } - searchAuthor(bibSummary: any) { + searchIsDone(): boolean { + return this.searchContext.searchState == CatalogSearchState.COMPLETE; } + } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/routing.module.ts b/Open-ILS/webby-src/src/app/staff/catalog/routing.module.ts index ed8a55290d..f933e035fc 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/routing.module.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/routing.module.ts @@ -2,6 +2,7 @@ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; import {EgCatalogComponent} from './catalog.component'; import {ResultsComponent} from './result/results.component'; +import {RecordComponent} from './record/record.component'; import {EgCatalogResolver} from './resolver.service'; const routes: Routes = [{ @@ -11,6 +12,9 @@ const routes: Routes = [{ children : [{ path: 'search', component: ResultsComponent, + }, { + path: 'record/:id', + component: RecordComponent, }] }]; diff --git a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html index 831bb3d833..993f4f38a0 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.html @@ -76,7 +76,7 @@ TODO focus search input