| ... |
... |
@@ -9,19 +9,37 @@ |
| 9 |
9 |
this.attachShadow({ mode: 'open'}); |
| 10 |
10 |
} |
| 11 |
11 |
|
| 12 |
|
- createTemplate(htmlString) { |
|
12 |
+ get template() { |
| 13 |
13 |
const template = document.createElement('template'); |
| 14 |
|
- template.innerHTML = htmlString; |
|
14 |
+ template.innerHTML = ` |
|
15 |
+ <style> |
|
16 |
+ ${this.styles} |
|
17 |
+ </style> |
|
18 |
+ ${this.html} |
|
19 |
+ `; |
| 15 |
15 |
return template; |
| 16 |
16 |
} |
|
22 |
+ |
|
23 |
+ |
|
24 |
+ get styles() { |
|
25 |
+ return ``; |
|
26 |
+ } |
|
27 |
+ $(selector) { |
|
28 |
+ return this.shadowRoot.querySelector(selector); |
|
29 |
+ } |
|
30 |
+ |
|
31 |
+ $$(selector) { |
|
32 |
+ return this.shadowRoot.querySelectorAll(selector); |
|
33 |
+ } |
| 17 |
17 |
} |
| 18 |
18 |
|
| 19 |
19 |
customElements.define('clb-simplified-search', |
| 20 |
20 |
class extends ClbComponent { |
| 21 |
|
- searchBaseUrl = 'https://wiki-dev.ebrains.eu/bin/get/XWiki/SuggestSolrService?outputSyntax=plain&media=json&nb=10&offset=0&query=q%3D%22__INPUT__%22~100%0Afq%3Dtype%3ADOCUMENT%0Afq%3Dspace%3ACollabs.*&input='; |
|
38 |
+ searchBaseUrl = '/bin/get/XWiki/SuggestSolrService?outputSyntax=plain&media=json&nb=10&query=q%3D%22__INPUT__%22~100%0Afq%3Dtype%3ADOCUMENT%0Afq%3Dspace%3ACollabs.*&input='; |
| 22 |
22 |
constructor() { |
| 23 |
23 |
super(); |
| 24 |
24 |
this.results = []; |
|
42 |
+ this.offset = 0; |
| 25 |
25 |
} |
| 26 |
26 |
|
| 27 |
27 |
connectedCallback() { |
| ... |
... |
@@ -28,36 +28,56 @@ |
| 28 |
28 |
// this.attachShadow({ mode: 'open' }); |
| 29 |
29 |
super.connectedCallback(); |
| 30 |
30 |
this.render(); |
| 31 |
|
- this.searchButton.addEventListener('click', () => this.handleSearch()); |
|
49 |
+ this.$('#search').addEventListener('click', this.handleSearch); |
|
50 |
+ this.$('#prev').addEventListener('click', this.handlePrevPage); |
|
51 |
+ this.$('#next').addEventListener('click', this.handleNextPage; |
| 32 |
32 |
} |
| 33 |
33 |
|
| 34 |
|
- |
| 35 |
|
- handleSearch() { |
| 36 |
|
- // fetch(`${this.searchBaseUrl}${encodeURIComponent(this.searchInput.value)}`) |
| 37 |
|
- // .then(res => res.json()) |
| 38 |
|
- //.then(this.renderResults); |
| 39 |
|
- const res = [{"id":"xwiki:Collabs.bougault.Collabs Search.WebHome_en","hidden":false,"wiki":"xwiki","name":"WebHome","space":"Collabs.bougault.Collabs Search","spaces":["Collabs","bougault","Collabs Search"],"locale":"en","language":"en","type":"DOCUMENT","fullname":"Collabs.bougault.Collabs Search.WebHome","title_en":["Collabs Search"],"title_":"Collabs Search","doccontentraw_en":["{{velocity output=\"false\"}}\r\n #set($displayContentFooter=false)\r\n #set($displayDocExtra=false)\r\n #set($displayContentMenu=false)\r\n $xwiki.ssx.use('Collaboratory.UX.SSX.noheader')\r\n\r\n #set ($clbaction = $request.getParameter(\"clbaction\"))\r\n #set ($isCreationForm = $clbaction.equals('create'))\r\n #set ($isAuthenticated = ($xcontext.user != 'XWiki.XWikiGuest'))\r\n #if($isCreationForm)\r\n #set ($moduleCSS = 'collab-settings.css')\r\n #set ($moduleJS = 'collab-settings.js')\r\n #else\r\n #set ($moduleCSS = 'collab-search.css')\r\n #set ($moduleJS = 'collab-search.js')\r\n #end\r\n{{/velocity}}\r\n\r\n{{velocity}}\r\n\r\n{{html wiki=\"true\"}}\r\n\r\n #if($isCreationForm)\r\n (% id=\"root\" %)((()))\r\n #else\r\n (% class=\"container\" %)\r\n (((\r\n #if($isAuthenticated)\r\n (% class=\"row\" %)\r\n (((\r\n (% class=\"col-md-6 pull-right\" %)\r\n (((\r\n {{html}}\r\n <a href=\"/bin/view/Collabs?clbaction=create\" class=\"btn btn-primary pull-right\">Create a collab</a>\r\n {{/html}}\r\n )))\r\n )))\r\n #end\r\n )))\r\n (% id=\"root\" %)((()))\r\n #end\r\n{{/html}}\r\n\r\n{{html clean=\"false\"}}\r\n <link rel=\"stylesheet\" type=\"text/css\" href=\"$services.webjars.url('eu.hbp.wiki:xwiki-webapp-collaboratory', $moduleCSS)\" />\r\n <script type=\"module\" src=\"$services.webjars.url('eu.hbp.wiki:xwiki-webapp-collaboratory', $moduleJS)\"></script>\r\n{{/html}}\r\n\r\n{{/velocity}}\r\n\r\n\r\n"],"doccontentraw_":"{{velocity output=\"false\"}}\r\n #set($displayContentFooter=false)\r\n #set($displayDocExtra=false)\r\n #set($displayContentMenu=false)\r\n $xwiki.ssx.use('Collaboratory.UX.SSX.noheader')\r\n\r\n #set ($clbaction = $request.getParameter(\"clbaction\"))\r\n #set ($isCreationForm = $clbaction.equals('create'))\r\n #set ($isAuthenticated = ($xcontext.user != 'XWiki.XWikiGuest'))\r\n #if($isCreationForm)\r\n #set ($moduleCSS = 'collab-settings.css')\r\n #set ($moduleJS = 'collab-settings.js')\r\n #else\r\n #set ($moduleCSS = 'collab-search.css')\r\n #set ($moduleJS = 'collab-search.js')\r\n #end\r\n{{/velocity}}\r\n\r\n{{velocity}}\r\n\r\n{{html wiki=\"true\"}}\r\n\r\n #if($isCreationForm)\r\n (% id=\"root\" %)((()))\r\n #else\r\n (% class=\"container\" %)\r\n (((\r\n #if($isAuthenticated)\r\n (% class=\"row\" %)\r\n (((\r\n (% class=\"col-md-6 pull-right\" %)\r\n (((\r\n {{html}}\r\n <a href=\"/bin/view/Collabs?clbaction=create\" class=\"btn btn-primary pull-right\">Create a collab</a>\r\n {{/html}}\r\n )))\r\n )))\r\n #end\r\n )))\r\n (% id=\"root\" %)((()))\r\n #end\r\n{{/html}}\r\n\r\n{{html clean=\"false\"}}\r\n <link rel=\"stylesheet\" type=\"text/css\" href=\"$services.webjars.url('eu.hbp.wiki:xwiki-webapp-collaboratory', $moduleCSS)\" />\r\n <script type=\"module\" src=\"$services.webjars.url('eu.hbp.wiki:xwiki-webapp-collaboratory', $moduleJS)\"></script>\r\n{{/html}}\r\n\r\n{{/velocity}}\r\n\r\n\r\n","doccontent_en":["\n\n"],"doccontent_":"\n\n","version":"28.1","doclocale":"","locales":["","en"],"lang":["","en"],"author":"xwiki:XWiki.bougault","author_display":"François B.","creator":"xwiki:XWiki.bougault","creator_display":"François B.","creationdate":1617976623000,"date":1618401384000,"_version_":1752657755570700288,"score":7.453887},{"id":"xwiki:Collabs.collab-dev.WebHome_en","hidden":false,"wiki":"xwiki","name":"WebHome","space":"Collabs.collab-dev","spaces":["Collabs","collab-dev"],"locale":"en","language":"en","type":"DOCUMENT","fullname":"Collabs.collab-dev.WebHome","title_en":["Collab dev"],"title_":"Collab dev","doccontentraw_en":["(% class=\"jumbotron\" %)\n(((\n(% class=\"container\" %)\n(((\n= My Collab's Extended Title =\n\nMy collab's subtitle\n)))\n)))\n\n(% class=\"row\" %)\n(((\n(% class=\"col-xs-12 col-sm-8\" %)\n(((\n= What can I find here? =\n\n* Notice how the table of contents on the right\n* is automatically updated\n* to hold this page's headers\n\n= Who has access? =\n\nDescribe the audience of this collab.\n)))\n\n\n(% class=\"col-xs-12 col-sm-4\" %)\n(((\n{{box title=\"**Contents**\"}}\n{{toc/}}\n{{/box}}\n\n \n)))\n)))"],"doccontentraw_":"(% class=\"jumbotron\" %)\n(((\n(% class=\"container\" %)\n(((\n= My Collab's Extended Title =\n\nMy collab's subtitle\n)))\n)))\n\n(% class=\"row\" %)\n(((\n(% class=\"col-xs-12 col-sm-8\" %)\n(((\n= What can I find here? =\n\n* Notice how the table of contents on the right\n* is automatically updated\n* to hold this page's headers\n\n= Who has access? =\n\nDescribe the audience of this collab.\n)))\n\n\n(% class=\"col-xs-12 col-sm-4\" %)\n(((\n{{box title=\"**Contents**\"}}\n{{toc/}}\n{{/box}}\n\n \n)))\n)))","doccontent_en":["My Collab's Extended Title\n\nMy collab's subtitle\n\nWhat can I find here?\n\nNotice how the table of contents on the right\nis automatically updated\nto hold this page's headers\n\nWho has access?\n\nDescribe the audience of this collab.\n\n\n "],"doccontent_":"My Collab's Extended Title\n\nMy collab's subtitle\n\nWhat can I find here?\n\nNotice how the table of contents on the right\nis automatically updated\nto hold this page's headers\n\nWho has access?\n\nDescribe the audience of this collab.\n\n\n ","version":"10.1","doclocale":"","locales":["","en"],"lang":["","en"],"author":"xwiki:XWiki.messines","author_display":"Axel M.","creator":"xwiki:XWiki.collaboratory","creator_display":"collaboratory","creationdate":1558605692000,"date":1663716732000,"property.Collaboratory.Apps.Collab.Code.CollabClass.chat_boolean":[false],"object.Collaboratory.Apps.Collab.Code.CollabClass_en":["false","","All usefull contents for collaboratory developers.","true","messines"],"objcontent_en":["chat : false","content : ","description : All usefull contents for collaboratory developers.","drive : true","menu : ","owner : messines","public : false","title : ","allow : true","groups : Collabs.collab-dev._.groups.collab-collab-dev-viewer","levels : view,comment","users : ","groups : Collabs.collab-dev._.groups.collab-collab-dev-editor","levels : view,comment,edit","groups : Collabs.collab-dev._.groups.collab-collab-dev-administrator","levels : view,comment,edit,delete"],"property.Collaboratory.Apps.Collab.Code.CollabClass.content_string":[""],"property.Collaboratory.Apps.Collab.Code.CollabClass.description_en":["All usefull contents for collaboratory developers."],"property.Collaboratory.Apps.Collab.Code.CollabClass.drive_boolean":[true],"property.Collaboratory.Apps.Collab.Code.CollabClass.menu_string":[""],"property.Collaboratory.Apps.Collab.Code.CollabClass.owner_en":["messines"],"property.Collaboratory.Apps.Collab.Code.CollabClass.owner_string":["messines"],"property.Collaboratory.Apps.Collab.Code.CollabClass.public_boolean":[false],"property.Collaboratory.Apps.Collab.Code.CollabClass.title_string":[""],"class":["Collaboratory.Apps.Collab.Code.CollabClass","XWiki.XWikiRights"],"property.XWiki.XWikiRights.allow_boolean":[true,true,true],"object.XWiki.XWikiRights_en":["true","Collabs.collab-dev._.groups.collab-collab-dev-viewer","view,comment","","Collabs.collab-dev._.groups.collab-collab-dev-editor","view,comment,edit","Collabs.collab-dev._.groups.collab-collab-dev-administrator","view,comment,edit,delete"],"property.XWiki.XWikiRights.groups_string":["Collabs.collab-dev._.groups.collab-collab-dev-viewer","Collabs.collab-dev._.groups.collab-collab-dev-editor","Collabs.collab-dev._.groups.collab-collab-dev-administrator"],"property.XWiki.XWikiRights.levels_string":["view,comment","view,comment,edit","view,comment,edit,delete"],"property.XWiki.XWikiRights.users_string":["","",""],"_version_":1752657767917682688,"score":7.453887}]; |
| 40 |
|
- this.renderResults(res); |
|
54 |
+ disconnectedCallback() { |
|
55 |
+ this.$('#search').removeEventListener('click', this.handleSearch; |
|
56 |
+ this.$('#prev').removeEventListener('click', this.handlePrevPage); |
|
57 |
+ this.$('#next').removeEventListener('click', this.handleNextPage); |
| 41 |
41 |
} |
| 42 |
42 |
|
| 43 |
|
- get searchInput() { |
| 44 |
|
- return this.shadowRoot.querySelector('input[type="text"]'); |
|
60 |
+ get styles() { |
|
61 |
+ return ` |
|
62 |
+ input[type="text"] { |
|
63 |
+ border: 1px solid red; |
|
64 |
+ } |
|
65 |
+ ` |
| 45 |
45 |
} |
| 46 |
|
- |
| 47 |
|
- get searchButton() { |
| 48 |
|
- return this.shadowRoot.querySelector('button'); |
|
67 |
+ handlePrevPage = () => { |
|
68 |
+ if(this.offset > 0) { |
|
69 |
+ this.offset--; |
|
70 |
+ this.handleSearch(); |
|
71 |
+ } |
| 49 |
49 |
} |
|
73 |
+ handleNextPage = () => { |
|
74 |
+ this.offset++; |
|
75 |
+ this.handleSearch(); |
|
76 |
+ } |
| 50 |
50 |
|
| 51 |
|
- get searchInputTemplate() { |
| 52 |
|
- return this.createTemplate('<div><input type="text"><button>Search</button><div id="results"></div></div>'); |
|
78 |
+ handleSearch = () => { |
|
79 |
+ const value = this.$('input[type="text"]').value; |
|
80 |
+ fetch(`${this.searchBaseUrl}${encodeURIComponent(value)}&offset=${this.offset}`) |
|
81 |
+ .then(res => res.json()) |
|
82 |
+ .then(this.renderResults); |
| 53 |
53 |
} |
| 54 |
54 |
|
| 55 |
|
- resultsContainer = () => { |
| 56 |
|
- return this.shadowRoot.querySelector('#results'); |
|
85 |
+ |
|
86 |
+ get html() { |
|
87 |
+ return ` |
|
88 |
+ <div> |
|
89 |
+ <input type="text"><button id="search">Search</button> |
|
90 |
+ <div id="results"></div> |
|
91 |
+ <button id="prev">prev</button> |
|
92 |
+ <button id="next">next</button> |
|
93 |
+ </div> |
|
94 |
+ `; |
| 57 |
57 |
} |
| 58 |
58 |
|
| 59 |
|
- renderResults(results) { |
| 60 |
|
- const resultsContainer = this.shadowRoot.querySelector('#results'); |
|
97 |
+ renderResults = (results) => { |
|
98 |
+ const resultsContainer = this.$('#results'); |
| 61 |
61 |
resultsContainer.replaceChildren(); |
| 62 |
62 |
for(let i = 0, j = results.length; i < j; i++) { |
| 63 |
63 |
const { title_, spaces, doccontent_en } = results[i]; |
| ... |
... |
@@ -70,7 +70,7 @@ |
| 70 |
70 |
} |
| 71 |
71 |
|
| 72 |
72 |
render() { |
| 73 |
|
- this.shadowRoot.appendChild(this.searchInputTemplate.content.cloneNode(true)); |
|
111 |
+ this.shadowRoot.appendChild(this.template.content.cloneNode(true)); |
| 74 |
74 |
} |
| 75 |
75 |
} |
| 76 |
76 |
); |
| ... |
... |
@@ -89,21 +89,29 @@ |
| 89 |
89 |
return this.getAttribute('data-href'); |
| 90 |
90 |
} |
| 91 |
91 |
|
| 92 |
|
- get resultTemplate() { |
| 93 |
|
- return this.createTemplate(` |
|
130 |
+ get styles() { |
|
131 |
+ return ` |
|
132 |
+ a { |
|
133 |
+ color: var(--color-brand-primary); |
|
134 |
+ } |
|
135 |
+ `; |
|
136 |
+ } |
|
137 |
+ get html() { |
|
138 |
+ return ` |
| 94 |
94 |
<div> |
| 95 |
95 |
<a href=${this.hrefAttr}>${this.titleAttr}</a> |
| 96 |
96 |
<div> |
| 97 |
97 |
<slot></slot> |
| 98 |
98 |
</div> |
| 99 |
|
- </div> |
| 100 |
|
- `); |
|
144 |
+ </div> ` |
| 101 |
101 |
} |
|
146 |
+ |
| 102 |
102 |
connectedCallback() { |
| 103 |
103 |
this.attachShadow({ mode: 'open' }); |
| 104 |
|
- this.shadowRoot.appendChild(this.resultTemplate.content.cloneNode(true)); |
|
149 |
+ this.shadowRoot.appendChild(this.template.content.cloneNode(true)); |
| 105 |
105 |
} |
| 106 |
106 |
} |
| 107 |
107 |
); |
| 108 |
108 |
</script> |
|
154 |
+<clb-simplified-search></clb-simplified-search> |
| 109 |
109 |
{{/html}} |