-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
267 additions
and
9 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
grails-app/assets/javascripts/streama/controllers/admin-certification-ctrl.js
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,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.') | ||
}); | ||
} | ||
}) | ||
} | ||
|
||
}]); | ||
|
||
|
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
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
51 changes: 51 additions & 0 deletions
51
grails-app/assets/javascripts/streama/templates/admin-certifications.tpl.htm
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,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> |
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
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
95 changes: 95 additions & 0 deletions
95
grails-app/controllers/streama/CertificationController.groovy
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,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] | ||
} | ||
} |
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,17 @@ | ||
package streama | ||
|
||
class Certification { | ||
|
||
String certification | ||
String type | ||
String description | ||
|
||
static mapping = { | ||
description type: 'text' | ||
} | ||
|
||
static constraints = { | ||
certification nullable: false | ||
description nullable: true | ||
} | ||
} |
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
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