1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/**
* Build methods for Search Facets.
*/
import * as models from "../../api/models";
import * as serverData from "../../foundation/json-parsing/server-data";
import { categoryListFromApiResponse } from "../categories";
import * as metricsClickHelpers from "../metrics/helpers/clicks";
/**
* Create Search Facets. Theres platform specific variations here.
* @param requestFacets Facets in current request.
* @param categoryFacetsData Additional
*/
export function createSearchFacets(objectGraph, requestFacets, categoryFacetsData) {
const selectedFacets = requestFacets || {};
const facets = [];
// Device Type
if (objectGraph.client.deviceType !== "mac") {
facets.push(new models.SearchFacetSet("targetPlatform", [
new models.SearchFacetValue(objectGraph.loc.string("Search.Facets.iPadAndIPhone"), null, selectedFacets["targetPlatform"]),
new models.SearchFacetValue(objectGraph.loc.string("Search.Facets.iPhoneOnly"), "iphone", selectedFacets["targetPlatform"]),
]));
}
// Price
facets.push(new models.SearchFacetSet("price", [
new models.SearchFacetValue(objectGraph.loc.string("SEARCH_FACET_ANY_PRICE", "Any"), null, selectedFacets["price"]),
new models.SearchFacetValue(objectGraph.loc.string("SEARCH_FACET_FREE", "Any"), "free", selectedFacets["price"]),
]));
// Categories
const categoryList = categoryListFromApiResponse(objectGraph, categoryFacetsData, false);
if (categoryList) {
const serverCategories = categoryList.categories;
if (serverCategories.length) {
const genreFacetValues = serverCategories
.filter((category) => {
return serverData.isDefinedNonNull(category.genreId);
})
.map((category) => {
return new models.SearchFacetValue(category.name, category.genreId, selectedFacets["genre"]);
});
genreFacetValues.unshift(new models.SearchFacetValue(objectGraph.loc.string("SEARCH_FACET_ANY_CATEGORY", "Any"), null, selectedFacets["genre"]));
facets.push(new models.SearchFacetSet("genre", genreFacetValues));
}
}
const searchSortOptions = objectGraph.bag.searchSortOptions;
// Sorts
const sortFacetValues = [];
sortFacetValues.push(new models.SearchFacetValue(objectGraph.loc.string("SEARCH_FACET_RELEVANCE"), null, selectedFacets["sort"]));
for (const sortValue of searchSortOptions) {
sortFacetValues.push(new models.SearchFacetValue(objectGraph.loc.string("SEARCH_FACET_" + sortValue), sortValue, selectedFacets["sort"]));
}
if (sortFacetValues.length > 1) {
facets.push(new models.SearchFacetSet("sort", sortFacetValues));
}
const serverAgeBands = objectGraph.bag.ageBands;
const ageBandFacetValues = serverAgeBands.map((ageBand) => {
return new models.SearchFacetValue(serverData.asString(ageBand, "name"), serverData.asString(ageBand, "ageBandId"), selectedFacets["ages"]);
});
if (ageBandFacetValues.length > 0 && objectGraph.client.deviceType !== "mac") {
facets.push(new models.SearchFacetSet("ages", ageBandFacetValues));
}
return facets;
}
/**
* Create Search Facets. Theres platform specific variations here.
* @param categoryFacetsData Additional
*/
export function createSearchPageFacets(objectGraph, categoryFacetsData) {
let categoryFacet = null;
let sortsFacet = null;
let ageBandsFacet = null;
// Platform
const deviceTypeFacet = new models.PageFacetsFacet("targetPlatform", "targetPlatform", objectGraph.loc.string("SEARCH_FACET_TYPE_TITLE_DEVICE_TYPE"), "singleSelection", [
new models.PageFacetOption(objectGraph.loc.string("Search.Facets.iPadAndIPhone"), null),
new models.PageFacetOption(objectGraph.loc.string("Search.Facets.iPhoneOnly"), "iphone"),
], null, null, pageFacetChangeAction(objectGraph, "targetPlatform"));
// Price
const priceFacet = new models.PageFacetsFacet("filter[price]", "filter[price]", objectGraph.loc.string("SEARCH_FACET_TYPE_TITLE_PRICE"), "singleSelection", [
new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_ANY_PRICE", "Any"), null),
new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_FREE", "Any"), "free"),
], null, null, pageFacetChangeAction(objectGraph, "price"));
// Categories
const categoryList = categoryListFromApiResponse(objectGraph, categoryFacetsData, false);
if (categoryList) {
const serverCategories = categoryList.categories;
if (serverCategories.length) {
const categories = serverCategories.filter((category) => {
return serverData.isDefinedNonNull(category.genreId);
});
categoryFacet = new models.PageFacetsFacet("filter[genre]", "filter[genre]", objectGraph.loc.string("SEARCH_FACET_TYPE_TITLE_CATEGORY"), "singleSelection", [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_ANY_CATEGORY", "Any"), null)], null, null, pageFacetChangeAction(objectGraph, "genre"));
for (const category of categories) {
categoryFacet.options.push(new models.PageFacetOption(category.name, category.genreId));
}
}
}
// Sorts
const searchSortOptions = objectGraph.bag.searchSortOptions;
sortsFacet = new models.PageFacetsFacet("sort", "sort", objectGraph.loc.string("SEARCH_FACET_TYPE_TITLE_SORT"), "singleSelection", [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_RELEVANCE"), null)], null, null, pageFacetChangeAction(objectGraph, "sort"));
for (const sortValue of searchSortOptions) {
sortsFacet.options.push(new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_" + sortValue), sortValue));
}
// Age Bands
const serverAgeBands = objectGraph.bag.ageBands;
const ageBandFacetOptions = serverAgeBands.map((ageBand) => {
return new models.PageFacetOption(serverData.asString(ageBand, "name"), serverData.asString(ageBand, "ageBandId"));
});
if (ageBandFacetOptions.length > 0 && objectGraph.client.deviceType !== "mac") {
ageBandsFacet = new models.PageFacetsFacet("filter[ages]", "filter[ages]", objectGraph.loc.string("SEARCH_FACET_TYPE_TITLE_AGE_BAND"), "singleSelection", ageBandFacetOptions, null, null, pageFacetChangeAction(objectGraph, "ages"));
}
const pageFacets = new models.PageFacets([], false, null);
if (objectGraph.client.isMac) {
pageFacets.facetGroups.push(new models.PageFacetsGroup([priceFacet]));
if (serverData.isDefinedNonNull(categoryFacet)) {
pageFacets.facetGroups.push(new models.PageFacetsGroup([categoryFacet]));
}
pageFacets.facetGroups.push(new models.PageFacetsGroup([sortsFacet]));
}
else {
const facets = [deviceTypeFacet, priceFacet];
if (serverData.isDefinedNonNull(categoryFacet)) {
facets.push(categoryFacet);
}
facets.push(sortsFacet);
if (serverData.isDefinedNonNull(ageBandsFacet)) {
facets.push(ageBandsFacet);
}
for (const facet of facets) {
facet.showsSelectedOptions = true;
}
pageFacets.facetGroups.push(new models.PageFacetsGroup(facets));
}
return pageFacets;
}
export function createDefaultSelectedFacetOptions(objectGraph) {
return {
"targetPlatform": [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_IPAD_ONLY"), null)],
"filter[price]": [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_ANY_PRICE", "Any"), null)],
"sort": [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_RELEVANCE"), null)],
"filter[genre]": [new models.PageFacetOption(objectGraph.loc.string("SEARCH_FACET_ANY_CATEGORY", "Any"), null)],
};
}
function pageFacetChangeAction(objectGraph, facetParameter) {
const action = new models.BlankAction();
metricsClickHelpers.addClickEventToPageFacetsChangeAction(objectGraph, action, facetParameter);
return action;
}
//# sourceMappingURL=search-facets.js.map
|