Navigation Menu

Skip to content

Commit

Permalink
Display a link to the XML editor if an error occurs (#1806)
Browse files Browse the repository at this point in the history
Display a link to the XML editor if a error occurs while saving the
editor form contents. See attached screenshot.
  • Loading branch information
juanluisrp authored and fxprunayre committed Dec 19, 2016
1 parent 3936fa5 commit 07bdcd2
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 75 deletions.
Expand Up @@ -255,6 +255,7 @@
solrproxy: '../api/0.1/search'
});


/**
* @ngdoc service
* @kind function
Expand Down
Expand Up @@ -24,17 +24,17 @@
(function() {
goog.provide('gn_crs_selector');

var module = angular.module('gn_crs_selector', []);
var module = angular.module('gn_crs_selector', ['pascalprecht.translate']);

/**
*
*
*/
module.directive('gnCrsSelector',
['$rootScope', '$timeout', '$http',
'gnEditor', 'gnEditorXMLService', 'gnCurrentEdit',
'gnEditor', 'gnEditorXMLService', 'gnCurrentEdit', '$translate',
function($rootScope, $timeout, $http,
gnEditor, gnEditorXMLService, gnCurrentEdit) {
gnEditor, gnEditorXMLService, gnCurrentEdit, $translate) {

return {
restrict: 'A',
Expand Down Expand Up @@ -94,7 +94,16 @@

$timeout(function() {
// Save the metadata and refresh the form
gnEditor.save(gnCurrentEdit.id, true);
gnEditor.save(gnCurrentEdit.id, true).then(function() {
// Success. Do nothing.
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
});

return false;
Expand Down
Expand Up @@ -32,7 +32,7 @@

var module = angular.module('gn_directory_entry_selector',
['gn_metadata_manager_service', 'gn_schema_manager_service',
'gn_editor_xml_service']);
'gn_editor_xml_service', 'pascalprecht.translate']);

/**
*
Expand Down Expand Up @@ -149,7 +149,16 @@
scope.elementRef, scope.elementName,
scope.domId, 'before').then(function() {
if (scope.templateAddAction) {
gnEditor.save(gnCurrentEdit.id, true);
gnEditor.save(gnCurrentEdit.id, true).then(function() {
// success. Nothing to do.
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('saveMetadataError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
}
});
};
Expand Down Expand Up @@ -180,7 +189,14 @@
// Save the metadata and refresh the form
gnEditor.save(gnCurrentEdit.id, true).then(
function(r) {
defer.resolve();
defer.resolve(r);
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
});
}
Expand Down
Expand Up @@ -29,7 +29,7 @@
/**
*/
angular.module('gn_geopublisher_directive',
['gn_owscontext_service'])
['gn_owscontext_service', 'pascalprecht.translate'])
.directive('gnGeoPublisher', [
'gnMap',
'gnOwsContextService',
Expand All @@ -39,9 +39,10 @@
'gnCurrentEdit',
'$timeout',
'$translate',
'$rootScope',
function(gnMap, gnOwsContextService, gnOnlinesrc,
gnGeoPublisher, gnEditor, gnCurrentEdit,
$timeout, $translate) {
$timeout, $translate, $rootScope) {
return {
restrict: 'A',
replace: true,
Expand Down Expand Up @@ -150,7 +151,16 @@
}

$timeout(function() {
gnEditor.save(true);
gnEditor.save(true).then(function () {
// success. Nothing to do.
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
});
};
scope.openStyler = function() {
Expand Down
Expand Up @@ -159,6 +159,7 @@

/**
* Run a service (not a batch) to add or remove
*
* an onlinesrc.
* Save the form, launch the service, then refresh
* the form and reload the onlinesrc list.
Expand Down
Expand Up @@ -32,7 +32,7 @@

var module = angular.module('gn_organisation_entry_selector',
['gn_metadata_manager_service', 'gn_schema_manager_service',
'gn_editor_xml_service']);
'gn_editor_xml_service', 'pascalprecht.translate']);

/**
*
Expand All @@ -42,11 +42,11 @@
['$rootScope', '$timeout', '$q', '$http',
'gnEditor', 'gnSchemaManagerService',
'gnEditorXMLService', 'gnHttp', 'gnConfig',
'gnCurrentEdit', 'gnConfigService',
function($rootScope, $timeout, $q, $http,
gnEditor, gnSchemaManagerService,
gnEditorXMLService, gnHttp, gnConfig,
gnCurrentEdit, gnConfigService) {
'gnCurrentEdit', 'gnConfigService', '$translate',
function($rootScope, $timeout, $q, $http,
gnEditor, gnSchemaManagerService,
gnEditorXMLService, gnHttp, gnConfig,
gnCurrentEdit, gnConfigService, $translate) {

return {
restrict: 'A',
Expand Down Expand Up @@ -109,7 +109,16 @@
scope.elementRef, scope.elementName,
scope.domId, 'before').then(function() {
if (scope.templateAddAction) {
gnEditor.save(gnCurrentEdit.id, true);
gnEditor.save(gnCurrentEdit.id, true).then(function() {
// success. Nothing to do.
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
}
});
return false;
Expand All @@ -134,7 +143,16 @@

$timeout(function() {
// Save the metadata and refresh the form
gnEditor.save(gnCurrentEdit.id, true);
gnEditor.save(gnCurrentEdit.id, true).then(function() {
// success. Nothing to do
}, function(rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
});
}
};
Expand Down
Expand Up @@ -21,49 +21,59 @@
* Rome - Italy. email: geonetwork@osgeo.org
*/

(function() {
(function () {
goog.provide('gn_template_field_directive');

var module = angular.module('gn_template_field_directive', []);
module.directive('gnTemplateFieldAddButton', ['gnEditor', 'gnCurrentEdit',
function(gnEditor, gnCurrentEdit) {
var module = angular.module('gn_template_field_directive', ['pascalprecht.translate']);
module.directive('gnTemplateFieldAddButton', ['gnEditor', 'gnCurrentEdit', '$rootScope', '$translate',
function (gnEditor, gnCurrentEdit, $rootScope, $translate) {

return {
restrict: 'A',
replace: true,
scope: {
id: '@gnTemplateFieldAddButton'
},
link: function(scope, element, attrs) {
link: function (scope, element, attrs) {
var textarea = $(element).parent()
.find('textarea[name=' + scope.id + ']');
.find('textarea[name=' + scope.id + ']');
// Unregister this textarea to the form
// It will be only submitted if user click the add button
textarea.removeAttr('name');

scope.addFromTemplate = function() {
scope.addFromTemplate = function () {
textarea.attr('name', scope.id);

// Save and refreshform
gnEditor.save(gnCurrentEdit.id, true);
gnEditor.save(gnCurrentEdit.id, true).then(function () {
// success. Do nothing
}, function (rejectedValue) {
$rootScope.$broadcast('StatusUpdated', {
title: $translate.instant('runServiceError'),
error: rejectedValue,
timeout: 0,
type: 'danger'
});
});
};

$(element).click(scope.addFromTemplate);
}
};
}]),
}]);

/**
* The template field directive managed a custom field which
* is based on an XML snippet to be sent in the form with some
* string to be replace from related inputs.
*
* This allows to edit a complex XML structure with simple
* form fields. eg. a date of creation where only the date field
* is displayed to the end user and the creation codelist value
* is in the XML template for the field.
*/
* The template field directive managed a custom field which
* is based on an XML snippet to be sent in the form with some
* string to be replace from related inputs.
*
* This allows to edit a complex XML structure with simple
* form fields. eg. a date of creation where only the date field
* is displayed to the end user and the creation codelist value
* is in the XML template for the field.
*/
module.directive('gnTemplateField', ['$http', '$rootScope', '$timeout',
function($http, $rootScope, $timeout) {
function ($http, $rootScope, $timeout) {

return {
restrict: 'A',
Expand All @@ -75,17 +85,17 @@
values: '@',
notSetCheck: '@'
},
link: function(scope, element, attrs) {
link: function (scope, element, attrs) {
var xmlSnippetTemplate = element[0].innerHTML;
var separator = '$$$';
var fields = scope.keys && scope.keys.split(separator);
var values = scope.values && scope.values.split(separator);

// Replace all occurence of {{fieldname}} by its value
var generateSnippet = function() {
var generateSnippet = function () {
var xmlSnippet = xmlSnippetTemplate, isOneFieldDefined = false;

angular.forEach(fields, function(fieldName) {
angular.forEach(fields, function (fieldName) {
var field = $('#' + scope.id + '_' + fieldName);
var value = '';
if (field.attr('type') === 'checkbox') {
Expand All @@ -96,17 +106,17 @@

if (value !== '') {
xmlSnippet = xmlSnippet.replace(
'{{' + fieldName + '}}',
value.replace(/\&/g, '&')
'{{' + fieldName + '}}',
value.replace(/\&/g, '&')
.replace(/\"/g, '"'));

// If one value is defined the field
// is defined
isOneFieldDefined = true;
} else {
xmlSnippet = xmlSnippet.replace(
'{{' + fieldName + '}}',
'');
'{{' + fieldName + '}}',
'');
}
});

Expand All @@ -125,9 +135,9 @@
element[0].innerHTML = '';
}
};
var init = function() {
var init = function () {
// Initialize all values
angular.forEach(values, function(value, key) {
angular.forEach(values, function (value, key) {
var selector = '#' + scope.id + '_' + fields[key];
if ($(selector).attr('type') === 'checkbox') {
$(selector).attr('checked', value === 'true');
Expand All @@ -138,8 +148,8 @@

// Register change event on each fields to be
// replaced in the XML snippet.
angular.forEach(fields, function(value) {
$('#' + scope.id + '_' + value).change(function() {
angular.forEach(fields, function (value) {
$('#' + scope.id + '_' + value).change(function () {
generateSnippet();
});
});
Expand All @@ -152,7 +162,7 @@
element[0].innerHTML = '';
// When checkbox is checked generate default
// snippet.
unsetCheckbox.change(function() {
unsetCheckbox.change(function () {
$('#' + scope.notSetCheck).toggleClass('hidden');
if (unsetCheckbox[0].checked) {
element[0].innerHTML = '';
Expand All @@ -164,7 +174,7 @@
generateSnippet();
}
};
$timeout(function() {
$timeout(function () {
init();
});
}
Expand Down

0 comments on commit 07bdcd2

Please sign in to comment.