-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
576b4ac
commit 49cb656
Showing
6 changed files
with
116 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,6 +552,17 @@ angular.module('idai.components') | |
* transl8keys, which are also used to automatically | ||
* retrieve the message texts via transl8. | ||
* | ||
* <b>Note</b> that the basic assumption here is that the | ||
* iDAI transl8 service tool is up and running and the translations have | ||
* been fetched when calling methods of the message service. | ||
* The assumption is made because we say that if the transl8 service is | ||
* down you cannot navigate anyway so you will not try to perform actions | ||
* that require communication with users, which is the purpose of this service. | ||
* | ||
* Another assumption is that a transl8Key used to add a message exists and | ||
* that the developer is responsible for creating it prior to using it. For this | ||
* reason exceptions get thrown if unkown transl8Keys are used. | ||
* | ||
* @author Sebastian Cuy | ||
* @author Daniel M. de Oliveira | ||
*/ | ||
|
@@ -560,20 +571,47 @@ angular.module('idai.components') | |
.factory('message', [ '$rootScope', 'transl8', function( $rootScope, transl8 ) { | ||
|
||
/** | ||
* A Map. | ||
* A Map [transl8Key,message]. | ||
*/ | ||
var messages = {}; | ||
|
||
/** | ||
* The message data structure. | ||
* @param transl8Key | ||
*/ | ||
function Message(transl8Key) { | ||
this.text = transl8.getTranslation(transl8Key); | ||
this.level = 'warning'; | ||
this.contactInfo = transl8.getTranslation('components.message.contact') | ||
.replace('CONTACT', '[email protected]'); | ||
} | ||
|
||
function isUnknown(level){ | ||
return (['success', 'info', 'warning', 'danger'].indexOf(level) === -1); | ||
} | ||
|
||
/** | ||
* Clears all the actual messages. | ||
* @private | ||
*/ | ||
function _clear() { | ||
angular.forEach(messages, function(msg, key) { | ||
delete messages[key]; | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a new message and adds it to the actual messages. | ||
* @param transl8Key | ||
* @returns {*} | ||
* @private | ||
*/ | ||
function _create(transl8Key) { | ||
messages[transl8Key]= new Message(transl8Key); | ||
return messages[transl8Key]; | ||
} | ||
|
||
|
||
/** | ||
* Clear actual messages when location changes. | ||
*/ | ||
|
@@ -601,20 +639,16 @@ angular.module('idai.components') | |
*/ | ||
addMessageForCode: function(transl8Key, level, showContactInfo) { | ||
|
||
messages[transl8Key] = { | ||
text: transl8.getTranslation(transl8Key), | ||
level: 'warning', | ||
contactInfo: 'Please contact [email protected] if the errors persist.' | ||
}; | ||
var message = _create(transl8Key); | ||
|
||
if (level) { | ||
if (isUnknown(level)) | ||
throw new Error("If used, level must be set to an allowed value."); | ||
messages[transl8Key].level = level; | ||
message.level = level; | ||
} | ||
|
||
if (showContactInfo==false||messages[transl8Key].level=='success') | ||
delete messages[transl8Key].contactInfo; | ||
if (showContactInfo==false||message.level=='success') | ||
delete message.contactInfo; | ||
}, | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -552,6 +552,17 @@ angular.module('idai.components') | |
* transl8keys, which are also used to automatically | ||
* retrieve the message texts via transl8. | ||
* | ||
* <b>Note</b> that the basic assumption here is that the | ||
* iDAI transl8 service tool is up and running and the translations have | ||
* been fetched when calling methods of the message service. | ||
* The assumption is made because we say that if the transl8 service is | ||
* down you cannot navigate anyway so you will not try to perform actions | ||
* that require communication with users, which is the purpose of this service. | ||
* | ||
* Another assumption is that a transl8Key used to add a message exists and | ||
* that the developer is responsible for creating it prior to using it. For this | ||
* reason exceptions get thrown if unkown transl8Keys are used. | ||
* | ||
* @author Sebastian Cuy | ||
* @author Daniel M. de Oliveira | ||
*/ | ||
|
@@ -560,20 +571,47 @@ angular.module('idai.components') | |
.factory('message', [ '$rootScope', 'transl8', function( $rootScope, transl8 ) { | ||
|
||
/** | ||
* A Map. | ||
* A Map [transl8Key,message]. | ||
*/ | ||
var messages = {}; | ||
|
||
/** | ||
* The message data structure. | ||
* @param transl8Key | ||
*/ | ||
function Message(transl8Key) { | ||
this.text = transl8.getTranslation(transl8Key); | ||
this.level = 'warning'; | ||
this.contactInfo = transl8.getTranslation('components.message.contact') | ||
.replace('CONTACT', '[email protected]'); | ||
} | ||
|
||
function isUnknown(level){ | ||
return (['success', 'info', 'warning', 'danger'].indexOf(level) === -1); | ||
} | ||
|
||
/** | ||
* Clears all the actual messages. | ||
* @private | ||
*/ | ||
function _clear() { | ||
angular.forEach(messages, function(msg, key) { | ||
delete messages[key]; | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a new message and adds it to the actual messages. | ||
* @param transl8Key | ||
* @returns {*} | ||
* @private | ||
*/ | ||
function _create(transl8Key) { | ||
messages[transl8Key]= new Message(transl8Key); | ||
return messages[transl8Key]; | ||
} | ||
|
||
|
||
/** | ||
* Clear actual messages when location changes. | ||
*/ | ||
|
@@ -601,20 +639,16 @@ angular.module('idai.components') | |
*/ | ||
addMessageForCode: function(transl8Key, level, showContactInfo) { | ||
|
||
messages[transl8Key] = { | ||
text: transl8.getTranslation(transl8Key), | ||
level: 'warning', | ||
contactInfo: 'Please contact [email protected] if the errors persist.' | ||
}; | ||
var message = _create(transl8Key); | ||
|
||
if (level) { | ||
if (isUnknown(level)) | ||
throw new Error("If used, level must be set to an allowed value."); | ||
messages[transl8Key].level = level; | ||
message.level = level; | ||
} | ||
|
||
if (showContactInfo==false||messages[transl8Key].level=='success') | ||
delete messages[transl8Key].contactInfo; | ||
if (showContactInfo==false||message.level=='success') | ||
delete message.contactInfo; | ||
}, | ||
|
||
/** | ||
|
Oops, something went wrong.