Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Commit

Permalink
+display server messages, errors...
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdemonte committed Jan 19, 2017
1 parent 41f3c52 commit 943bb72
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 236 deletions.
55 changes: 50 additions & 5 deletions public/app.js
Expand Up @@ -3,7 +3,6 @@
var app = angular.module('app', ['ui.router', 'ngFileUpload', 'infinite-scroll']);

app.config(['$stateProvider', '$httpProvider', '$locationProvider', function ($stateProvider, $httpProvider, $locationProvider) {

$httpProvider.defaults.headers.delete = {"Content-Type": "application/json;charset=utf-8"};

var systemResolver = ['$stateParams', function ($stateParams) {
Expand Down Expand Up @@ -79,7 +78,7 @@ app.config(['$stateProvider', '$httpProvider', '$locationProvider', function ($s
return $http
.get('api/sources')
.then(function (response) {
return response.data;
return response.data.sources;
});
}]
}
Expand All @@ -94,7 +93,7 @@ app.config(['$stateProvider', '$httpProvider', '$locationProvider', function ($s
return $http
.get('api/sources/' + $stateParams.sourceId)
.then(function (response) {
return response.data;
return response.data.source;
});
}]
}
Expand Down Expand Up @@ -147,7 +146,7 @@ app.config(['$stateProvider', '$httpProvider', '$locationProvider', function ($s
return $http
.get('api/system/' + $stateParams.systemId + '/sources/' + $stateParams.sourceId)
.then(function (response) {
return response.data;
return response.data.source;
});
}]
}
Expand Down Expand Up @@ -212,6 +211,53 @@ app.component('uploadingList', {
}
});

app.component('serverMessage', {
templateUrl: '/partials/server-message.html',
controller: ['$timeout', 'socket', function ($timeout, socket) {
var self = this;
var count = 0;

self.messages = [{information: true, msg: 'Pause for 3000ms', visible:true}];

self.remove = function (message) {
self.messages.splice(self.messages.indexOf(message), 1);
};

function display(message, duration) {
message.id = 'message-' + Date.now() + '-' + (count++);
self.messages.push(message);


$timeout(function () {
message.visible = true;
angular.element(document.getElementById(message.id)).css('maxHeight', '100px');
}, 100);
$timeout(function () {
message.visible = false;
angular.element(document.getElementById(message.id)).css({maxHeight: '0px'});

$timeout(function () {
self.remove(message);
}, 500);

}, duration || 3000);

}

socket.on('server-error', function (data) {
display({error: true, msg: data.error}, 10000);
});

socket.on('pause', function (data) {
display({information: true, msg: 'Pause for ' + data.duration + 'ms'});
});

socket.on('complete', function (data) {
display({congrats: true, msg: 'Download complete (' + data.game.name + ')'});
});
}]
});

app.filter("noExtension", function () {
return function (file) {
file = file.split('.');
Expand Down Expand Up @@ -246,7 +292,6 @@ app.controller('HomeCtrl', ['$scope', function ($scope) {
}]);

app.controller('BiosCtrl', ['$scope', '$http', 'Upload', 'listing', function ($scope, $http, Upload, listing) {

$scope.selected = {};
$scope.bios = [];
$scope.uploading = [];
Expand Down
6 changes: 6 additions & 0 deletions public/partials/server-message.jade
@@ -0,0 +1,6 @@
.message(ng-repeat="message in $ctrl.messages", ng-class="{error: message.error, congrats: message.congrats, visible: message.visible}", id="{{::message.id}}")
i.msg-type.fa.fa-exclamation-triangle(ng-if="message.error")
i.msg-type.fa.fa-info-circle(ng-if="message.information")
i.msg-type.fa.fa-check-circle-o(ng-if="message.congrats")
i.fa.fa-times(ng-click="$ctrl.remove(message)")
span {{::message.msg}}
42 changes: 42 additions & 0 deletions public/stylesheets/styl/component/server-message.styl
@@ -0,0 +1,42 @@
server-message
position absolute
right 10px
bottom 10px

.message
color #fff
text-align center
padding 0
animation max-height 1s linear
min-width 200px
max-height 0
position relative
overflow hidden
background #00a3ff

.msg-type
position absolute
top 10px
left 10px

i.fa-times
position absolute
top 1px
right 1px
border 1px solid transparent
padding 1px 2px
border-radius 3px
&:hover
cursor pointer
background rgba(204, 204, 204, 0.4)

span
display block
padding 10px 25px 10px 35px

& + .message
margin-top 5px
&.error
background #e44949
&.congrats
background #00dc65

0 comments on commit 943bb72

Please sign in to comment.