Skip to content

Commit

Permalink
Application now ignores settings for storage & API-Key in config.groo…
Browse files Browse the repository at this point in the history
…vy. These values can now be adjusted in the user-interface. If the values are empty at first, the user gehts redirected to the settings page when trying to access the dashboard.
  • Loading branch information
dularion committed Jul 31, 2015
1 parent 3cdf99b commit 68cf2fb
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 113 deletions.
7 changes: 4 additions & 3 deletions grails-app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//
// Any JavaScript file within this directory can be referenced here using a relative path.
//
// You're free to add application-wide JavaScript to this file, but it's generally better
// You're free to add application-wide JavaScript to this file, but it's generally better
// to create separate JavaScript files as needed.
//
//= require jquery
//= require spring-websocket
//= require jquery/dist/jquery.js
//= require angular/angular.js
//= require angular-ui-router/release/angular-ui-router.js
//= require angular-sanitize/angular-sanitize.js
Expand All @@ -18,6 +18,7 @@
//= require jquery-ui-1.11.4.custom/jquery-ui.js
//= require angular-ui-slider/src/slider.js
//= require mousetrap/mousetrap.js
//= require Autolinker.js/dist/Autolinker.js
//= require streama-app.js
//= require_tree .
//= require_self
//= require_self
59 changes: 59 additions & 0 deletions grails-app/assets/javascripts/controllers/admin-settings-ctrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

streamaApp.controller('adminSettingsCtrl', ['$scope', 'apiService', '$sce', function ($scope, apiService, $sce) {

$scope.loading = true;

apiService.settings.list().success(function (data) {
$scope.settings = data;

_.forEach(data, function (setting) {
setting.description = $sce.trustAsHtml(Autolinker.link(setting.description, { newWindow: "true" } ));
});
$scope.loading = false;
});

$scope.updateMultipleSettings = function (settings) {
settings.invalid = false;

apiService.settings.updateMultiple(settings)
.success(function () {
window.location.reload();
})
.error(function () {
alertify.error('There was an error saving your settings. Please refer to the server-log.');
});
};


$scope.validateSettings = function (settings) {
$scope.changeValue(settings);
$scope.loading = true;

apiService.settings.validateSettings(settings)
.success(function (data) {
alertify.success(data.message);
settings.valid = true;
$scope.loading = false;
})
.error(function (data) {
alertify.error(data.message);
settings.invalid = true;
$scope.loading = false;
});
};

$scope.changeValue = function (settings) {
settings.valid = undefined;
settings.invalid = undefined;
settings.dirty = settings.value;
};


$scope.anySettingsInvalid = function () {
return _.find($scope.settings, function (setting) {
return setting.invalid || (setting.dirty && !setting.valid) || !setting.value;
});
};

}]);
38 changes: 24 additions & 14 deletions grails-app/assets/javascripts/controllers/dash-ctrl.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
'use strict';

streamaApp.controller('dashCtrl', ['$scope', 'apiService', function ($scope, apiService) {
streamaApp.controller('dashCtrl', ['$scope', 'apiService', '$state', function ($scope, apiService, $state) {
$scope.loading = true;

apiService.video.dash()
.success(function (data) {
$scope.episodes = data.firstEpisodes;
$scope.continueWatching = data.continueWatching;
$scope.movies = data.movies;
$scope.loading = false;
})
.error(function () {
alertify('A server error occured.');
$scope.loading = false;
});

}]);
apiService.settings.list().success(function (data) {
var TheMovieDbAPI = _.find(data, {settingsKey: 'TheMovieDB API key'});

if(!TheMovieDbAPI.value){
alertify.alert('You need to fill out some required base-settings. You will be redirected to the settings page now.', function () {
$state.go('admin.settings');
});
}else{
apiService.video.dash()
.success(function (data) {
$scope.episodes = data.firstEpisodes;
$scope.continueWatching = data.continueWatching;
$scope.movies = data.movies;
$scope.loading = false;
})
.error(function () {
alertify('A server error occured.');
$scope.loading = false;
});
}
});

}]);
23 changes: 18 additions & 5 deletions grails-app/assets/javascripts/services/api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ streamaApp.factory('apiService', ['$http', function ($http) {
currentUser: function () {
return $http.get(urlBase + 'user/current.json');
},


tvShow: {
get: function (id) {
return $http.get(urlBase + 'tvShow/show.json', {params: {id: id}});
Expand Down Expand Up @@ -89,7 +89,7 @@ streamaApp.factory('apiService', ['$http', function ($http) {
return $http.get(urlBase + 'episode.json', {params: params});
}
},

movie: {
get: function (id) {
return $http.get(urlBase + 'movie/show.json', {params: {id: id}});
Expand All @@ -115,6 +115,19 @@ streamaApp.factory('apiService', ['$http', function ($http) {
},


settings: {
list: function () {
return $http.get(urlBase + 'settings.json');
},
updateMultiple: function (data) {
return $http.post(urlBase + 'settings/updateMultiple.json', data);
},
validateSettings: function (data) {
return $http.post(urlBase + 'settings/validateSettings.json', data);
}
},


theMovieDb: {
search: function (type, name) {
return $http.get(urlBase + 'theMovieDb/search.json', {params: {type: type, name: name}});
Expand All @@ -123,11 +136,11 @@ streamaApp.factory('apiService', ['$http', function ($http) {
return $http.get(urlBase + 'theMovieDb/seasonForShow.json', {params: params});
}
},

websocket: {
triggerPlayerAction: function (params) {
return $http.get(urlBase + 'websocket/triggerPlayerAction.json', {params: params});
}
}
};
}]);
}]);
8 changes: 6 additions & 2 deletions grails-app/assets/javascripts/services/upload-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ streamaApp.factory('uploadService', ['$http', 'Upload', '$location', function ($
uploadStatus.percentage = progressPercentage;
})

.success(callback || angular.noop);
.success(callback || angular.noop)
.error(function (err) {
console.log('%c err', 'color: deeppink; font-weight: bold; text-shadow: 0 0 5px deeppink;', arguments);
alertify.error(err)
});

}
}
}
};
}]);
}]);
12 changes: 11 additions & 1 deletion grails-app/assets/javascripts/streama-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ streamaApp.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', func
templateUrl: 'admin-users.htm',
controller: 'adminUsersCtrl'
})
.state('admin.settings', {
url: '/settings',
templateUrl: 'admin-settings.htm',
controller: 'adminSettingsCtrl'
})
.state('admin.shows', {
url: '/shows',
templateUrl: 'admin-shows.htm',
Expand Down Expand Up @@ -70,6 +75,11 @@ streamaApp.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', func
return response || $q.when(response);
},
responseError: function (response) {

if(response.status != 404){
alertify.error('A system error occurred');
}

return $q.reject(response);
}
};
Expand All @@ -80,4 +90,4 @@ streamaApp.run(['$rootScope', '$state', function ($rootScope, $state) {
$rootScope.isCurrentState = function (stateName) {
return ($state.current.name == stateName);
};
}]);
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1>
Settings

<div class="spinner" ng-show="loading">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</h1>



<hr/>

<form name="settings-form" class="settings-form">
<div class="form-group row-slim" ng-repeat="setting in settings">
<div class="col-sm-3">
<label class="control-label">{{setting.settingsKey}}</label>
</div>
<div class="col-sm-7" ng-class="{'has-error has-feedback': setting.invalid, 'has-success has-feedback': setting.valid}">
<input required type="text" class="form-control" ng-model="setting.value" placeholder="{{setting.settingsKey}}" ng-change="changeValue(setting)">

<span class="glyphicon ion-close form-control-feedback" ng-show="setting.invalid" aria-hidden="true"></span>
<span class="glyphicon ion-checkmark form-control-feedback" ng-show="setting.valid" aria-hidden="true"></span>

</div>
<div class="col-sm-2">
<button type="button" class="btn btn-success btn-block" ng-click="validateSettings(setting)" ng-show="!setting.valid && setting.dirty">validate</button>
</div>
<div class="col-sm-7 col-sm-offset-3">
<p class="settings-description" ng-bind-html="setting.description"></p>
</div>
</div>
</form>


<hr/>

<button class="btn btn-primary" ng-click="updateMultipleSettings(settings)" ng-disabled="anySettingsInvalid()">Save Settings</button>

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
<li ng-class="{'active': isCurrentState('admin.users')}">
<a ui-sref="admin.users">Users</a>
</li>
<li ng-class="{'active': isCurrentState('admin.settings')}">
<a ui-sref="admin.settings">Settings</a>
</li>
</ul>
</div>

<div class="admin-content">
<ui-view/>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions grails-app/assets/stylesheets/_settings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.settings-form{
@include clearfix;

.settings-description{
margin-top: 7px;
opacity: 0.8;
margin-bottom: 30px;
}
}
9 changes: 9 additions & 0 deletions grails-app/assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4245,3 +4245,12 @@ body.mdx-active #mdx-control-view {
.modal-dialog .modal-footer {
border-color: rgba(255, 255, 255, 0.25);
padding: 9px 14px; }

.settings-form:after {
content: "";
display: table;
clear: both; }
.settings-form .settings-description {
margin-top: 7px;
opacity: 0.8;
margin-bottom: 30px; }
1 change: 1 addition & 0 deletions grails-app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
@import "player-controls";
@import "invite";
@import "modal";
@import "settings";
3 changes: 2 additions & 1 deletion grails-app/conf/BootStrap.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class BootStrap {

def marshallerService
def defaultDataService

def init = { servletContext ->
marshallerService.init()
defaultDataService.createDefaultRoles()
defaultDataService.createDefaultUsers()
defaultDataService.createDefaultSettings()
}
def destroy = {
}
Expand Down
10 changes: 2 additions & 8 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ log4j.main = {
}


streama {
storage {
path = "/data/streama"
}
themoviedbAPI = "e1584c7cc0072947d4776de6df7b8822"
}

grails.databinding.dateFormats = [
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", // javascript format in json
Expand All @@ -167,13 +161,12 @@ grails.databinding.dateFormats = [
grails.plugin.springsecurity.userLookup.userDomainClassName = 'streama.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'streama.UserRole'
grails.plugin.springsecurity.authority.className = 'streama.Role'
grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/user/loginTarget'

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/': ['IS_AUTHENTICATED_REMEMBERED'],
'/index': ['IS_AUTHENTICATED_REMEMBERED'],
'/index.gsp': ['IS_AUTHENTICATED_REMEMBERED'],

'/tvShow/**': ['IS_AUTHENTICATED_REMEMBERED'],
'/video/**': ['IS_AUTHENTICATED_REMEMBERED'],
'/viewingStatus/**': ['IS_AUTHENTICATED_REMEMBERED'],
Expand All @@ -186,6 +179,7 @@ grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/appSettings/**': ['IS_AUTHENTICATED_REMEMBERED'],
'/stomp/**': ['IS_AUTHENTICATED_REMEMBERED'],
'/websocket/**': ['IS_AUTHENTICATED_REMEMBERED'],
'/settings/**': ['IS_AUTHENTICATED_REMEMBERED'],

'/invite/**': ['permitAll'],
'/assets/**': ['permitAll'],
Expand Down
2 changes: 2 additions & 0 deletions grails-app/conf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class UrlMappings {
}

"/"(view:"/index")
"/setSettings"(view:'/setSettings')

"500"(view:'/error')
}
}
Loading

0 comments on commit 68cf2fb

Please sign in to comment.