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


CLB Search Component

Version 1.1 by bougault on 2023/01/13 12:05
Warning: For security reasons, the document is displayed in restricted mode as it is not the current version. There may be differences and errors due to this.

class ClbComponent extends HTMLElement {
    constructor() {
        super();
    }

    connectedCallback() {
        this.attachShadow({ mode: 'open'});
    }

    createTemplate(htmlString) {
        const template = document.createElement('template');
        template.innerHTML = htmlString;
        return template;
    }
}

customElements.define('clb-simplified-search',
    class extends ClbComponent {
        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=';
        constructor() {
            super();
            this.results = [];
        }

        connectedCallback() {
            this.attachShadow({ mode: 'open' });
            super.connectedCallback();
            this.render();
            this.searchButton.addEventListener('click', () => this.handleSearch());
        }

        handleSearch() {
            fetch(`${this.searchBaseUrl}${encodeURIComponent(this.searchInput.value)}`)
            
.then(res => res.json())
           .then(this.renderResults);
            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":["Failed to execute the [velocity] macro. Cause: [The execution of the [velocity] script macro is not allowed in [xwiki:Collabs.bougaultx.CLB Search Component.WebHome]. Check the rights of its last author or the parameters if it's rendered from another script.]. Click on this message for details.
\r\n\r\nFailed to execute the [velocity] macro. Cause: [The execution of the [velocity] script macro is not allowed in [xwiki:Collabs.bougaultx.CLB Search Component.WebHome]. Check the rights of its last author or the parameters if it's rendered from another script.]. Click on this message for details.
\r\n\r\n\r\n"],"doccontentraw_":"Failed to execute the [velocity] macro. Cause: [The execution of the [velocity] script macro is not allowed in [xwiki:Collabs.bougaultx.CLB Search Component.WebHome]. Check the rights of its last author or the parameters if it's rendered from another script.]. Click on this message for details.
\r\n\r\nFailed to execute the [velocity] macro. Cause: [The execution of the [velocity] script macro is not allowed in [xwiki:Collabs.bougaultx.CLB Search Component.WebHome]. Check the rights of its last author or the parameters if it's rendered from another script.]. Click on this message for details.
\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":["\n

\n\n

\n= My Collab's Extended Title =\n\nMy collab's subtitle\n

\n

\n\n\n

\n\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\n

\n\nThe [toc] macro is a standalone macro and it cannot be used inline. Click on this message for details.
\n
\n\n \n

\n

"],"doccontentraw_":"\n

\n\n

\n= My Collab's Extended Title =\n\nMy collab's subtitle\n

\n

\n\n\n

\n\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\n

\n\nThe [toc] macro is a standalone macro and it cannot be used inline. Click on this message for details.
\n
\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}];
            this.renderResults(res);
        }

        get searchInput() {
            return this.shadowRoot.querySelector('input[type="text"]');
        }

        get searchButton() {
            return this.shadowRoot.querySelector('button');
        }

        get searchInputTemplate() {
            return this.createTemplate('<div><input type="text"><button>Search</button><div id="results"></div></div>');
        }

        resultsContainer = () => {
            return this.shadowRoot.querySelector('#results');
        }

        renderResults(results) {
            const resultsContainer = this.shadowRoot.querySelector('#results');
            resultsContainer.replaceChildren();
            for(let i = 0, j = results.length; i < j; i++) {
                const { title_, spaces, doccontent_en } = results[i];
                const elt = document.createElement('clb-search-result');
                elt.setAttribute('data-title', title_);
                elt.setAttribute('data-href', spaces.join('/'));
                elt.innerHTML = doccontent_en;
                resultsContainer.appendChild(elt);
            }
        }

        render() {
            this.shadowRoot.appendChild(this.searchInputTemplate.content.cloneNode(true));
        }
    }
);

customElements.define('clb-search-result',
    class extends ClbComponent {
        constructor() {
            super();
        }

        get titleAttr() {
            return this.getAttribute('data-title');
        }

        get hrefAttr() {
            return this.getAttribute('data-href');
        }

        get resultTemplate() {
            return this.createTemplate(`
                <div>
                    <a href=${this.hrefAttr}>${this.titleAttr}</a>
                    <div>
                        <slot></slot>
                    </div>
                </div>
                `);
        }
        connectedCallback() {
            this.attachShadow({ mode: 'open' });
            this.shadowRoot.appendChild(this.resultTemplate.content.cloneNode(true));
        }
    }
);