Add ability to click on category/licence/language/tags in watch page
authorChocobozzz <me@florianbigard.com>
Tue, 24 Jul 2018 09:40:04 +0000 (11:40 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 24 Jul 2018 12:04:05 +0000 (14:04 +0200)
client/src/app/search/advanced-search.model.ts
client/src/app/search/search.component.html
client/src/app/search/search.component.ts
client/src/app/search/search.service.ts
client/src/app/videos/+video-watch/video-watch.component.html
client/src/app/videos/+video-watch/video-watch.component.scss
client/src/app/videos/+video-watch/video-watch.component.ts

index ce22c3f84e290f39bab31bf43fa8868a796a4862..48616a9ae2161e12d858fc717b7eca7921ebf41c 100644 (file)
@@ -99,14 +99,22 @@ export class AdvancedSearch {
       startDate: this.startDate,
       endDate: this.endDate,
       nsfw: this.nsfw,
-      categoryOneOf: this.categoryOneOf ? this.categoryOneOf.split(',') : undefined,
-      licenceOneOf: this.licenceOneOf ? this.licenceOneOf.split(',') : undefined,
-      languageOneOf: this.languageOneOf ? this.languageOneOf.split(',') : undefined,
-      tagsOneOf: this.tagsOneOf ? this.tagsOneOf.split(',') : undefined,
-      tagsAllOf: this.tagsAllOf ? this.tagsAllOf.split(',') : undefined,
+      categoryOneOf: this.intoArray(this.categoryOneOf),
+      licenceOneOf: this.intoArray(this.licenceOneOf),
+      languageOneOf: this.intoArray(this.languageOneOf),
+      tagsOneOf: this.intoArray(this.tagsOneOf),
+      tagsAllOf: this.intoArray(this.tagsAllOf),
       durationMin: this.durationMin,
       durationMax: this.durationMax,
       sort: this.sort
     }
   }
+
+  private intoArray (value: any) {
+    if (!value) return undefined
+
+    if (typeof value === 'string') return value.split(',')
+
+    return [ value ]
+  }
 }
index a0b5e6e790c4f88f6f5ff5e9a43d78e26213e798..9d14daa4b6f51505da6416aff1ef4cea3e58eb26 100644 (file)
@@ -3,7 +3,10 @@
     <div class="first-line">
       <div class="results-counter">
         <ng-container *ngIf="pagination.totalItems">
-          {{ pagination.totalItems | myNumberFormatter }} results for <span class="search-value">{{ currentSearch }}</span>
+          {{ pagination.totalItems | myNumberFormatter }} results
+          <span *ngIf="currentSearch">
+            for <span class="search-value">{{ currentSearch }}</span>
+          </span>
         </ng-container>
       </div>
 
index 8860b9268cc40d54769b2a5fb5ebaea51a3cea3b..8d615fd058dd990674217300592a632870ab6629 100644 (file)
@@ -44,7 +44,8 @@ export class SearchComponent implements OnInit, OnDestroy {
       queryParams => {
         const querySearch = queryParams['search']
 
-        if (!querySearch) return this.redirectService.redirectToHomepage()
+        // New empty search
+        if (this.currentSearch && !querySearch) return this.redirectService.redirectToHomepage()
 
         // Search updated, reset filters
         if (this.currentSearch !== querySearch) {
index b46cb97f41f903bfba0695a90878c0c0bfaac2e9..a37c4916122bc585b1fb7220a883ae4cdab7fbaf 100644 (file)
@@ -36,7 +36,8 @@ export class SearchService {
 
     let params = new HttpParams()
     params = this.restService.addRestGetParams(params, pagination)
-    params = params.append('search', search)
+
+    if (search) params = params.append('search', search)
 
     const advancedSearchObject = advancedSearch.toAPIObject()
 
index e7e9f367c8bb28cbd687df2f664328492c59fd7a..8764d38c7365555378ed795b62dea0cb6c14b3d5 100644 (file)
 
       <div class="video-attributes">
         <div class="video-attribute">
-          <span i18n class="video-attribute-label">
-            Privacy
-          </span>
-          <span class="video-attribute-value">
-            {{ video.privacy.label }}
-          </span>
+          <span i18n class="video-attribute-label">Privacy</span>
+          <span class="video-attribute-value">{{ video.privacy.label }}</span>
         </div>
 
         <div class="video-attribute">
-          <span i18n class="video-attribute-label">
-            Category
-          </span>
-          <span class="video-attribute-value">
-            {{ video.category.label }}
-          </span>
+          <span i18n class="video-attribute-label">Category</span>
+          <span *ngIf="!video.category.id" class="video-attribute-value">{{ video.category.label }}</span>
+          <a
+            *ngIf="video.category.id" class="video-attribute-value"
+            [routerLink]="[ '/search' ]" [queryParams]="{ categoryOneOf: [ video.category.id ] }"
+          >{{ video.category.label }}</a>
         </div>
 
         <div class="video-attribute">
-          <span i18n class="video-attribute-label">
-            Licence
-          </span>
-          <span class="video-attribute-value">
-            {{ video.licence.label }}
-          </span>
+          <span i18n class="video-attribute-label">Licence</span>
+          <span *ngIf="!video.licence.id" class="video-attribute-value">{{ video.licence.label }}</span>
+          <a
+            *ngIf="video.licence.id" class="video-attribute-value"
+            [routerLink]="[ '/search' ]" [queryParams]="{ licenceOneOf: [ video.licence.id ] }"
+          >{{ video.licence.label }}</a>
         </div>
 
         <div class="video-attribute">
-          <span i18n class="video-attribute-label">
-            Language
-          </span>
-          <span class="video-attribute-value">
-            {{ video.language.label }}
-          </span>
+          <span i18n class="video-attribute-label">Language</span>
+          <span *ngIf="!video.language.id" class="video-attribute-value">{{ video.language.label }}</span>
+          <a
+            *ngIf="video.language.id" class="video-attribute-value"
+            [routerLink]="[ '/search' ]" [queryParams]="{ languageOneOf: [ video.language.id ] }"
+          >{{ video.language.label }}</a>
         </div>
 
-        <div class="video-attribute">
-          <span i18n class="video-attribute-label">
-            Tags
-          </span>
-
-          <span class="video-attribute-value">
-            {{ getVideoTags() }}
-          </span>
+        <div class="video-attribute video-attribute-tags">
+          <span i18n class="video-attribute-label">Tags</span>
+          <a
+            *ngFor="let tag of getVideoTags()"
+            class="video-attribute-value" [routerLink]="[ '/search' ]" [queryParams]="{ tagsOneOf: [ tag ] }"
+          >{{ tag }}</a>
         </div>
       </div>
 
index a2d56bd39b2f4729a7e96937611eef62f59984f1..7bc2cae02b7fb23f819ffb99a9573e04f7478d36 100644 (file)
         color: #585858;
         font-weight: $font-bold;
       }
+
+      a.video-attribute-value {
+        @include disable-default-a-behaviour;
+        color: #000;
+
+        &:hover {
+          opacity: 0.9;
+        }
+      }
+
+      &.video-attribute-tags {
+        .video-attribute-value:not(:nth-child(2)) {
+          &::before {
+            content: ', '
+          }
+        }
+      }
     }
   }
 
index ff8baaeb3ff1a6e1ef848745976673d460578865..afbb0c596eed30cca94c5b221b858f3889e20c38 100644 (file)
@@ -252,7 +252,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   getVideoTags () {
     if (!this.video || Array.isArray(this.video.tags) === false) return []
 
-    return this.video.tags.join(', ')
+    return this.video.tags
   }
 
   isVideoRemovable () {