mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-07 21:51:13 -07:00
Refactor status translation into a dedicated pipe
This commit is contained in:
parent
6fd59c6163
commit
abf0ddf74a
8 changed files with 28 additions and 32 deletions
|
@ -27,7 +27,7 @@
|
||||||
<hr>
|
<hr>
|
||||||
<div>
|
<div>
|
||||||
<span class="label">{{'MediaDetails.Status' | translate }}</span>
|
<span class="label">{{'MediaDetails.Status' | translate }}</span>
|
||||||
<span id="status">{{ getMovieStatusLabel()}}</span>
|
<span id="status">{{ this.movie.status | translateStatus }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="label">{{'MediaDetails.Availability' | translate }}</span>
|
<span class="label">{{'MediaDetails.Availability' | translate }}</span>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Component, ViewEncapsulation, Input, OnInit, Inject } from "@angular/core";
|
import { Component, ViewEncapsulation, Input, OnInit, Inject } from "@angular/core";
|
||||||
import { TranslateService } from "@ngx-translate/core";
|
|
||||||
import { ISearchMovieResultV2 } from "../../../../interfaces/ISearchMovieResultV2";
|
import { ISearchMovieResultV2 } from "../../../../interfaces/ISearchMovieResultV2";
|
||||||
import { IMovieRequests } from "../../../../interfaces";
|
import { IMovieRequests } from "../../../../interfaces";
|
||||||
import { SearchV2Service } from "../../../../services/searchV2.service";
|
import { SearchV2Service } from "../../../../services/searchV2.service";
|
||||||
|
@ -14,8 +13,7 @@ import { IStreamingData } from "../../../../interfaces/IStreams";
|
||||||
})
|
})
|
||||||
export class MovieInformationPanelComponent implements OnInit {
|
export class MovieInformationPanelComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private searchService: SearchV2Service, @Inject(APP_BASE_HREF) public internalBaseUrl: string,
|
constructor(private searchService: SearchV2Service, @Inject(APP_BASE_HREF) public internalBaseUrl: string) { }
|
||||||
private translate: TranslateService) { }
|
|
||||||
|
|
||||||
@Input() public movie: ISearchMovieResultV2;
|
@Input() public movie: ISearchMovieResultV2;
|
||||||
@Input() public request: IMovieRequests;
|
@Input() public request: IMovieRequests;
|
||||||
|
@ -35,14 +33,4 @@ export class MovieInformationPanelComponent implements OnInit {
|
||||||
|
|
||||||
this.searchService.getMovieStreams(this.movie.id).subscribe(x => this.streams = x);
|
this.searchService.getMovieStreams(this.movie.id).subscribe(x => this.streams = x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMovieStatusLabel() {
|
|
||||||
const textKey = 'MediaDetails.StatusValues.' + this.movie.status;
|
|
||||||
const text = this.translate.instant(textKey);
|
|
||||||
if (text !== textKey) {
|
|
||||||
return text;
|
|
||||||
} else {
|
|
||||||
return this.movie.status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<hr>
|
<hr>
|
||||||
<div *ngIf="tv.status">
|
<div *ngIf="tv.status">
|
||||||
<span class="label">{{'MediaDetails.Status' | translate }}</span>
|
<span class="label">{{'MediaDetails.Status' | translate }}</span>
|
||||||
<span id="status">{{ getTVStatusLabel()}}</span>
|
<span id="status">{{ this.tv.status | translateStatus }}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class="label">{{'MediaDetails.FirstAired' | translate }}</span>
|
<span class="label">{{'MediaDetails.FirstAired' | translate }}</span>
|
||||||
{{tv.firstAired | localizedDate: 'mediumDate'}}
|
{{tv.firstAired | localizedDate: 'mediumDate'}}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { APP_BASE_HREF } from "@angular/common";
|
import { APP_BASE_HREF } from "@angular/common";
|
||||||
import { Component, ViewEncapsulation, Input, OnInit, Inject } from "@angular/core";
|
import { Component, ViewEncapsulation, Input, OnInit, Inject } from "@angular/core";
|
||||||
import { TranslateService } from "@ngx-translate/core";
|
|
||||||
import { ITvRequests } from "../../../../../interfaces";
|
import { ITvRequests } from "../../../../../interfaces";
|
||||||
import { ITvRatings } from "../../../../../interfaces/IRatings";
|
import { ITvRatings } from "../../../../../interfaces/IRatings";
|
||||||
import { ISearchTvResultV2 } from "../../../../../interfaces/ISearchTvResultV2";
|
import { ISearchTvResultV2 } from "../../../../../interfaces/ISearchTvResultV2";
|
||||||
|
@ -15,8 +14,7 @@ import { SearchV2Service } from "../../../../../services";
|
||||||
})
|
})
|
||||||
export class TvInformationPanelComponent implements OnInit {
|
export class TvInformationPanelComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private searchService: SearchV2Service, @Inject(APP_BASE_HREF) public internalBaseUrl: string,
|
constructor(private searchService: SearchV2Service, @Inject(APP_BASE_HREF) public internalBaseUrl: string) { }
|
||||||
private translate: TranslateService) { }
|
|
||||||
|
|
||||||
@Input() public tv: ISearchTvResultV2;
|
@Input() public tv: ISearchTvResultV2;
|
||||||
@Input() public request: ITvRequests;
|
@Input() public request: ITvRequests;
|
||||||
|
@ -46,14 +44,4 @@ export class TvInformationPanelComponent implements OnInit {
|
||||||
public sortBy(prop: string) {
|
public sortBy(prop: string) {
|
||||||
return this.streams.sort((a, b) => a[prop] > b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
|
return this.streams.sort((a, b) => a[prop] > b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTVStatusLabel() {
|
|
||||||
const textKey = 'MediaDetails.StatusValues.' + this.tv.status;
|
|
||||||
const text = this.translate.instant(textKey);
|
|
||||||
if (text !== textKey) {
|
|
||||||
return text;
|
|
||||||
} else {
|
|
||||||
return this.tv.status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
19
src/Ombi/ClientApp/src/app/pipes/TranslateStatus.ts
Normal file
19
src/Ombi/ClientApp/src/app/pipes/TranslateStatus.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
@Pipe({
|
||||||
|
name: 'translateStatus'
|
||||||
|
})
|
||||||
|
export class TranslateStatusPipe implements PipeTransform {
|
||||||
|
constructor(private translateService: TranslateService) {}
|
||||||
|
|
||||||
|
transform(value: string): string {
|
||||||
|
const textKey = 'MediaDetails.StatusValues.' + value;
|
||||||
|
const text = this.translateService.instant(textKey);
|
||||||
|
if (text !== textKey) {
|
||||||
|
return text;
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import { ModuleWithProviders, NgModule } from "@angular/core";
|
import { ModuleWithProviders, NgModule } from "@angular/core";
|
||||||
import { HumanizePipe } from "./HumanizePipe";
|
import { HumanizePipe } from "./HumanizePipe";
|
||||||
import { LocalizedDatePipe } from "./LocalizedDate";
|
import { LocalizedDatePipe } from "./LocalizedDate";
|
||||||
|
import { TranslateStatusPipe } from "./TranslateStatus";
|
||||||
import { ThousandShortPipe } from "./ThousandShortPipe";
|
import { ThousandShortPipe } from "./ThousandShortPipe";
|
||||||
import { SafePipe } from "./SafePipe";
|
import { SafePipe } from "./SafePipe";
|
||||||
import { QualityPipe } from "./QualityPipe";
|
import { QualityPipe } from "./QualityPipe";
|
||||||
|
@ -8,8 +9,8 @@ import { UserLocalePipe } from "./UserLocalePipe";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [],
|
imports: [],
|
||||||
declarations: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe ],
|
declarations: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe, TranslateStatusPipe ],
|
||||||
exports: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe ],
|
exports: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe, TranslateStatusPipe ],
|
||||||
})
|
})
|
||||||
export class PipeModule {
|
export class PipeModule {
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
<ng-container matColumnDef="status">
|
<ng-container matColumnDef="status">
|
||||||
<th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> {{ 'Requests.Status' | translate}} </th>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header disableClear> {{ 'Requests.Status' | translate}} </th>
|
||||||
<td mat-cell id="status{{element.id}}" *matCellDef="let element"> {{element.status}} </td>
|
<td mat-cell id="status{{element.id}}" *matCellDef="let element"> {{element.status |translateStatus }} </td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
<ng-container matColumnDef="status">
|
<ng-container matColumnDef="status">
|
||||||
<th mat-header-cell *matHeaderCellDef> {{'Requests.Status' | translate}} </th>
|
<th mat-header-cell *matHeaderCellDef> {{'Requests.Status' | translate}} </th>
|
||||||
<td mat-cell id="status{{element.id}}" *matCellDef="let element">
|
<td mat-cell id="status{{element.id}}" *matCellDef="let element">
|
||||||
{{element.parentRequest.status}}
|
{{element.parentRequest.status | translateStatus }}
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue