Failed to execute template. Cause: [Access denied when checking [script] access to [xwiki:Collaboratory.UX.HbpSkin.WebHome] for user [xwiki:XWiki.Admin]]. Click on this message for details.

CLB Search Component - HBP Wiki

IAM21 instance, do not create collab nor modify a team, your changes will be lost


Changes for page CLB Search Component

Last modified by bougault on 2023/01/17 11:42

From version 7.13
edited by bougault
on 2023/01/13 14:10
Change comment: There is no comment for this version
To version 7.21
edited by bougault
on 2023/01/13 14:33
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -9,17 +9,21 @@
9 9   this.attachShadow({ mode: 'open'});
10 10   }
11 11  
12 - createTemplate(htmlString) {
12 + get template() {
13 13   const template = document.createElement('template');
14 14   template.innerHTML = `
15 15   <style>
16 16   ${this.styles}
17 17   </style>
18 - ${htmlString}
18 + ${this.html}
19 19   `;
20 20   return template;
21 21   }
22 22  
23 +
24 + get styles() {
25 + return ``;
26 + }
23 23   $(selector) {
24 24   return this.shadowRoot.querySelector(selector);
25 25   }
... ... @@ -39,23 +39,37 @@
39 39   }
40 40  
41 41   connectedCallback() {
42 - // this.attachShadow({ mode: 'open' });
43 43   super.connectedCallback();
44 44   this.render();
45 - this.$('#search').addEventListener('click', () => this.handleSearch());
46 - this.$('#prev').addEventListener('click', () => {
47 - if(this.offset > 0) {
48 - this.offset--;
49 - this.handleSearch();
50 - }
51 - });
52 - this.$('#next').addEventListener('click', () => {
53 - this.offset++;
54 - this.handleSearch();
55 - });
48 + this.$('#search').addEventListener('click', this.handleSearch);
49 + this.$('#prev').addEventListener('click', this.handlePrevPage);
50 + this.$('#next').addEventListener('click', this.handleNextPage;
56 56   }
57 57  
53 + disconnectedCallback() {
54 + this.$('#search').removeEventListener('click', this.handleSearch;
55 + this.$('#prev').removeEventListener('click', this.handlePrevPage);
56 + this.$('#next').removeEventListener('click', this.handleNextPage);
57 + }
58 58  
59 + get styles() {
60 + return `
61 + input[type="text"] {
62 + border: 1px solid red;
63 + }
64 + `
65 + }
66 + handlePrevPage = () => {
67 + if(this.offset > 0) {
68 + this.offset--;
69 + this.handleSearch();
70 + }
71 + }
72 + handleNextPage = () => {
73 + this.offset++;
74 + this.handleSearch();
75 + }
76 +
59 59   handleSearch = () => {
60 60   const value = this.$('input[type="text"]').value;
61 61   fetch(`${this.searchBaseUrl}${encodeURIComponent(value)}&offset=${this.offset}`)
... ... @@ -64,8 +64,8 @@
64 64   }
65 65  
66 66  
67 - get searchInputTemplate() {
68 - return this.createTemplate(`
85 + get html() {
86 + return `
69 69   <div>
70 70   <input type="text"><button id="search">Search</button>
71 71   <div id="results"></div>
... ... @@ -72,7 +72,7 @@
72 72   <button id="prev">prev</button>
73 73   <button id="next">next</button>
74 74   </div>
75 - `);
93 + `;
76 76   }
77 77  
78 78   renderResults = (results) => {
... ... @@ -89,7 +89,7 @@
89 89   }
90 90  
91 91   render() {
92 - this.shadowRoot.appendChild(this.searchInputTemplate.content.cloneNode(true));
110 + this.shadowRoot.appendChild(this.template.content.cloneNode(true));
93 93   }
94 94   }
95 95  );
... ... @@ -108,19 +108,26 @@
108 108   return this.getAttribute('data-href');
109 109   }
110 110  
111 - get resultTemplate() {
112 - return this.createTemplate(`
129 + get styles() {
130 + return `
131 + a {
132 + color: var(--color-brand-primary);
133 + }
134 + `;
135 + }
136 + get html() {
137 + return `
113 113   <div>
114 114   <a href=${this.hrefAttr}>${this.titleAttr}</a>
115 115   <div>
116 116   <slot></slot>
117 117   </div>
118 - </div>
119 - `);
143 + </div> `
120 120   }
145 +
121 121   connectedCallback() {
122 122   this.attachShadow({ mode: 'open' });
123 - this.shadowRoot.appendChild(this.resultTemplate.content.cloneNode(true));
148 + this.shadowRoot.appendChild(this.template.content.cloneNode(true));
124 124   }
125 125   }
126 126  );