@internetarchive/ia-book-actions 0.0.30-alpha3 → 0.0.30-alpha4
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/package.json +1 -1
- package/src/components/text-group.js +2 -9
- package/src/core/services/actions-handler/actions-handler-service.js +2 -5
- package/src/core/services/actions-handler/actions-handler.js +15 -8
- package/src/core/services/get-lending-actions.js +10 -11
- package/src/ia-book-actions.js +2 -51
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@ export class TextGroup extends LitElement {
|
|
|
5
5
|
return {
|
|
6
6
|
texts: { type: String },
|
|
7
7
|
textClass: { type: String },
|
|
8
|
-
hasAdminBorrowedAccess: { type: Boolean },
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -13,16 +12,11 @@ export class TextGroup extends LitElement {
|
|
|
13
12
|
super();
|
|
14
13
|
this.texts = '';
|
|
15
14
|
this.textClass = '';
|
|
16
|
-
this.hasAdminBorrowedAccess = false;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
render() {
|
|
20
18
|
return html`
|
|
21
|
-
<span class="variable-texts ${this.textClass}">
|
|
22
|
-
${this.hasAdminBorrowedAccess
|
|
23
|
-
? html`<slot name="sticky-access-checkbox">${this.texts}</slot>`
|
|
24
|
-
: this.texts}
|
|
25
|
-
</span>
|
|
19
|
+
<span class="variable-texts ${this.textClass}">${this.texts}</span>
|
|
26
20
|
`;
|
|
27
21
|
}
|
|
28
22
|
|
|
@@ -35,13 +29,12 @@ export class TextGroup extends LitElement {
|
|
|
35
29
|
margin-left: 10px;
|
|
36
30
|
vertical-align: middle;
|
|
37
31
|
font-size: 1.7rem;
|
|
38
|
-
align-items: center;
|
|
39
32
|
}
|
|
40
33
|
.hidden {
|
|
41
34
|
display: none;
|
|
42
35
|
}
|
|
43
36
|
.visible {
|
|
44
|
-
display:
|
|
37
|
+
display: inline-block;
|
|
45
38
|
}
|
|
46
39
|
`;
|
|
47
40
|
}
|
|
@@ -8,8 +8,8 @@ export default async function ActionsHandlerService(options) {
|
|
|
8
8
|
const option = {
|
|
9
9
|
action: null,
|
|
10
10
|
identifier: '',
|
|
11
|
-
success() {},
|
|
12
|
-
error() {},
|
|
11
|
+
success() { },
|
|
12
|
+
error() { },
|
|
13
13
|
...options,
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -30,9 +30,6 @@ export default async function ActionsHandlerService(options) {
|
|
|
30
30
|
let formData = new FormData();
|
|
31
31
|
formData.append('action', option.action);
|
|
32
32
|
formData.append('identifier', option.identifier);
|
|
33
|
-
formData.append('sticky-admin', option.stickyAccess);
|
|
34
|
-
console.log(option.stickyAccess);
|
|
35
|
-
|
|
36
33
|
try {
|
|
37
34
|
await fetch(baseHost, {
|
|
38
35
|
method: 'POST',
|
|
@@ -83,6 +83,8 @@ export default class ActionsHandler extends LitElement {
|
|
|
83
83
|
const { category, action } = detail.event;
|
|
84
84
|
this.sendEvent(category, action);
|
|
85
85
|
|
|
86
|
+
this.toggleStickyAdminAccess(true);
|
|
87
|
+
|
|
86
88
|
// keep existing params and add new one
|
|
87
89
|
const url = new URL(window.location.href);
|
|
88
90
|
url.searchParams.append('admin', 1);
|
|
@@ -92,20 +94,14 @@ export default class ActionsHandler extends LitElement {
|
|
|
92
94
|
this.addEventListener('exitAdminAccess', ({ detail }) => {
|
|
93
95
|
const { category, action } = detail.event;
|
|
94
96
|
this.sendEvent(category, action);
|
|
97
|
+
|
|
98
|
+
this.toggleStickyAdminAccess(false);
|
|
95
99
|
});
|
|
96
100
|
|
|
97
101
|
this.addEventListener('bookTitleBar', ({ detail }) => {
|
|
98
102
|
const { category, action } = detail.event;
|
|
99
103
|
this.sendEvent(category, action);
|
|
100
104
|
});
|
|
101
|
-
|
|
102
|
-
document.addEventListener('stickyAdminAccess', ({ detail }) => {
|
|
103
|
-
ActionsHandlerService({
|
|
104
|
-
action: 'toggle_sticky_admin_access', // toggle_sticky_admin_access
|
|
105
|
-
stickyAccess: detail.hasStickyAdminAccess,
|
|
106
|
-
identifier: this.identifier,
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
105
|
}
|
|
110
106
|
|
|
111
107
|
handleBrowseIt() {
|
|
@@ -293,4 +289,15 @@ export default class ActionsHandler extends LitElement {
|
|
|
293
289
|
'.archive.org'
|
|
294
290
|
);
|
|
295
291
|
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Toggles sticky admin access on or off.
|
|
295
|
+
* @see WEBDEV-6835
|
|
296
|
+
*
|
|
297
|
+
* @param {boolean} value - Whether to enable or disable sticky admin access.
|
|
298
|
+
* @returns {void}
|
|
299
|
+
*/
|
|
300
|
+
toggleStickyAdminAccess(value) {
|
|
301
|
+
Cookies.setItem('sticky-admin-access', value);
|
|
302
|
+
}
|
|
296
303
|
}
|
|
@@ -51,7 +51,6 @@ export const bookTitles = {
|
|
|
51
51
|
on_waitlist: 'You are on the waitlist for this book.',
|
|
52
52
|
session_expired: 'Your loan has expired.',
|
|
53
53
|
unavailable: 'This book is not available at this time.',
|
|
54
|
-
admin_borrowed: 'Default to admin access mode',
|
|
55
54
|
};
|
|
56
55
|
|
|
57
56
|
export class GetLendingActions {
|
|
@@ -84,7 +83,7 @@ export class GetLendingActions {
|
|
|
84
83
|
|
|
85
84
|
adminOrPrintDisabledReadingAction() {
|
|
86
85
|
return {
|
|
87
|
-
primaryTitle:
|
|
86
|
+
primaryTitle: '',
|
|
88
87
|
primaryActions: [],
|
|
89
88
|
secondaryActions: [this.actionsConfig.adminOrPrintDisabledExitConfig()],
|
|
90
89
|
borrowType: 'adminBorrowed',
|
|
@@ -234,8 +233,8 @@ export class GetLendingActions {
|
|
|
234
233
|
const title = lendingStatus.available_to_browse
|
|
235
234
|
? bookTitles.available_1hr
|
|
236
235
|
: lendingStatus.available_to_borrow
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
? bookTitles.available_14d
|
|
237
|
+
: bookTitles.unavailable;
|
|
239
238
|
|
|
240
239
|
return {
|
|
241
240
|
primaryTitle: title,
|
|
@@ -278,16 +277,16 @@ export class GetLendingActions {
|
|
|
278
277
|
const allBrowsableCopiesTaken =
|
|
279
278
|
lendingStatus.available_browsable_copies < 1 &&
|
|
280
279
|
lendingStatus.available_browsable_copies <
|
|
281
|
-
|
|
280
|
+
lendingStatus.max_browsable_copies;
|
|
282
281
|
// end config
|
|
283
282
|
|
|
284
283
|
const title = browsingHasExpired
|
|
285
284
|
? bookTitles.session_expired
|
|
286
285
|
: !canBrowse && allBrowsableCopiesTaken
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
286
|
+
? bookTitles.being_borrowed
|
|
287
|
+
: !canBrowse && lendingStatus.available_to_waitlist
|
|
288
|
+
? bookTitles.available_waitlist
|
|
289
|
+
: bookTitles.available_1hr;
|
|
291
290
|
|
|
292
291
|
// one hour borrow config
|
|
293
292
|
const oneHrBorrow = browsingHasExpired
|
|
@@ -301,8 +300,8 @@ export class GetLendingActions {
|
|
|
301
300
|
const dropdownOptions = canBrowseAndBorrow
|
|
302
301
|
? [oneHrBorrow, borrow, printDisability]
|
|
303
302
|
: canBrowseHasWaitlist
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
? [oneHrBorrow, waitlist, printDisability]
|
|
304
|
+
: [];
|
|
306
305
|
const actions = canBrowseCantBorrowCantWaitlist
|
|
307
306
|
? [oneHrBorrow, printDisability]
|
|
308
307
|
: dropdownOptions;
|
package/src/ia-book-actions.js
CHANGED
|
@@ -12,7 +12,7 @@ import './components/info-icon.js';
|
|
|
12
12
|
import { GetLendingActions } from './core/services/get-lending-actions.js';
|
|
13
13
|
import { mobileContainerWidth } from './core/config/constants.js';
|
|
14
14
|
import { LoanTokenPoller } from './core/services/loan-token-poller.js';
|
|
15
|
-
import {
|
|
15
|
+
import { setItem } from './core/services/doc-cookies.js';
|
|
16
16
|
|
|
17
17
|
export const events = {
|
|
18
18
|
browseExpired: 'IABookReader:BrowsingHasExpired',
|
|
@@ -37,7 +37,6 @@ export default class IABookActions extends LitElement {
|
|
|
37
37
|
disableActionGroup: { type: Boolean },
|
|
38
38
|
modal: { Object },
|
|
39
39
|
tokenDelay: { type: Number },
|
|
40
|
-
hasStickyAdminAccess: { Boolean },
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -56,7 +55,6 @@ export default class IABookActions extends LitElement {
|
|
|
56
55
|
this.disableActionGroup = false;
|
|
57
56
|
this.modal = undefined;
|
|
58
57
|
this.tokenDelay = 120000; // 2 minutes
|
|
59
|
-
this.hasStickyAdminAccess = false;
|
|
60
58
|
|
|
61
59
|
// private props
|
|
62
60
|
this.primaryActions = [];
|
|
@@ -81,7 +79,7 @@ export default class IABookActions extends LitElement {
|
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
// manage sticky-admin-acces by cookie
|
|
84
|
-
this.hasStickyAdminAccess = getItem('sticky-admin-access') === 'true';
|
|
82
|
+
// this.hasStickyAdminAccess = getItem('sticky-admin-access') === 'true';
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
updated(changed) {
|
|
@@ -369,22 +367,6 @@ export default class IABookActions extends LitElement {
|
|
|
369
367
|
});
|
|
370
368
|
}
|
|
371
369
|
|
|
372
|
-
// eslint-disable-next-line class-methods-use-this
|
|
373
|
-
toggleStickyAdminAccess() {
|
|
374
|
-
this.hasStickyAdminAccess = !this.hasStickyAdminAccess;
|
|
375
|
-
|
|
376
|
-
// set in cookies
|
|
377
|
-
setItem('sticky-admin-access', this.hasStickyAdminAccess);
|
|
378
|
-
|
|
379
|
-
document.dispatchEvent(
|
|
380
|
-
new CustomEvent('stickyAdminAccess', {
|
|
381
|
-
detail: {
|
|
382
|
-
hasStickyAdminAccess: this.hasStickyAdminAccess,
|
|
383
|
-
},
|
|
384
|
-
})
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
370
|
get iconClass() {
|
|
389
371
|
return this.width <= mobileContainerWidth ? 'mobile' : 'desktop';
|
|
390
372
|
}
|
|
@@ -401,37 +383,10 @@ export default class IABookActions extends LitElement {
|
|
|
401
383
|
return html`<text-group
|
|
402
384
|
textClass=${this.textClass}
|
|
403
385
|
texts=${this.primaryTitle}
|
|
404
|
-
?hasAdminBorrowedAccess=${this.hasAdminBorrowedAccess}
|
|
405
386
|
>
|
|
406
|
-
${this.hasAdminBorrowedAccess
|
|
407
|
-
? html`<div slot="sticky-access-checkbox">
|
|
408
|
-
${this.stickyAdminAccess}
|
|
409
|
-
</div>`
|
|
410
|
-
: ''}
|
|
411
387
|
</text-group>`;
|
|
412
388
|
}
|
|
413
389
|
|
|
414
|
-
get stickyAdminAccess() {
|
|
415
|
-
return html`
|
|
416
|
-
<label class="stick-admin" for="sticky-admin-access">
|
|
417
|
-
<input
|
|
418
|
-
type="checkbox"
|
|
419
|
-
id="sticky-admin-access"
|
|
420
|
-
aria-label="Checkbox"
|
|
421
|
-
?checked=${this.hasStickyAdminAccess}
|
|
422
|
-
@click=${this.toggleStickyAdminAccess}
|
|
423
|
-
/>
|
|
424
|
-
<span>${this.primaryTitle}</span>
|
|
425
|
-
</label>
|
|
426
|
-
`;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
get hasAdminBorrowedAccess() {
|
|
430
|
-
return this.secondaryActions.some(
|
|
431
|
-
action => action.id === 'exitAdminAccess'
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
390
|
get hasAdminAccess() {
|
|
436
391
|
return !this.lendingStatus.userHasBorrowed && this.lendingStatus.isAdmin;
|
|
437
392
|
}
|
|
@@ -451,10 +406,6 @@ export default class IABookActions extends LitElement {
|
|
|
451
406
|
justify-content: center;
|
|
452
407
|
flex-wrap: wrap;
|
|
453
408
|
}
|
|
454
|
-
.stick-admin {
|
|
455
|
-
user-select: none;
|
|
456
|
-
cursor: pointer;
|
|
457
|
-
}
|
|
458
409
|
`;
|
|
459
410
|
}
|
|
460
411
|
}
|