From 905b6c9d5088a2113eaead55c040ea9bc5de944a Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Tue, 16 Jun 2020 17:43:39 +0200 Subject: [PATCH] Stop passing around a complete ontology everywhere (#289) 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. --- .../panel-annotation-edit-view-test.ts | 1 - .../annotation/panel-annotation-edit-view.ts | 13 +++++++---- frontend/src/aspects/readit.ts | 22 ++++++++----------- .../explorer-event-controller.ts | 2 -- .../src/panel-explorer/explorer-view-test.ts | 6 +---- frontend/src/panel-explorer/explorer-view.ts | 6 ----- 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/frontend/src/annotation/panel-annotation-edit-view-test.ts b/frontend/src/annotation/panel-annotation-edit-view-test.ts index d912ce4a..72d15d02 100644 --- a/frontend/src/annotation/panel-annotation-edit-view-test.ts +++ b/frontend/src/annotation/panel-annotation-edit-view-test.ts @@ -32,7 +32,6 @@ describe('AnnotationEditView', function() { range, positionDetails: this.positionDetails, source: new Node({'@id': 'x'}), - ontology: new Graph(), model: undefined, })).not.toThrow(); }); diff --git a/frontend/src/annotation/panel-annotation-edit-view.ts b/frontend/src/annotation/panel-annotation-edit-view.ts index b636b1f3..047ff95a 100644 --- a/frontend/src/annotation/panel-annotation-edit-view.ts +++ b/frontend/src/annotation/panel-annotation-edit-view.ts @@ -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'; @@ -22,6 +23,13 @@ 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(ontology, isRdfsClass); +} export interface ViewOptions extends BaseOpt { /** @@ -29,7 +37,6 @@ export interface ViewOptions extends BaseOpt { * can be undefined if range and positionDetails are set (i.e. in case of a new annotation) */ model: Node; - ontology: Graph; collection?: FlatCollection; /** @@ -50,7 +57,6 @@ export interface ViewOptions extends BaseOpt { export default class AnnotationEditView extends BaseAnnotationView { collection: FlatCollection; - ontology: Graph; source: Node; range: Range; positionDetails: AnnotationPositionDetails; @@ -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); @@ -135,7 +140,7 @@ export default class AnnotationEditView extends BaseAnnotationView { initClassPicker(): this { this.classPicker = new ClassPickerView({ - collection: new FilteredCollection(this.ontology, isRdfsClass), + collection: getOntologyClasses(), preselection: this.preselection }); diff --git a/frontend/src/aspects/readit.ts b/frontend/src/aspects/readit.ts index 4b1a20bb..035bc17f 100644 --- a/frontend/src/aspects/readit.ts +++ b/frontend/src/aspects/readit.ts @@ -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'; @@ -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'; @@ -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'; @@ -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(); } }); diff --git a/frontend/src/panel-explorer/explorer-event-controller.ts b/frontend/src/panel-explorer/explorer-event-controller.ts index 1a8fe650..35ecaf4b 100644 --- a/frontend/src/panel-explorer/explorer-event-controller.ts +++ b/frontend/src/panel-explorer/explorer-event-controller.ts @@ -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); @@ -251,7 +250,6 @@ export default class ExplorerEventController { range: range, positionDetails: positionDetails, source: source, - ontology: this.explorerView.ontology, model: undefined, collection: sourceView.collection, }); diff --git a/frontend/src/panel-explorer/explorer-view-test.ts b/frontend/src/panel-explorer/explorer-view-test.ts index db09d627..e33f0d1e 100644 --- a/frontend/src/panel-explorer/explorer-view-test.ts +++ b/frontend/src/panel-explorer/explorer-view-test.ts @@ -7,9 +7,6 @@ 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 () { @@ -17,8 +14,7 @@ describe('ExplorerView', function () { 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() { diff --git a/frontend/src/panel-explorer/explorer-view.ts b/frontend/src/panel-explorer/explorer-view.ts index b78673cd..c1c45739 100644 --- a/frontend/src/panel-explorer/explorer-view.ts +++ b/frontend/src/panel-explorer/explorer-view.ts @@ -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'; @@ -19,11 +18,9 @@ import fastTimeout from '../utilities/fastTimeout'; export interface ViewOptions extends BaseOpt { // TODO: do we need a PanelBaseView? first: View; - ontology: Graph; } export default class ExplorerView extends View { - ontology: Graph; stacks: PanelStackView[]; eventController: EventController; @@ -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 = {};