Skip to content
Snippets Groups Projects
Verified Commit 494fd13c authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: ext_entity_state

parent dd86218d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
/*
* ** 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);
}
});
......@@ -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.
......
......@@ -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">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment