@internetarchive/collection-browser 0.2.15-0 → 0.2.16-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/app-root.d.ts +1 -0
- package/dist/src/app-root.js +29 -2
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/assets/img/icons/arrow-left.d.ts +2 -0
- package/dist/src/assets/img/icons/arrow-left.js +10 -0
- package/dist/src/assets/img/icons/arrow-left.js.map +1 -0
- package/dist/src/assets/img/icons/arrow-right.d.ts +2 -0
- package/dist/src/assets/img/icons/arrow-right.js +10 -0
- package/dist/src/assets/img/icons/arrow-right.js.map +1 -0
- package/dist/src/collection-browser.d.ts +2 -0
- package/dist/src/collection-browser.js +9 -13
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/more-facets-content.d.ts +56 -0
- package/dist/src/collection-facets/more-facets-content.js +374 -0
- package/dist/src/collection-facets/more-facets-content.js.map +1 -0
- package/dist/src/collection-facets/more-facets-pagination.d.ts +27 -0
- package/dist/src/collection-facets/more-facets-pagination.js +193 -0
- package/dist/src/collection-facets/more-facets-pagination.js.map +1 -0
- package/dist/src/collection-facets.d.ts +19 -2
- package/dist/src/collection-facets.js +102 -0
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/models.d.ts +3 -2
- package/dist/src/models.js +8 -4
- package/dist/src/models.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +23 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.js +96 -12
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/test/collection-browser.test.js +35 -0
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -0
- package/dist/test/collection-facets/more-facets-content.test.js +75 -0
- package/dist/test/collection-facets/more-facets-content.test.js.map +1 -0
- package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -0
- package/dist/test/collection-facets/more-facets-pagination.test.js +38 -0
- package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -0
- package/dist/test/mocks/mock-search-responses.js +13 -0
- package/dist/test/mocks/mock-search-responses.js.map +1 -1
- package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -0
- package/dist/test/sort-filter-bar/sort-filter-bar.test.js +122 -0
- package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -0
- package/package.json +3 -1
- package/src/app-root.ts +29 -2
- package/src/assets/img/icons/arrow-left.ts +10 -0
- package/src/assets/img/icons/arrow-right.ts +10 -0
- package/src/collection-browser.ts +8 -13
- package/src/collection-facets/more-facets-content.ts +393 -0
- package/src/collection-facets/more-facets-pagination.ts +201 -0
- package/src/collection-facets.ts +117 -1
- package/src/models.ts +9 -4
- package/src/sort-filter-bar/sort-filter-bar.ts +98 -12
- package/test/collection-browser.test.ts +43 -0
- package/test/collection-facets/more-facets-content.test.ts +113 -0
- package/test/collection-facets/more-facets-pagination.test.ts +70 -0
- package/test/mocks/mock-search-responses.ts +13 -0
- package/test/sort-filter-bar/sort-filter-bar.test.ts +187 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CSSResultGroup, LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import type { Aggregation, Bucket, SearchServiceInterface } from '@internetarchive/search-service';
|
|
3
|
+
import type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';
|
|
4
|
+
import type { ModalManagerInterface } from '@internetarchive/modal-manager';
|
|
5
|
+
import { SelectedFacets } from '../models';
|
|
6
|
+
import type { LanguageCodeHandlerInterface } from '../language-code-handler/language-code-handler';
|
|
7
|
+
import '@internetarchive/ia-activity-indicator/ia-activity-indicator';
|
|
8
|
+
import './more-facets-pagination';
|
|
9
|
+
export declare class MoreFacetsContent extends LitElement {
|
|
10
|
+
facetKey?: string;
|
|
11
|
+
facetAggregationKey?: string;
|
|
12
|
+
fullQuery?: string;
|
|
13
|
+
modalManager?: ModalManagerInterface;
|
|
14
|
+
searchService?: SearchServiceInterface;
|
|
15
|
+
collectionNameCache?: CollectionNameCacheInterface;
|
|
16
|
+
languageCodeHandler?: LanguageCodeHandlerInterface;
|
|
17
|
+
selectedFacets?: SelectedFacets;
|
|
18
|
+
aggregations?: Record<string, Aggregation>;
|
|
19
|
+
castedBuckets?: Bucket[];
|
|
20
|
+
pageNumber: number;
|
|
21
|
+
/**
|
|
22
|
+
* Facets are loading on popup
|
|
23
|
+
*/
|
|
24
|
+
facetsLoading: boolean;
|
|
25
|
+
paginationSize: number;
|
|
26
|
+
private facetsPerPage;
|
|
27
|
+
updated(changed: PropertyValues): void;
|
|
28
|
+
firstUpdated(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Close more facets modal on Escape click
|
|
31
|
+
*/
|
|
32
|
+
private setupEscapeListeners;
|
|
33
|
+
/**
|
|
34
|
+
* Get specific facets data from search-service API based of currently query params
|
|
35
|
+
* - this.aggregations - hold result of search service and being used for further processing.
|
|
36
|
+
*/
|
|
37
|
+
updateSpecificFacets(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Filter facets data stored in this.aggregations, eg.
|
|
40
|
+
* - we don't want to entertain year_histogram data since we using new date-picker
|
|
41
|
+
* - name of collections needs to be load inside cache using this.collectionNameCache
|
|
42
|
+
*
|
|
43
|
+
* this.castedBuckets - hold filtered facets data which will be render in modal
|
|
44
|
+
*/
|
|
45
|
+
filterFacets(): Promise<void>;
|
|
46
|
+
private pageNumberClicked;
|
|
47
|
+
private get getMoreFacetsTemplate();
|
|
48
|
+
private facetClicked;
|
|
49
|
+
private get loaderTemplate();
|
|
50
|
+
private get facetsPaginationTemplate();
|
|
51
|
+
private get facetsContentTemplate();
|
|
52
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
53
|
+
private applySearchFacetsClicked;
|
|
54
|
+
private cancelClick;
|
|
55
|
+
static get styles(): CSSResultGroup;
|
|
56
|
+
}
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
/* eslint-disable dot-notation */
|
|
3
|
+
import { css, html, LitElement, nothing, } from 'lit';
|
|
4
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
5
|
+
import { defaultSelectedFacets } from '../models';
|
|
6
|
+
import '@internetarchive/ia-activity-indicator/ia-activity-indicator';
|
|
7
|
+
import './more-facets-pagination';
|
|
8
|
+
let MoreFacetsContent = class MoreFacetsContent extends LitElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.castedBuckets = [];
|
|
12
|
+
this.pageNumber = 1;
|
|
13
|
+
/**
|
|
14
|
+
* Facets are loading on popup
|
|
15
|
+
*/
|
|
16
|
+
this.facetsLoading = true;
|
|
17
|
+
this.paginationSize = 0;
|
|
18
|
+
this.facetsPerPage = 60; // TODO: Q. how many items we want to have on popup view
|
|
19
|
+
}
|
|
20
|
+
updated(changed) {
|
|
21
|
+
if (changed.has('facetKey')) {
|
|
22
|
+
this.facetsLoading = true;
|
|
23
|
+
this.pageNumber = 1;
|
|
24
|
+
this.updateSpecificFacets();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
firstUpdated() {
|
|
28
|
+
this.setupEscapeListeners();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Close more facets modal on Escape click
|
|
32
|
+
*/
|
|
33
|
+
setupEscapeListeners() {
|
|
34
|
+
if (this.modalManager) {
|
|
35
|
+
document.addEventListener('keydown', (e) => {
|
|
36
|
+
var _a;
|
|
37
|
+
if (e.key === 'Escape') {
|
|
38
|
+
(_a = this.modalManager) === null || _a === void 0 ? void 0 : _a.closeModal();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
document.removeEventListener('keydown', () => { });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get specific facets data from search-service API based of currently query params
|
|
48
|
+
* - this.aggregations - hold result of search service and being used for further processing.
|
|
49
|
+
*/
|
|
50
|
+
async updateSpecificFacets() {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
const aggregations = {
|
|
53
|
+
advancedParams: [
|
|
54
|
+
{
|
|
55
|
+
field: this.facetAggregationKey,
|
|
56
|
+
size: 1000000, // todo - do we want to have all the records at once?
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
const params = {
|
|
61
|
+
query: this.fullQuery,
|
|
62
|
+
fields: ['identifier'],
|
|
63
|
+
aggregations,
|
|
64
|
+
rows: 1, // todo - do we want server-side pagination with offset/page/limit flag?
|
|
65
|
+
};
|
|
66
|
+
const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params));
|
|
67
|
+
this.aggregations = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response.aggregations;
|
|
68
|
+
// filter facets data to be rendered in modal-manager
|
|
69
|
+
await this.filterFacets();
|
|
70
|
+
this.facetsLoading = false;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Filter facets data stored in this.aggregations, eg.
|
|
74
|
+
* - we don't want to entertain year_histogram data since we using new date-picker
|
|
75
|
+
* - name of collections needs to be load inside cache using this.collectionNameCache
|
|
76
|
+
*
|
|
77
|
+
* this.castedBuckets - hold filtered facets data which will be render in modal
|
|
78
|
+
*/
|
|
79
|
+
async filterFacets() {
|
|
80
|
+
var _a;
|
|
81
|
+
Object.entries((_a = this.aggregations) !== null && _a !== void 0 ? _a : []).forEach(([key, buckets]) => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
if (key === 'year_histogram')
|
|
84
|
+
return;
|
|
85
|
+
this.castedBuckets = buckets['buckets'];
|
|
86
|
+
if (this.facetKey === 'collection') {
|
|
87
|
+
// for collections, we need to asynchronously load the collection name
|
|
88
|
+
// so we use the `async-collection-name` widget and for the rest, we have a static value to use
|
|
89
|
+
const collectionIds = (_a = this.castedBuckets) === null || _a === void 0 ? void 0 : _a.map(option => option.key);
|
|
90
|
+
const collectionIdsArray = Array.from(new Set(collectionIds));
|
|
91
|
+
(_b = this.collectionNameCache) === null || _b === void 0 ? void 0 : _b.preloadIdentifiers(collectionIdsArray);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const { length } = Object.keys(this.castedBuckets);
|
|
95
|
+
this.paginationSize = Math.ceil(length / this.facetsPerPage);
|
|
96
|
+
}
|
|
97
|
+
pageNumberClicked(e) {
|
|
98
|
+
var _a;
|
|
99
|
+
const page = (_a = e === null || e === void 0 ? void 0 : e.detail) === null || _a === void 0 ? void 0 : _a.page;
|
|
100
|
+
if (page) {
|
|
101
|
+
this.pageNumber = Number(page);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
get getMoreFacetsTemplate() {
|
|
105
|
+
var _a;
|
|
106
|
+
this.facetsLoading = false;
|
|
107
|
+
// render only items which will be visible as per this.facetsPerPage
|
|
108
|
+
const currentPageContent = (_a = this.castedBuckets) === null || _a === void 0 ? void 0 : _a.slice((this.pageNumber - 1) * this.facetsPerPage, this.pageNumber * this.facetsPerPage);
|
|
109
|
+
return html `<ul class="facet-list">
|
|
110
|
+
${currentPageContent === null || currentPageContent === void 0 ? void 0 : currentPageContent.map(facet => {
|
|
111
|
+
var _a, _b;
|
|
112
|
+
let displayText = facet.key;
|
|
113
|
+
if (this.facetKey === 'language') {
|
|
114
|
+
displayText =
|
|
115
|
+
(_b = (_a = this.languageCodeHandler) === null || _a === void 0 ? void 0 : _a.getLanguageNameFromCodeString(displayText)) !== null && _b !== void 0 ? _b : displayText;
|
|
116
|
+
}
|
|
117
|
+
return html `
|
|
118
|
+
<li class="facet-row">
|
|
119
|
+
<div class="facet-checkbox">
|
|
120
|
+
<input
|
|
121
|
+
type="checkbox"
|
|
122
|
+
class="selected-facets"
|
|
123
|
+
id="${facet.key}"
|
|
124
|
+
data-facet="${this.facetKey}"
|
|
125
|
+
.value="${facet.key}"
|
|
126
|
+
@click=${(e) => {
|
|
127
|
+
this.facetClicked(e);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
<label
|
|
132
|
+
class="facet-info-display"
|
|
133
|
+
for="${facet.key}"
|
|
134
|
+
title=${facet.key}
|
|
135
|
+
>
|
|
136
|
+
<div class="facet-title">
|
|
137
|
+
${this.facetKey !== 'collection'
|
|
138
|
+
? html `${displayText}`
|
|
139
|
+
: html `<async-collection-name
|
|
140
|
+
.collectionNameCache=${this.collectionNameCache}
|
|
141
|
+
.identifier=${displayText}
|
|
142
|
+
placeholder="-"
|
|
143
|
+
></async-collection-name>`}
|
|
144
|
+
</div>
|
|
145
|
+
<div class="facet-count">${facet.doc_count}</div>
|
|
146
|
+
</label>
|
|
147
|
+
</li>
|
|
148
|
+
`;
|
|
149
|
+
})}
|
|
150
|
+
</ul>`;
|
|
151
|
+
}
|
|
152
|
+
facetClicked(e) {
|
|
153
|
+
const { selectedFacets } = this;
|
|
154
|
+
const target = e.target;
|
|
155
|
+
const { checked, value } = target;
|
|
156
|
+
let newFacets;
|
|
157
|
+
if (selectedFacets) {
|
|
158
|
+
newFacets = {
|
|
159
|
+
...selectedFacets,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
newFacets = defaultSelectedFacets;
|
|
164
|
+
}
|
|
165
|
+
if (checked) {
|
|
166
|
+
newFacets[this.facetKey][value] = 'selected';
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
delete newFacets[this.facetKey][value];
|
|
170
|
+
}
|
|
171
|
+
this.selectedFacets = newFacets;
|
|
172
|
+
}
|
|
173
|
+
get loaderTemplate() {
|
|
174
|
+
return this.facetsLoading
|
|
175
|
+
? html `<div class="facets-loader">
|
|
176
|
+
<ia-activity-indicator .mode="processing"></ia-activity-indicator>
|
|
177
|
+
</div>`
|
|
178
|
+
: nothing;
|
|
179
|
+
}
|
|
180
|
+
// render pagination if more then 1 page
|
|
181
|
+
get facetsPaginationTemplate() {
|
|
182
|
+
return this.paginationSize > 1
|
|
183
|
+
? html `<more-facets-pagination
|
|
184
|
+
.size=${this.paginationSize}
|
|
185
|
+
@pageNumberClicked=${this.pageNumberClicked}
|
|
186
|
+
></more-facets-pagination>`
|
|
187
|
+
: nothing;
|
|
188
|
+
}
|
|
189
|
+
get facetsContentTemplate() {
|
|
190
|
+
return html `
|
|
191
|
+
<div class="facets-content">${this.getMoreFacetsTemplate}</div>
|
|
192
|
+
${this.paginationSize > 0
|
|
193
|
+
? html `${this.facetsPaginationTemplate}
|
|
194
|
+
<div class="footer">
|
|
195
|
+
<button
|
|
196
|
+
class="btn btn-cancel"
|
|
197
|
+
type="button"
|
|
198
|
+
@click=${this.cancelClick}
|
|
199
|
+
>
|
|
200
|
+
Cancel
|
|
201
|
+
</button>
|
|
202
|
+
<button
|
|
203
|
+
class="btn btn-submit"
|
|
204
|
+
type="button"
|
|
205
|
+
@click=${this.applySearchFacetsClicked}
|
|
206
|
+
>
|
|
207
|
+
Apply filters
|
|
208
|
+
</button>
|
|
209
|
+
</div>`
|
|
210
|
+
: html `No result found. please try again later.`}
|
|
211
|
+
`;
|
|
212
|
+
}
|
|
213
|
+
render() {
|
|
214
|
+
return html `
|
|
215
|
+
<div id="more-facets-page">
|
|
216
|
+
<form>
|
|
217
|
+
${this.facetsLoading
|
|
218
|
+
? this.loaderTemplate
|
|
219
|
+
: this.facetsContentTemplate}
|
|
220
|
+
</form>
|
|
221
|
+
</div>
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
applySearchFacetsClicked() {
|
|
225
|
+
var _a;
|
|
226
|
+
const event = new CustomEvent('facetsChanged', {
|
|
227
|
+
detail: this.selectedFacets,
|
|
228
|
+
bubbles: true,
|
|
229
|
+
composed: true,
|
|
230
|
+
});
|
|
231
|
+
this.dispatchEvent(event);
|
|
232
|
+
(_a = this.modalManager) === null || _a === void 0 ? void 0 : _a.closeModal();
|
|
233
|
+
}
|
|
234
|
+
cancelClick() {
|
|
235
|
+
var _a;
|
|
236
|
+
(_a = this.modalManager) === null || _a === void 0 ? void 0 : _a.closeModal();
|
|
237
|
+
}
|
|
238
|
+
static get styles() {
|
|
239
|
+
const modalSubmitButton = css `var(--primaryButtonBGColor, #194880)`;
|
|
240
|
+
return css `
|
|
241
|
+
#more-facets-page {
|
|
242
|
+
margin-bottom: 2rem;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.facets-content {
|
|
246
|
+
-webkit-column-width: 25rem;
|
|
247
|
+
-moz-column-width: 25rem;
|
|
248
|
+
column-width: 25rem;
|
|
249
|
+
font-size: 1.2rem;
|
|
250
|
+
padding: 0 10px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
ul.facet-list {
|
|
254
|
+
list-style: none;
|
|
255
|
+
margin: 0;
|
|
256
|
+
padding: 0;
|
|
257
|
+
}
|
|
258
|
+
ul.facet-list li {
|
|
259
|
+
margin-bottom: 2px;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.facet-row {
|
|
263
|
+
text-align: left;
|
|
264
|
+
display: flex;
|
|
265
|
+
align-items: start;
|
|
266
|
+
font-weight: 500;
|
|
267
|
+
font-size: 1.2rem;
|
|
268
|
+
}
|
|
269
|
+
.facet-row input {
|
|
270
|
+
margin: 1px 5px 1px 0;
|
|
271
|
+
vertical-align: middle;
|
|
272
|
+
}
|
|
273
|
+
.facet-info-display {
|
|
274
|
+
display: flex;
|
|
275
|
+
flex: 1 1 0%;
|
|
276
|
+
cursor: pointer;
|
|
277
|
+
}
|
|
278
|
+
.facet-title {
|
|
279
|
+
flex: 1 1 0%;
|
|
280
|
+
}
|
|
281
|
+
.facet-count {
|
|
282
|
+
margin-left: 5px;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.page-number {
|
|
286
|
+
background: none;
|
|
287
|
+
border: 0;
|
|
288
|
+
cursor: pointer;
|
|
289
|
+
border-radius: 100%;
|
|
290
|
+
width: 25px;
|
|
291
|
+
height: 25px;
|
|
292
|
+
margin: 10px;
|
|
293
|
+
font-size: 1.4rem;
|
|
294
|
+
vertical-align: middle;
|
|
295
|
+
}
|
|
296
|
+
.current-page {
|
|
297
|
+
background: black;
|
|
298
|
+
color: white;
|
|
299
|
+
}
|
|
300
|
+
.facets-loader {
|
|
301
|
+
text-align: center;
|
|
302
|
+
margin-bottom: 2rem;
|
|
303
|
+
height: 7rem;
|
|
304
|
+
width: 7rem;
|
|
305
|
+
display: inline-block;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.btn {
|
|
309
|
+
border: none;
|
|
310
|
+
padding: 10px;
|
|
311
|
+
margin-bottom: 10px;
|
|
312
|
+
width: auto;
|
|
313
|
+
border-radius: 0.4rem;
|
|
314
|
+
cursor: pointer;
|
|
315
|
+
}
|
|
316
|
+
.btn-cancel {
|
|
317
|
+
background-color: #000;
|
|
318
|
+
color: white;
|
|
319
|
+
}
|
|
320
|
+
.btn-submit {
|
|
321
|
+
background-color: ${modalSubmitButton};
|
|
322
|
+
color: white;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.footer {
|
|
326
|
+
margin-top: 10px;
|
|
327
|
+
}
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
__decorate([
|
|
332
|
+
property({ type: String })
|
|
333
|
+
], MoreFacetsContent.prototype, "facetKey", void 0);
|
|
334
|
+
__decorate([
|
|
335
|
+
property({ type: String })
|
|
336
|
+
], MoreFacetsContent.prototype, "facetAggregationKey", void 0);
|
|
337
|
+
__decorate([
|
|
338
|
+
property({ type: String })
|
|
339
|
+
], MoreFacetsContent.prototype, "fullQuery", void 0);
|
|
340
|
+
__decorate([
|
|
341
|
+
property({ type: Object })
|
|
342
|
+
], MoreFacetsContent.prototype, "modalManager", void 0);
|
|
343
|
+
__decorate([
|
|
344
|
+
property({ type: Object })
|
|
345
|
+
], MoreFacetsContent.prototype, "searchService", void 0);
|
|
346
|
+
__decorate([
|
|
347
|
+
property({ type: Object })
|
|
348
|
+
], MoreFacetsContent.prototype, "collectionNameCache", void 0);
|
|
349
|
+
__decorate([
|
|
350
|
+
property({ type: Object })
|
|
351
|
+
], MoreFacetsContent.prototype, "languageCodeHandler", void 0);
|
|
352
|
+
__decorate([
|
|
353
|
+
property({ type: Object })
|
|
354
|
+
], MoreFacetsContent.prototype, "selectedFacets", void 0);
|
|
355
|
+
__decorate([
|
|
356
|
+
state()
|
|
357
|
+
], MoreFacetsContent.prototype, "aggregations", void 0);
|
|
358
|
+
__decorate([
|
|
359
|
+
state()
|
|
360
|
+
], MoreFacetsContent.prototype, "castedBuckets", void 0);
|
|
361
|
+
__decorate([
|
|
362
|
+
state()
|
|
363
|
+
], MoreFacetsContent.prototype, "pageNumber", void 0);
|
|
364
|
+
__decorate([
|
|
365
|
+
state()
|
|
366
|
+
], MoreFacetsContent.prototype, "facetsLoading", void 0);
|
|
367
|
+
__decorate([
|
|
368
|
+
state()
|
|
369
|
+
], MoreFacetsContent.prototype, "paginationSize", void 0);
|
|
370
|
+
MoreFacetsContent = __decorate([
|
|
371
|
+
customElement('more-facets-content')
|
|
372
|
+
], MoreFacetsContent);
|
|
373
|
+
export { MoreFacetsContent };
|
|
374
|
+
//# sourceMappingURL=more-facets-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"more-facets-content.js","sourceRoot":"","sources":["../../../src/collection-facets/more-facets-content.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,OAAO,EACL,GAAG,EAEH,IAAI,EACJ,UAAU,EACV,OAAO,GAER,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AASnE,OAAO,EAAkB,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElE,OAAO,8DAA8D,CAAC;AACtE,OAAO,0BAA0B,CAAC;AAGlC,IAAa,iBAAiB,GAA9B,MAAa,iBAAkB,SAAQ,UAAU;IAAjD;;QAqBW,kBAAa,GAAc,EAAE,CAAC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ACwB;AAGnD;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8DACwB;AAEvB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAAiC;AAEnD;IAAR,KAAK,EAAE;uDAA4C;AAE3C;IAAR,KAAK,EAAE;wDAA+B;AAE9B;IAAR,KAAK,EAAE;qDAAgB;AAKf;IAAR,KAAK,EAAE;wDAAsB;AAErB;IAAR,KAAK,EAAE;yDAAoB;AA9BjB,iBAAiB;IAD7B,aAAa,CAAC,qBAAqB,CAAC;GACxB,iBAAiB,CAgX7B;SAhXY,iBAAiB","sourcesContent":["/* eslint-disable dot-notation */\nimport {\n css,\n CSSResultGroup,\n html,\n LitElement,\n nothing,\n PropertyValues,\n} from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\nimport type {\n Aggregation,\n Bucket,\n SearchServiceInterface,\n SearchParams,\n} from '@internetarchive/search-service';\nimport type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';\nimport type { ModalManagerInterface } from '@internetarchive/modal-manager';\nimport { SelectedFacets, defaultSelectedFacets } from '../models';\nimport type { LanguageCodeHandlerInterface } from '../language-code-handler/language-code-handler';\nimport '@internetarchive/ia-activity-indicator/ia-activity-indicator';\nimport './more-facets-pagination';\n\n@customElement('more-facets-content')\nexport class MoreFacetsContent extends LitElement {\n @property({ type: String }) facetKey?: string;\n\n @property({ type: String }) facetAggregationKey?: string;\n\n @property({ type: String }) fullQuery?: string;\n\n @property({ type: Object }) modalManager?: ModalManagerInterface;\n\n @property({ type: Object }) searchService?: SearchServiceInterface;\n\n @property({ type: Object })\n collectionNameCache?: CollectionNameCacheInterface;\n\n @property({ type: Object })\n languageCodeHandler?: LanguageCodeHandlerInterface;\n\n @property({ type: Object }) selectedFacets?: SelectedFacets;\n\n @state() aggregations?: Record<string, Aggregation>;\n\n @state() castedBuckets?: Bucket[] = [];\n\n @state() pageNumber = 1;\n\n /**\n * Facets are loading on popup\n */\n @state() facetsLoading = true;\n\n @state() paginationSize = 0;\n\n private facetsPerPage = 60; // TODO: Q. how many items we want to have on popup view\n\n updated(changed: PropertyValues) {\n if (changed.has('facetKey')) {\n this.facetsLoading = true;\n this.pageNumber = 1;\n\n this.updateSpecificFacets();\n }\n }\n\n firstUpdated() {\n this.setupEscapeListeners();\n }\n\n /**\n * Close more facets modal on Escape click\n */\n private setupEscapeListeners() {\n if (this.modalManager) {\n document.addEventListener('keydown', (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n this.modalManager?.closeModal();\n }\n });\n } else {\n document.removeEventListener('keydown', () => {});\n }\n }\n\n /**\n * Get specific facets data from search-service API based of currently query params\n * - this.aggregations - hold result of search service and being used for further processing.\n */\n async updateSpecificFacets(): Promise<void> {\n const aggregations = {\n advancedParams: [\n {\n field: this.facetAggregationKey as string,\n size: 1000000, // todo - do we want to have all the records at once?\n },\n ],\n };\n\n const params: SearchParams = {\n query: this.fullQuery as string,\n fields: ['identifier'],\n aggregations,\n rows: 1, // todo - do we want server-side pagination with offset/page/limit flag?\n };\n\n const results = await this.searchService?.search(params);\n this.aggregations = results?.success?.response.aggregations as any;\n\n // filter facets data to be rendered in modal-manager\n await this.filterFacets();\n this.facetsLoading = false;\n }\n\n /**\n * Filter facets data stored in this.aggregations, eg.\n * - we don't want to entertain year_histogram data since we using new date-picker\n * - name of collections needs to be load inside cache using this.collectionNameCache\n *\n * this.castedBuckets - hold filtered facets data which will be render in modal\n */\n async filterFacets(): Promise<void> {\n Object.entries(this.aggregations ?? []).forEach(([key, buckets]) => {\n if (key === 'year_histogram') return;\n\n this.castedBuckets = buckets['buckets'] as Bucket[];\n\n if (this.facetKey === 'collection') {\n // for collections, we need to asynchronously load the collection name\n // so we use the `async-collection-name` widget and for the rest, we have a static value to use\n const collectionIds = this.castedBuckets?.map(option => option.key);\n const collectionIdsArray = Array.from(\n new Set(collectionIds)\n ) as string[];\n this.collectionNameCache?.preloadIdentifiers(collectionIdsArray);\n }\n });\n\n const { length } = Object.keys(this.castedBuckets as []);\n this.paginationSize = Math.ceil(length / this.facetsPerPage);\n }\n\n private pageNumberClicked(e: CustomEvent<{ page: string }>) {\n const page = e?.detail?.page;\n if (page) {\n this.pageNumber = Number(page);\n }\n }\n\n private get getMoreFacetsTemplate() {\n this.facetsLoading = false;\n\n // render only items which will be visible as per this.facetsPerPage\n const currentPageContent = this.castedBuckets?.slice(\n (this.pageNumber - 1) * this.facetsPerPage,\n this.pageNumber * this.facetsPerPage\n );\n\n return html`<ul class=\"facet-list\">\n ${currentPageContent?.map(facet => {\n let displayText = facet.key;\n\n if (this.facetKey === 'language') {\n displayText =\n this.languageCodeHandler?.getLanguageNameFromCodeString(\n displayText as string\n ) ?? displayText;\n }\n\n return html`\n <li class=\"facet-row\">\n <div class=\"facet-checkbox\">\n <input\n type=\"checkbox\"\n class=\"selected-facets\"\n id=\"${facet.key}\"\n data-facet=\"${this.facetKey}\"\n .value=\"${facet.key}\"\n @click=${(e: Event) => {\n this.facetClicked(e);\n }}\n />\n </div>\n <label\n class=\"facet-info-display\"\n for=\"${facet.key}\"\n title=${facet.key}\n >\n <div class=\"facet-title\">\n ${this.facetKey !== 'collection'\n ? html`${displayText}`\n : html`<async-collection-name\n .collectionNameCache=${this.collectionNameCache}\n .identifier=${displayText}\n placeholder=\"-\"\n ></async-collection-name>`}\n </div>\n <div class=\"facet-count\">${facet.doc_count}</div>\n </label>\n </li>\n `;\n })}\n </ul>`;\n }\n\n private facetClicked(e: Event) {\n const { selectedFacets } = this;\n\n const target = e.target as HTMLInputElement;\n const { checked, value } = target;\n\n let newFacets: SelectedFacets;\n if (selectedFacets) {\n newFacets = {\n ...selectedFacets,\n };\n } else {\n newFacets = defaultSelectedFacets;\n }\n\n if (checked) {\n newFacets[this.facetKey as keyof typeof newFacets][value] = 'selected';\n } else {\n delete newFacets[this.facetKey as keyof typeof newFacets][value];\n }\n\n this.selectedFacets = newFacets;\n }\n\n private get loaderTemplate() {\n return this.facetsLoading\n ? html`<div class=\"facets-loader\">\n <ia-activity-indicator .mode=\"processing\"></ia-activity-indicator>\n </div>`\n : nothing;\n }\n\n // render pagination if more then 1 page\n private get facetsPaginationTemplate() {\n return this.paginationSize > 1\n ? html`<more-facets-pagination\n .size=${this.paginationSize}\n @pageNumberClicked=${this.pageNumberClicked}\n ></more-facets-pagination>`\n : nothing;\n }\n\n private get facetsContentTemplate() {\n return html`\n <div class=\"facets-content\">${this.getMoreFacetsTemplate}</div>\n ${this.paginationSize > 0\n ? html`${this.facetsPaginationTemplate}\n <div class=\"footer\">\n <button\n class=\"btn btn-cancel\"\n type=\"button\"\n @click=${this.cancelClick}\n >\n Cancel\n </button>\n <button\n class=\"btn btn-submit\"\n type=\"button\"\n @click=${this.applySearchFacetsClicked}\n >\n Apply filters\n </button>\n </div>`\n : html`No result found. please try again later.`}\n `;\n }\n\n render() {\n return html`\n <div id=\"more-facets-page\">\n <form>\n ${this.facetsLoading\n ? this.loaderTemplate\n : this.facetsContentTemplate}\n </form>\n </div>\n `;\n }\n\n private applySearchFacetsClicked() {\n const event = new CustomEvent<SelectedFacets>('facetsChanged', {\n detail: this.selectedFacets,\n bubbles: true,\n composed: true,\n });\n this.dispatchEvent(event);\n this.modalManager?.closeModal();\n }\n\n private cancelClick() {\n this.modalManager?.closeModal();\n }\n\n static get styles(): CSSResultGroup {\n const modalSubmitButton = css`var(--primaryButtonBGColor, #194880)`;\n\n return css`\n #more-facets-page {\n margin-bottom: 2rem;\n }\n\n .facets-content {\n -webkit-column-width: 25rem;\n -moz-column-width: 25rem;\n column-width: 25rem;\n font-size: 1.2rem;\n padding: 0 10px;\n }\n\n ul.facet-list {\n list-style: none;\n margin: 0;\n padding: 0;\n }\n ul.facet-list li {\n margin-bottom: 2px;\n }\n\n .facet-row {\n text-align: left;\n display: flex;\n align-items: start;\n font-weight: 500;\n font-size: 1.2rem;\n }\n .facet-row input {\n margin: 1px 5px 1px 0;\n vertical-align: middle;\n }\n .facet-info-display {\n display: flex;\n flex: 1 1 0%;\n cursor: pointer;\n }\n .facet-title {\n flex: 1 1 0%;\n }\n .facet-count {\n margin-left: 5px;\n }\n\n .page-number {\n background: none;\n border: 0;\n cursor: pointer;\n border-radius: 100%;\n width: 25px;\n height: 25px;\n margin: 10px;\n font-size: 1.4rem;\n vertical-align: middle;\n }\n .current-page {\n background: black;\n color: white;\n }\n .facets-loader {\n text-align: center;\n margin-bottom: 2rem;\n height: 7rem;\n width: 7rem;\n display: inline-block;\n }\n\n .btn {\n border: none;\n padding: 10px;\n margin-bottom: 10px;\n width: auto;\n border-radius: 0.4rem;\n cursor: pointer;\n }\n .btn-cancel {\n background-color: #000;\n color: white;\n }\n .btn-submit {\n background-color: ${modalSubmitButton};\n color: white;\n }\n\n .footer {\n margin-top: 10px;\n }\n `;\n }\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CSSResultGroup, LitElement } from 'lit';
|
|
2
|
+
export declare class MoreFacetsPagination extends LitElement {
|
|
3
|
+
/**
|
|
4
|
+
* Total number of pages
|
|
5
|
+
*/
|
|
6
|
+
size?: any | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Number of pages can be moved in back/forward
|
|
9
|
+
*/
|
|
10
|
+
step: number;
|
|
11
|
+
pages?: number[];
|
|
12
|
+
currentPage: number;
|
|
13
|
+
firstUpdated(): void;
|
|
14
|
+
observePageCount(): void;
|
|
15
|
+
private createFirstNode;
|
|
16
|
+
private createMiddelNode;
|
|
17
|
+
private createLastNode;
|
|
18
|
+
private get getEllipsisTemplate();
|
|
19
|
+
private emitPageClick;
|
|
20
|
+
private onRewind;
|
|
21
|
+
private onForward;
|
|
22
|
+
private onChange;
|
|
23
|
+
private getPageTemplate;
|
|
24
|
+
private get getPagesTemplate();
|
|
25
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
26
|
+
static get styles(): CSSResultGroup;
|
|
27
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
3
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
4
|
+
import arrowLeftIcon from '../assets/img/icons/arrow-left';
|
|
5
|
+
import arrowRightIcon from '../assets/img/icons/arrow-right';
|
|
6
|
+
let MoreFacetsPagination = class MoreFacetsPagination extends LitElement {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
/**
|
|
10
|
+
* Number of pages can be moved in back/forward
|
|
11
|
+
*/
|
|
12
|
+
this.step = 2;
|
|
13
|
+
this.pages = [];
|
|
14
|
+
this.currentPage = 1;
|
|
15
|
+
}
|
|
16
|
+
firstUpdated() {
|
|
17
|
+
this.observePageCount();
|
|
18
|
+
}
|
|
19
|
+
observePageCount() {
|
|
20
|
+
this.pages = [];
|
|
21
|
+
let startPage = this.currentPage - this.step;
|
|
22
|
+
let endPage = this.currentPage + this.step;
|
|
23
|
+
if (startPage <= 0) {
|
|
24
|
+
endPage += -startPage + 1;
|
|
25
|
+
startPage = 1;
|
|
26
|
+
}
|
|
27
|
+
if (endPage >= this.size) {
|
|
28
|
+
startPage = Math.max(startPage - (endPage - this.size), 1);
|
|
29
|
+
endPage = this.size;
|
|
30
|
+
}
|
|
31
|
+
// create first page node
|
|
32
|
+
this.createFirstNode(startPage);
|
|
33
|
+
// create middle pages node
|
|
34
|
+
this.createMiddelNode(startPage, endPage);
|
|
35
|
+
// create last page node
|
|
36
|
+
this.createLastNode(endPage);
|
|
37
|
+
}
|
|
38
|
+
createFirstNode(startPage) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
if (startPage > 1) {
|
|
41
|
+
(_a = this.pages) === null || _a === void 0 ? void 0 : _a.push(1);
|
|
42
|
+
(_b = this.pages) === null || _b === void 0 ? void 0 : _b.push(0); // let's asssume 0 is for ellipsis template
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
createMiddelNode(startPage, endPage) {
|
|
46
|
+
var _a;
|
|
47
|
+
for (let page = startPage; page <= endPage; page += 1) {
|
|
48
|
+
(_a = this.pages) === null || _a === void 0 ? void 0 : _a.push(page);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
createLastNode(endPage) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (endPage < this.size) {
|
|
54
|
+
(_a = this.pages) === null || _a === void 0 ? void 0 : _a.push(0); // let's asssume 0 is for ellipsis template
|
|
55
|
+
(_b = this.pages) === null || _b === void 0 ? void 0 : _b.push(this.size);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
get getEllipsisTemplate() {
|
|
59
|
+
return html `<i>...</i>`;
|
|
60
|
+
}
|
|
61
|
+
emitPageClick() {
|
|
62
|
+
this.dispatchEvent(new CustomEvent('pageNumberClicked', {
|
|
63
|
+
detail: { page: this.currentPage },
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
onRewind() {
|
|
67
|
+
this.currentPage -= 1;
|
|
68
|
+
if (this.currentPage < 1) {
|
|
69
|
+
this.currentPage = 1;
|
|
70
|
+
}
|
|
71
|
+
this.observePageCount();
|
|
72
|
+
this.emitPageClick();
|
|
73
|
+
}
|
|
74
|
+
onForward() {
|
|
75
|
+
this.currentPage += 1;
|
|
76
|
+
if (this.currentPage > this.size) {
|
|
77
|
+
this.currentPage = this.size;
|
|
78
|
+
}
|
|
79
|
+
this.observePageCount();
|
|
80
|
+
this.emitPageClick();
|
|
81
|
+
}
|
|
82
|
+
onChange(page) {
|
|
83
|
+
this.currentPage = page;
|
|
84
|
+
this.observePageCount();
|
|
85
|
+
this.emitPageClick();
|
|
86
|
+
}
|
|
87
|
+
getPageTemplate(page) {
|
|
88
|
+
return html `
|
|
89
|
+
<button
|
|
90
|
+
@click="${() => this.onChange(page)}"
|
|
91
|
+
class="${this.currentPage === page ? 'current' : nothing}"
|
|
92
|
+
>
|
|
93
|
+
${page}
|
|
94
|
+
</button>
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
get getPagesTemplate() {
|
|
98
|
+
var _a;
|
|
99
|
+
return html `
|
|
100
|
+
${(_a = this.pages) === null || _a === void 0 ? void 0 : _a.map(page => html `${page !== 0
|
|
101
|
+
? this.getPageTemplate(page)
|
|
102
|
+
: this.getEllipsisTemplate}`)}
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
return html `
|
|
107
|
+
<div class="facets-pagination">
|
|
108
|
+
<button class="arrow-icon" @click=${this.onRewind}>
|
|
109
|
+
<span class="sr-only">Rewind pagination:</span>
|
|
110
|
+
${arrowLeftIcon}
|
|
111
|
+
</button>
|
|
112
|
+
<div class="page-numbers">${this.getPagesTemplate}</div>
|
|
113
|
+
<button class="arrow-icon" @click=${this.onForward}>
|
|
114
|
+
<span class="sr-only">Forward pagination:</span>
|
|
115
|
+
${arrowRightIcon}
|
|
116
|
+
</button>
|
|
117
|
+
</div>
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
static get styles() {
|
|
121
|
+
return css `
|
|
122
|
+
.facets-pagination {
|
|
123
|
+
user-select: none;
|
|
124
|
+
margin-top: 10px;
|
|
125
|
+
background-color: #eee;
|
|
126
|
+
text-align: center;
|
|
127
|
+
font-size: 3.2rem;
|
|
128
|
+
}
|
|
129
|
+
.facets-pagination button {
|
|
130
|
+
border: none;
|
|
131
|
+
background: none;
|
|
132
|
+
}
|
|
133
|
+
.facets-pagination .arrow-icon {
|
|
134
|
+
width: 2.5rem;
|
|
135
|
+
vertical-align: initial;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.facets-pagination button,
|
|
139
|
+
.facets-pagination i {
|
|
140
|
+
background: none;
|
|
141
|
+
border: 0;
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
border-radius: 100%;
|
|
144
|
+
margin: 10px;
|
|
145
|
+
padding: 5px;
|
|
146
|
+
font-size: 1.4rem;
|
|
147
|
+
vertical-align: middle;
|
|
148
|
+
display: inline-block;
|
|
149
|
+
min-width: 2.5rem;
|
|
150
|
+
}
|
|
151
|
+
.facets-pagination i {
|
|
152
|
+
cursor: auto;
|
|
153
|
+
display: inline;
|
|
154
|
+
}
|
|
155
|
+
.facets-pagination button.current {
|
|
156
|
+
background: black;
|
|
157
|
+
color: white;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.page-numbers {
|
|
161
|
+
display: inline-block;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.sr-only {
|
|
165
|
+
position: absolute;
|
|
166
|
+
width: 1px;
|
|
167
|
+
height: 1px;
|
|
168
|
+
padding: 0;
|
|
169
|
+
margin: -1px;
|
|
170
|
+
overflow: hidden;
|
|
171
|
+
clip: rect(0, 0, 0, 0);
|
|
172
|
+
border: 0;
|
|
173
|
+
}
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
__decorate([
|
|
178
|
+
property({ type: Number })
|
|
179
|
+
], MoreFacetsPagination.prototype, "size", void 0);
|
|
180
|
+
__decorate([
|
|
181
|
+
property({ type: Number })
|
|
182
|
+
], MoreFacetsPagination.prototype, "step", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
state()
|
|
185
|
+
], MoreFacetsPagination.prototype, "pages", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
state()
|
|
188
|
+
], MoreFacetsPagination.prototype, "currentPage", void 0);
|
|
189
|
+
MoreFacetsPagination = __decorate([
|
|
190
|
+
customElement('more-facets-pagination')
|
|
191
|
+
], MoreFacetsPagination);
|
|
192
|
+
export { MoreFacetsPagination };
|
|
193
|
+
//# sourceMappingURL=more-facets-pagination.js.map
|