Skip to content
Snippets Groups Projects
Commit 2bd9f60b authored by Timm Fitschen's avatar Timm Fitschen Committed by Henrik tom Wörden
Browse files

ENH: trigger crawler form

parent 8313185f
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added (for new features, dependecies etc.) ### 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. * Support for deeply nested selectors in SELECT queries.
* edit_mode supports reference properties when inserting/updating properties * edit_mode supports reference properties when inserting/updating properties
(See [#83](https://gitlab.com/caosdb/caosdb-webui/-/issues/83) and (See [#83](https://gitlab.com/caosdb/caosdb-webui/-/issues/83) and
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
############################################################################## ##############################################################################
BUILD_MODULE_EXT_PREVIEW=ENABLED BUILD_MODULE_EXT_PREVIEW=ENABLED
BUILD_MODULE_EXT_RESOLVE_REFERENCES=ENABLED BUILD_MODULE_EXT_RESOLVE_REFERENCES=ENABLED
BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM=DISABLED
############################################################################## ##############################################################################
# Navbar properties # Navbar properties
...@@ -76,4 +77,7 @@ BUILD_FOOTER_CUSTOM_ELEMENT_TWO= ...@@ -76,4 +77,7 @@ BUILD_FOOTER_CUSTOM_ELEMENT_TWO=
# BUILD_FOOTER_CUSTOM_ELEMENT_TWO=$(cat footer_element_2.html) # BUILD_FOOTER_CUSTOM_ELEMENT_TWO=$(cat footer_element_2.html)
BUILD_CUSTOM_IMPRINT='<p> Put an imprint note here </p>' BUILD_CUSTOM_IMPRINT='<p> Put an imprint note here </p>'
##############################################################################
# ext_trigger_crawler_form properties
##############################################################################
BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM_TOOLBOX="Tools"
/*
* ** 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">&times;</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);
}
});
...@@ -240,6 +240,11 @@ ...@@ -240,6 +240,11 @@
<xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_revisions.js')"/> <xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_revisions.js')"/>
</xsl:attribute> </xsl:attribute>
</xsl:element> </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--> <!--JS_EXTENSIONS-->
</xsl:template> </xsl:template>
<xsl:template name="caosdb-data-container"> <xsl:template name="caosdb-data-container">
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
<script src="js/ext_bottom_line.js"></script> <script src="js/ext_bottom_line.js"></script>
<script src="js/ext_revisions.js"></script> <script src="js/ext_revisions.js"></script>
<script src="js/autocomplete.js"></script> <script src="js/autocomplete.js"></script>
<script src="js/ext_trigger_crawler_form.js"></script>
<!--EXTENSIONS--> <!--EXTENSIONS-->
<script src="js/modules/webcaosdb.js.js"></script> <script src="js/modules/webcaosdb.js.js"></script>
<script src="js/modules/caosdb.js.js"></script> <script src="js/modules/caosdb.js.js"></script>
...@@ -85,5 +86,6 @@ ...@@ -85,5 +86,6 @@
<script src="js/modules/ext_bottom_line.js.js"></script> <script src="js/modules/ext_bottom_line.js.js"></script>
<script src="js/modules/ext_revisions.js.js"></script> <script src="js/modules/ext_revisions.js.js"></script>
<script src="js/modules/autocomplete.js.js"></script> <script src="js/modules/autocomplete.js.js"></script>
<script src="js/modules/ext_trigger_crawler_form.js.js"></script>
</body> </body>
</html> </html>
/*
* ** 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);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment