Skip to content
Snippets Groups Projects

ENH: Allow sorting of properties

Merged Florian Spreckelsen requested to merge f-sort-properties into dev
All threads resolved!
Files
4
@@ -51,7 +51,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -51,7 +51,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
return $(".caosdb-entity-panel,.caosdb-entity-preview");
return $(".caosdb-entity-panel,.caosdb-entity-preview");
}
}
this.unhideProperties = function (entities, conf, allTypes, userName, userRoles) {
this.displayProperties = function (entities, conf, allTypes, userName, userRoles) {
for (let ent of entities) {
for (let ent of entities) {
let parents = getParents(ent).map(par => par.name);
let parents = getParents(ent).map(par => par.name);
@@ -66,9 +66,12 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -66,9 +66,12 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
for (let typeName of Object.keys(conf)) {
for (let typeName of Object.keys(conf)) {
let typeConf = conf[typeName];
let typeConf = conf[typeName];
let allNames = allTypes.typesWithChildren[typeName];
let allNames = allTypes.typesWithChildren[typeName];
// only hide something if there is a match in at least one parent type
// only change the display something if there is a match in
 
// at least one parent type
if (parents.some(par => allNames.includes(par)) ||
if (parents.some(par => allNames.includes(par)) ||
(getEntityRole(ent) == "RecordType" && allNames.includes(getEntityName(ent)))) {
(getEntityRole(ent) == "RecordType" && allNames.includes(getEntityName(ent)))) {
 
// first sort the properties
 
this._sortProperties(ent, properties, typeConf);
properties.forEach((prop, index) => {
properties.forEach((prop, index) => {
if (this._hide_property(getPropertyName(prop), userName, userRoles, typeConf)) {
if (this._hide_property(getPropertyName(prop), userName, userRoles, typeConf)) {
// Should be hidden by default but better safe than sorry
// Should be hidden by default but better safe than sorry
@@ -87,6 +90,31 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -87,6 +90,31 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
}
}
}
}
 
this._sortProperties = function (entity, properties, conf) {
 
if (conf.order == undefined || conf.order.length == 0) {
 
return;
 
}
 
properties.sort(function (a, b) {
 
let confIndexA = conf.order.indexOf(getPropertyName(a));
 
let confIndexB = conf.order.indexOf(getPropertyName(b));
 
if (confIndexA < 0 && confIndexB < 0) {
 
// both are not part of order list
 
return 0;
 
}
 
if (confIndexA < 0) {
 
// only b is part of order list , so it is placed before a
 
return 1;
 
}
 
if (confIndexB < 0) {
 
// only a is part of order list, so it is placed before b
 
return -1;
 
}
 
// From here, we can assume that both are in the order list:
 
return confIndexA - confIndexB;
 
});
 
$(entity).find(".caosdb-properties").append(properties);
 
}
 
this._hide_property = function (propname, userName, userRoles, conf) {
this._hide_property = function (propname, userName, userRoles, conf) {
// is this property only shown for certain users/groups?
// is this property only shown for certain users/groups?
@@ -154,7 +182,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -154,7 +182,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
return result;
return result;
}
}
this._unhidePropertiesWrapper = function (original, conf, allTypes) {
this._displayPropertiesWrapper = function (original, conf, allTypes) {
// Same as above, but for when there actually may be something to hide
// Same as above, but for when there actually may be something to hide
// (i.e., build variable is set and config is non-empty).
// (i.e., build variable is set and config is non-empty).
const result = function (entitiy) {
const result = function (entitiy) {
@@ -165,7 +193,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -165,7 +193,7 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
var entities = prop_display.getEntitiesInView();
var entities = prop_display.getEntitiesInView();
const userName = getUserName();
const userName = getUserName();
const userRoles = getUserRoles();
const userRoles = getUserRoles();
prop_display.unhideProperties(entities, conf, allTypes, userName, userRoles);
prop_display.displayProperties(entities, conf, allTypes, userName, userRoles);
return original_return;
return original_return;
}
}
@@ -179,11 +207,11 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
@@ -179,11 +207,11 @@ var prop_display = new function ($, edit_mode, getEntityName, getEntityRole, get
var entities = this.getEntitiesInView();
var entities = this.getEntitiesInView();
const userName = getUserName();
const userName = getUserName();
const userRoles = getUserRoles();
const userRoles = getUserRoles();
this.unhideProperties(entities, conf, allTypes, userName, userRoles);
this.displayProperties(entities, conf, allTypes, userName, userRoles);
// If we are in the edit mode, (un)hide properties after ending
// If we are in the edit mode, (un)hide properties after ending
// the editing of an entity
// the editing of an entity
document.body.addEventListener(edit_mode.start_edit.type, (e) => {
document.body.addEventListener(edit_mode.start_edit.type, (e) => {
edit_mode.app.onAfterShowResults = this._unhidePropertiesWrapper(edit_mode.app.onAfterShowResults, conf, allTypes);
edit_mode.app.onAfterShowResults = this._displayPropertiesWrapper(edit_mode.app.onAfterShowResults, conf, allTypes);
}, true);
}, true);
} else {
} else {
Loading