Skip to content

Commit

Permalink
Reintroduce source type in source metadata view, reformat (#37 #517)
Browse files Browse the repository at this point in the history
Most likely, the source type was originally in a dedicated predicate
in the sourceOntology graph. At some point, it moved to the rdfs:type,
which requires custom logic to unpack the value.
  • Loading branch information
jgonggrijp committed Mar 22, 2023
1 parent ab59b9a commit 3fa1964
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions frontend/src/source-metadata/source-metadata-view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extend } from 'lodash';
import { find, extend } from 'lodash';
import { ViewOptions as BaseOpt } from 'backbone';
import * as i18next from 'i18next';

Expand All @@ -13,6 +13,8 @@ import DateField from "./date-field-view";

import sourceMetadataTemplate from './source-metadata-template';

const sourceTypePrefix = sourceNS('TF');
const isSourceType = t => t.startsWith(sourceTypePrefix);

const externalAttributes = [
'language',
Expand Down Expand Up @@ -143,25 +145,26 @@ export default class SourceMetadataView extends CompositeView {
renderValues(): this {
if (!this.model) return this;
for (let attribute in this.model.attributes) {
const values = this.model.get(attribute);
if (!values.length) continue;
if (attribute.startsWith(sourceOntologyPrefix)) {
const attributeLabel = getLabelFromId(attribute) as string;
const queryString = `[name='` + `${attributeLabel}` + `']`;
const element = this.$(queryString);
if (element.length) {
let value = this.model.get(attribute)[0];
if (externalAttributes.includes(attributeLabel)) {
const nodeFromUri = ldChannel.request(
"obtain",
value.id
);
value =
typeof nodeFromUri === "string"
? nodeFromUri
: getLabel(nodeFromUri);
}
element.val(value);
}
let value = values[0];
} else if (attribute === '@type') {
const attributeLabel = 'sourceType';
let value = find(values, isSourceType);
if (!value) continue;
} else continue;
const queryString = `[name="${attributeLabel}"]`;
const element = this.$(queryString);
if (!element.length) continue;
if (externalAttributes.includes(attributeLabel)) {
const nodeFromUri = ldChannel.request("obtain", value.id);
value = typeof nodeFromUri === "string"
? nodeFromUri
: getLabel(nodeFromUri);
}
element.val(value);
}
return this;
}
Expand Down

0 comments on commit 3fa1964

Please sign in to comment.