Skip to content

Commit

Permalink
Merge branch 'v1.11'
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeSteward committed Mar 5, 2021
2 parents 31501c6 + a5a7858 commit 8fc43ca
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//= wrapped

angular.module('streama').controller('adminCertificationsCtrl', [
'apiService', '$state', '$rootScope', '$filter', function (apiService, $state, $rootScope, $filter) {
var vm = this;

vm.addCertification = addCertification;
vm.importCertifications = importCertifications;
vm.deleteCertification = deleteCertification;

apiService.certifications.list().then(function (response){
vm.certifications = response.data;
});


function addCertification(){
alertify.set({ buttonReverse: true, labels: {ok: "Create", cancel : "Cancel"}});
alertify.prompt('Add a new custom certification.', function (confirmed, name) {
if(confirmed){
apiService.certifications.create(name).then(function (response) {
alertify.success('The Certification was created.');
vm.certifications.push(response.data);
});
}
})
}

function importCertifications(type){
apiService.certifications.import(type).then(function (response) {
alertify.success(response.data.length + 'Certifications were imported.');
$state.reload();
// vm.certifications.push(response.data);
});
}

function deleteCertification(id){
alertify.set({ buttonReverse: true, labels: {ok: "Yes", cancel : "Cancel"}});
alertify.confirm("Are you sure, you want to delete this Certification?", function (confirmed) {
if(confirmed){
apiService.certifications.delete(id).then(function () {
_.remove(vm.certifications, {id: id});
}, function (){
alertify.error('Certification is probably used in a video / tvShow or liked by a user. Delete all usages first, then try again.')
});
}
})
}

}]);


18 changes: 18 additions & 0 deletions grails-app/assets/javascripts/streama/services/api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,24 @@ angular.module('streama').factory('apiService', function ($http, $rootScope, con
}
},

certifications: {
get: function (id) {
return $http.get('certification/show.json', {params: {id: id}});
},
import: function (type) {
return $http.get('certification/importCertifications.json', {params: {type: type}});
},
list: function () {
return $http.get('certification.json');
},
create: function (name) {
return $http.post('certification/save', {name: name});
},
delete: function (id) {
return $http.delete('certification/delete', {params: {id: id}});
}
},

settings: {
list: function () {
return $http.get('settings.json');
Expand Down
2 changes: 2 additions & 0 deletions grails-app/assets/javascripts/streama/streama.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//= require_tree filters
//= require_tree templates

//= require_tree genre

//= require streama.run
//= require streama.routes
//= require streama.interceptor
Expand Down
7 changes: 7 additions & 0 deletions grails-app/assets/javascripts/streama/streama.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ angular.module('streama').config(function ($stateProvider) {
controllerAs: "vm"
})

.state('admin.certifications', {
url: '/certifications',
templateUrl: '/streama/admin-certifications.htm',
controller: 'adminCertificationsCtrl',
controllerAs: "vm"
})



//SETTINGS ROUTES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

<div class="row">
<div class="col-xs-8">
<h1>Certification <span class="text-muted text-xs">({{vm.certifications.length}} items)</span></h1>
<p>Here you can manage the certifications for Videos / TvShows.</p>
<p>Usually, Certification are automatically added alongside TMDb-videos & shows. But if TMDb isn't enabled or you want to add your own custom Certifications, you can do so here.</p>
</div>
<div class="col-xs-4 text-right">
<br>
<div class="btn-group">
<button class="btn btn-sm btn-primary" ng-click="vm.addCertification()">Add new</button>
<button class="btn btn-sm btn-default" ng-click="vm.importCertifications('movie')">Import For Movies</button>
<button class="btn btn-sm btn-default" ng-click="vm.importCertifications('tv')">Import For TV-Shows</button>
</div>
</div>
</div>


<div>
<table class="table table-striped table-reports">
<thead>
<tr>
<th>ID</th>
<th>Certification</th>
<th>Type</th>
<th>Description</th>
<th></th>
</tr>
</thead>
<tr ng-repeat="certification in vm.certifications | orderBy:'-id' ">
<td>
{{certification.id}}
</td>
<td>
{{certification.certification}}
</td>
<td>
{{certification.type}}
</td>
<td>
{{certification.description}}
</td>

<td>
<button class="btn btn-xs btn-danger" ng-click="vm.deleteCertification(certification.id)">Delete</button>
</td>
</tr>
</table>


</div>
3 changes: 3 additions & 0 deletions grails-app/assets/javascripts/streama/templates/admin.tpl.htm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<li ng-class="{'active': isCurrentState('admin.genres')}" ng-if="$root.currentUser.isContentManager">
<a ui-sref="admin.genres">Genres</a>
</li>
<li ng-class="{'active': isCurrentState('admin.certifications')}" ng-if="$root.currentUser.isContentManager">
<a ui-sref="admin.certifications">Certifications</a>
</li>
</ul>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</div>
</div>

<div ng-hide="addManually">
<div>
<div class="form-group">
<div class="col-sm-12">
<label>Genre</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</div>
</div>

<div ng-hide="tvShow.manualInput">
<div>
<div class="form-group">
<div class="col-sm-12">
<label>Genre</label>
Expand Down
1 change: 1 addition & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ grails.plugin.springsecurity.controllerAnnotations.staticRules = [
[pattern:'/subtitles/getVideoSubtitles', access :['IS_AUTHENTICATED_REMEMBERED']],

[pattern:'/genericVideo/**', access :['ROLE_CONTENT_MANAGER']],
[pattern:'/certification/**', access :['ROLE_CONTENT_MANAGER']],
[pattern:'/genre/**', access :['ROLE_CONTENT_MANAGER']],
[pattern:'/tvShow/**', access :['ROLE_CONTENT_MANAGER']],
[pattern:'/video/**', access :['ROLE_CONTENT_MANAGER']],
Expand Down
95 changes: 95 additions & 0 deletions grails-app/controllers/streama/CertificationController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package streama


import grails.transaction.Transactional

import static org.springframework.http.HttpStatus.*

@Transactional(readOnly = true)
class CertificationController {

def theMovieDbService

static responseFormats = ['json', 'xml']
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

def index(Integer max) {
params.max = 999
respond Certification.list(params), [status: OK]
}

@Transactional
def save() {
def data = request.JSON
Certification certificationInstance = data.id ? Certification.get(data.id) : new Certification()

certificationInstance.properties = data
certificationInstance.validate()
if (certificationInstance.hasErrors()) {
render status: NOT_ACCEPTABLE
return
}

certificationInstance.save flush:true
respond certificationInstance, [status: CREATED]
}

@Transactional
def importCertifications() {
String type = params.type
def certifications = theMovieDbService.listCertifications(type)
List<Certification> certificationResult = []

certifications.each{ certData ->
if(Certification.findByCertificationAndType(certData.certification, type)){
return
}
Certification certification = new Certification()
certification.certification = certData.certification
certification.description = certData.meaning
certification.type = type
certification.save()

certificationResult.add(certification)
}

respond certificationResult
}

@Transactional
def update(Certification certificationInstance) {
if (certificationInstance == null) {
render status: NOT_FOUND
return
}

certificationInstance.validate()
if (certificationInstance.hasErrors()) {
render status: NOT_ACCEPTABLE
return
}

certificationInstance.save flush:true
respond certificationInstance, [status: OK]
}

@Transactional
def delete(Certification certificationInstance) {

if (certificationInstance == null) {
render status: NOT_FOUND
return
}
if (certificationInstance.apiId) {
render status: PRECONDITION_FAILED
return
}

certificationInstance.delete flush:true
render status: NO_CONTENT
}

def show(Certification certificationInstance) {
respond certificationInstance, [status: OK]
}
}
10 changes: 6 additions & 4 deletions grails-app/controllers/streama/MovieController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import grails.transaction.Transactional
@Transactional(readOnly = true)
class MovieController {
def videoService
def theMovieDbService

static responseFormats = ['json', 'xml']
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
Expand All @@ -26,8 +27,10 @@ class MovieController {
return
}

if (!movieInstance.imdb_id && movieInstance.apiId) {
movieInstance.imdb_id = movieInstance.fullMovieMeta?.imdb_id
if(data.apiId){
movieInstance = theMovieDbService.createEntityFromApiId('movie', data.apiId)
}else{
movieInstance.properties = data
}

List tags = []
Expand All @@ -42,8 +45,7 @@ class MovieController {
}

data.tags = tags*.id
movieInstance.properties = data
movieInstance.properties.dateCreated = data
movieInstance.properties.dateCreated = new Date()

movieInstance.validate()
if (movieInstance.hasErrors()) {
Expand Down
17 changes: 17 additions & 0 deletions grails-app/domain/streama/Certification.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package streama

class Certification {

String certification
String type
String description

static mapping = {
description type: 'text'
}

static constraints = {
certification nullable: false
description nullable: true
}
}
4 changes: 3 additions & 1 deletion grails-app/domain/streama/TvShow.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ class TvShow implements SimpleInstance {
Double vote_average
Integer vote_count
Double popularity
static hasMany = [episodes: Episode, genre: Genre]
String certification //PG-Rating, available values U,PG,13,15,18,No Restriction

File poster_image
File backdrop_image

static hasMany = [episodes: Episode, genre: Genre]

static mapping = {
cache true
episodes cache: true
Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/streama/Video.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Video implements SimpleInstance{
Integer reportCount
Boolean deleted = false
String imdb_id
String certification //PG-Rating, available values U,PG,13,15,18,No Restriction

static hasMany = [files: File]
static simpleInstanceFields = ['overview', 'poster_path:posterPath', 'title']
Expand Down
12 changes: 10 additions & 2 deletions grails-app/services/streama/TheMovieDbService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TheMovieDbService {
def uploadService

def getAPI_PARAMS(){
return "api_key=$API_KEY&language=$API_LANGUAGE"
return "api_key=$API_KEY&language=$API_LANGUAGE&append_to_response=release_dates"
}
def getAPI_PARAMS_WITHOUT_LANG(){
return "api_key=$API_KEY"
Expand Down Expand Up @@ -199,7 +199,7 @@ class TheMovieDbService {
}

@Transactional
def createEntityFromApiId(type, id, data = [:]){
def createEntityFromApiId(String type, id, Map data = [:]){
def apiData = getEntryById(type, id, data)
def entity
try{
Expand Down Expand Up @@ -232,6 +232,7 @@ class TheMovieDbService {
// log.debug("epiosde data")
}

data.certification = data.release_dates?.results?.find{it.iso_3166_1 == 'US'}?.release_dates[0]?.certification
entity.properties = data
if(data.genres){
entity.genre = parseGenres(data.genres*.id)
Expand Down Expand Up @@ -329,4 +330,11 @@ class TheMovieDbService {
}

}

def listCertifications(String type){
def requestUrl = "${BASE_URL}/certification/${type}/list?${API_PARAMS_WITHOUT_LANG}"
def JsonContent = new URL(requestUrl).getText("UTF-8")
def json = new JsonSlurper().parseText(JsonContent)
return json.certifications['US']
}
}

0 comments on commit 8fc43ca

Please sign in to comment.