@ucd-lib/theme-elements 0.0.17 → 1.0.2
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.
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {html, LitElement} from 'lit';
|
|
2
|
+
import {render, styles} from "./ucd-theme-author-profile.tpl.js";
|
|
3
|
+
import {TaskController} from '../../utils/controllers/task.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @class AuthorProfile
|
|
7
|
+
* @description This author profile hydrates with the website wordpress api and goes into a profile block.
|
|
8
|
+
* @property {String} email - Email to reference person
|
|
9
|
+
* @property {String} domain - Specify the domain to choose from
|
|
10
|
+
*
|
|
11
|
+
* <ucdlib-theme-author-profile domain="sandbox" email='sabaggett@ucdavis.edu></ucdlib-theme-author-profile>
|
|
12
|
+
*/
|
|
13
|
+
export default class UcdlibAuthorProfile extends LitElement {
|
|
14
|
+
static get properties() {
|
|
15
|
+
return {
|
|
16
|
+
results : {type: Object, attribute:false},
|
|
17
|
+
email : {type: String},
|
|
18
|
+
id: {type: Number},
|
|
19
|
+
nameLast: {type: String},
|
|
20
|
+
nameFirst: {type: String},
|
|
21
|
+
link: {type: String},
|
|
22
|
+
contactWebsite: {type: String},
|
|
23
|
+
contactEmail: {type: String},
|
|
24
|
+
contactPhone: {type: String},
|
|
25
|
+
contactWebsiteLabel: {type: String},
|
|
26
|
+
contactEmailLabel: {type: String},
|
|
27
|
+
contactPhoneLabel: {type: String},
|
|
28
|
+
contactAppointmentUrl: {type: String},
|
|
29
|
+
positionTitle: {type: String},
|
|
30
|
+
photo: {type: Object},
|
|
31
|
+
department: {type: String},
|
|
32
|
+
domain: {type: String}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static get styles() {
|
|
37
|
+
return styles();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor() {
|
|
41
|
+
super();
|
|
42
|
+
this.PENDING = false;
|
|
43
|
+
this.LOADING = false;
|
|
44
|
+
this.COMPLETE = false;
|
|
45
|
+
this.ERROR = false;
|
|
46
|
+
this.results = {};
|
|
47
|
+
this.email = '';
|
|
48
|
+
this.domain = '';
|
|
49
|
+
this.errorMessage = 'This is not an email.';
|
|
50
|
+
|
|
51
|
+
this.svgIcon = {
|
|
52
|
+
'url': html`
|
|
53
|
+
<svg class="svg-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">
|
|
54
|
+
<path d="M640,328V312a16,16,0,0,0-16-16H344V256h72a32,32,0,0,0,32-32V96a32,32,0,0,0-32-32H224a32,32,0,0,0-32,32V224a32,32,0,0,0,32,32h72v40H16A16,16,0,0,0,0,312v16a16,16,0,0,0,16,16H120v40H64a32,32,0,0,0-32,32V544a32,32,0,0,0,32,32H224a32,32,0,0,0,32-32V416a32,32,0,0,0-32-32H168V344H472v40H416a32,32,0,0,0-32,32V544a32,32,0,0,0,32,32H576a32,32,0,0,0,32-32V416a32,32,0,0,0-32-32H520V344H624A16,16,0,0,0,640,328ZM256,192V128H384v64ZM192,512H96V448h96Zm352,0H448V448h96Z"/>
|
|
55
|
+
</svg> `,
|
|
56
|
+
'email': html`
|
|
57
|
+
<svg class="svg-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
|
58
|
+
<path d="M502.3,190.8a6,6,0,0,1,9.7,4.7V400a48,48,0,0,1-48,48H48A48,48,0,0,1,0,400V195.6a6,6,0,0,1,9.7-4.7c22.4,17.4,52.1,39.5,154.1,113.6,21.1,15.4,56.7,47.8,92.2,47.6,35.7.3,72-32.8,92.3-47.6C450.3,230.4,479.9,208.2,502.3,190.8ZM256,320c23.2.4,56.6-29.2,73.4-41.4,132.7-96.3,142.8-104.7,173.4-128.7A23.93,23.93,0,0,0,512,131V112a48,48,0,0,0-48-48H48A48,48,0,0,0,0,112v19a24.08,24.08,0,0,0,9.2,18.9c30.6,23.9,40.7,32.4,173.4,128.7,16.8,12.2,50.2,41.8,73.4,41.4Z"/>
|
|
59
|
+
</svg>`,
|
|
60
|
+
'calendar': html `
|
|
61
|
+
<svg class="svg-icon" xmlns="http://www.w3.org/2000/svg"viewBox="0 0 512 512">
|
|
62
|
+
<path d="M12 192h424c6.6 0 12 5.4 12 12v260c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V204c0-6.6 5.4-12 12-12zm436-44v-36c0-26.5-21.5-48-48-48h-48V12c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v52H160V12c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v52H48C21.5 64 0 85.5 0 112v36c0 6.6 5.4 12 12 12h424c6.6 0 12-5.4 12-12z"/>
|
|
63
|
+
</svg>`,
|
|
64
|
+
'phone': html `
|
|
65
|
+
<svg class="svg-icon" xmlns="http://www.w3.org/2000/svg"viewBox="0 0 512 512">
|
|
66
|
+
<path d="M497.39 361.8l-112-48a24 24 0 0 0-28 6.9l-49.6 60.6A370.66 370.66 0 0 1 130.6 204.11l60.6-49.6a23.94 23.94 0 0 0 6.9-28l-48-112A24.16 24.16 0 0 0 122.6.61l-104 24A24 24 0 0 0 0 48c0 256.5 207.9 464 464 464a24 24 0 0 0 23.4-18.6l24-104a24.29 24.29 0 0 0-14.01-27.6z"/>
|
|
67
|
+
</svg>
|
|
68
|
+
`
|
|
69
|
+
};
|
|
70
|
+
this.render=render.bind(this);
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @method updated
|
|
77
|
+
*
|
|
78
|
+
* @description request user data when email or domain changes
|
|
79
|
+
*
|
|
80
|
+
* @param {Object} props
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
updated(props){
|
|
84
|
+
if( props.has('email') || props.has('domain') ){
|
|
85
|
+
if( !this.email ) return;
|
|
86
|
+
this.eController = new TaskController(this, this._requestUrl());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @method validationLink
|
|
92
|
+
*
|
|
93
|
+
* @description Validates the email to make sure it is an email
|
|
94
|
+
*
|
|
95
|
+
* @param {String} email
|
|
96
|
+
*
|
|
97
|
+
* @returns {String}
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
validationLink(email){
|
|
101
|
+
const regexExp = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/gi;
|
|
102
|
+
return regexExp.test(email);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @method validationLink
|
|
107
|
+
*
|
|
108
|
+
* @description Validates the email to make sure it is an email
|
|
109
|
+
*
|
|
110
|
+
* @param {String} email
|
|
111
|
+
*
|
|
112
|
+
* @returns {String}
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
_onPending(){
|
|
116
|
+
this.PENDING = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @method _onError
|
|
121
|
+
*
|
|
122
|
+
* @description Sets error variable to true
|
|
123
|
+
*
|
|
124
|
+
* @param {String} e
|
|
125
|
+
*
|
|
126
|
+
*/
|
|
127
|
+
_onError(e){
|
|
128
|
+
this.ERROR = true;
|
|
129
|
+
console.log(this.ERROR);
|
|
130
|
+
console.error(e);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @method _onComplete
|
|
135
|
+
*
|
|
136
|
+
* @description on complete defines the forms and updates
|
|
137
|
+
*
|
|
138
|
+
* @param {Object} results
|
|
139
|
+
*
|
|
140
|
+
*
|
|
141
|
+
*/
|
|
142
|
+
_onComplete(results){
|
|
143
|
+
this.results = results;
|
|
144
|
+
if(this.results.data != undefined) {
|
|
145
|
+
this.ERROR = true;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.COMPLETE = true;
|
|
149
|
+
this.PENDING = false;
|
|
150
|
+
this.LOADING = false;
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
this.id = this.results.id;
|
|
154
|
+
|
|
155
|
+
this.nameLast = this.results.nameLast;
|
|
156
|
+
|
|
157
|
+
this.nameFirst = this.results.nameFirst;
|
|
158
|
+
|
|
159
|
+
this.link = this.results.link;
|
|
160
|
+
|
|
161
|
+
this.contactWebsite = this.results.contactWebsite.length !== 0 ? this.results.contactWebsite[0].value :null;
|
|
162
|
+
|
|
163
|
+
this.contactEmail = this.results.contactEmail.length !== 0 ? this.results.contactEmail[0].value : null;
|
|
164
|
+
|
|
165
|
+
this.contactPhone = this.results.contactPhone.length !== 0 ? this.results.contactPhone[0].value : null;
|
|
166
|
+
|
|
167
|
+
this.contactAppointmentUrl = this.results.contactAppointmentUrl != "" ? this.results.contactAppointmentUrl : undefined;
|
|
168
|
+
|
|
169
|
+
this.positionTitle = this.results.positionTitle;
|
|
170
|
+
|
|
171
|
+
this.photo = Object.keys(this.results.photo).length !== 0 ? this.results.photo : "Empty";
|
|
172
|
+
|
|
173
|
+
this.department = this.results.department.title;
|
|
174
|
+
|
|
175
|
+
this.photoAlt = this.nameFirst + "_" + this.nameLast + "_Img";
|
|
176
|
+
|
|
177
|
+
this.requestUpdate();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @method _requestUrl
|
|
186
|
+
*
|
|
187
|
+
* @description configures the url and checks for email validation
|
|
188
|
+
*
|
|
189
|
+
* @returns {String}
|
|
190
|
+
*
|
|
191
|
+
*/
|
|
192
|
+
_requestUrl(){
|
|
193
|
+
let email =this.email;
|
|
194
|
+
let validate = this.validationLink(email);
|
|
195
|
+
if(!validate) console.error(email);
|
|
196
|
+
let url;
|
|
197
|
+
|
|
198
|
+
url = "https://library.ucdavis.edu/wp-json/ucdlib-directory/person/" + String(email);
|
|
199
|
+
if (this.domain != "")
|
|
200
|
+
url = "https://" + this.domain + ".library.ucdavis.edu/wp-json/ucdlib-directory/person/" + String(email);
|
|
201
|
+
this.requestUpdate();
|
|
202
|
+
|
|
203
|
+
return url;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @method _onLoading
|
|
208
|
+
*
|
|
209
|
+
* @description Sets loading variable to true
|
|
210
|
+
*
|
|
211
|
+
*
|
|
212
|
+
*/
|
|
213
|
+
_onLoading(){
|
|
214
|
+
this.LOADING = true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
customElements.define('ucdlib-theme-author-profile', UcdlibAuthorProfile);
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { html, css } from 'lit';
|
|
2
|
+
|
|
3
|
+
import normalizeCss from "@ucd-lib/theme-sass/normalize.css.js";
|
|
4
|
+
import teaserStyles from "@ucd-lib/theme-sass/4_component/_index.css.js";
|
|
5
|
+
import baseStyles from "@ucd-lib/theme-sass/1_base_html/_index.css.js";
|
|
6
|
+
import buttons from "@ucd-lib/theme-sass/2_base_class/_index.css.js";
|
|
7
|
+
export function styles() {
|
|
8
|
+
const elementStyles = css`
|
|
9
|
+
:host {
|
|
10
|
+
display: block;
|
|
11
|
+
}
|
|
12
|
+
form {
|
|
13
|
+
width:100%;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
return [elementStyles,baseStyles,teaserStyles,normalizeCss, buttons];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function render() {
|
|
21
|
+
return html`
|
|
22
|
+
<style>
|
|
23
|
+
.vm-teaser__figure.category_loading{
|
|
24
|
+
background-color:#dcdcdc;
|
|
25
|
+
height:165px;
|
|
26
|
+
width:135px;
|
|
27
|
+
}
|
|
28
|
+
.load_teaser_a{
|
|
29
|
+
background-color:#dcdcdc;
|
|
30
|
+
width: 85%;
|
|
31
|
+
height:25px;
|
|
32
|
+
}
|
|
33
|
+
.load_teaser_b{
|
|
34
|
+
background-color:#dcdcdc;
|
|
35
|
+
width: 67%;
|
|
36
|
+
height:20px;
|
|
37
|
+
}
|
|
38
|
+
.load_teaser_c{
|
|
39
|
+
background-color:#dcdcdc;
|
|
40
|
+
width: 33.3%;
|
|
41
|
+
height:18px;
|
|
42
|
+
}
|
|
43
|
+
.container {
|
|
44
|
+
display: inline-grid;
|
|
45
|
+
grid-template-columns: 15% 85%;
|
|
46
|
+
width:100%;
|
|
47
|
+
}
|
|
48
|
+
.container-no-image {
|
|
49
|
+
display: inline-grid;
|
|
50
|
+
width:100%;
|
|
51
|
+
}
|
|
52
|
+
article {
|
|
53
|
+
margin-bottom: 50px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.photo {
|
|
57
|
+
position: relative;
|
|
58
|
+
width:90%;
|
|
59
|
+
height:90%;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.photo:after {
|
|
63
|
+
content: "";
|
|
64
|
+
display:inline-block;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.content {
|
|
68
|
+
position: absolute;
|
|
69
|
+
width: 70%;
|
|
70
|
+
height: 70%;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.text_container {
|
|
74
|
+
vertical-align:top;
|
|
75
|
+
display:inline-block;
|
|
76
|
+
}
|
|
77
|
+
.name {
|
|
78
|
+
color:var(--ucd-blue-80);
|
|
79
|
+
margin-bottom:0;
|
|
80
|
+
}
|
|
81
|
+
.title {
|
|
82
|
+
margin-bottom:0;
|
|
83
|
+
}
|
|
84
|
+
.info {
|
|
85
|
+
color:var(--ucd-blue-80);
|
|
86
|
+
margin-bottom:0;
|
|
87
|
+
}
|
|
88
|
+
.svg-icon {
|
|
89
|
+
width: 20px;
|
|
90
|
+
height: 20px;
|
|
91
|
+
fill: #73ABDD;
|
|
92
|
+
margin-right: 5px;
|
|
93
|
+
}
|
|
94
|
+
.contact-list{
|
|
95
|
+
display:inline-block;
|
|
96
|
+
margin-top:5px;
|
|
97
|
+
}
|
|
98
|
+
.pipe {
|
|
99
|
+
font-size:30px;
|
|
100
|
+
vertical-align: middle;
|
|
101
|
+
font-weight: lighter;
|
|
102
|
+
line-height: 25px;
|
|
103
|
+
color:#36454F;
|
|
104
|
+
}
|
|
105
|
+
.noApp-pipe {
|
|
106
|
+
display:none;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@media (max-width: 800px) {
|
|
110
|
+
|
|
111
|
+
.contact-list {
|
|
112
|
+
display:block;
|
|
113
|
+
margin-bottom:5px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.contact-list .pipe {
|
|
117
|
+
display:none;
|
|
118
|
+
}
|
|
119
|
+
.photo {
|
|
120
|
+
width:90%;
|
|
121
|
+
height:90%;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@media (max-width: 550px) {
|
|
127
|
+
.container {
|
|
128
|
+
grid-template-columns: 35% 65%;
|
|
129
|
+
}
|
|
130
|
+
.photo {
|
|
131
|
+
width:80%;
|
|
132
|
+
height:80%;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
137
|
+
<!--
|
|
138
|
+
Starts the Permalink Fetch
|
|
139
|
+
-->
|
|
140
|
+
${this.eController ? html`
|
|
141
|
+
${this.eController.render({
|
|
142
|
+
complete: (result) => this._onComplete(result),
|
|
143
|
+
initial: () => this._onLoading(),
|
|
144
|
+
pending: () => this._onPending(),
|
|
145
|
+
error: (e) => this._onError(e)
|
|
146
|
+
})
|
|
147
|
+
}`:html``
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
<article>
|
|
151
|
+
${!this.LOADING ? html`
|
|
152
|
+
${this.photo != "Empty" && this.photo != undefined ?
|
|
153
|
+
html`
|
|
154
|
+
<div class="container">
|
|
155
|
+
<div class="photo"><img src="${this.photo.link}" alt="${this.photoAlt}"></div>
|
|
156
|
+
<div class="text_container">
|
|
157
|
+
<h3 class="name"><a class="name" href="">${this.nameFirst} ${this.nameLast}</a></h3>
|
|
158
|
+
<p class="title">${this.positionTitle} <span class="pipe">|</span> ${this.department}</p>
|
|
159
|
+
<p class="contact-list">${this.contactPhone ? html`${this.svgIcon.phone} <a class="info" href="tel:${this.contactPhone}">${this.contactPhone}</a> <span class="pipe">|</span>`: html``}</p>
|
|
160
|
+
<p class="contact-list">${this.contactEmail ? html`${this.svgIcon.email} <a class="info" href="mailto:${this.contactEmail}">${this.contactEmail}</a> ${this.contactAppointmentUrl ? html`<span class="pipe">|</span>`:html`<span class="noApp-pipe">|</span>`}`: html``}</p>
|
|
161
|
+
<p class="contact-list">${this.contactAppointmentUrl ? html`${this.svgIcon.calendar} <a class="info" href="${this.contactAppointmentUrl ? this.contactAppointmentUrl:"#"}">Book an Appointment</a>`: html``}</p>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
`
|
|
165
|
+
:html`
|
|
166
|
+
<div class="container-no-image">
|
|
167
|
+
<div class="text_container">
|
|
168
|
+
<h3 class="name"><a class="name" href="">${this.nameFirst} ${this.nameLast}</a></h3>
|
|
169
|
+
<p class="title">${this.positionTitle} <span class="pipe">|</span> ${this.department}</p>
|
|
170
|
+
<p class="contact-list">${this.contactPhone ? html`${this.svgIcon.phone} <a class="info" href="tel:${this.contactPhone}">${this.contactPhone}</a> <span class="pipe">|</span> `: html``}</p>
|
|
171
|
+
<p class="contact-list">${this.contactEmail ? html`${this.svgIcon.email} <a class="info" href="mailto:${this.contactEmail}">${this.contactEmail}</a> ${this.contactAppointmentUrl ? html`<span class="pipe">|</span>`:html`<span class="noApp-pipe">|</span>`}`: html``}</p>
|
|
172
|
+
<p class="contact-list">${this.contactAppointmentUrl ? html`${this.svgIcon.calendar} <a class="info" href="${this.contactAppointmentUrl ? this.contactAppointmentUrl:"#"}">Book an Appointment</a>`: html``}</p>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
`}
|
|
176
|
+
|
|
177
|
+
`:html`
|
|
178
|
+
${this.ERROR ? html`
|
|
179
|
+
<p>Person does not exist!</p>
|
|
180
|
+
`: html`
|
|
181
|
+
<!--
|
|
182
|
+
If it is in the loading stage of the permalink fetch
|
|
183
|
+
it will render this
|
|
184
|
+
look.
|
|
185
|
+
-->
|
|
186
|
+
<div class="vm-teaser__figure category_loading"></div>
|
|
187
|
+
<div class="vm-teaser__body">
|
|
188
|
+
<div class="load_teaser_a"></div>
|
|
189
|
+
<br/>
|
|
190
|
+
<div class="load_teaser_b"></div>
|
|
191
|
+
<br/>
|
|
192
|
+
<div class="load_teaser_c"></div>
|
|
193
|
+
<br/>
|
|
194
|
+
<div class="load_teaser_c"></div>
|
|
195
|
+
</div>
|
|
196
|
+
`}
|
|
197
|
+
|
|
198
|
+
`}
|
|
199
|
+
</article>
|
|
200
|
+
`;
|
|
201
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ucd-lib/theme-elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Custom elements for the UCD brand theme",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@lit-labs/task": "^1.0.0",
|
|
13
13
|
"@ucd-lib/theme-sass": "^5.0.15",
|
|
14
|
-
"dompurify": "^2.3.
|
|
14
|
+
"dompurify": "^2.3.9",
|
|
15
15
|
"ip-cidr": "^3.0.4",
|
|
16
16
|
"lit": "^2.0.2",
|
|
17
|
-
"marked": "^4.0.
|
|
17
|
+
"marked": "^4.0.18",
|
|
18
18
|
"photoswipe": "^4.1.3",
|
|
19
19
|
"slim-select": "^1.26.2"
|
|
20
20
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LitElement} from 'lit';
|
|
2
2
|
import {render, styles} from "./ucdlib-sils-permalink.tpl.js";
|
|
3
3
|
import {PermalinkController} from './ucdlib-sils-permalink-controller.js';
|
|
4
|
+
import {TaskController} from '../../utils/controllers/task.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @class UcdlibSilsPermalink
|
|
@@ -99,7 +100,8 @@ export default class UcdlibSilsPermalink extends LitElement {
|
|
|
99
100
|
*/
|
|
100
101
|
firstUpdated(changedProperties){
|
|
101
102
|
if(this.permalink != ''){
|
|
102
|
-
this.perma = new
|
|
103
|
+
this.perma = new TaskController(this, this._requestUrl());
|
|
104
|
+
|
|
103
105
|
this.requestUpdate();
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {Task} from '@lit-labs/task';
|
|
2
|
+
|
|
3
|
+
export class TaskController {
|
|
4
|
+
// host;
|
|
5
|
+
// value;
|
|
6
|
+
// kinds = Names.kinds;
|
|
7
|
+
// task;
|
|
8
|
+
constructor(host, url) {
|
|
9
|
+
const baseUrl = url;
|
|
10
|
+
this.url = baseUrl;
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.task = new Task(
|
|
13
|
+
this.host,
|
|
14
|
+
async () => {
|
|
15
|
+
const response = await fetch(`${baseUrl}`);
|
|
16
|
+
const result = await response.json();
|
|
17
|
+
const error = result.error;
|
|
18
|
+
if (error !== undefined) {
|
|
19
|
+
throw new Error(error);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
() => [this.url]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
render(renderFunctions) {
|
|
31
|
+
return this.task.render(renderFunctions);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
}
|