Skip to content

Commit

Permalink
fix(mess): add translation error messages
Browse files Browse the repository at this point in the history
closes #379
  • Loading branch information
Pewillia committed Jun 6, 2019
1 parent 738c199 commit 652b319
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 48 deletions.
15 changes: 13 additions & 2 deletions src/app/core/common.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ angular
* define common Javascript methods
* @function commonService
* @param {Object} $translate translation service Angular object
* @param {object} $rootScope Angular Object
* @param {Object} events Angular object
* @param {Object} $timeout promise with timeout Angular object
* @param {Object} constants modules that contain all the constants
* @return {Object} service common service
*/
function commonService($translate, events, $timeout, constants) {
function commonService($translate, $rootScope, events, $timeout, constants) {

const service = {
parseJSON,
Expand All @@ -36,7 +37,8 @@ function commonService($translate, events, $timeout, constants) {
clickTab,
clickSubTab,
scrollToElement,
validServiceUrl
validServiceUrl,
validateForm
};

let languages;
Expand Down Expand Up @@ -106,6 +108,15 @@ function commonService($translate, events, $timeout, constants) {
return Array.from(new Set(arr));
}

/**
* Validate form after the current language is set to the supplied value.
* @function validateForm
*/
function validateForm() {
// validate form
$rootScope.$broadcast('schemaFormValidate');
}

/**
* Sets the current language to the supplied value and broadcasts schema initialization event.
* @function setLang
Expand Down
43 changes: 37 additions & 6 deletions src/app/ui/forms/form.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,51 @@ function formService($timeout, $rootScope, events, $mdDialog, $translate, keyNam
* @function setErrorMessage
* @param {Object} form form object to get value from
* @param {String} message message to get from translation.csv
* @param {Array} variables variables to replace
* @param {Array} variables variables to replace
* @return {String} mess the updated message
*/
function setErrorMessage(form, message, variables) {
let mess = $translate.instant(message);

for (let variable of variables) {
let errorcode = form.error;
// if value is not a valid number, called by opacity if invalid value
if (errorcode === 'number') {
mess = $translate.instant('form.map.wkidnuminvalid');
} // value is greater than maximum,called by opacity value positive 2 digits
if (errorcode === 'max') {
mess = $translate.instant('form.map.layeropacitymaxerr');
} // value is les than minimim, called by opacity, value negative 2 digits
if (errorcode === 'min') {
mess = $translate.instant('form.map.extentdefxminerr');
} // value is required wkid, extents, id, name, description, alt text
else if (errorcode === '302') {
mess = $translate.instant('form.map.requirederr');
} // number less than minimum, called by expand factor, opacity, tolerance
else if ((errorcode === '101') && (message === '')) {
mess = $translate.instant('form.map.extentdefxminerr');
} // number greater than maximum called by opacity - single value
else if ((errorcode === '103') && (message === '')) {
mess = $translate.instant('form.map.layeropacitymaxerr');
}
else if (message !=='') {
mess = $translate.instant(message);
}
if (typeof variables !== 'undefined') {
for (let variable of variables) {
// get the replacing value from form object
let replace = form;
variable.split('.').map(item => { replace = replace[item] });
let replace = form;
variable.split('.').map(item => { replace = replace[item] });

// replace value in the message
mess = mess.replace(`{${variable}}`, replace);
// replace value in the message
mess = mess.replace(`{${variable}}`, replace);
}
}
else if (typeof variables === 'undefined') {
// replace values in message string if no parameters passed to replace them with
mess = mess.replace(/{.+?}/, ' ');
mess = mess.replace(/{.+?}/, ' ');
mess = mess.replace("( )", ' ');
}

return mess;
}
Expand Down
Loading

0 comments on commit 652b319

Please sign in to comment.