Client: support video language
authorChocobozzz <florian.bigard@gmail.com>
Fri, 7 Apr 2017 12:57:05 +0000 (14:57 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 7 Apr 2017 12:57:05 +0000 (14:57 +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 3c06b320e03a873b1eb94f974026e58f56f513cd..c29790d96e24a72bf662658a6b2809429030d9c5 100644 (file)
@@ -42,6 +42,7 @@ export class AppComponent implements OnInit {
     this.configService.loadConfig();
     this.videoService.loadVideoCategories();
     this.videoService.loadVideoLicences();
+    this.videoService.loadVideoLanguages();
   }
 
   isInAdmin() {
index 50d7304b5998dc8c345d2d9f244cfce1ad514a46..293fd805fdd600c548640e1c42aca58de2941050 100644 (file)
@@ -23,6 +23,11 @@ export const VIDEO_LICENCE = {
   }
 };
 
+export const VIDEO_LANGUAGE = {
+  VALIDATORS: [ ],
+  MESSAGES: {}
+};
+
 export const VIDEO_DESCRIPTION = {
   VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
   MESSAGES: {
index 3c588c446f332ab93ce3e4d17b617daf6b7491ef..f135ca707e77f795214bb22f3ee9dd1a3275f882 100644 (file)
@@ -6,6 +6,7 @@ export class Video {
   createdAt: Date;
   categoryLabel: string;
   licenceLabel: string;
+  languageLabel: string;
   description: string;
   duration: string;
   id: string;
@@ -38,6 +39,7 @@ export class Video {
     createdAt: string,
     categoryLabel: string,
     licenceLabel: string,
+    languageLabel: string;
     description: string,
     duration: number;
     id: string,
@@ -56,6 +58,7 @@ export class Video {
     this.createdAt = new Date(hash.createdAt);
     this.categoryLabel = hash.categoryLabel;
     this.licenceLabel = hash.licenceLabel;
+    this.languageLabel = hash.languageLabel;
     this.description = hash.description;
     this.duration = Video.createDurationString(hash.duration);
     this.id = hash.id;
index 15f017e33d3b92c395441d0e442349283e657d52..13d4ca246a11db03c8c2108fbb6308bcb1c7bbfc 100644 (file)
@@ -24,6 +24,7 @@ export class VideoService {
 
   videoCategories: Array<{ id: number, label: string }> = [];
   videoLicences: Array<{ id: number, label: string }> = [];
+  videoLanguages: Array<{ id: number, label: string }> = [];
 
   constructor(
     private authService: AuthService,
@@ -59,6 +60,19 @@ export class VideoService {
                     });
   }
 
+  loadVideoLanguages() {
+    return this.http.get(VideoService.BASE_VIDEO_URL + 'languages')
+                    .map(this.restExtractor.extractDataGet)
+                    .subscribe(data => {
+                      Object.keys(data).forEach(languageKey => {
+                        this.videoLanguages.push({
+                          id: parseInt(languageKey),
+                          label: data[languageKey]
+                        });
+                      });
+                    });
+  }
+
   getVideo(id: string): Observable<Video> {
     return this.http.get(VideoService.BASE_VIDEO_URL + id)
                     .map(this.restExtractor.extractDataGet)
index a3c25c14b1b2c43c18304cbc144082f10f04ca13..104747a8ca3acdc245351e3514c7fcdf0e3970d7 100644 (file)
     </div>
   </div>
 
+  <div class="form-group">
+    <label for="language">Language</label>
+    <select class="form-control" id="language" formControlName="language">
+      <option></option>
+      <option *ngFor="let language of videoLanguages" [value]="language.id">{{ language.label }}</option>
+    </select>
+
+    <div *ngIf="formErrors.language" class="alert alert-danger">
+      {{ formErrors.language }}
+    </div>
+  </div>
+
   <div class="form-group">
     <label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span>
     <input
index ea7ad2e5caffca83bf07b41e93b9dd7b9a41b815..da556f48d75a452d8f304de0d229e64d5e77a62c 100644 (file)
@@ -11,6 +11,7 @@ import {
   VIDEO_NAME,
   VIDEO_CATEGORY,
   VIDEO_LICENCE,
+  VIDEO_LANGUAGE,
   VIDEO_DESCRIPTION,
   VIDEO_TAGS
 } from '../../shared';
@@ -27,6 +28,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
   uploader: FileUploader;
   videoCategories = [];
   videoLicences = [];
+  videoLanguages = [];
 
   error: string = null;
   form: FormGroup;
@@ -34,6 +36,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
     name: '',
     category: '',
     licence: '',
+    language: '',
     description: '',
     currentTag: ''
   };
@@ -41,6 +44,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
     name: VIDEO_NAME.MESSAGES,
     category: VIDEO_CATEGORY.MESSAGES,
     licence: VIDEO_LICENCE.MESSAGES,
+    language: VIDEO_LANGUAGE.MESSAGES,
     description: VIDEO_DESCRIPTION.MESSAGES,
     currentTag: VIDEO_TAGS.MESSAGES
   };
@@ -74,6 +78,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
       nsfw: [ false ],
       category: [ '', VIDEO_CATEGORY.VALIDATORS ],
       licence: [ '', VIDEO_LICENCE.VALIDATORS ],
+      language: [ '', VIDEO_LANGUAGE.VALIDATORS ],
       description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
       currentTag: [ '', VIDEO_TAGS.VALIDATORS ]
     });
@@ -84,6 +89,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
   ngOnInit() {
     this.videoCategories = this.videoService.videoCategories;
     this.videoLicences = this.videoService.videoLicences;
+    this.videoLanguages = this.videoService.videoLanguages;
 
     this.uploader = new FileUploader({
       authToken: this.authService.getRequestHeaderValue(),
@@ -97,12 +103,19 @@ export class VideoAddComponent extends FormReactive implements OnInit {
       const nsfw = this.form.value['nsfw'];
       const category = this.form.value['category'];
       const licence = this.form.value['licence'];
+      const language = this.form.value['language'];
       const description = this.form.value['description'];
 
       form.append('name', name);
       form.append('category', category);
       form.append('nsfw', nsfw);
       form.append('licence', licence);
+
+      // Language is optional
+      if (language) {
+        form.append('language', language);
+      }
+
       form.append('description', description);
 
       for (let i = 0; i < this.tags.length; i++) {
index 897561c1436a6a9cf85591ecd82a39d5d51a2b87..a6ec7b20fda6158604a65d2039d8173931410f3d 100644 (file)
     </div>
   </div>
 
+  <div id="video-language" class="row">
+    <div class="col-md-12">
+      <span id="language-label">Language:</span>
+      {{ video.languageLabel }}
+    </div>
+  </div>
+
   <div id="video-description" class="row">
     <div class="col-md-12">
       <div id="description-label">Description</div>
index bf989e78badc1b2b38855604509d843a1ed63b7b..92192221f01b3d6f7ccf1dd709775dab99c771c7 100644 (file)
     }
   }
 
-  #video-licence #licence-label {
+  #video-licence #licence-label, #video-language #language-label {
     font-weight: bold;
   }