Skip to content

Commit 0ffccef

Browse files
committed
Merge branch 'release/1.0.1'
2 parents 0f00a70 + 8f4da4d commit 0ffccef

File tree

8 files changed

+107
-38
lines changed

8 files changed

+107
-38
lines changed

app.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ function getLocalObjectByTitle (title) {
7272
}
7373

7474

75+
function getLocalObjectByAlias (alias) {
76+
return asArray(data_objects[config.a.JSONContainer]).find(function (e) {
77+
return asArray(e[config.v.aliasElement]).includes(alias);
78+
});
79+
}
80+
81+
7582
// get the value using the path_key from config template
7683
function deepFind (obj, path_key) {
7784
// Dynamic attributes
@@ -137,9 +144,17 @@ function replaceLocalIDInFrontend(old_id, new_id) {
137144
}
138145

139146

147+
function dataToString (data) {
148+
if (Array.isArray(data)) {
149+
data = data.join(', ');
150+
}
151+
return data;
152+
}
153+
154+
140155
function createNewHTMLObject(data){
141156
if(config.v.descriptionElement !== undefined && data[config.v.descriptionElement] != null){
142-
description_html = '<p class="mb-1">'+ data[config.v.descriptionElement] + '</p>';
157+
description_html = '<p class="mb-1">' + dataToString(data[config.v.descriptionElement]) + '</p>';
143158
} else {
144159
description_html = '<p class="mb-1"></p>'
145160
}
@@ -662,7 +677,6 @@ function changeStatus (trigger_element, element_id, current_status, new_status){
662677
function prepareValueMapping (mapping_config, mapping_value) {
663678
var ret = mapping_value;
664679
if (mapping_config.multiple){
665-
// is expectes that in mapping_value multiple values include
666680
if (typeof mapping_value === 'string') {
667681
var value_arr = mapping_value.split('\n');
668682
if (value_arr.length > 1) {
@@ -761,7 +775,7 @@ function editObject(id) {
761775
/* 2. update frontend
762776
Update title and description of list item */
763777
$('#' + id + ' h5').text(local_object[config.v.titleElement]);
764-
$('#' + id + ' p').text(local_object[config.v.descriptionElement]);
778+
$('#' + id + ' p').text(dataToString(local_object[config.v.descriptionElement]));
765779
// Close modal,
766780
$('#object-modal').modal('hide');
767781
}

basic-backend-api.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var plugin_xml_datasets = $('<div id="xml-datasets-dropdown"></div>')
3535

3636

3737
// Add plugin section
38-
var basicPluginXMLStorage = new BasicAppPlugin('app-plugin-xml', 'eXist Storage Configuration', 'fas fa-database', '#app-content-plugins-configuration');
38+
var basicPluginXMLStorage = new BasicAppPlugin('app-plugin-xml', 'eXist Storage Configuration', 'fas fa-database', '#app-content-plugins-configuration', 'NO');
3939
basicPluginXMLStorage.render(plugin_xml_datasets);
4040

4141

@@ -225,22 +225,24 @@ function APIDatasets () {
225225
cds = sessionStorage.getItem(context);
226226
query_dataset = {'dataset': cds};
227227
}
228-
// Load objects from cds in object cache
229-
$.getJSON(config.app.config.baseURL + config.app.config.api[context].RESTAPI, query_dataset).done(function (result) {
230-
var cnt = 0;
231-
if (result) {
232-
cnt = 1;
233-
if (Array.isArray(result[config.a.JSONContainer])) {
234-
cnt = result[config.a.JSONContainer].length;
228+
if (cds) {
229+
// Load objects from cds in object cache
230+
$.getJSON(config.app.config.baseURL + config.app.config.api[context].RESTAPI, query_dataset).done(function (result) {
231+
var cnt = 0;
232+
if (result) {
233+
cnt = 1;
234+
if (Array.isArray(result[config.a.JSONContainer])) {
235+
cnt = result[config.a.JSONContainer].length;
236+
}
237+
data_objects = result;
235238
}
236-
data_objects = result;
237-
}
238-
console.log('REST-API: ' + cnt + ' object(s) loaded.');
239-
// Create result list representation
240-
asArray(data_objects[config.a.JSONContainer]).reverse().forEach(function (obj) {createNewHTMLObject(obj)});
241-
// Set current dataset
242-
$('#xml-dataset-current').html(cds);
243-
// dataset loaded
244-
$('body').trigger('datasetLoaded');
245-
});
239+
console.log('REST-API: ' + cnt + ' object(s) loaded.');
240+
// Create result list representation
241+
asArray(data_objects[config.a.JSONContainer]).reverse().forEach(function (obj) {createNewHTMLObject(obj)});
242+
// Set current dataset
243+
$('#xml-dataset-current').html(cds);
244+
// dataset loaded
245+
$('body').trigger('datasetLoaded');
246+
});
247+
}
246248
}

config.tpl.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var config = {
22
"app": {
3-
"version": "1.0.1-dev",
3+
"version": "1.0.1",
44
"config": {
55
"use_corsanywhere": false,
66
"footer": {
@@ -36,23 +36,26 @@ var config = {
3636
"statusElement": "status",
3737
"identifierElement": "ref",
3838
"identifierAbbreviation": "DNB",
39-
"identifierBaseURL": "http://d-nb.info/gnd/"
39+
"identifierBaseURL": "http://d-nb.info/gnd/",
40+
"aliasElement": "alias"
4041
},
4142
"places": {
4243
"titleElement": "name",
4344
"descriptionElement": "description",
4445
"statusElement": "status",
4546
"identifierElement": "ref",
4647
"identifierAbbreviation": "GEO",
47-
"identifierBaseURL": "http://www.geonames.org/"
48+
"identifierBaseURL": "http://www.geonames.org/",
49+
"aliasElement": "alias"
4850
},
4951
"organisations":{
5052
"titleElement": "name",
5153
"descriptionElement": "description",
5254
"statusElement": "status",
5355
"identifierElement": "ref",
5456
"identifierAbbreviation": "DNB",
55-
"identifierBaseURL": "http://d-nb.info/gnd/"
57+
"identifierBaseURL": "http://d-nb.info/gnd/",
58+
"aliasElement": "alias"
5659
}
5760

5861
},
@@ -124,7 +127,9 @@ var config = {
124127
"localJSONPath": "name"
125128
},{
126129
"displayName": "Namensvariante",
127-
"JSONPath": "alternateNames.name"
130+
"JSONPath": "alternateNames.name",
131+
"localJSONPath": "alias",
132+
"multiple": true
128133
},{
129134
"displayName": "Breitengrad",
130135
"JSONPath": "lat"

local-storage-api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var plugin_ls_dataset_info = $('<div id="ls-dataset-info"></div>')
2525

2626

2727
// Add plugin section
28-
var basicPluginLocalStorage = new BasicAppPlugin('app-plugin-ls', 'Local Storage Configuration', 'fas fa-database', '#app-content-plugins-configuration');
28+
var basicPluginLocalStorage = new BasicAppPlugin('app-plugin-ls', 'Local Storage Configuration', 'fas fa-database', '#app-content-plugins-configuration', 'NO');
2929
basicPluginLocalStorage.render([plugin_ls_datasets, plugin_ls_dataset_info, plugin_ls_dataset_name]);
3030

3131

@@ -171,7 +171,6 @@ LocalStorageAdapter.prototype.load = function () {
171171
console.log('Local Storage API: ' + objects_array.length + ' object(s) loaded (context: ' + ctx + ', dataset: ' + ds + ')');
172172
// Update frontend info
173173
updateFrontendDatasetInformation(this.last_updated, objects_array.length);
174-
$('body').trigger('datasetLoaded');
175174
} else {
176175
console.log('Local Storage API (ERROR): Context or dataset is null. Nothing loaded.');
177176
}
@@ -203,6 +202,7 @@ LocalStorageAdapter.prototype.setDataset = function (ds) {
203202
// Save current dataset name
204203
localStorage.setItem(this.ls_key_last, ds);
205204
console.log('Local Storage API: Current dataset: ' + ds);
205+
$('body').trigger('datasetLoaded');
206206
return this;
207207
}
208208

plugin-actions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
function BasicAppPlugin (id, title, icon_classes, container_selector) {
1+
function BasicAppPlugin (id, title, icon_classes, container_selector, dataset_dependency) {
22
this.id = id;
33
this.title = title;
44
this.icon_classes = icon_classes;
55
this.DOMContainer = $(container_selector);
6+
this.dataset_dependency = dataset_dependency || 'YES';
67
}
78

89

@@ -14,6 +15,10 @@ BasicAppPlugin.prototype.renderPluginBase = function () {
1415
.append('<h6 class="text-light app-plugin-title"><i class="' + this.icon_classes + '"></i> ' + this.title + '</h6>')
1516
.append('<div class="app-plugin-content"></div>')
1617
.appendTo(this.DOMContainer);
18+
// add class to hide an action section
19+
if (this.dataset_dependency == 'YES') {
20+
this.plugin.addClass('plugin-hidden');
21+
}
1722
return this;
1823
}
1924

@@ -38,6 +43,11 @@ BasicAppPlugin.prototype.render = function (content) {
3843
return this;
3944
}
4045

46+
// if dataset are loaded remove class to show the sections
47+
$('body').on('datasetLoaded', function (e) {
48+
$('.plugin-hidden').removeClass('plugin-hidden').show();
49+
})
50+
4151

4252
function ActionButtonPlugin (id, title, icon_classes, container_selector) {
4353
BasicAppPlugin.call(this, id, title, icon_classes, container_selector)

plugin-csv-imexport.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ function CSVImportExportPlugin() {
3434
</button>\
3535
</div>\
3636
<div class="modal-body">\
37-
<div class="form-group">\
38-
<label for="uploadFileCSV">CSV-file to load data from</label>\
39-
<input type="file" class="form-control-file" id="uploadFileCSV">\
37+
<div class="custom-file mb-2">\
38+
<label for="uploadFileCSV" class="custom-file-label" id="uploadFileCSVLabel">CSV-file to load data from</label>\
39+
<input type="file" class="custom-file-input" id="uploadFileCSV">\
4040
</div>\
4141
<form id="import-csvdata-form"></form>\
42+
</div>\
43+
<div class="modal-footer">\
4244
<button type="button" class="btn btn-primary disabled" id="btn-import-from-csv">Import <span class="badge badge-light found-csv-objects">0</span> objects</button>\
4345
<button type="button" class="btn btn-primary disabled" id="btn-add-from-csv">Add <span class="badge badge-light found-csv-objects">0</span> objects</button>\
4446
</div>\
@@ -86,6 +88,7 @@ function CSVImportExportPlugin() {
8688
}
8789
});
8890
$('#modals').on('change', '#uploadFileCSV', function (e){
91+
$('#uploadFileCSVLabel').html(this.files[0].name);
8992
plugin.getObjectsFromCSV();
9093
});
9194
$('#modals').on('change', '#mergeFileCSV', function (e){
@@ -173,14 +176,36 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
173176
var id = letter[column + 'ID'];
174177
var entity = {};
175178
// Name and ID are given. Check for duplicate ID
176-
// TODO: if ID already imported and name differs add name as alias
177179
if (name && id && !found_ids.includes(id)) {
178180
entity[config.v.titleElement] = name;
179181
entity[config.v.identifierElement] = id;
180182
importable_entities.push(entity);
181183
unique_names.push(name);
182184
found_ids.push(id);
183185
}
186+
// If ID already imported and name differs add name as alias
187+
else if (name && id && found_ids.includes(id) && !unique_names.includes(name)) {
188+
if (config.v.aliasElement != undefined) {
189+
// Update importable entity with id and add an alias, if not already done
190+
var already_imported_entity = importable_entities.find(function (e) {
191+
return e[config.v.identifierElement] == id;
192+
});
193+
if (already_imported_entity[config.v.aliasElement] == undefined) {
194+
// there is no alias yet
195+
already_imported_entity[config.v.aliasElement] = name;
196+
} else {
197+
// Alias(es) aready set.
198+
var old_aliases = asArray(already_imported_entity[config.v.aliasElement]);
199+
// Add if not already done.
200+
if (!old_aliases.includes(name)) {
201+
old_aliases.push(name);
202+
already_imported_entity[config.v.aliasElement] = old_aliases;
203+
}
204+
}
205+
} else {
206+
// If aliases aren't configured, we can't handle this case
207+
}
208+
}
184209
// Only the name is given. Check for duplicate name.
185210
else if (name && !id && !unique_names.includes(name)) {
186211
entity[config.v.titleElement] = name;
@@ -195,12 +220,12 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
195220
count_span.html(importable_entities.length);
196221
if (importable_entities.length > 0) {
197222
// Add importable entities to import form with filter buttons
198-
$('#csv-file-upload-modal .form-group button[type="button"]').remove();
199-
var chk_button_filter = '<div class="btn-group mt-2" id="check-buttons" role="group">\
223+
var chk_button_filter = '<div class="btn-group form-group" id="check-buttons" role="group">\
200224
<button class="btn btn-sm btn-secondary" id="import-csv-btn-chk-all" type="button">Select All</button>\
201225
<button class="btn btn-sm btn-secondary" id="import-csv-btn-chk-none" type="button">Deselect All</button>\
202226
</div>';
203-
$(chk_button_filter).appendTo('#csv-file-upload-modal .form-group');
227+
$(chk_button_filter).appendTo(entities_form);
228+
var entities_btn_group = $('<div class="form-group"></div>').appendTo(entities_form);
204229
importable_entities.forEach(function (e, i) {
205230
var ref_html = '';
206231
if (e[config.v.identifierElement] && e[config.v.identifierElement].startsWith(config.v.identifierBaseURL)) {
@@ -212,7 +237,7 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
212237
' + e[config.v.titleElement] + ref_html +'\
213238
</label>\
214239
</div>';
215-
$(chk_html).appendTo(entities_form);
240+
$(chk_html).appendTo(entities_btn_group);
216241
})
217242
$(btn_import).removeClass('disabled');
218243
$(btn_add).removeClass('disabled');
@@ -265,6 +290,9 @@ CSVImportExportPlugin.prototype.addEntities = function(event) {
265290
'preferred': 'YES'
266291
};
267292
}
293+
if (e[config.v.aliasElement] != undefined) {
294+
params[config.v.aliasElement] = e[config.v.aliasElement];
295+
}
268296
addObject(event.target, params)
269297
}
270298
});
@@ -285,6 +313,7 @@ CSVImportExportPlugin.prototype.mergeObjectsWithCSV = function() {
285313
var context2columnnames = plugin.context2columnnames;
286314
var preselected_statuus = ['safe'];
287315

316+
// TODO: Check if file type is text/csv and handle error case
288317
if (file) {
289318
Papa.parse(file, {
290319
header: true,
@@ -360,7 +389,12 @@ CSVImportExportPlugin.prototype.mergeCSV = function() {
360389
// Don't replace/add anything in 'soft' mode if an ID is already given
361390
if (name != undefined && name.trim() != '' && !(method == 'soft' && id.trim() != '')) {
362391
// Get matching object
392+
// Default case is matching with preferred name (titleElement)
363393
var obj = getLocalObjectByTitle(name);
394+
// If there is no match on titleElement, try to find one with matching alias, if alias is configured
395+
if (obj == undefined && config.v.aliasElement != undefined) {
396+
obj = getLocalObjectByAlias(name);
397+
}
364398
// Check if object is in correct state
365399
if (obj !== undefined && statuus.includes(obj[config.v.statusElement])) {
366400
// Get preferred ID from local object

plugin-json-imexport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function ImportExportPlugin() {
66
<span class="fas fa-file-download"></span> Download JSON\
77
</button>');
88
this.btn_json_down.on('click', function(e){
9-
plugin.downloadJSON(data_objects, 'basic-app-data');
9+
plugin.downloadJSON(data_objects, 'basic-' + context);
1010
// Hide plugins
1111
$('#app-content-plugins-area').collapse('hide');
1212
})

styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,7 @@ a.link-seealso {
331331
height: 100%;
332332
}
333333
}
334+
335+
.plugin-hidden {
336+
display: none;
337+
}

0 commit comments

Comments
 (0)