identQueryType: null,
org: null,
limit: null,
- offset: null
+ offset: null,
+ copyLocations: null
};
params.org = context.searchOrg.id();
}));
});
+ if (context.copyLocations.length && context.copyLocations[0] !== '') {
+ params.copyLocations = context.copyLocations.join(',');
+ }
+
return params;
}
if (params.get('org')) {
context.searchOrg = this.org.get(+params.get('org'));
}
+
+ if (params.get('copyLocations')) {
+ context.copyLocations = params.get('copyLocations').split(/,/);
+ }
}
}
import {Observable} from 'rxjs/Observable';
import {mergeMap} from 'rxjs/operators/mergeMap';
import {map} from 'rxjs/operators/map';
+import {tap} from 'rxjs/operators/tap';
import {OrgService} from '@eg/core/org.service';
import {UnapiService} from '@eg/share/catalog/unapi.service';
import {IdlService, IdlObject} from '@eg/core/idl.service';
ccvmMap: {[ccvm: string]: IdlObject[]} = {};
cmfMap: {[cmf: string]: IdlObject} = {};
+ copyLocations: IdlObject[];
// Keep a reference to the most recently retrieved facet data,
// since facet data is consistent across a given search.
);
});
}
+
+ fetchCopyLocations(contextOrg: number | IdlObject): Promise<any> {
+ const orgIds = this.org.fullPath(contextOrg, true);
+ this.copyLocations = [];
+
+ return this.pcrud.search('acpl',
+ {deleted: 'f', opac_visible: 't', owning_lib: orgIds},
+ {order_by: {acpl: 'name'}},
+ {anonymous: true}
+ ).pipe(tap(loc => this.copyLocations.push(loc))).toPromise()
+ }
}
facetFilters: FacetFilter[];
isStaff: boolean;
basket = false;
+ copyLocations: string[]; // ID's, but treated as strings in the UI.
// Result from most recent search.
result: any = {};
this.resultIds = [];
this.searchState = CatalogSearchState.PENDING;
this.basket = false;
+ this.copyLocations = [''];
}
isSearchable(): boolean {
this.org.root().ou_type().depth() + ')';
}
+ if (this.copyLocations[0] !== '') {
+ str += ' locations(' + this.copyLocations + ')';
+ }
+
str += ' site(' + this.searchOrg.shortname() + ')';
Object.keys(this.ccvmFilters).forEach(field => {
<button class="btn btn-outline-secondary" type="button"
*ngIf="!showAdvanced()"
[disabled]="searchIsActive()"
- (click)="showAdvancedSearch=true">
+ (click)="toggleAdvancedSearch()">
More Filters
</button>
<button class="btn btn-outline-secondary" type="button"
*ngIf="showAdvanced()"
- (click)="showAdvancedSearch=false">
+ (click)="toggleAdvancedSearch()">
Hide Filters
</button>
</div>
</select>
</div>
<div class="col-lg-2">
- <i>Copy location filter goes here...</i>
+ <ng-container *ngIf="copyLocations.length > 0">
+ <select class="form-control"
+ [(ngModel)]="searchContext.copyLocations" multiple="true">
+ <option value='' i18n>All Copy Locations</option>
+ <option *ngFor="let loc of copyLocations" value="{{loc.id()}}" i18n>
+ {{loc.name()}} ({{orgName(loc.owning_lib())}})
+ </option>
+ </select>
+ </ng-container>
</div>
</div>
</div>
ccvmMap: {[ccvm: string]: IdlObject[]} = {};
cmfMap: {[cmf: string]: IdlObject} = {};
showAdvancedSearch = false;
+ copyLocations: IdlObject[];
constructor(
private renderer: Renderer2,
private org: OrgService,
private cat: CatalogService,
private staffCat: StaffCatalogService
- ) {}
+ ) {
+ this.copyLocations = [];
+ }
ngOnInit() {
this.ccvmMap = this.cat.ccvmMap;
// Otherwise focus the main query input
this.renderer.selectRootElement('#first-query-input').focus();
}
+
+ this.refreshCopyLocations();
}
/**
return this.showAdvancedSearch;
}
+ toggleAdvancedSearch() {
+ this.showAdvancedSearch = !this.showAdvancedSearch;
+ this.refreshCopyLocations();
+ }
+
hasAdvancedOptions(): boolean {
+
+ if (this.searchContext.copyLocations[0] !== '') { return true; }
+ if (this.searchContext.identQuery) { return true; }
+
// ccvm filters may be present without any filters applied.
// e.g. if filters were applied then removed.
let show = false;
}
});
- if (this.searchContext.identQuery) {
- show = true;
- }
-
return show;
}
orgOnChange = (org: IdlObject): void => {
this.searchContext.searchOrg = org;
+ this.refreshCopyLocations();
+ }
+
+ refreshCopyLocations() {
+ if (!this.showAdvanced()) { return; }
+
+ // TODO: is this how we avoid displaying too many locations?
+ const org = this.searchContext.searchOrg;
+ if (org.id() === this.org.root().id()) { return; }
+
+ this.cat.fetchCopyLocations(org).then(() =>
+ this.copyLocations = this.cat.copyLocations
+ );
+ }
+
+ orgName(orgId: number): string {
+ return this.org.get(orgId).shortname();
}
addSearchRow(index: number): void {