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.

Context Search - HBP Wiki

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


Wiki source code of Context Search

Version 26.63 by bougault on 2022/11/17 09:54

Hide last authors
bougault 1.1 1 {{html clean="false"}}
bougault 26.45 2 <script type="module">
3 import {LitElement, html} from 'https://cdn.jsdelivr.net/gh/lit/dist@2/core/lit-core.min.js';
bougault 26.46 4 class UnifiedSearch extends LitElement {
bougault 26.47 5 static properties = {
bougault 26.49 6 searchText: { type: String },
bougault 26.50 7 favoritesFilter: { type: Boolean },
8 administratorFilter: { type: Boolean },
9 editorFilter: { type: Boolean },
10 viewerFilter: { type: Boolean },
11 publicFilter: { type: Boolean },
12 privateFilter: { type: Boolean },
bougault 26.47 13 }
bougault 26.49 14 constructor() {
15 super();
16 this.searchText = "";
17 this.favoritesFilter = false;
bougault 26.63 18 this.administratorFilter = false;
bougault 26.49 19 this.editorFilter = false;
20 this.viewerFilter = false;
21 this.publicFilter = false;
22 this.privateFilter = false;
23 }
bougault 26.63 24 toggleBooleanFilter(filterName) {
bougault 26.60 25 this[filterName] = !this[filterName];
bougault 26.58 26 console.log(this.administratorFilter);
bougault 26.57 27 }
bougault 26.47 28 setSearchText(e) {
29 this.searchText = e.target.value;
30 }
31 handleSearch() {
bougault 26.63 32 // check if text changed
bougault 26.47 33 console.log(this.searchText);
34 }
bougault 26.46 35 render() {
bougault 26.49 36 return html`
37 <div>
38 <div>
39 <input @change="${this.setSearchText}" type="text" placeholder="Search..." />
40 <button @click="${this.handleSearch}">Search</button>
41 </div>
bougault 26.61 42 <div>
bougault 26.63 43 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('favoritesFilter')}" .checked="${this.favoritesFilter}"/> Favorites</label>
44 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('administratorFilter')}" .checked="${this.administratorFilter}"/> Administrator</label>
45 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('editorFilter')}" .checked="${this.editorFilter}"/> Editor</label>
46 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('viewerFilter')}" .checked="${this.viewerFilter}"/> Viewer</label>
47 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('publicFilter')}" .checked="${this.publicFilter}"/> Public</label>
48 <label><input type="checkbox" @change="${() => this.toggleBooleanFilter('privateFilter')}" .checked="${this.privateFilter}"/> Public</label>
bougault 26.61 49 </div>
bougault 26.49 50 </div>
51 `
bougault 26.46 52 }
53 }
54 customElements.define('clb-unified-search', UnifiedSearch);
bougault 26.45 55 </script>
bougault 1.1 56
bougault 26.46 57 <clb-unified-search></clb-unified-search>
bougault 26.62 58 <!--
bougault 1.1 59 <select id="context-search-type">
60 <option value="all">All</option>
61 <option value="collabs">Collabs</option>
62 <option value="current-collab">Current Collab</option>
63 </select>
bougault 26.37 64 <input type="text" id="context-search-text" />
65 <button id="context-search-button" class="btn btn-primary">Search</button>
bougault 26.36 66 <div class="form-group">
bougault 26.37 67 <label>
68 <input type="checkbox" data-role-filter="administrator"> Administrator
69 </label>
70 <label>
71 <input type="checkbox" data-role-filter="editor"> Editor
72 </label>
bougault 26.36 73 </div>
bougault 1.1 74
bougault 26.37 75
bougault 2.2 76 <pre id="context-search-response"></pre>
77 <script>
78 window.addEventListener('DOMContentLoaded', function() {
bougault 26.30 79 const filters = {
80 search: '',
81 offset: 0,
82 orderField: 'title',
83 order: 'asc',
84 favorite: false,
85 roles: [] // to be joined as administrator+editor+viewer
86 };
87
88 function addRole(role) {
89 if(filters.roles.indexOf(role) == -1) {
90 filters.roles.push(role);
91 }
92 }
93
94 function removeRole(role) {
bougault 26.39 95 filters.roles = filters.roles.filter(r => r !== role)
bougault 26.30 96 }
97
bougault 26.34 98 const filterInputs = document.querySelectorAll('input[data-role-filter]');
bougault 26.40 99
bougault 26.32 100 filterInputs.forEach(function(filterIpt) {
bougault 26.35 101 filterIpt.addEventListener('click', function() {
bougault 26.30 102 const role = this.getAttribute('data-role-filter');
103 if(this.checked) {
104 addRole(role);
105 } else {
106 removeRole(role);
107 }
bougault 26.42 108 runFilteredRequest();
bougault 26.30 109 })
110 });
111
bougault 26.42 112 function runFilteredRequest() {
bougault 26.43 113 const urlParams = new URLSearchParams();
bougault 26.44 114 const tmpFilters = filters;
115 tmpFilters.roles = tmpFilters.roles.join("+");
116 for(filter in tmpFilters) {
117 urlParams.set(filter, tmpFilters[filter]);
bougault 26.41 118 }
bougault 26.43 119 console.log(urlParams);
bougault 26.41 120 }
bougault 26.30 121 // https://wiki-dev.ebrains.eu/rest/v1/collabs?search=&offset=0&orderField=title&order=asc&favorite=false&roles=administrator
bougault 2.2 122 const contextSearchType = document.getElementById("context-search-type");
123 const contextSearchText = document.getElementById("context-search-text");
124 const contextSearchResponse = document.getElementById("context-search-response");
125 const contextSearchButton = document.getElementById("context-search-button");
126 contextSearchButton.addEventListener('click', function() {
127 const context = contextSearchType.options[contextSearchType.selectedIndex].value;
bougault 2.3 128 const term = contextSearchText.value;
129 switch(context) {
130 case 'collabs':
131 document.location.href = `/bin/view/Collabs/#search=${term}`;
132 break;
133 case 'current-collab':
bougault 19.1 134 handleXWikiSearch('bougaultx');
bougault 2.3 135 break
136 default:
bougault 26.40 137 handleXWikiSearch('')
bougault 2.3 138 }
139
bougault 2.2 140 });
bougault 26.12 141 function handleXWikiSearch(space, callback) {
bougault 26.2 142 require(['jquery'], function($) {
143 var solrServiceURL = new XWiki.Document('SuggestSolrService', 'XWiki').getURL('get');
144 const contextSearchButton = document.getElementById("context-search-button");
145 const xwikiSpace = space ? `.${space}` : '';
146 contextSearchButton.addEventListener('click', function() {
147 $.post(solrServiceURL, {
148 outputSyntax: 'plain',
149 media: 'json',
150 query: [
151 'q="__INPUT__"~100',
152 'fq=type:DOCUMENT',
153 `fq=space:Collabs${xwikiSpace}.*`
154 ].join('\n'),
155 input: $('#context-search-text').val()
156 }).then(res => {
bougault 26.12 157 if(callback) {
158 callback(res).then(results => {
159 contextSearchResponse.innerText = JSON.stringify(results, null, 2);
160 })
161 } else {
162 contextSearchResponse.innerText = JSON.stringify(res, null, 2);
163 }
bougault 26.2 164 });
165 });
bougault 23.1 166 });
bougault 26.2 167 }
bougault 26.11 168 function applyAdministratorFilter(results) {
bougault 26.12 169 return new Promise((resolve, reject) => {
bougault 26.22 170 //fetch("/rest/v1/collabs?roles=administrator")
171 fetch("/rest/v1/collabs?search=&offset=0&orderField=title&order=asc&favorite=false&roles=administrator")
bougault 26.12 172 .then(res => res.json())
bougault 26.14 173 .then(collabs => {
174 const spaces = collabs.map(collab => `Collabs.${collab.name}`);
bougault 26.25 175 const filtered = results.filter(result => spaces.some(space => result.space.startsWith(space)));
bougault 26.18 176 resolve(filtered);
bougault 26.12 177 })
178
179 })
bougault 26.2 180 }
181 });
bougault 2.2 182 </script>
bougault 26.62 183 -->
bougault 1.1 184 {{/html}}