diff --git a/build.properties.d/00_default.properties b/build.properties.d/00_default.properties index a64d39fec41232a8fd889e4b61679b0ffb15ec9c..895820353eba3a8b680df238c2379e0c162f81f6 100644 --- a/build.properties.d/00_default.properties +++ b/build.properties.d/00_default.properties @@ -45,6 +45,7 @@ BUILD_MODULE_EXT_PREVIEW=ENABLED BUILD_MODULE_EXT_RESOLVE_REFERENCES=ENABLED BUILD_MODULE_EXT_SSS_MARKDOWN=DISABLED BUILD_MODULE_EXT_TRIGGER_CRAWLER_FORM=DISABLED +BUILD_MODULE_EXT_ENTITY_STATE=ENABLED ############################################################################## # Navbar properties diff --git a/src/core/js/ext_applicable.js b/src/core/js/ext_applicable.js index 8ff06bc0f162062ca512ba0f144e559a187ccaf6..55e3bc2ab60b9cd533d1d0a67b0d90a4937e7f74 100644 --- a/src/core/js/ext_applicable.js +++ b/src/core/js/ext_applicable.js @@ -233,11 +233,14 @@ var ext_applicable = function($, logger, is_in_view_port, load_config, getEntity * @return {Creator} */ const _make_fallback_creator = function(fallback) { - return { - id: "_generated_fallback_creator", - is_applicable: (entity) => true, // always applicable - create: typeof fallback === "function" ? fallback : (entity) => fallback, - }; + if (fallback) { + return { + id: "_generated_fallback_creator", + is_applicable: (entity) => true, // always applicable + create: typeof fallback === "function" ? fallback : (entity) => fallback, + }; + } + return undefined; } const _make_creator = function (c) { @@ -289,7 +292,8 @@ var ext_applicable = function($, logger, is_in_view_port, load_config, getEntity const _make_get_container_wrapper = function (get_container_cb, app_name) { const _wrapper = function (entity) { const container = get_container_cb(entity); - if(!$(container).data(app_name)) { + const app_done = $(container).data(app_name); + if(!app_done) { // mark container as used $(container).data(app_name, "done"); return container diff --git a/src/core/js/ext_entity_state.js b/src/core/js/ext_entity_state.js new file mode 100644 index 0000000000000000000000000000000000000000..fdfdaf5a2473ebb63e61c4430122e3c8d5611e67 --- /dev/null +++ b/src/core/js/ext_entity_state.js @@ -0,0 +1,98 @@ +/* + * ** 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'; + +/** + * Module for handling the entity state. + */ +var ext_entity_state = function($, logger, ext_applicable, getProperty) { + + const version = "0.1"; + + const _css_class_entity_state_container = "caosdb-f-entity-state-container"; + const _selector_entity_parent_element = ".caosdb-v-entity-header-buttons-list"; + + const getEntityState = function (entity) { + // TODO + const state = getProperty(entity, "State"); + return state; + } + + const _has_state = function (entity) { + const has_state = !!ext_entity_state.getEntityState(entity) + return has_state; + } + + const _create_state_info = function (entity) { + return ext_entity_state.getEntityState(entity); + } + + const _creators = [{ + id: "ext_entity_state", + is_applicable: _has_state, + create: _create_state_info, + }]; + + const add_container = function (entity) { + const container = $(`<span class="${_css_class_entity_state_container}"/>`); + $(entity).find(_selector_entity_parent_element).append(container); + return container[0]; + } + + const get_container = function (entity) { + const container = $(entity) + .find(`.${_css_class_entity_state_container}`)[0] || + add_container(entity); + return container; + } + + const default_config = { + version: "0.1", + creators: _creators, + fallback: undefined, + init_watcher: true, + delay: 500, + } + + const init = function (config) { + const _config = config || default_config; + ext_entity_state.app = ext_applicable.create_is_applicable_app( + "entity_state", _config, get_container); + } + + return { + version: version, + init: init, + app: undefined, + get_container: get_container, + getEntityState: getEntityState, + }; + +}($, log.getLogger("ext_entity_state"), ext_applicable, getProperty); + +$(document).ready(function () { + if("${BUILD_MODULE_EXT_ENTITY_STATE}" == "ENABLED") { + caosdb_modules.register(ext_entity_state); + } +}); diff --git a/src/core/js/ext_references.js b/src/core/js/ext_references.js index d9829cb9959c1249a4381bd45be9429f7dbef855..7aecb16a9c8158683f84e364dc1362103f296c45 100644 --- a/src/core/js/ext_references.js +++ b/src/core/js/ext_references.js @@ -24,12 +24,14 @@ /* - * Check if an element is out of the viewport + * Check if an element is out of the viewport. Based on * * (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com * * https://gomakethings.com/how-to-check-if-any-part-of-an-element-is-out-of-the-viewport-with-vanilla-js/ * + * Changed by Timm Fitschen 2020 + * * @param {Node} elem - The element to check * @return {Object} A set of booleans for each side of the element. */ @@ -38,18 +40,27 @@ var isOutOfViewport = function (elem) { // Get element's bounding var bounding = elem.getBoundingClientRect(); + const view = { + top: 0, + left: 0, + bottom: (window.innerHeight || document.documentElement.clientHeight), + right: (window.innerWidth || document.documentElement.clientWidth), + }; + // Check if it's out of the viewport on each side var out = {}; - out.top = bounding.top < 0; - out.left = bounding.left < 0; - out.bottom = bounding.bottom > (window.innerHeight || - document.documentElement.clientHeight); - out.right = bounding.right > - (window.innerWidth || document.documentElement.clientWidth); - out.any = - out.top || out.left || out.bottom || out.right; - out.all = out.top && - out.left && out.bottom && out.right; + + out.top = bounding.top < view.top || bounding.top > view.bottom ; + out.left = bounding.left < view.left || bounding.left > view.right; + out.bottom = bounding.bottom > view.bottom || bounding.bottom < view.top; + out.right = bounding.right > view.right || bounding.right < view.left; + // bottom is out, top is out and both are out on the same side. + out.vertically = !( + bounding.bottom > view.bottom + && bounding.top < view.top + ) && out.top && out.bottom; + out.any = out.top || out.left || out.bottom || out.right; + out.all = out.top && out.left && out.bottom && out.right; return out; }; @@ -241,9 +252,8 @@ var resolve_references = new function () { * */ this.is_in_viewport_vertically = function (elem) { - var out = - isOutOfViewport(elem); - return !(out.top || out.bottom); + var out = isOutOfViewport(elem); + return !out.vertically; } /** Check if an element is inside of the viewport on the horizontal axis. diff --git a/src/core/xsl/main.xsl b/src/core/xsl/main.xsl index 96ed02c906bc9f04949c44e219f0eedf477af4f2..10a4887aed065a5c8ffc74e463fc7660f81d743b 100644 --- a/src/core/xsl/main.xsl +++ b/src/core/xsl/main.xsl @@ -260,6 +260,11 @@ <xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_trigger_crawler_form.js')"/> </xsl:attribute> </xsl:element> + <xsl:element name="script"> + <xsl:attribute name="src"> + <xsl:value-of select="concat($basepath,'webinterface/${BUILD_NUMBER}/js/ext_entity_state.js')"/> + </xsl:attribute> + </xsl:element> <!--JS_EXTENSIONS--> </xsl:template> <xsl:template name="caosdb-data-container">