Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions addons/metadata/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class AddonAppConfig(BaseAddonAppConfig):

node_settings_template = os.path.join(TEMPLATE_PATH, 'metadata_node_settings.mako')

excel_maximun_file_size = 10485760
text_maximun_file_size = 10485760
image_maximun_file_size = 10485760
other_maximun_file_size = 10485760
excel_file_maximum_size = 10485760
text_file_maximum_size = 10485760
image_file_maximum_size = 10485760
any_file_maximum_size = 10485760

text_file_extension = ['txt', 'csv', 'tsv']
excel_file_extension = ['xlsx', 'xls']
Expand Down
8 changes: 3 additions & 5 deletions addons/metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,13 @@ def get_project_metadata(self):
def get_report_formats_for(self, schemas):
formats = []
for schema in schemas:
for format in RegistrationReportFormat.objects \
.filter(registration_schema_id=schema._id) \
.order_by('order'):
for format in RegistrationReportFormat.objects.order_by('order'):
formats.append({
'id': f'format-{format.id}',
'schema_id': schema._id,
'name': format.name,
})

destinations = []
for addon in self.owner.get_addons():
if not hasattr(addon, 'has_metadata') or not addon.has_metadata:
Expand Down Expand Up @@ -648,8 +647,7 @@ def node(self):

class ImportedAddonSettings(BaseModel):
node_settings = models.ForeignKey(NodeSettings, related_name='imported_addon_settings',
db_index=True, null=True, blank=True,
on_delete=models.CASCADE)
db_index=True, null=True, blank=True, on_delete=models.CASCADE)

name = models.TextField(blank=True, null=True)

Expand Down
24 changes: 0 additions & 24 deletions addons/metadata/static/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,30 +474,6 @@ function MetadataButtons() {
* Start editing metadata.
*/
self.editMetadata = function(context, filepath, item) {
window.context = context;
window.item = item;

var file_total_size = 0;
var file_total_number_of_files = 0;
var file_total_number_of_folders = 0;
var file_maximum_number_of_layers = 0;
var root = '';
getFile(filepath);

function getFile(filepath) {
context.wbcache.searchFile(filepath, function (file) {
if (file.hasOwnProperty('links')) {
window.filepath = file.links.download;
root = file.attributes.materialized;
window.filesize = file.attributes.size;
}
else {
window.filepath = '';
root = '/'+ file.data.provider;
}
});
}

var dialog = null;
const extraMetadata = self.getExtraMetadata(item);
if ((context.projectMetadata || {}).editable && !extraMetadata) {
Expand Down
47 changes: 23 additions & 24 deletions addons/metadata/static/metadata-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const sizeofFormat = require("./util").sizeofFormat;
const getLocalizedText = util.getLocalizedText;
const normalizeText = util.normalizeText;

const logPrefix = '[metadata] ';
var filteredPages = [];

const logPrefix = '[metadata] ';

const QuestionPage = oop.defclass({
constructor: function(schema, fileItem, options) {
const self = this;
Expand All @@ -54,7 +55,7 @@ const QuestionPage = oop.defclass({
filteredPages = [];
filteredPages = (self.schema.pages || []).filter(function(page) {
return (page.questions || []).some(function(question){
return question.hide === true;
return question.concealment_page === "buttonHide";
})
}).map(function(page){
return page;
Expand Down Expand Up @@ -190,6 +191,7 @@ const QuestionField = oop.extend(Emitter, {

create: function() {
const self = this;
self.element = $('<div></div>').addClass('form-group');
if(filteredPages.length > 0 && filteredPages.length != 1){
const currentPage = filteredPages.filter(function(page) {
return (page.questions || []).some(function (question) {
Expand All @@ -199,26 +201,26 @@ const QuestionField = oop.extend(Emitter, {

const filteredPageIds = currentPage.flatMap(function(page) {
return (page.questions || []).filter(function (question) {
return question.hide === true;
return question.concealment_page === "buttonHide";
})
.map(function (question) {
return question.qid.split(':')[1];
});
});

const isHide = currentPage.some(function(page) {
const isConcealmentPage = currentPage.some(function(page) {
return (page.questions || []).some(function (question) {
return question.qid === self.question.qid && self.question.qid.split(':')[1] != filteredPageIds && self.question.required != true;
})
});

if (isHide && filteredPageIds.length == 1) {
self.element = $('<div></div>').addClass('form-group-'+filteredPageIds).css('height','0').css('overflow', 'hidden').css('margin','0px');
if (isConcealmentPage && filteredPageIds.length == 1) {
self.element = $('<div></div>').addClass('concealment-page-'+filteredPageIds).css('height','0').css('overflow', 'scroll');
}else{
self.element = $('<div></div>').addClass('form-group').css('margin','0px');
self.element = $('<div></div>').addClass('form-group');
}
}else{
self.element = $('<div></div>').addClass('form-group').css('margin','0px');
self.element = $('<div></div>').addClass('form-group');
}

// construct header
Expand All @@ -228,10 +230,6 @@ const QuestionField = oop.extend(Emitter, {
// construct label
const label = $('<label></label>')
.text(self.question.title ? getLocalizedText(self.question.title) : self.question.label);

if(self.question.auto_value){
label.append($(' <span>&nbsp; &#10227</span> '));
}
if (self.question.required) {
label.append($('<span></span>')
.css('color', 'red')
Expand All @@ -240,18 +238,18 @@ const QuestionField = oop.extend(Emitter, {
}
header.append(label);

if(self.question.hasOwnProperty('hide') && self.question.hide){
if(self.question.hasOwnProperty('concealment_page') && self.question.concealment_page == "buttonHide"){
const p = $('<p></p>');
const a = $('<a></a>').text('▼ '+_('Show Items'));
p.on('click', function(){
$('.form-group-'+self.question.qid.split(':')[1]).each(function() {
$('.concealment-page-'+self.question.qid.split(':')[1]).each(function() {
if($(this).height() === 0){
$(this).animate({height: $(this).get(0).scrollHeight}, 'fast', function() {
$(this).css('height', '');
$(this).css('height', '').addClass('form-group');
});
a.text('▲ '+_('Hide Items'));
}else {
$(this).animate({height: 0}, 'fast');
$(this).animate({height: 0}, 'fast').removeClass('form-group');
a.text('▼ '+_('Show Items'));
}
});
Expand Down Expand Up @@ -384,7 +382,7 @@ function createFormField(question, options, value) {
formField = new TextFormField(question, options);
}
formField.create();
if (value != null && value !== '') {
if (value != null && value !== '' || (question.hasOwnProperty('initial_row_addition') && question.initial_row_addition)) {
try {
formField.setValue(value);
} catch (error) {
Expand Down Expand Up @@ -729,11 +727,7 @@ const ArrayFormField = oop.extend(FormFieldInterface, {
const headRow = $('<tr>');
const thead = $('<thead>').append(headRow);
self.question.properties.forEach(function(prop) {
if(prop.auto_value){
headRow.append($('<th>' + getLocalizedText(prop.title) + '<span>&nbsp; &#10227</span></th>'));
}else{
headRow.append($('<th>' + getLocalizedText(prop.title) + '</th>'));
}
headRow.append($('<th>' + getLocalizedText(prop.title) + '</th>'));
});
headRow.append($('<th>')); // remove button header

Expand Down Expand Up @@ -846,6 +840,11 @@ const ArrayFormField = oop.extend(FormFieldInterface, {
} else {
rows = value || [];
}

if(self.question.hasOwnProperty('initial_row_addition') && self.question.initial_row_addition ){
self.addRow();
}

rows.forEach(function(row) {
self.addRow(row);
});
Expand Down Expand Up @@ -1145,8 +1144,8 @@ function createSuggestionButton(container, question, buttonSuggestions, options,
.then(function (value) {
if(value == 'error'){
return;
}else if( value == 'auto-value-filesize-over-error'){
var name = question.qid.split(':')[1];
}else if( value == 'get-filesize-over-error'){
var name = question.qid.split(':')[1].replace('/', '-');
$('.'+name).remove();
container.after(
'<div class="'+name+'" style="color: red;">'+ _("File size exceeds the maximum allowed size.")+'</div>'
Expand Down
Loading