Skip to content
Snippets Groups Projects
Commit e7566b6d authored by florian's avatar florian
Browse files

ENH: Hide hidden properties

parent 11061075
No related branches found
No related tags found
2 merge requests!89Release v0.10.0,!86F hide properties
Pipeline #31037 passed
......@@ -381,6 +381,10 @@ h5 {
margin-right: 0px;
}
.caosdb-v-hidden-property {
display: None;
}
.caosdb-v-edit-drag {
padding: 5px;
}
......
......@@ -25,7 +25,7 @@
* @requires log (singleton from loglevel library)
* @requires load_config (function from webcaosdb.js)
*/
var prop_display = new function ($, logger, load_config) {
var prop_display = new function ($, getEntityName, getPropertyElements, getPropertyName, getUserName, getUserRoles, logger, load_config, query) {
/**
* Return the property-display config file; `ext_prop_display.json` by
......@@ -47,10 +47,90 @@ var prop_display = new function ($, logger, load_config) {
return conf;
}
this.init = async function() {
this._get_entities_in_view = function () {
// Use all entities, both in entity panel and in preview.
return $(".caosdb-entity-panel,.caosdb-entity-preview")
}
this._hide_properties = function (entities, conf, typesWithChildren) {
const userName = getUserName();
const userRoles = getUserRoles();
for (let typeName of Object.keys(conf)) {
let typeConf = conf[typeName];
let allNames = typesWithChildren[typeName];
for (let ent of entities) {
let parents = getParents(ent).map(par => par.name);
// only hide something if there is a match in at least one parent type
if (parents.some(par => allNames.includes(par))) {
let properties = getPropertyElements(ent);
for (let prop of properties) {
if (this._hide_property(getPropertyName(prop), userName, userRoles, typeConf)) {
console.log(prop);
$(prop).toggleClass("caosdb-v-hidden-property");
}
else {
$(prop).toggleClass("caosdb-v-show-property");
}
}
}
}
}
}
this._hide_property = function (propname, userName, userRoles, conf) {
// is this property only shown for certain users/groups?
if ((conf.show != undefined) && conf.show.length > 0) {
for (let def of conf.show) {
if (propname.toLowerCase() == def.name.toLowerCase()) {
if (!(def.users.includes(userName)) && !(userRoles.some(role => def.roles.includes(role)))) {
return true
}
}
}
}
// is this property hidden for certain users/groups?
if ((conf.hide != undefined) && conf.hide.length > 0) {
for (let def of conf.hide) {
if (propname.toLowerCase() == def.name.toLowerCase()) {
console.log(propname);
console.log(`${userName} - ${def.users}`);
console.log(`${userRoles} - ${def.roles}`);
if (def.users.includes(userName) || userRoles.some(role => def.roles.includes(role))) {
return true
}
}
}
}
return false;
}
this._getRecordTypes = async function (conf) {
const parentTypes = Object.keys(conf);
var typesWithChildren = {};
for (let parentName of parentTypes) {
const children = await query(`FIND RECORDTYPE "${parentName}"`);
const names = children.map(ent => getEntityName(ent));
typesWithChildren[parentName] = names;
}
return typesWithChildren;
}
this.init = async function () {
console.log("initializing ext_prop_display.js");
const conf = await this.load_config();
const typesWithChildren = await this._getRecordTypes(conf);
var entities = this._get_entities_in_view();
this._hide_properties(entities, conf, typesWithChildren)
}
}($, log.getLogger("ext_prop_display"), load_config);
}($, getEntityName, getPropertyElements, getPropertyName, getUserName, getUserRoles, log.getLogger("ext_prop_display"), load_config, query);
$(document).ready(() => caosdb_modules.register(prop_display));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment