Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alert service can be called from anywhere do display an alert bar on top of the window. Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
- Loading branch information
Pierre Tardy
committed
Aug 10, 2013
1 parent
4a7896a
commit c1b7e5b
Showing
4 changed files
with
88 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
angular.module('app').controller 'alertPanelController', | ||
['$log', '$scope', '$rootScope', '$timeout', 'alert' | ||
($log, $scope, $rootScope, $timeout) -> | ||
$scope.alerts = [] | ||
$scope.closeAlert = (index) -> | ||
$scope.alerts.splice(index, 1) | ||
|
||
$rootScope.$on 'alert', (ev, p) -> | ||
found = false | ||
for v in $scope.alerts | ||
if v.msg is p.msg | ||
found = true | ||
v.occur ?= 1 | ||
v.occur += 1 | ||
v.occur_msg = "(x#{v.occur})" | ||
if not found | ||
$scope.alerts.push p | ||
$timeout( -> | ||
for i, v of $scope.alerts | ||
if v is p | ||
$scope.closeAlert(i) | ||
null | ||
, 10000) | ||
] |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
angular.module('app').factory 'alert', ['$rootScope', ($rootScope) -> | ||
|
||
alert = (msg, type) -> | ||
type ?= 'danger' | ||
$rootScope.$broadcast 'alert', type:type, msg: msg | ||
|
||
alert.error = (msg) -> | ||
alert msg, 'danger' | ||
|
||
alert.warning = (msg) -> | ||
alert msg, 'info' | ||
|
||
alert.success = (msg) -> | ||
alert msg, 'success' | ||
window.alert = alert | ||
return alert | ||
] | ||
angular.module('app').config ['$httpProvider', ($httpProvider) -> | ||
$httpProvider.responseInterceptors.push ["alert", (alert) -> | ||
return (promise) -> | ||
promise.then (res)-> | ||
res | ||
, (res) -> | ||
if res.config.url.indexOf("views") == 0 and res.status == 404 | ||
alert.error "view does not exist: " + res.config.url | ||
else | ||
console.log res | ||
alert.error res.data | ||
] | ||
|
||
] |
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 |
---|---|---|
@@ -1,5 +1,34 @@ | ||
@import "bootstrap.less"; | ||
@import "font-awesome/font-awesome.less"; | ||
|
||
.ng-cloak { | ||
display: none; | ||
} | ||
} | ||
|
||
.repeat-enter { | ||
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
|
||
opacity:0; | ||
position:relative; | ||
} | ||
|
||
.repeat-enter.repeat-enter-active { | ||
opacity:1; | ||
} | ||
|
||
.repeat-leave { | ||
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s; | ||
|
||
opacity:1; | ||
position:relative; | ||
} | ||
|
||
.repeat-leave.repeat-leave-active { | ||
opacity:0; | ||
} |