diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0318f9a6edb2805a3a975b39b6253849cf78b5..fde6b8fb755fc8f8818bd1d7afd8474c18873ebf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added (for new features, dependecies etc.) +* `ext_trigger_crawler_form` module which generates a form for triggering the + crawler. See module docstring for more info. * Support for deeply nested selectors in SELECT queries. * edit_mode supports reference properties when inserting/updating properties (See [#83](https://gitlab.com/caosdb/caosdb-webui/-/issues/83) and diff --git a/build.properties.d/00_default.properties b/build.properties.d/00_default.properties index 6185725aefd266b45ef5024bd3e47a78801fef1f..da4c8d0035970069b6762206477ae3b250b521c7 100644 --- a/build.properties.d/00_default.properties +++ b/build.properties.d/00_default.properties @@ -43,6 +43,7 @@ ############################################################################## BUILD_MODULE_EXT_PREVIEW=ENABLED BUILD_MODULE_EXT_RESOLVE_REFERENCES=ENABLED +BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM=DISABLED ############################################################################## # Navbar properties @@ -76,4 +77,7 @@ BUILD_FOOTER_CUSTOM_ELEMENT_TWO= # BUILD_FOOTER_CUSTOM_ELEMENT_TWO=$(cat footer_element_2.html) BUILD_CUSTOM_IMPRINT='<p> Put an imprint note here </p>' - +############################################################################## +# ext_trigger_crawler_form properties +############################################################################## +BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX="Tools" diff --git a/src/core/js/ext_trigger_crawler_form.js b/src/core/js/ext_trigger_crawler_form.js new file mode 100644 index 0000000000000000000000000000000000000000..94ea6feb672cc3a2be8c87cb6bd6f5c8a5087d3f --- /dev/null +++ b/src/core/js/ext_trigger_crawler_form.js @@ -0,0 +1,132 @@ +/* + * ** header v3.0 + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2019 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2019 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * ** end header + */ + +'use strict'; + +/** + * @module ext_trigger_crawler_form + * @version 0.1 + * + * Adds a button to a configurable navbar toolbox which opens a form for + * triggering the crawler as a server-side scripting job. + * + * The form has two fields. The text field `Path` sets the directory tree which + * is searched by the crawler. The checkbox `Suppress Warnings` can be checked + * to suppress the crawlers warnings. + * + * The module has to be enabled via the + * `BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM=ENABLED` build variable. + * + * The toolbox where the button is added can be configured via the build + * variable `BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX`. The default is + * `Tools`. + */ +var ext_trigger_crawler_form = function () { + + var init = function (toolbox) { + const _toolbox = toolbox || "${BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX}"; + + const script = "crawl.py" + const button_name = "Trigger Crawler"; + const title = "The LinkAhead-Crawler will run over the filesystem and make necessary updates."; + + const crawler_form = make_scripting_caller_form( + script, button_name); + const modal = make_form_modal(crawler_form); + + + navbar.add_tool(button_name, _toolbox, { + title: title, + callback: () => { + $(modal).modal("toggle"); + } + }); + } + + /** + * Wrap the form into a Bootstrap modal. + */ + var make_form_modal = function (form) { + const title = "Trigger the Crawler"; + const modal = $(` + <div class="modal fade" tabindex="-1" role="dialog"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" + class="close" + data-dismiss="modal" + aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + <h4 class="modal-title">${title}</h4> + </div> + <div class="modal-body"> + </div> + </div> + </div>`); + modal.find(".modal-body").append(form); + return modal[0]; + } + + /** + * Create the trigger crawler form. + */ + var make_scripting_caller_form = function (script, button_name) { + const path_field = form_elements.make_text_input({ + name: "-p1", + value: "/", + label: "Path" + }); + const warning_checkbox = form_elements.make_checkbox_input({ + name: "-Osuppress", + label: "Suppress Warnings" + }); + $(warning_checkbox).find("input").attr("value", "TRUE"); + + const scripting_caller = $(` + <form method="POST" action="/scripting"> + <input type="hidden" name="call" value="${script}"/> + <input type="hidden" name="-p0" value=""/> + <div class="form-group"> + <input type="submit" + class="form-control btn btn-primary" value="${button_name}"/> + </div> + </form>`); + + scripting_caller.prepend(warning_checkbox).prepend(path_field); + + return scripting_caller[0]; + } + + return { + init: init, + }; + +}(); + +$(document).ready(function () { + if ("${BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM}" === "ENABLED") { + caosdb_modules.register(ext_trigger_crawler_form); + } +}); diff --git a/src/core/xsl/main.xsl b/src/core/xsl/main.xsl index f4a128f63f52488657b32e8ff03043c276d4aaa3..52e5b4249fa85479efc69bd7d8c63de80fbb2631 100644 --- a/src/core/xsl/main.xsl +++ b/src/core/xsl/main.xsl @@ -240,6 +240,11 @@ <xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_revisions.js')"/> </xsl:attribute> </xsl:element> + <xsl:element name="script"> + <xsl:attribute name="src"> + <xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_trigger_crawler_form.js')"/> + </xsl:attribute> + </xsl:element> <!--JS_EXTENSIONS--> </xsl:template> <xsl:template name="caosdb-data-container"> diff --git a/test/core/index.html b/test/core/index.html index 0d97a415334fd441319eec7e4db262c34d64ef07..ab65f0d9546c671ad55485a187154d7a165f3e5c 100644 --- a/test/core/index.html +++ b/test/core/index.html @@ -67,6 +67,7 @@ <script src="js/ext_bottom_line.js"></script> <script src="js/ext_revisions.js"></script> <script src="js/autocomplete.js"></script> + <script src="js/ext_trigger_crawler_form.js"></script> <!--EXTENSIONS--> <script src="js/modules/webcaosdb.js.js"></script> <script src="js/modules/caosdb.js.js"></script> @@ -85,5 +86,6 @@ <script src="js/modules/ext_bottom_line.js.js"></script> <script src="js/modules/ext_revisions.js.js"></script> <script src="js/modules/autocomplete.js.js"></script> + <script src="js/modules/ext_trigger_crawler_form.js.js"></script> </body> </html> diff --git a/test/core/js/modules/ext_trigger_crawler_form.js.js b/test/core/js/modules/ext_trigger_crawler_form.js.js new file mode 100644 index 0000000000000000000000000000000000000000..e2a4b0c8a494e43234547de4740ea62dde77beac --- /dev/null +++ b/test/core/js/modules/ext_trigger_crawler_form.js.js @@ -0,0 +1,55 @@ +/* + * ** header v3.0 + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + * ** end header + */ + +'use strict'; + +QUnit.module("ext_trigger_crawler_form", { + before: () => { + $(document.body).append('<div id="top-navbar"><ul class="caosdb-navbar"/></div>'); + }, + beforeEach: () => { + $(".caosdb-f-navbar-toolbox").remove(); + }, + after: () => { + $("#top-navbar").remove(); + }, +}); + +QUnit.test("test build variables and availability", function(assert) { + assert.ok(ext_trigger_crawler_form, "availble"); + assert.equal("${BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM}", "DISABLED", "BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM disabled by default."); + assert.equal("${BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX}", "Tools", "BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX defaults to Tools"); +}); + +QUnit.test("test init", function(assert) { + var tools = navbar.get_toolbox("Tools"); + + assert.equal($(tools).length, 1); + assert.equal($(tools).find("button").length, 0); + ext_trigger_crawler_form.init() + tools = navbar.get_toolbox("Tools"); + assert.equal($(tools).find("button").length, 1); + +}); + +