Skip to content

Commit

Permalink
More comments and logging
Browse files Browse the repository at this point in the history
More logging to monitor behaviour in practice (easier than trying to work out what's going on from the code!) Added comments for future reference.
  • Loading branch information
brianritchie1312 committed Apr 23, 2019
1 parent e25c1ff commit 4801200
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions yo/app/scripts/controllers/meta-panel.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,40 @@
};

console.log("MetaPanel: entity type: " + entity.type);

// Initialise the query for the metatab fields
var queryBuilder = facility.icat().queryBuilder(entity.type).where(entity.type + ".id = " + entity.id);
var entityType = entity.type;
_.each(config, function(metaTab){
_.each(metaTab.items, function(item){
var field = item.field;
if(!field) return;
var matches;
// Test for compound field expressions, e.g. "investigationUser.role"
if(matches = field.replace(/\|.+$/, '').match(/^([^\[\]]+).*?\.([^\.\[\]]+)$/)){
// For a compound expression, we need to extract the corresponding entity type (e.g. "investigationUser" maps to "user")
var variableName = matches[1];
entityType = icatSchema.variableEntityTypes[variableName];
console.log("MetaPanel: var: " + variableName + "; type: " + entityType);
if(!entityType){
console.error("Unknown variableName: " + variableName, item)
}
// Add this entity type to the includes list
queryBuilder.include(entityType);
// (Re)set the field to the second value of the compound expression (e.g. "role")
field = matches[2];
} else {
// Fixes issue #407 : ensure translation label for unmatched fields is set to the current entity,
// rather than possibly inherited from the previous metaTab item.
entityType = entity.type;
}

// Size values are special - calculated lazily on request
if(field == 'size'){
item.template = '<span><span ng-if="item.entity.isGettingSize && $root.requestCounter != 0" class="loading collapsed">&nbsp;</span>{{item.entity.size|bytes}}<button class="btn btn-default btn-xs" ng-click="meta.getSize(item.entity)" ng-if="!item.entity.isGettingSize && item.entity.size === undefined">Calculate</button></span>';
}

// If the config doesn't explicitly define the label, calculate its translation string from the type and field
if(!item.label && item.label !== ''){
var entityTypeNamespace = helpers.constantify(entityType);
var fieldNamespace = helpers.constantify(field);
Expand Down Expand Up @@ -123,14 +131,18 @@
_.each(tabConfig.items, function(itemConfig){
var find = entity.entityType;
var field = itemConfig.field;
console.log("MP 1: find=" + find + ", field=" + field);
var matches;
if(matches = itemConfig.field.replace(/\|.+$/, '').match(/^(.*)?\.([^\.\[\]]+)$/)){
find = matches[1];
field = matches[2]
console.log("MP 2: find=" + find + ", field=" + field);
}
if(!find.match(/\]$/)) find = find + '[]';
console.log("MP 3: find=" + find);
_.each(entity.find(find), function(entity){
var value = entity.find(field)[0];
console.log("MP 4: value=" + value);
if(value !== undefined || field == 'size'){
tab.items.push({
label: itemConfig.label ? $translate.instant(itemConfig.label) : null,
Expand Down

0 comments on commit 4801200

Please sign in to comment.