Skip to content

Commit

Permalink
Stop passing around a complete ontology everywhere (#289)
Browse files Browse the repository at this point in the history
Now that we have a self-updating annotation editing panel, we finally
don't need to do all of that anymore. This brings us a step closer
to #106 and #62.
  • Loading branch information
jgonggrijp committed Jun 16, 2020
1 parent e3b411c commit 905b6c9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
1 change: 0 additions & 1 deletion frontend/src/annotation/panel-annotation-edit-view-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('AnnotationEditView', function() {
range,
positionDetails: this.positionDetails,
source: new Node({'@id': 'x'}),
ontology: new Graph(),
model: undefined,
})).not.toThrow();
});
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/annotation/panel-annotation-edit-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { extend } from 'lodash';

import Model from '../core/model';
import { oa, rdf, skos } from '../jsonld/ns';
import ldChannel from '../jsonld/radio';
import Node from '../jsonld/node';
import Graph from '../jsonld/graph';

Expand All @@ -22,14 +23,20 @@ import FlatCollection from './flat-annotation-collection';

import annotationEditTemplate from './panel-annotation-edit-template';

/**
* Helper function in order to pass the right classes to the classPicker.
*/
function getOntologyClasses() {
const ontology = ldChannel.request('ontology:graph') || new Graph();
return new FilteredCollection<Node, Graph>(ontology, isRdfsClass);
}

export interface ViewOptions extends BaseOpt<Model> {
/**
* An instance of oa:Annotation that links to a oa:TextQuoteSelector,
* can be undefined if range and positionDetails are set (i.e. in case of a new annotation)
*/
model: Node;
ontology: Graph;
collection?: FlatCollection;

/**
Expand All @@ -50,7 +57,6 @@ export interface ViewOptions extends BaseOpt<Model> {

export default class AnnotationEditView extends BaseAnnotationView {
collection: FlatCollection;
ontology: Graph;
source: Node;
range: Range;
positionDetails: AnnotationPositionDetails;
Expand All @@ -70,7 +76,6 @@ export default class AnnotationEditView extends BaseAnnotationView {
}

initialize(options: ViewOptions): this {
this.ontology = options.ontology;
this.itemOptions = new ItemGraph();
this.itemPicker = new PickerView({collection: this.itemOptions});
this.itemPicker.on('change', this.selectItem, this);
Expand Down Expand Up @@ -135,7 +140,7 @@ export default class AnnotationEditView extends BaseAnnotationView {

initClassPicker(): this {
this.classPicker = new ClassPickerView({
collection: new FilteredCollection<Node, Graph>(this.ontology, isRdfsClass),
collection: getOntologyClasses(),
preselection: this.preselection
});

Expand Down
22 changes: 9 additions & 13 deletions frontend/src/aspects/readit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { history, View } from 'backbone';
import { parallel } from 'async';
import footerView from '../global/footer-view';
import menuView from '../global/menu-view';
import welcomeView from '../global/welcome-view';
Expand All @@ -11,7 +10,8 @@ import user from './../global/user';
import Graph from './../jsonld/graph';
import Node from './../jsonld/node';
import { JsonLdObject } from './../jsonld/json';
import { item, readit, rdf, vocab } from '../jsonld/ns';
import { item, readit, rdf, vocab, oa } from '../jsonld/ns';
import ldChannel from '../jsonld/radio';

import { getOntology, getSources } from './../utilities/utilities';

Expand All @@ -25,8 +25,6 @@ import uploadSourceForm from './../global/upload-source-form';
import registrationFormView from './../global/registration-view';
import confirmRegistrationView from './../global/confirm-registration-view';

import { oa } from './../jsonld/ns';

import mockOntology from './../mock-data/mock-ontology';
import mockItems from './../mock-data/mock-items';
import mockSources from './../mock-data/mock-sources';
Expand Down Expand Up @@ -122,31 +120,29 @@ function getViewportHeight(): number {
return Math.max(vh - 160, 555);
}

function initExplorer(first: SourceListView, ontology: Graph): ExplorerView {
explorerView = new ExplorerView({ first: first, ontology: ontology });
function initExplorer(first: SourceListView): ExplorerView {
explorerView = new ExplorerView({ first });
explorerView.setHeight(getViewportHeight());
explorerView.$el.appendTo('#main');
return explorerView;
}

function initSourceList() {
let ontology = ldChannel.request('ontology:graph');
let sources = new Graph();
let ontology = new Graph();
let sourceListView = new SourceListView({
collection: sources
});

let explorerView = initExplorer(sourceListView, ontology);

parallel([getOntology, getSources], function (error, results) {
let explorerView = initExplorer(sourceListView);

getSources(function (error, results) {
if (error) console.debug(error);
else {
ontology = results[0];
sources = results[1];
sources = results;
sourceListView.collection.reset(sources.models);
let ccView = new CategoryColorView({ collection: ontology});
ccView.render().$el.appendTo('body');
explorerView.ontology.reset(ontology.models);
explorerView.render();
}
});
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/panel-explorer/explorer-event-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export default class ExplorerEventController {

ldItemEditAnnotation(ldItemview: LdItemView, annotation: Node): this {
let annoEditView = new AnnotationEditView({
ontology: this.explorerView.ontology,
model: annotation,
});
this.explorerView.overlay(annoEditView, ldItemview);
Expand Down Expand Up @@ -251,7 +250,6 @@ export default class ExplorerEventController {
range: range,
positionDetails: positionDetails,
source: source,
ontology: this.explorerView.ontology,
model: undefined,
collection: sourceView.collection,
});
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/panel-explorer/explorer-view-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ import { enableI18n } from '../test-util';
import ExplorerView from './explorer-view';
import View from './../core/view';

import mockOntology from './../mock-data/mock-ontology';
import Graph from './../jsonld/graph';

import fastTimeout from '../utilities/fastTimeout';

describe('ExplorerView', function () {
beforeAll(enableI18n);

beforeEach(function () {
let firstPanel = new View();
let ontology = new Graph(mockOntology);
this.view = new ExplorerView({ first: firstPanel, ontology: ontology });
this.view = new ExplorerView({ first: firstPanel });
});

afterEach(function() {
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/panel-explorer/explorer-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import Model from '../core/model';
import View from '../core/view';

import Graph from '../jsonld/graph';
import PanelStackView from './explorer-panelstack-view';
import EventController from './explorer-event-controller';
import { animatedScroll, ScrollType } from './../utilities/scrolling-utilities';
Expand All @@ -19,11 +18,9 @@ import fastTimeout from '../utilities/fastTimeout';
export interface ViewOptions extends BaseOpt<Model> {
// TODO: do we need a PanelBaseView?
first: View;
ontology: Graph;
}

export default class ExplorerView extends View {
ontology: Graph;
stacks: PanelStackView[];

eventController: EventController;
Expand All @@ -42,9 +39,6 @@ export default class ExplorerView extends View {

constructor(options?: ViewOptions) {
super(options);
if (!options.ontology) throw new TypeError('ontology cannot be null or undefined');

this.ontology = options.ontology;
this.stacks = [];
this.eventController = new EventController(this);
this.rltPanelStack = {};
Expand Down

0 comments on commit 905b6c9

Please sign in to comment.