Skip to content

Commit

Permalink
Always include all possible fields in the column choice menu (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonggrijp committed Nov 11, 2024
1 parent dedb056 commit 3675db7
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions frontend/vre/utils/tabulator-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import _ from 'lodash';
import {Model, Collection} from 'backbone';
import {MappedCollection} from './mapped.collection.js';
import {properties} from './record-ontology';
import {getStringLiteral} from './jsonld.model';

Expand Down Expand Up @@ -70,41 +72,48 @@ const defaultColumnFeatures = {

const columnProperties = {
'edpoprec:title': {
visible: true,
widthGrow: 5,
formatter: 'textarea',
},
'edpoprec:placeOfPublication': {
visible: true,
},
'edpoprec:placeOfPublication': {},
'edpoprec:dating': {
visible: true,
widthGrow: 0.5,
},
'edpoprec:publisherOrPrinter': {
visible: true,
},
'edpoprec:contributor': {
visible: true,
},
'edpoprec:activity': {
visible: true,
},
'edpoprec:publisherOrPrinter': {},
'edpoprec:contributor': {},
'edpoprec:activity': {},
};

function adjustDefinition(bareDefinition) {
const property = properties.get(bareDefinition.field);
const addedTitle = property ? {
const columnOrder = _.invert(_.keys(columnProperties));

const ColumnDefinition = Model.extend({
idAttribute: 'field',
});

function byPreference(columnDef) {
const definedOrder = columnOrder[columnDef.id];
return definedOrder != null ? definedOrder : columnOrder.length;
}

function property2definition(property) {
return _.assign({
title: getStringLiteral(property.get('skos:prefLabel')),
} : null;
const customProperties = columnProperties[bareDefinition.field];
return _.assign(
{},
bareDefinition,
defaultColumnFeatures,
addedTitle,
customProperties
);
field: property.id,
}, defaultColumnFeatures, columnProperties[property.id])
}

export const adjustDefinitions = _.partial(_.map, _, adjustDefinition);
const standardColumns = new MappedCollection(
properties,
property2definition,
{model: ColumnDefinition, comparator: byPreference},
);

export function adjustDefinitions(autodetected) {
const customizedColumns = new Collection(standardColumns.models);
_.each(autodetected, autoColumn => {
if (!(autoColumn.field in columnProperties)) return;
const customColumn = customizedColumns.get(autoColumn.field);
customColumn && customColumn.set('visible', true);
});
return customizedColumns.toJSON();
}

0 comments on commit 3675db7

Please sign in to comment.