searchContext: CatalogSearchContext;
isRecordSelected: boolean;
- basketSub: Subscription;
+ selectorSub: Subscription;
hasCourse = false;
courses: any[] = [];
ngOnInit() {
this.searchContext = this.staffCat.searchContext;
this.loadCourseInformation(this.summary.id);
- this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
-
- // Watch for basket changes caused by other components
- this.basketSub = this.basket.onChange.subscribe(() => {
- this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
- });
if (this.searchContext.showBasket) {
this.recordSelector = this.basketSelect;
} else {
this.recordSelector = this.basket;
}
+
+ this.isRecordSelected = this.recordSelector.hasRecordId(this.summary.id);
+
+ // Watch for basket changes caused by other components
+ this.selectorSub = this.recordSelector.onChange.subscribe(() => {
+ this.isRecordSelected =
+ this.recordSelector.hasRecordId(this.summary.id);
+ });
}
ngOnDestroy() {
- this.basketSub.unsubscribe();
+ this.selectorSub.unsubscribe();
}
loadCourseInformation(recordId) {
searchSub: Subscription;
routeSub: Subscription;
basketSub: Subscription;
+ basketSelectSub: Subscription;
+ showingBasket = false;
recordSelector: BasketService | BasketSelectionService;
// searches.
//
// This will also fire on page load.
- this.routeSub =
- this.route.queryParamMap.subscribe((params: ParamMap) => {
-
- // TODO: Angular docs suggest using switchMap(), but
- // it's not firing for some reason. Also, could avoid
- // firing unnecessary searches when a param unrelated to
- // searching is changed by .map()'ing out only the desired
- // params and running through .distinctUntilChanged(), but
- // .map() is not firing either. I'm missing something.
- this.searchByUrl(params);
+ this.routeSub = this.route.queryParamMap.subscribe((params: ParamMap) => {
+
+ // TODO: Angular docs suggest using switchMap(), but
+ // it's not firing for some reason. Also, could avoid
+ // firing unnecessary searches when a param unrelated to
+ // searching is changed by .map()'ing out only the desired
+ // params and running through .distinctUntilChanged(), but
+ // .map() is not firing either. I'm missing something.
+ this.searchByUrl(params);
+
+ if (this.searchContext.showBasket) {
+ if (!this.showingBasket) {
+ // Only init the basket selector when navigating
+ // to the basket view from a non-basket view.
+ this.basketSelect.init();
+ this.showingBasket = true;
+ }
+ } else {
+ this.showingBasket = false;
+ }
});
// After each completed search, update the record selector.
this.basketSub = this.basket.onChange.subscribe(
() => this.applyRecordSelection());
+ this.basketSelectSub = this.basketSelect.onChange.subscribe(
+ () => this.applyRecordSelection());
+
if (this.searchContext.showBasket) {
this.recordSelector = this.basketSelect;
- this.basketSelect.init();
} else {
this.recordSelector = this.basket;
}
this.routeSub.unsubscribe();
this.searchSub.unsubscribe();
this.basketSub.unsubscribe();
+ this.basketSelectSub.unsubscribe();
}
}
// Apply the select-all checkbox when all visible records
// are selected.
applyRecordSelection() {
- const ids = this.searchContext.currentResultIds();
+ const ids = this.showingBasket ? this.basket.idList :
+ this.searchContext.currentResultIds();
+
let allChecked = true;
ids.forEach(id => {
if (!this.recordSelector.hasRecordId(id)) {
}
toggleAllRecsSelected() {
- const ids = this.searchContext.currentResultIds();
- if (this.allRecsSelected) {
- this.recordSelector.addRecordIds(ids);
+ if (this.showingBasket) {
+ if (this.allRecsSelected) {
+ this.basketSelect.init();
+ } else {
+ this.basketSelect.removeAllRecordIds();
+ }
+
} else {
- this.recordSelector.removeRecordIds(ids);
+
+ const ids = this.searchContext.currentResultIds();
+
+ if (this.allRecsSelected) {
+ this.recordSelector.addRecordIds(ids);
+ } else {
+ this.recordSelector.removeRecordIds(ids);
+ }
}
}
}