]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Client: add support for video licences
authorChocobozzz <florian.bigard@gmail.com>
Mon, 27 Mar 2017 19:11:37 +0000 (21:11 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Mon, 27 Mar 2017 19:11:37 +0000 (21:11 +0200)
client/src/app/app.component.ts
client/src/app/shared/forms/form-validators/video.ts
client/src/app/videos/shared/video.model.ts
client/src/app/videos/shared/video.service.ts
client/src/app/videos/video-add/video-add.component.html
client/src/app/videos/video-add/video-add.component.ts
client/src/app/videos/video-watch/video-watch.component.html
client/src/app/videos/video-watch/video-watch.component.scss

index c7310690f5db2a98f31dbf66c656d19cc44dee00..4e33fae52b08c9ccff2618edfcdc9c0fe001527b 100644 (file)
@@ -39,6 +39,7 @@ export class AppComponent implements OnInit {
     }
 
     this.videoService.loadVideoCategories();
+    this.videoService.loadVideoLicences();
   }
 
   isInAdmin() {
index de5112238083910a9dc8dc6a046bc386e213597c..50d7304b5998dc8c345d2d9f244cfce1ad514a46 100644 (file)
@@ -8,12 +8,21 @@ export const VIDEO_NAME = {
     'maxlength': 'Video name cannot be more than 50 characters long.'
   }
 };
+
 export const VIDEO_CATEGORY = {
   VALIDATORS: [ Validators.required ],
   MESSAGES: {
     'required': 'Video category is required.'
   }
 };
+
+export const VIDEO_LICENCE = {
+  VALIDATORS: [ Validators.required ],
+  MESSAGES: {
+    'required': 'Video licence is required.'
+  }
+};
+
 export const VIDEO_DESCRIPTION = {
   VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
   MESSAGES: {
index b5d96f63a45b91b27eb8b355441d4eec8c2d5234..5ed622dce63757067c7d8c2c39ba40b675db32b2 100644 (file)
@@ -3,6 +3,7 @@ export class Video {
   by: string;
   createdAt: Date;
   categoryLabel: string;
+  licenceLabel: string;
   description: string;
   duration: string;
   id: string;
@@ -33,6 +34,7 @@ export class Video {
     author: string,
     createdAt: string,
     categoryLabel: string,
+    licenceLabel: string,
     description: string,
     duration: number;
     id: string,
@@ -49,6 +51,7 @@ export class Video {
     this.author  = hash.author;
     this.createdAt = new Date(hash.createdAt);
     this.categoryLabel = hash.categoryLabel;
+    this.licenceLabel = hash.licenceLabel;
     this.description = hash.description;
     this.duration = Video.createDurationString(hash.duration);
     this.id = hash.id;
index debc114aaca36cee3a068276c501631439ca0d4d..15f017e33d3b92c395441d0e442349283e657d52 100644 (file)
@@ -23,6 +23,7 @@ export class VideoService {
   private static BASE_VIDEO_URL = '/api/v1/videos/';
 
   videoCategories: Array<{ id: number, label: string }> = [];
+  videoLicences: Array<{ id: number, label: string }> = [];
 
   constructor(
     private authService: AuthService,
@@ -45,6 +46,19 @@ export class VideoService {
                     });
   }
 
+  loadVideoLicences() {
+    return this.http.get(VideoService.BASE_VIDEO_URL + 'licences')
+                    .map(this.restExtractor.extractDataGet)
+                    .subscribe(data => {
+                      Object.keys(data).forEach(licenceKey => {
+                        this.videoLicences.push({
+                          id: parseInt(licenceKey),
+                          label: data[licenceKey]
+                        });
+                      });
+                    });
+  }
+
   getVideo(id: string): Observable<Video> {
     return this.http.get(VideoService.BASE_VIDEO_URL + id)
                     .map(this.restExtractor.extractDataGet)
index c6692b21db9d5f9ec8fc996708ea849c1f86e55c..97a3c846ac3651e03051ec817fe785f0c1976699 100644 (file)
     </div>
   </div>
 
+  <div class="form-group">
+    <label for="licence">Licence</label>
+    <select class="form-control" id="licence" formControlName="licence">
+      <option></option>
+      <option *ngFor="let licence of videoLicences" [value]="licence.id">{{ licence.label }}</option>
+    </select>
+
+    <div *ngIf="formErrors.licence" class="alert alert-danger">
+      {{ formErrors.licence }}
+    </div>
+  </div>
+
   <div class="form-group">
     <label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span>
     <input
index 5ed1d8841de6a562d30febba79417670373a76e1..8fae233d31b911559998b5ed53a8eb2eeec35427 100644 (file)
@@ -10,6 +10,7 @@ import {
   FormReactive,
   VIDEO_NAME,
   VIDEO_CATEGORY,
+  VIDEO_LICENCE,
   VIDEO_DESCRIPTION,
   VIDEO_TAGS
 } from '../../shared';
@@ -25,18 +26,21 @@ export class VideoAddComponent extends FormReactive implements OnInit {
   tags: string[] = [];
   uploader: FileUploader;
   videoCategories = [];
+  videoLicences = [];
 
   error: string = null;
   form: FormGroup;
   formErrors = {
     name: '',
     category: '',
+    licence: '',
     description: '',
     currentTag: ''
   };
   validationMessages = {
     name: VIDEO_NAME.MESSAGES,
     category: VIDEO_CATEGORY.MESSAGES,
+    licence: VIDEO_LICENCE.MESSAGES,
     description: VIDEO_DESCRIPTION.MESSAGES,
     currentTag: VIDEO_TAGS.MESSAGES
   };
@@ -68,6 +72,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
     this.form = this.formBuilder.group({
       name: [ '', VIDEO_NAME.VALIDATORS ],
       category: [ '', VIDEO_CATEGORY.VALIDATORS ],
+      licence: [ '', VIDEO_LICENCE.VALIDATORS ],
       description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
       currentTag: [ '', VIDEO_TAGS.VALIDATORS ]
     });
@@ -77,6 +82,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
 
   ngOnInit() {
     this.videoCategories = this.videoService.videoCategories;
+    this.videoLicences = this.videoService.videoLicences;
 
     this.uploader = new FileUploader({
       authToken: this.authService.getRequestHeaderValue(),
@@ -88,10 +94,12 @@ export class VideoAddComponent extends FormReactive implements OnInit {
     this.uploader.onBuildItemForm = (item, form) => {
       const name = this.form.value['name'];
       const category = this.form.value['category'];
+      const licence = this.form.value['licence'];
       const description = this.form.value['description'];
 
       form.append('name', name);
       form.append('category', category);
+      form.append('licence', licence);
       form.append('description', description);
 
       for (let i = 0; i < this.tags.length; i++) {
index e754d69e51436f9aad1e84e76f511b870ae21aae..897561c1436a6a9cf85591ecd82a39d5d51a2b87 100644 (file)
     </div>
   </div>
 
+  <div id="video-licence" class="row">
+    <div class="col-md-12">
+      <span id="licence-label">Licence:</span>
+      {{ video.licenceLabel }}
+    </div>
+  </div>
+
   <div id="video-description" class="row">
     <div class="col-md-12">
       <div id="description-label">Description</div>
index 799e37b5dcaf43e414e6ea64ba45ed169de57990..bf989e78badc1b2b38855604509d843a1ed63b7b 100644 (file)
     }
   }
 
+  #video-licence #licence-label {
+    font-weight: bold;
+  }
+
   #video-description {
     margin-top: 10px;