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.24
edited by bougault
on 2023/01/13 14:35
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -9,17 +9,24 @@
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 + get styles() {
24 + return '';
25 + }
26 +
27 + get html() {
28 + return '';
29 + }
23 23   $(selector) {
24 24   return this.shadowRoot.querySelector(selector);
25 25   }
... ... @@ -39,23 +39,38 @@
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 - });
51 + this.$('#search').addEventListener('click', this.handleSearch);
52 + this.$('#prev').addEventListener('click', this.handlePrevPage);
53 + this.$('#next').addEventListener('click', this.handleNextPage);
54 + this.$('input[type="text"]').focus();
56 56   }
57 57  
57 + disconnectedCallback() {
58 + this.$('#search').removeEventListener('click', this.handleSearch);
59 + this.$('#prev').removeEventListener('click', this.handlePrevPage);
60 + this.$('#next').removeEventListener('click', this.handleNextPage);
61 + }
58 58  
63 + get styles() {
64 + return `
65 + input[type="text"] {
66 + border: 1px solid red;
67 + }
68 + `
69 + }
70 + handlePrevPage = () => {
71 + if(this.offset > 0) {
72 + this.offset--;
73 + this.handleSearch();
74 + }
75 + }
76 + handleNextPage = () => {
77 + this.offset++;
78 + this.handleSearch();
79 + }
80 +
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(`
89 + get html() {
90 + 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 - `);
97 + `;
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));
114 + 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(`
133 + get styles() {
134 + return `
135 + a {
136 + color: var(--color-brand-primary);
137 + }
138 + `;
139 + }
140 + get html() {
141 + 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 - `);
147 + </div> `
120 120   }
149 +
121 121   connectedCallback() {
122 122   this.attachShadow({ mode: 'open' });
123 - this.shadowRoot.appendChild(this.resultTemplate.content.cloneNode(true));
152 + this.shadowRoot.appendChild(this.template.content.cloneNode(true));
124 124   }
125 125   }
126 126  );