Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverted expand #9

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import template from "./exclude-beyond-toggle.html";
import { Analytics } from "@src/shared/services/analytics";
import { compose } from "@src/util";

/**
* Removes CDI/PCI results that do not have full-text availability
* (inversion of Primo's "expand beyond" toggle).
*/
class ExcludeBeyondToggleController implements ng.IController {
private rapidoSearchSlots: string[];
private facetCtrl: ng.IController;
private enabledProperties: (object: { property: boolean }) => string[] =
compose(_.keys, _.pickBy);

static $inject = ["analytics", "$location", "$window"];
constructor(
private analytics: Analytics,
private $location: ng.ILocationService,
private $window: ng.IWindowService
) {}

$onInit() {
this.rapidoSearchSlots = this.enabledProperties(
this.$window.appConfig["system-configuration"].hide_rapido_expand_link_map
);
}

/**
* Track toggle clicks
*/
onChange(): void {
this.analytics.trackEvent(
"Exclude CDI Availability Toggle",
this.excludePcAvailability ? "Enabled" : "Disabled"
);
}

get enabled(): boolean {
return this.rapidoSearchSlots.includes(this.activeSearchSlot);
}

get excludePcAvailability(): boolean {
return this.$location.search()["pcAvailability"] === "false";
}

set excludePcAvailability(value: boolean) {
if (value === true) {
this.$location.search("pcAvailability", "false");
} else {
this.$location.search("pcAvailability", null);
}
}

private get activeSearchSlot(): string {
return this.facetCtrl.searchService.getSearchObject().tab;
}
}

export const ExcludeBeyondToggleComponent: ng.IComponentOptions = {
controller: ExcludeBeyondToggleController,
bindings: { facetCtrl: "<" },
template,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div
ng-if="$ctrl.enabled"
class="switch-results switch-results-sliders-ctm"
layout="column"
layout-align="center start"
>
<div class="expand-results-ctm">
<md-switch
class="tiny-switch zero-margin md-primoExplore-theme"
ng-model="$ctrl.excludePcAvailability"
ng-change="$ctrl.onChange()"
ng-class="$ctrl.excludePcAvailability ? 'active' : 'inactive'"
>
<span class="slider-text-wrap"
>Exclude items only available through interlibrary loan</span
>
</md-switch>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./exclude-beyond-toggle.component";
7 changes: 7 additions & 0 deletions src/shared/components/search/facet/facet.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ExcludeBeyondToggleComponent } from "./exclude-beyond-toggle";
import { PrmFacetAfterComponent } from "./prm-facet-after.component";

export const FacetModule = angular
.module("facet", [])
.component("excludeBeyondToggle", ExcludeBeyondToggleComponent)
.component("prmFacetAfter", PrmFacetAfterComponent).name;
1 change: 1 addition & 0 deletions src/shared/components/search/facet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./facet.module";
30 changes: 30 additions & 0 deletions src/shared/components/search/facet/prm-facet-after.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class PrmFacetAfterController implements ng.IController {
private parentCtrl: ng.IController;
static $inject = ["$element", "$scope", "$compile", "$timeout"];
constructor(
private $element: ng.IAugmentedJQuery,
private $scope: ng.IScope,
private $compile: ng.ICompileService,
private $timeout: ng.ITimeoutService
) {}

$onInit() {
this.$timeout(() => this.injectExcludeToggle());
}

injectExcludeToggle() {
const template =
"<exclude-beyond-toggle facet-ctrl=$ctrl.parentCtrl></exclude-beyond-toggle>";
this.$element
.parent()
.find("div")
.children()
.eq(2)
.append(this.$compile(template)(this.$scope));
}
}

export const PrmFacetAfterComponent: ng.IComponentOptions = {
controller: PrmFacetAfterController,
bindings: { parentCtrl: "<" },
};
2 changes: 2 additions & 0 deletions src/shared/components/search/search.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { FullViewModule } from "./full-view";
import { SearchBarModule } from "./search-bar";
import { SearchResultModule } from "./search-result";
import { TopbarModule } from "./topbar";
import { FacetModule } from "./facet";

export const SearchModule = angular.module("search", [
FullViewModule,
SearchBarModule,
SearchResultModule,
TopbarModule,
FacetModule,
]).name;
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const compose =
<T>(...fns: Function[]) =>
(x: T) =>
fns.reduceRight((y, fn) => fn(y), x);

export { compose };
Loading