refactor(*): simplify message API

test-unit-sauce
Brian Ford 10 years ago
parent decec2685d
commit 556b6d0e0b

@ -19,16 +19,19 @@
</ul>
<div class="row" style="padding: 5px 0px">
<div class="col-md-2">
<!--
<ul class="nav nav-pills nav-stacked">
<li ng-class="{active: type === label}" ng-repeat="label in labels" ng-click="setType(label)">
<a class="offsetTab">{{label}}</a>
</li>
</ul>
-->
<!--
<div ng-show="suppressedMessagesLength">
<hr>
<h5 class="offsetTab">Suppressed Errors:</h5>
<ul class="nav nav-pills nav-stacked">
<li ng-repeat="(key,message) in suppressedMessages">
<li ng-repeat="(key, message) in suppressedMessages">
<div class="suppressedMessage">
<div class='alert alert-warning condenseAlert'>
{{message}}
@ -42,39 +45,31 @@
</li>
</ul>
</div>
-->
</div>
<div class="col-md-10">
<div class="input-group">
<div class="input-group-addon"><span class="glyphicon glyphicon-search"></span></div>
<input class="form-control" type="text" placeholder="Search Messages" ng-model="search">
</div>
<table class="table table-striped table-hover" ng-show="messageData[module][type].length">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>No.</th>
<th ng-show="module === 'All' && type === 'All Messages' ">Module</th>
<th>Module</th>
<th>Message</th>
<th ng-show="type === 'All Messages'">Type</th>
<th>Suppress</th>
<th>Severity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="message in messageData[module][type] | filter:search"
ng-class="{danger: type === 'All Messages' && message.type === 'Error Messages',
warning: type === 'All Messages' && message.type === 'Warning Messages',
info: type === 'All Messages' && message.type === 'Suggestion Messages'}"
ng-hide="isSuppressed(message.message)">
<tr ng-repeat="hint in hints">
<td>{{$index + 1}}</td>
<td ng-show="module === 'All' && type === 'All Messages'">{{message.module}}</td>
<td>{{message.message || message}}</td>
<td ng-show="type === 'All Messages'">{{ message.type.split(' ')[0] }}</td>
<td align="center"><button type="button" class="btn btn-default btn-xs" ng-click="suppressMessage(message.message)"><span class="glyphicon glyphicon-minus-sign"></span></button></td>
<td>{{hint.module}}</td>
<td>{{hint.message}}</td>
<td>{{hint.severity}}</td>
</tr>
</tbody>
</table>
<div ng-show="!messageData[module][type].length">
<h3>There are no messages in this category.</h3>
</div>
</div>
</div>
</div>

@ -6,6 +6,17 @@ var customEvent = document.createEvent('Event');
customEvent.initEvent('myCustomEvent', true, true);
angular.hint.onMessage = function (moduleName, message, messageType) {
eventProxyElement.innerText = moduleName + '##' + message + '##' + messageType;
if (!message) {
message = moduleName;
moduleName = 'Unknown'
}
if (typeof messageType === 'undefined') {
messageType = 1;
}
eventProxyElement.innerText = JSON.stringify({
module: moduleName,
message: message,
severity: messageType
});
eventProxyElement.dispatchEvent(customEvent);
};

@ -1,106 +1,6 @@
angular.module('ngHintUI', []).
controller('HintController', ['$scope', 'hintService',
function($scope, hintService) {
//Set the hint service to perform this action when the page is refreshed
hintService.onRefresh(function() {
$scope.messageData = {
'All' : {
'Error Messages': [],
'Warning Messages': [],
'Suggestion Messages': [],
'All Messages': []
}
};
});
//Set the hint service to perform this action whenever
//a new hint message is received.
hintService.onHint(function(msg) {
//If there is no scope data, initialize a new data object
$scope.messageData = $scope.messageData || {
'All' : {
'Error Messages': [],
'Warning Messages': [],
'Suggestion Messages': [],
'All Messages': []
}
};
// Split the hint message into useful information
var result = msg.split('##'),
modName = result[0],
message = result[1],
messageType = result[2];
//If there are no messages for this module, make new arrays for this module's messages
if(!$scope.messageData[modName]) {
$scope.messageData[modName] = {
'Error Messages': [],
'Warning Messages': [],
'Suggestion Messages': [],
'All Messages': []
};
}
$scope.messageData['All']['All Messages'].push({
message: message,
type: messageType,
module: modName
});
if(!$scope.messageData['All'][messageType]) {
$scope.messageData['All'][messageType] = [];
}
$scope.messageData['All'][messageType].push(message);
$scope.messageData[modName]['All Messages'].push({message: message, type: messageType});
$scope.messageData[modName][messageType].push(message);
});
$scope.suppressedMessages = {};
$scope.suppressedMessagesLength = 0;
$scope.labels = ['All Messages', 'Error Messages', 'Warning Messages', 'Suggestion Messages'];
$scope.setModule = function(module) {
$scope.module = module;
};
$scope.setType = function(type) {
$scope.type = type;
};
$scope.setModule('All');
$scope.setType('All Messages');
$scope.isSuppressed = function(message) {
message = message.split(' ').slice(6,9).join('');
return message in $scope.suppressedMessages;
};
$scope.suppressMessage = function(message) {
$scope.suppressedMessagesLength++;
var key = message.split(' ').slice(6,9).join('');
var secondSpace = message.indexOf(' ', message.indexOf(' '));
var endInd = 60;
while(message.charAt(endInd) !== ' ') {
endInd++;
if(endInd > 75) {
break;
}
}
$scope.suppressedMessages[key] = '...' + message.substr(secondSpace+1,endInd) + '...';
};
$scope.unsuppressMessage = function(messageKey) {
$scope.suppressedMessagesLength--;
delete $scope.suppressedMessages[messageKey];
};
}]).
controller('HintController', ['$scope', 'hintService', HintController]).
service('hintService', ['$rootScope', function($rootScope) {
var onHintCallback,
@ -121,7 +21,8 @@ service('hintService', ['$rootScope', function($rootScope) {
if (msg === 'refresh') {
onRefreshCallback();
} else {
onHintCallback(msg);
var hint = JSON.parse(msg);
onHintCallback(hint);
}
});
});
@ -132,3 +33,20 @@ service('hintService', ['$rootScope', function($rootScope) {
}]);
function HintController($scope, hintService) {
resetMessageData();
// TODO: rename this ?
hintService.onRefresh(resetMessageData);
function resetMessageData() {
$scope.hints = [];
}
//Set the hint service to perform this action whenever
//a new hint message is received.
hintService.onHint(function(hint) {
$scope.hints.push(hint);
});
}