Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ukretschmer committed Dec 7, 2018
2 parents 0f00a70 + 8f4da4d commit 0ffccef
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 38 deletions.
20 changes: 17 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ function getLocalObjectByTitle (title) {
}


function getLocalObjectByAlias (alias) {
return asArray(data_objects[config.a.JSONContainer]).find(function (e) {
return asArray(e[config.v.aliasElement]).includes(alias);
});
}


// get the value using the path_key from config template
function deepFind (obj, path_key) {
// Dynamic attributes
Expand Down Expand Up @@ -137,9 +144,17 @@ function replaceLocalIDInFrontend(old_id, new_id) {
}


function dataToString (data) {
if (Array.isArray(data)) {
data = data.join(', ');
}
return data;
}


function createNewHTMLObject(data){
if(config.v.descriptionElement !== undefined && data[config.v.descriptionElement] != null){
description_html = '<p class="mb-1">'+ data[config.v.descriptionElement] + '</p>';
description_html = '<p class="mb-1">' + dataToString(data[config.v.descriptionElement]) + '</p>';
} else {
description_html = '<p class="mb-1"></p>'
}
Expand Down Expand Up @@ -662,7 +677,6 @@ function changeStatus (trigger_element, element_id, current_status, new_status){
function prepareValueMapping (mapping_config, mapping_value) {
var ret = mapping_value;
if (mapping_config.multiple){
// is expectes that in mapping_value multiple values include
if (typeof mapping_value === 'string') {
var value_arr = mapping_value.split('\n');
if (value_arr.length > 1) {
Expand Down Expand Up @@ -761,7 +775,7 @@ function editObject(id) {
/* 2. update frontend
Update title and description of list item */
$('#' + id + ' h5').text(local_object[config.v.titleElement]);
$('#' + id + ' p').text(local_object[config.v.descriptionElement]);
$('#' + id + ' p').text(dataToString(local_object[config.v.descriptionElement]));
// Close modal,
$('#object-modal').modal('hide');
}
Expand Down
38 changes: 20 additions & 18 deletions basic-backend-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var plugin_xml_datasets = $('<div id="xml-datasets-dropdown"></div>')


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


Expand Down Expand Up @@ -225,22 +225,24 @@ function APIDatasets () {
cds = sessionStorage.getItem(context);
query_dataset = {'dataset': cds};
}
// Load objects from cds in object cache
$.getJSON(config.app.config.baseURL + config.app.config.api[context].RESTAPI, query_dataset).done(function (result) {
var cnt = 0;
if (result) {
cnt = 1;
if (Array.isArray(result[config.a.JSONContainer])) {
cnt = result[config.a.JSONContainer].length;
if (cds) {
// Load objects from cds in object cache
$.getJSON(config.app.config.baseURL + config.app.config.api[context].RESTAPI, query_dataset).done(function (result) {
var cnt = 0;
if (result) {
cnt = 1;
if (Array.isArray(result[config.a.JSONContainer])) {
cnt = result[config.a.JSONContainer].length;
}
data_objects = result;
}
data_objects = result;
}
console.log('REST-API: ' + cnt + ' object(s) loaded.');
// Create result list representation
asArray(data_objects[config.a.JSONContainer]).reverse().forEach(function (obj) {createNewHTMLObject(obj)});
// Set current dataset
$('#xml-dataset-current').html(cds);
// dataset loaded
$('body').trigger('datasetLoaded');
});
console.log('REST-API: ' + cnt + ' object(s) loaded.');
// Create result list representation
asArray(data_objects[config.a.JSONContainer]).reverse().forEach(function (obj) {createNewHTMLObject(obj)});
// Set current dataset
$('#xml-dataset-current').html(cds);
// dataset loaded
$('body').trigger('datasetLoaded');
});
}
}
15 changes: 10 additions & 5 deletions config.tpl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var config = {
"app": {
"version": "1.0.1-dev",
"version": "1.0.1",
"config": {
"use_corsanywhere": false,
"footer": {
Expand Down Expand Up @@ -36,23 +36,26 @@ var config = {
"statusElement": "status",
"identifierElement": "ref",
"identifierAbbreviation": "DNB",
"identifierBaseURL": "http://d-nb.info/gnd/"
"identifierBaseURL": "http://d-nb.info/gnd/",
"aliasElement": "alias"
},
"places": {
"titleElement": "name",
"descriptionElement": "description",
"statusElement": "status",
"identifierElement": "ref",
"identifierAbbreviation": "GEO",
"identifierBaseURL": "http://www.geonames.org/"
"identifierBaseURL": "http://www.geonames.org/",
"aliasElement": "alias"
},
"organisations":{
"titleElement": "name",
"descriptionElement": "description",
"statusElement": "status",
"identifierElement": "ref",
"identifierAbbreviation": "DNB",
"identifierBaseURL": "http://d-nb.info/gnd/"
"identifierBaseURL": "http://d-nb.info/gnd/",
"aliasElement": "alias"
}

},
Expand Down Expand Up @@ -124,7 +127,9 @@ var config = {
"localJSONPath": "name"
},{
"displayName": "Namensvariante",
"JSONPath": "alternateNames.name"
"JSONPath": "alternateNames.name",
"localJSONPath": "alias",
"multiple": true
},{
"displayName": "Breitengrad",
"JSONPath": "lat"
Expand Down
4 changes: 2 additions & 2 deletions local-storage-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var plugin_ls_dataset_info = $('<div id="ls-dataset-info"></div>')


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


Expand Down Expand Up @@ -171,7 +171,6 @@ LocalStorageAdapter.prototype.load = function () {
console.log('Local Storage API: ' + objects_array.length + ' object(s) loaded (context: ' + ctx + ', dataset: ' + ds + ')');
// Update frontend info
updateFrontendDatasetInformation(this.last_updated, objects_array.length);
$('body').trigger('datasetLoaded');
} else {
console.log('Local Storage API (ERROR): Context or dataset is null. Nothing loaded.');
}
Expand Down Expand Up @@ -203,6 +202,7 @@ LocalStorageAdapter.prototype.setDataset = function (ds) {
// Save current dataset name
localStorage.setItem(this.ls_key_last, ds);
console.log('Local Storage API: Current dataset: ' + ds);
$('body').trigger('datasetLoaded');
return this;
}

Expand Down
12 changes: 11 additions & 1 deletion plugin-actions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function BasicAppPlugin (id, title, icon_classes, container_selector) {
function BasicAppPlugin (id, title, icon_classes, container_selector, dataset_dependency) {
this.id = id;
this.title = title;
this.icon_classes = icon_classes;
this.DOMContainer = $(container_selector);
this.dataset_dependency = dataset_dependency || 'YES';
}


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

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

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


function ActionButtonPlugin (id, title, icon_classes, container_selector) {
BasicAppPlugin.call(this, id, title, icon_classes, container_selector)
Expand Down
50 changes: 42 additions & 8 deletions plugin-csv-imexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ function CSVImportExportPlugin() {
</button>\
</div>\
<div class="modal-body">\
<div class="form-group">\
<label for="uploadFileCSV">CSV-file to load data from</label>\
<input type="file" class="form-control-file" id="uploadFileCSV">\
<div class="custom-file mb-2">\
<label for="uploadFileCSV" class="custom-file-label" id="uploadFileCSVLabel">CSV-file to load data from</label>\
<input type="file" class="custom-file-input" id="uploadFileCSV">\
</div>\
<form id="import-csvdata-form"></form>\
</div>\
<div class="modal-footer">\
<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>\
<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>\
</div>\
Expand Down Expand Up @@ -86,6 +88,7 @@ function CSVImportExportPlugin() {
}
});
$('#modals').on('change', '#uploadFileCSV', function (e){
$('#uploadFileCSVLabel').html(this.files[0].name);
plugin.getObjectsFromCSV();
});
$('#modals').on('change', '#mergeFileCSV', function (e){
Expand Down Expand Up @@ -173,14 +176,36 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
var id = letter[column + 'ID'];
var entity = {};
// Name and ID are given. Check for duplicate ID
// TODO: if ID already imported and name differs add name as alias
if (name && id && !found_ids.includes(id)) {
entity[config.v.titleElement] = name;
entity[config.v.identifierElement] = id;
importable_entities.push(entity);
unique_names.push(name);
found_ids.push(id);
}
// If ID already imported and name differs add name as alias
else if (name && id && found_ids.includes(id) && !unique_names.includes(name)) {
if (config.v.aliasElement != undefined) {
// Update importable entity with id and add an alias, if not already done
var already_imported_entity = importable_entities.find(function (e) {
return e[config.v.identifierElement] == id;
});
if (already_imported_entity[config.v.aliasElement] == undefined) {
// there is no alias yet
already_imported_entity[config.v.aliasElement] = name;
} else {
// Alias(es) aready set.
var old_aliases = asArray(already_imported_entity[config.v.aliasElement]);
// Add if not already done.
if (!old_aliases.includes(name)) {
old_aliases.push(name);
already_imported_entity[config.v.aliasElement] = old_aliases;
}
}
} else {
// If aliases aren't configured, we can't handle this case
}
}
// Only the name is given. Check for duplicate name.
else if (name && !id && !unique_names.includes(name)) {
entity[config.v.titleElement] = name;
Expand All @@ -195,12 +220,12 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
count_span.html(importable_entities.length);
if (importable_entities.length > 0) {
// Add importable entities to import form with filter buttons
$('#csv-file-upload-modal .form-group button[type="button"]').remove();
var chk_button_filter = '<div class="btn-group mt-2" id="check-buttons" role="group">\
var chk_button_filter = '<div class="btn-group form-group" id="check-buttons" role="group">\
<button class="btn btn-sm btn-secondary" id="import-csv-btn-chk-all" type="button">Select All</button>\
<button class="btn btn-sm btn-secondary" id="import-csv-btn-chk-none" type="button">Deselect All</button>\
</div>';
$(chk_button_filter).appendTo('#csv-file-upload-modal .form-group');
$(chk_button_filter).appendTo(entities_form);
var entities_btn_group = $('<div class="form-group"></div>').appendTo(entities_form);
importable_entities.forEach(function (e, i) {
var ref_html = '';
if (e[config.v.identifierElement] && e[config.v.identifierElement].startsWith(config.v.identifierBaseURL)) {
Expand All @@ -212,7 +237,7 @@ CSVImportExportPlugin.prototype.getObjectsFromCSV = function() {
' + e[config.v.titleElement] + ref_html +'\
</label>\
</div>';
$(chk_html).appendTo(entities_form);
$(chk_html).appendTo(entities_btn_group);
})
$(btn_import).removeClass('disabled');
$(btn_add).removeClass('disabled');
Expand Down Expand Up @@ -265,6 +290,9 @@ CSVImportExportPlugin.prototype.addEntities = function(event) {
'preferred': 'YES'
};
}
if (e[config.v.aliasElement] != undefined) {
params[config.v.aliasElement] = e[config.v.aliasElement];
}
addObject(event.target, params)
}
});
Expand All @@ -285,6 +313,7 @@ CSVImportExportPlugin.prototype.mergeObjectsWithCSV = function() {
var context2columnnames = plugin.context2columnnames;
var preselected_statuus = ['safe'];

// TODO: Check if file type is text/csv and handle error case
if (file) {
Papa.parse(file, {
header: true,
Expand Down Expand Up @@ -360,7 +389,12 @@ CSVImportExportPlugin.prototype.mergeCSV = function() {
// Don't replace/add anything in 'soft' mode if an ID is already given
if (name != undefined && name.trim() != '' && !(method == 'soft' && id.trim() != '')) {
// Get matching object
// Default case is matching with preferred name (titleElement)
var obj = getLocalObjectByTitle(name);
// If there is no match on titleElement, try to find one with matching alias, if alias is configured
if (obj == undefined && config.v.aliasElement != undefined) {
obj = getLocalObjectByAlias(name);
}
// Check if object is in correct state
if (obj !== undefined && statuus.includes(obj[config.v.statusElement])) {
// Get preferred ID from local object
Expand Down
2 changes: 1 addition & 1 deletion plugin-json-imexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function ImportExportPlugin() {
<span class="fas fa-file-download"></span> Download JSON\
</button>');
this.btn_json_down.on('click', function(e){
plugin.downloadJSON(data_objects, 'basic-app-data');
plugin.downloadJSON(data_objects, 'basic-' + context);
// Hide plugins
$('#app-content-plugins-area').collapse('hide');
})
Expand Down
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,7 @@ a.link-seealso {
height: 100%;
}
}

.plugin-hidden {
display: none;
}

0 comments on commit 0ffccef

Please sign in to comment.