Skip to content

Commit

Permalink
Improvements for PR (#2408) GNIP: GeoNode Metadata Editor Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Feb 28, 2017
1 parent ec5c9c5 commit 40bb74b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 28 deletions.
9 changes: 9 additions & 0 deletions geonode/base/models.py
Expand Up @@ -1015,6 +1015,15 @@ def resourcebase_post_save(instance, *args, **kwargs):
if tb:
logger.debug(tb)

# set default License if no specified
if instance.license is None:
no_license = License.objects.filter(name="Not Specified")

if no_license and len(no_license) > 0:
instance.license = no_license[0]
print("License: %s " % (instance.license))
instance.save()


def rating_post_save(instance, *args, **kwargs):
"""
Expand Down
8 changes: 4 additions & 4 deletions geonode/documents/templates/documents/document_metadata.html
Expand Up @@ -24,8 +24,8 @@ <h2 class="page-title">{% trans "Metadata" %}&nbsp;{% blocktrans with document.t
<div id="profileCompleteness" class="alert alert-info" style="position: absolute; right: 0; top: 0; padding: 4px;">
<strong>Completeness</strong>
<div style="padding: 2px;">
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Some mandatory fields missing</small>
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Metadata Schema mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Check Schema mandatory fields</small>
</div>
<div class="progress" style="margin-bottom:2px;">
<div class="progress-bar progress-bar-striped" role="progress-bar" >
Expand Down Expand Up @@ -65,7 +65,7 @@ <h2 class="page-title">{% trans "Metadata" %}&nbsp;{% blocktrans with document.t
{% form document_form using "layouts/doc_panels.html" %}
{# document_form|as_bootstrap #}
</div>

<div class="row">
<div class="col-md-12 grid-spacer">
<fieldset class="form-controls modal-forms modal hide fade" id="poc_form" >
Expand All @@ -78,7 +78,7 @@ <h2>{% trans "Metadata Provider" %}</h2>
{{ author_form|as_bootstrap }}
<button type='button' class="modal-cloose-btn btn btn-primary">Done</button>
</fieldset>

<div class="form-actions">
<input type="button" id="btn_back_dwn" class="btn btn-primary" style="display: none" value="{% trans "<< Back" %}"/>
<input type="submit" id="btn_upd_md_dwn" class="btn btn-primary" value="{% trans "Update" %}"/>
Expand Down
6 changes: 3 additions & 3 deletions geonode/layers/templates/layers/layer_metadata.html
Expand Up @@ -21,8 +21,8 @@ <h2 class="page-title">{% trans "Metadata" %}&nbsp;{% blocktrans with layer.titl
<div id="profileCompleteness" class="alert alert-info" style="position: absolute; right: 0; top: 0; padding: 4px;">
<strong>Completeness</strong>
<div style="padding: 2px;">
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Some mandatory fields missing</small>
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Metadata Schema mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Check Schema mandatory fields</small>
</div>
<div class="progress" style="margin-bottom:2px;">
<div class="progress-bar progress-bar-striped" role="progress-bar" >
Expand Down Expand Up @@ -104,4 +104,4 @@ <h2>{% trans "Metadata Provider" %}</h2>
</form>

{{ block.super }}
{% endblock body_outer %}
{% endblock body_outer %}
10 changes: 5 additions & 5 deletions geonode/maps/templates/maps/map_metadata.html
Expand Up @@ -22,8 +22,8 @@ <h2 class="page-title">{% trans "Metadata" %}&nbsp;{% blocktrans with map.title
<div id="profileCompleteness" class="alert alert-info" style="position: absolute; right: 0; top: 0; padding: 4px;">
<strong>Completeness</strong>
<div style="padding: 2px;">
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Some mandatory fields missing</small>
<small class="completed text-success" style="display: none; "><i class="fa fa-check"></i>Metadata Schema mandatory fields completed</small>
<small class="not-completed text-danger" style="display: none; "><i class="fa fa-remove"></i>Check Schema mandatory fields</small>
</div>
<div class="progress" style="margin-bottom:2px;">
<div class="progress-bar progress-bar-striped" role="progress-bar" >
Expand Down Expand Up @@ -56,13 +56,13 @@ <h2 class="page-title">{% trans "Metadata" %}&nbsp;{% blocktrans with map.title
</ul>
</div>
{% endif %}

{% csrf_token %}
<div id="mdeditor_form" class="col-md-12 form-controls">
{% form map_form using "layouts/map_panels.html" %}
{# map_form|as_bootstrap #}
</div>

<div class="row">
<div class="col-md-12 grid-spacer">
<fieldset class="form-controls modal-forms modal hide fade" id="poc_form" >
Expand All @@ -75,7 +75,7 @@ <h2>{% trans "Metadata Provider" %}</h2>
{{ author_form|as_bootstrap }}
<button type='button' class="modal-cloose-btn btn btn-primary">Done</button>
</fieldset>

<div class="form-actions">
<input type="button" id="btn_back_dwn" class="btn btn-primary" style="display: none" value="{% trans "<< Back" %}"/>
<input type="submit" id="btn_upd_md_dwn" class="btn btn-primary" value="{% trans "Update" %}"/>
Expand Down
87 changes: 71 additions & 16 deletions geonode/templates/metadata_form_js.html
Expand Up @@ -46,7 +46,7 @@
// done button tooltip variables
var tooltipShown = false;
var gotIt = false;
var tooltipContent = 'All mandatory fields are completed, you can continue editing the optional fields or click on "Done" to save your changes and close this page. '
var tooltipContent = 'All fields declared mandatory by the schema are completed, you can continue editing the optional fields or click on "Done" to save your changes and close this page. '
+ '<a id="close-popover-done" data-toggle="clickover" class="btn btn-small btn-primary pull-right">Got it</a><br/>';
$('.metadata-edit-done').popover({
placement: 'left',
Expand All @@ -64,16 +64,14 @@
$('#completeness-hints .mandatory-hint')
.toggleClass('progress-bar-danger', mandatoryMissing)
.toggleClass('progress-bar-success', !mandatoryMissing)
.attr('title', mandatoryMissing ? "some mandatory fields are missing" : "Mandatory fields completed" )
.attr('title', mandatoryMissing ? "some schema mandatory fields are missing" : "Metadata Schema mandatory fields completed" )
.tooltip('fixTitle');
$('#completeness-hints .advanced-hint')
.toggleClass('progress-bar-danger', advancedMissing)
.toggleClass('progress-bar-success', !advancedMissing)
.attr('title', advancedMissing ? "some mandatory fields are missing" : "Mandatory fields completed" )
.attr('title', advancedMissing ? "some schema mandatory fields are missing" : "Metadata Schema mandatory fields completed" )
.tooltip('fixTitle');



//done button tooltip
if(completeness === 1 && $('.metadata-edit-done').css('opacity')+"" === "0" && !tooltipShown && !gotIt) {
tooltipShown = true;
Expand Down Expand Up @@ -224,17 +222,70 @@
}

//check if a field is mandatory
var otherRestrictionsSelected = function(e){
var otherRestrictions = false
try {
idx = $('#id_resource-restriction_code_type')[0].selectedIndex;
value = $('#id_resource-restriction_code_type')[0].options[idx].text;
if(value === "otherRestrictions") {
otherRestrictions = true;
}
} catch (err) {
otherRestrictions = false;
}

return otherRestrictions;
}

var toggleRestrictionsConstraints = function(){
try {
var e = $('#id_resource-constraints_other')[0];
if(e) {
if(otherRestrictionsSelected() && e.value !== undefined && e.value.trim() === '') {
if(!$(e).hasClass("input-empty")){
setInputEmpty(e, true);
$(e).parent().append("<p class='xxs-font-size mandatory-warning'>&nbsp;&nbsp;&nbsp;<strong>* Field declared Mandatory by the Metadata Schema</strong></p>");
empty++;
}
} else {
setInputEmpty(e, false);
$(e).parent().find(".mandatory-warning").remove();
if(empty >= 1) empty--;
}
}
} catch (err) {
// Log error
return false;
}

return true;
}

var isMandatoryField = function (el) {
return el.id.indexOf("autocomplete") < 0 && !$(el).hasClass('value-select') && el.type !== 'radio' && el.type !== 'button'
if(el.id.indexOf("resource-constraints") >= 0) {
if(otherRestrictionsSelected()) {
return true;
}
return false;
}

var is_mandatory = (el.id.indexOf("autocomplete") < 0 &&
!$(el).hasClass('value-select') &&
el.type !== 'radio' &&
el.type !== 'button');
return is_mandatory;
}

var onInputChange = function(e){
toggleRestrictionsConstraints();

if(e.target.value !== undefined && e.target.value.trim() === ''){
if(!$(e.target).hasClass("input-empty")){
setInputEmpty(e.target, true);
if(!!$(this).closest('#mdinfo').length) {
$(e.target).parent().append("<p class='xxs-font-size mandatory-warning'>&nbsp;&nbsp;&nbsp;<strong>* Mandatory field</strong></p>");
}
if(isMandatoryField(this)) {
setInputEmpty(e.target, true);
if(!!$(this).closest('#mdinfo').length) {
$(e.target).parent().append("<p class='xxs-font-size mandatory-warning'>&nbsp;&nbsp;&nbsp;<strong>* Field declared Mandatory by the Metadata Schema</strong></p>");
}
empty++;
}
}
Expand All @@ -244,19 +295,22 @@
if(isMandatoryField(this)) {
empty--;
}
setInputEmpty(e.target, false);
$(e.target).parent().find(".mandatory-warning").remove();
}
setInputEmpty(e.target, false);
$(e.target).parent().find(".mandatory-warning").remove();
}

if(totalNum == prevNum) {
try {
updateCompleteness((totalNum-empty)/totalNum);
var perc = (totalNum-empty)/totalNum;
perc = (perc <= 1 ? perc : 1);
updateCompleteness(perc);
} catch(err) {
// Log error
}
}

};

$('#category_form').change(onInputChange).change();
$('#id_resource-regions').change(onInputChange).change();
$('#mandatory').find(":input:not(.value-select):not(.autocomplete)").each(function(){
Expand All @@ -281,10 +335,12 @@

$(this).change(onInputChange).change();

if(this.id.indexOf("autocomplete") < 0){
//if(this.id.indexOf("autocomplete") < 0){
if(isMandatoryField(this)){
totalNum++;
}
});

// Dataset attributes sorting
$(document).ready(function() {
//Helper function to keep table row from collapsing when being sorted
Expand Down Expand Up @@ -323,7 +379,6 @@
$(this).closest('tr').insertAfter(to.children().eq(nextIndex));
}
renumber_table('#dataset table')

}
});
});
Expand Down

0 comments on commit 40bb74b

Please sign in to comment.