Skip to content

Commit

Permalink
Merge pull request #214 from UUDigitalHumanitieslab/feature/tabulator
Browse files Browse the repository at this point in the history
Use Tabulator library for list view
  • Loading branch information
tijmenbaarda authored Aug 29, 2024
2 parents 112b3e0 + 138fdf5 commit 541af8e
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 145 deletions.
5 changes: 3 additions & 2 deletions backend/catalogs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from rest_framework.exceptions import ParseError
from rest_framework.renderers import JSONRenderer

from triplestore.constants import EDPOPREC, AS
from .graphs import SearchGraphBuilder, get_catalogs_graph, get_reader_by_uriref


class SearchView(RDFView):
"""Search in a given external catalog according to a query."""
renderer_classes = (JsonLdRenderer,)
json_ld_context = {
"edpoprec": "https://dhstatic.hum.uu.nl/edpop-records/latest/",
"as": "https://www.w3.org/ns/activitystreams#",
"edpoprec": str(EDPOPREC),
"as": str(AS),
}

def get_graph(self, request: views.Request, **kwargs) -> Graph:
Expand Down
21 changes: 11 additions & 10 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile
# pip-compile requirements.in
#
appdirs==1.4.4
# via edpop-explorer
asgiref==3.8.1
# via django
attrs==23.2.0
attrs==24.2.0
# via cmd2
beautifulsoup4==4.12.3
# via -r requirements.in
Expand All @@ -22,14 +22,14 @@ defusedxml==0.7.1
# via sruthi
dj-rest-auth==6.0.0
# via -r requirements.in
django==4.2.14
django==4.2.15
# via
# -r requirements.in
# dj-rest-auth
# django-filter
# djangorestframework
# restframework-rdf
django-filter==24.2
django-filter==24.3
# via -r requirements.in
django-json-widget==2.0.1
# via -r requirements.in
Expand All @@ -38,15 +38,15 @@ djangorestframework==3.15.2
# -r requirements.in
# dj-rest-auth
# restframework-rdf
edpop-explorer==0.10.0
edpop-explorer==0.10.1
# via -r requirements.in
flatten-dict==0.4.2
# via sruthi
idna==3.7
# via requests
isodate==0.6.1
# via rdflib
lxml==5.2.2
lxml==5.3.0
# via -r requirements.in
psycopg==3.2.1
# via -r requirements.in
Expand All @@ -56,7 +56,7 @@ pyparsing==3.1.2
# via rdflib
pyperclip==1.9.0
# via cmd2
pyyaml==6.0.1
pyyaml==6.0.2
# via edpop-explorer
rdflib==7.0.0
# via
Expand All @@ -74,11 +74,11 @@ six==1.16.0
# via
# flatten-dict
# isodate
soupsieve==2.5
soupsieve==2.6
# via beautifulsoup4
sparqlwrapper==2.0.0
# via edpop-explorer
sqlparse==0.5.0
sqlparse==0.5.1
# via django
sruthi==2.0.0
# via
Expand All @@ -88,6 +88,7 @@ termcolor==2.4.0
# via edpop-explorer
typing-extensions==4.12.2
# via
# asgiref
# edpop-explorer
# psycopg
urllib3==2.2.2
Expand Down
2 changes: 1 addition & 1 deletion backend/triplestore/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

EDPOPCOL = _EDPOPCOL.EDPOPCOL

EDPOPREC = Namespace('https://dhstatic.hum.uu.nl/edpop-records/0.1.0-SNAPSHOT/')
EDPOPREC = Namespace('https://dhstatic.hum.uu.nl/edpop-records/0.1.0/')
'''EDPOP Record Ontology'''

AS =_AS.AS
Expand Down
2 changes: 2 additions & 0 deletions frontend/vre/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />
<link href="https://unpkg.com/[email protected]/dist/css/tabulator_bootstrap3.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
Expand Down Expand Up @@ -51,6 +52,7 @@
></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/backbone-min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/js/tabulator.min.js"></script>
<script src="/static/bundle.js"></script>
</body>
</html>
1 change: 0 additions & 1 deletion frontend/vre/record/record.detail.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export var RecordDetailView = CompositeView.extend({
},

renderContainer: function() {
console.log(this.model);
this.$el.html(this.template({
title: this.model.getMainDisplay(),
uri: this.model.id,
Expand Down
37 changes: 0 additions & 37 deletions frontend/vre/record/record.list.item.view.js

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/vre/record/record.list.item.view.mustache

This file was deleted.

21 changes: 3 additions & 18 deletions frontend/vre/record/record.list.managing.view.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { CompositeView } from 'backbone-fractal';
import { VRECollectionView } from '../collection/collection.view';
import { SelectAllView } from './select-all.view';
import { RecordListView } from './record.list.view';
import { GlobalVariables } from '../globals/variables';
import recordListManagingTemplate from './record.list.managing.view.mustache';
import {RecordListView} from "./record.list.view";

export var RecordListManagingView = CompositeView.extend({
tagName: 'form',
template: recordListManagingTemplate,

subviews: [
{view: 'vreCollectionsSelect', method: 'prepend'},
'selectAllView',
'recordListView',
],

Expand All @@ -29,8 +27,8 @@ export var RecordListManagingView = CompositeView.extend({
collection: GlobalVariables.myCollections
}).render();
this.recordListView = new RecordListView({collection: this.collection});
this.selectAllView = new SelectAllView();
this.render().bindSelectAll();
this.render();
this.recordListView.render();
},

renderContainer: function() {
Expand All @@ -41,17 +39,4 @@ export var RecordListManagingView = CompositeView.extend({
loadMore: function(event) {
this.collection.trigger('moreRequested', event);
},

bindSelectAll: function() {
var selectAllView = this.selectAllView;
var recordListView = this.recordListView;
selectAllView.on({
check: recordListView.checkAll,
uncheck: recordListView.uncheckAll,
}, recordListView);
recordListView.on( {
allChecked: selectAllView.check,
notAllChecked: selectAllView.uncheck,
}, selectAllView);
},
});
109 changes: 57 additions & 52 deletions frontend/vre/record/record.list.view.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,66 @@
import _ from 'lodash';
import { CollectionView } from 'backbone-fractal';
import { RecordListItemView } from './record.list.item.view';
import recordListTemplate from './record.list.view.mustache';
import Backbone from "backbone";
import {properties} from "../utils/record-ontology";
import {getStringLiteral} from "../utils/jsonld.model";
import {vreChannel} from "../radio";

export var RecordListView = CollectionView.extend({
tagName: 'table',
className: 'table table-striped',
template: recordListTemplate,
container: 'tbody',
export var RecordListView = Backbone.View.extend({
id: "record-list",
/**
* The Tabulator instance
* @type {Tabulator}
*/
table: null,

initialize: function(options) {
this.initItems().render().initCollectionEvents();
this.checkedCount = 0;
this.collection.on("sync", () => {
this.updateTable();
});
},

renderContainer: function() {
this.$el.html(this.template({}));
return this;
createTable: function(initialData) {
this.table = new Tabulator("#record-list", {
height: 650, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
data: initialData,
autoColumns: true,
autoColumnsDefinitions: (definitions) => {
for (let definition of definitions) {
if (definition.field === "model") {
definition.visible = false;
}
const property = properties.get(definition.field);
if (property) {
definition.title = getStringLiteral(property.get("skos:prefLabel"));
}
}
return definitions;
},
layout: "fitColumns",
rowHeader: {
width: 50,
formatter: "rowSelection",
titleFormatter: "rowSelection",
headerSort: false,
resizable: false,
frozen:true,
headerHozAlign:"center",
hozAlign:"center",
cellClick:function(e, cell){
cell.getRow().toggleSelect();
},
},
});
this.table.on("rowClick", (e, row) => {
const model = row.getData().model;
vreChannel.trigger('displayRecord', model);
});
},

makeItem: function(model, collection, options) {
return new RecordListItemView({model: model}).on({
check: this.checkOne,
uncheck: this.uncheckOne,
}, this);
},

currentSelection: function() {
return _.chain(this.items)
.filter({selected: true})
.map('model')
.invokeMap('toJSON')
.value();
},

checkOne: function() {
if (++this.checkedCount === this.collection.length) {
this.trigger('allChecked');
updateTable: function() {
const data = this.collection.toTabularData();
if (this.table === null) {
this.createTable(data);
} else {
this.table.replaceData(data);
}
return this;
},

uncheckOne: function() {
--this.checkedCount;
this.trigger('notAllChecked');
return this;
},

checkAll: function() {
this.checkedCount = this.collection.length;
_.invokeMap(this.items, 'check');
return this;
},

uncheckAll: function() {
this.checkedCount = 0;
_.invokeMap(this.items, 'uncheck');
return this;
},
});
});
1 change: 0 additions & 1 deletion frontend/vre/record/record.list.view.mustache

This file was deleted.

11 changes: 11 additions & 0 deletions frontend/vre/record/record.model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { APIModel } from '../utils/api.model';
import { Annotations } from '../annotation/annotation.model';
import {JsonLdModel, JsonLdWithOCCollection} from "../utils/jsonld.model";
import {FlatFields} from "../field/field.model";

export var Record = JsonLdModel.extend({
urlRoot: '/api/records',
Expand All @@ -24,6 +25,16 @@ export var Record = JsonLdModel.extend({
return `<${this.id}>`;
}
},
toTabularData: function() {
const fields = new FlatFields(undefined, {record: this});
const data = {
model: this,
};
fields.forEach((field) => {
data[field.id] = field.getMainDisplay();
});
return data;
},
getAnnotations: function() {
if (!this.annotations) {
this.annotations = new Annotations();
Expand Down
18 changes: 0 additions & 18 deletions frontend/vre/record/select-all.view.js

This file was deleted.

3 changes: 0 additions & 3 deletions frontend/vre/record/select-all.view.mustache

This file was deleted.

Loading

0 comments on commit 541af8e

Please sign in to comment.