Skip to content

Commit

Permalink
✔ Kategori Film Lainnya
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Oct 15, 2023
1 parent 149b04b commit af72b60
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 113 deletions.
52 changes: 46 additions & 6 deletions src/api/controllers/berkas.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class BerkasController {
try {
if (
'name' in req.body && 'projectType_id' in req.body &&
('anime_id' in req.body || 'dorama_id' in req.body) &&
('anime_id' in req.body || 'dorama_id' in req.body || 'sn_code' in req.body) &&
('fansub_id' in req.body && Array.isArray(req.body.fansub_id) && req.body.fansub_id.length > 0)
) {
const user: UserModel = res.locals['user'];
Expand Down Expand Up @@ -282,6 +282,20 @@ export class BerkasController {
if ('image' in req.body) {
berkas.image_url = req.body.image;
}
if ('sn_code' in req.body) {
const sn = req.body.sn_code.toUpperCase().replace(/[^A-Z0-9\-]/g, '');
if (!sn) {
throw new HttpException({
info: `🙄 400 - Berkas API :: Gagal Menambahkan Berkas 😪`,
result: {
message: 'Kode Serial Hanya Huruf Besar, Strip, Dan Angka!'
}
}, HttpStatus.BAD_REQUEST);
}
berkas.anime_ = null;
berkas.dorama_ = null;
berkas.sn_code = sn;
}
if ('anime_id' in req.body) {
const anime = await this.animeRepo.findOneOrFail({
where: [
Expand All @@ -290,6 +304,7 @@ export class BerkasController {
});
berkas.anime_ = anime;
berkas.dorama_ = null;
berkas.sn_code = null;
}
if ('dorama_id' in req.body) {
const dorama = await this.doramaRepo.findOneOrFail({
Expand All @@ -299,6 +314,7 @@ export class BerkasController {
});
berkas.anime_ = null;
berkas.dorama_ = dorama;
berkas.sn_code = null;
}
const fansub = await this.fansubRepo.find({
where: [
Expand Down Expand Up @@ -355,7 +371,11 @@ export class BerkasController {
url: environment.baseUrl
})
.setDescription(this.gs.htmlToText(resFileSave.description))
.addField(resFileSave.anime_ ? 'Anime' : 'Dorama', resFileSave.anime_ ? resFileSave.anime_.name : resFileSave.dorama_.name, false)
.addField(
(resFileSave.anime_ ? 'Anime' : (resFileSave.dorama_ ? 'Dorama' : 'Film Lainnya')),
(resFileSave.anime_ ? resFileSave.anime_.name : (resFileSave.dorama_ ? resFileSave.dorama_.name : resFileSave.sn_code)),
false
)
.addFields(
{ name: 'Jenis', value: resFileSave.project_type_.name.split('_')[1], inline: true },
{ name: 'Ddl', value: (resFileSave.attachment_ ? 'Ya' : 'Tidak'), inline: true }
Expand Down Expand Up @@ -505,7 +525,7 @@ export class BerkasController {
try {
if (
'name' in req.body || 'description' in req.body || 'private' in req.body || 'image' in req.body || 'attachment_id' in req.body ||
('anime_id' in req.body || 'dorama_id' in req.body) || 'projectType_id' in req.body || 'r18' in req.body ||
('anime_id' in req.body || 'dorama_id' in req.body || 'sn_code' in req.body) || 'projectType_id' in req.body || 'r18' in req.body ||
('download_url' in req.body && Array.isArray(req.body.download_url) && req.body.download_url.length > 0) ||
('fansub_id' in req.body && Array.isArray(req.body.fansub_id) && req.body.fansub_id.length > 0)
) {
Expand Down Expand Up @@ -533,7 +553,7 @@ export class BerkasController {
if (user.verified) {
if (filteredUrls.length <= 0 && !req.body.attachment_id && !file.attachment_?.id) {
throw new HttpException({
info: `🙄 400 - Berkas API :: Gagal Menambahkan Berkas 😪`,
info: `🙄 400 - Berkas API :: Gagal Mengubah Berkas ${req.params['id']} 😪`,
result: {
message: 'Wajib Mengisi Min 1 URL Eksternal / Upload 1 DDL Stream!'
}
Expand All @@ -542,7 +562,7 @@ export class BerkasController {
} else {
if (filteredUrls.length <= 0) {
throw new HttpException({
info: `🙄 400 - Berkas API :: Gagal Menambahkan Berkas 😪`,
info: `🙄 400 - Berkas API :: Gagal Mengubah Berkas ${req.params['id']} 😪`,
result: {
message: 'Wajib Mengisi Min 1 URL Eksternal!'
}
Expand All @@ -564,6 +584,20 @@ export class BerkasController {
if ('r18' in req.body) {
file.r18 = (req.body.r18 === true);
}
if ('sn_code' in req.body) {
const sn = req.body.sn_code.toUpperCase().replace(/[^A-Z0-9\-]/g,'');
if (!sn) {
throw new HttpException({
info: `🙄 400 - Berkas API :: Gagal Mengubah Berkas ${req.params['id']} 😪`,
result: {
message: 'Kode Serial Hanya Huruf Besar, Strip, Dan Angka!'
}
}, HttpStatus.BAD_REQUEST);
}
file.anime_ = null;
file.dorama_ = null;
file.sn_code = sn;
}
if ('anime_id' in req.body) {
const anime = await this.animeRepo.findOneOrFail({
where: [
Expand All @@ -572,6 +606,7 @@ export class BerkasController {
});
file.anime_ = anime;
file.dorama_ = null;
file.sn_code = null;
}
if ('dorama_id' in req.body) {
const dorama = await this.doramaRepo.findOneOrFail({
Expand All @@ -581,6 +616,7 @@ export class BerkasController {
});
file.anime_ = null;
file.dorama_ = dorama;
file.sn_code = null;
}
if ('fansub_id' in req.body && Array.isArray(req.body.fansub_id) && req.body.fansub_id.length > 0) {
const fansub = await this.fansubRepo.find({
Expand Down Expand Up @@ -644,7 +680,11 @@ export class BerkasController {
url: environment.baseUrl
})
.setDescription(this.gs.htmlToText(resFileSave.description))
.addField(resFileSave.anime_ ? 'Anime' : 'Dorama', resFileSave.anime_ ? resFileSave.anime_.name : resFileSave.dorama_.name, false)
.addField(
(resFileSave.anime_ ? 'Anime' : (resFileSave.dorama_ ? 'Dorama' : 'Film Lainnya')),
(resFileSave.anime_ ? resFileSave.anime_.name : (resFileSave.dorama_ ? resFileSave.dorama_.name : resFileSave.sn_code)),
false
)
.addFields(
{ name: 'Jenis', value: resFileSave.project_type_.name.split('_')[1], inline: true },
{ name: 'Ddl', value: (resFileSave.attachment_ ? 'Ya' : 'Tidak'), inline: true }
Expand Down
3 changes: 3 additions & 0 deletions src/api/entities/Berkas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class Berkas implements BerkasModel {
@Column({ type: 'text', default: '/assets/img/favicon.png' })
image_url: string;

@Column({ type: 'text', nullable: true })
sn_code: string;

@Column({ type: 'int', default: 0 })
view_count: number;

Expand Down
12 changes: 8 additions & 4 deletions src/app/_pages/berkas/berkas-detail/berkas-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ <h2 class="border-bottom-dotted">
<mat-selection-list [multiple]="false">
<mat-list-option routerLink="/anime/{{ berkasData.anime_.id }}-{{ animeName }}" *ngIf="berkasData.anime_">
<img matListAvatar src="{{ berkasData.anime_.image_url }}" class="ms-3" style="border-radius: 0;" />
<h4>{{ berkasData.anime_.name }}</h4>
<h4 class="text-truncate">{{ berkasData.anime_.name }}</h4>
</mat-list-option>
<mat-list-option routerLink="/dorama/{{ berkasData.dorama_.slug }}" *ngIf="berkasData.dorama_">
<img matListAvatar src="{{ berkasData.dorama_.image_url }}" class="ms-3" style="border-radius: 0;" />
<h4>{{ berkasData.dorama_.name }}</h4>
<h4 class="text-truncate">{{ berkasData.dorama_.name }}</h4>
</mat-list-option>
<mat-list-option *ngIf="berkasData.sn_code">
<img matListAvatar src="{{ ENV.baseUrl }}/assets/img/favicon.png" class="ms-3" style="border-radius: 0;" />
<h4 class="text-truncate">{{ berkasData.sn_code }}</h4>
</mat-list-option>
<mat-list-option routerLink="/fansub/{{ fs.slug }}" *ngFor="let fs of berkasData.fansub_">
<img matListAvatar src="{{ fs.image_url }}" class="ms-3" style="border-radius: 0;" />
<h4>{{ fs.name }}</h4>
<h4 class="text-truncate">{{ fs.name }}</h4>
</mat-list-option>
<mat-list-option routerLink="/user/{{ berkasData.user_.username }}">
<img matListAvatar src="{{ berkasData.user_.image_url }}" class="ms-3" style="border-radius: 0;" />
<h4>{{ berkasData.user_.username }}</h4>
<h4 class="text-truncate">{{ berkasData.user_.username }}</h4>
</mat-list-option>
</mat-selection-list>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class BerkasDetailComponent implements OnInit, OnDestroy {
this.gs.bgRepeat = false;
}

get ENV(): any {
return environment;
}

get GS(): GlobalService {
return this.gs;
}
Expand Down
101 changes: 60 additions & 41 deletions src/app/_pages/berkas/berkas-edit/berkas-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,67 @@ <h2 class="pt-3 border-bottom-dotted">
<div *ngIf="fg.get('projectType_id').hasError('pattern')">Jenis Hanya Boleh Huruf Standar Papan Ketik</div>
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" class="p-3 w-100" *ngIf="berkasType.toLowerCase().includes('anime')" [color]="'accent'">
<mat-label>Anime Terkait</mat-label>
<input matInput formControlName="anime_id" placeholder="Full Metal Alchemist" [matAutocomplete]="autoCompleteAnime" (keyup)="resetSelectedAnime()" />
<mat-icon fontIcon="short_text" matSuffix></mat-icon>
<mat-autocomplete #autoCompleteAnime="matAutocomplete">
<mat-option *ngIf="isLoading" class="is-loading">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-option>
<ng-container *ngIf="!isLoading">
<mat-option *ngFor="let a of filteredAnime" [value]="a.id" class="px-1" (click)="filterAnimeSelected(a)">
<img src="{{ a.image_url }}" style="height: 40px; width: 30px; object-fit: cover;" class="me-1" />
<span class="ms-1">{{ a.id }} :: {{ a.media_type?.toUpperCase() }} :: {{ a.title }}</span>
<ng-container *ngIf="berkasType.toLowerCase().includes('anime_'); then anime_; else notAnime_;"></ng-container>
<ng-template #anime_>
<mat-form-field appearance="outline" class="p-3 w-100" [color]="'accent'">
<mat-label>Anime Terkait</mat-label>
<input matInput formControlName="anime_id" placeholder="Full Metal Alchemist" [matAutocomplete]="autoCompleteAnime" (keyup)="resetSelectedAnime()" />
<mat-icon fontIcon="short_text" matSuffix></mat-icon>
<mat-autocomplete #autoCompleteAnime="matAutocomplete">
<mat-option *ngIf="isLoading" class="is-loading">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-option>
</ng-container>
</mat-autocomplete>
<small *ngIf="fg.get('anime_name').value" class="text-warning">{{ fg.get('anime_name').value }}</small>
<mat-error>
<div *ngIf="fg.get('anime_id').hasError('required')">ID Anime Tidak Boleh Kosong</div>
<div *ngIf="fg.get('anime_id').hasError('pattern')">ID Anime Hanya Boleh Angka</div>
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" class="p-3 w-100" *ngIf="berkasType.toLowerCase().includes('dorama')" [color]="'accent'">
<mat-label>Dorama Terkait</mat-label>
<input matInput formControlName="dorama_id" placeholder="Flying Colors" [matAutocomplete]="autoCompleteDorama" (keyup)="resetSelectedDorama()" />
<mat-icon fontIcon="short_text" matSuffix></mat-icon>
<mat-autocomplete #autoCompleteDorama="matAutocomplete">
<mat-option *ngIf="isLoading" class="is-loading">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-option>
<ng-container *ngIf="!isLoading">
<mat-option *ngFor="let d of filteredDorama" [value]="d.mdl_id" class="px-1" (click)="filterDoramaSelected(d)">
<img src="{{ d.image_url }}" style="height: 40px; width: 30px; object-fit: cover;" class="me-1" />
<span class="ms-1">{{ d.mdl_id }} :: {{ d.title }}</span>
</mat-option>
</ng-container>
</mat-autocomplete>
<small *ngIf="fg.get('dorama_name').value" class="text-warning">{{ fg.get('dorama_name').value }}</small>
<mat-error>
<div *ngIf="fg.get('dorama_id').hasError('required')">ID Dorama Tidak Boleh Kosong</div>
<div *ngIf="fg.get('dorama_id').hasError('pattern')">ID Dorama Hanya Boleh Angka</div>
</mat-error>
</mat-form-field>
<ng-container *ngIf="!isLoading">
<mat-option *ngFor="let a of filteredAnime" [value]="a.id" class="px-1" (click)="filterAnimeSelected(a)">
<img src="{{ a.image_url }}" style="height: 40px; width: 30px; object-fit: cover;" class="me-1" />
<span class="ms-1">{{ a.id }} :: {{ a.media_type?.toUpperCase() }} :: {{ a.title }}</span>
</mat-option>
</ng-container>
</mat-autocomplete>
<small *ngIf="fg.get('anime_name').value" class="text-warning">{{ fg.get('anime_name').value }}</small>
<mat-error>
<div *ngIf="fg.get('anime_id').hasError('required')">ID Anime Tidak Boleh Kosong</div>
<div *ngIf="fg.get('anime_id').hasError('pattern')">ID Anime Hanya Boleh Angka</div>
</mat-error>
</mat-form-field>
</ng-template>
<ng-template #notAnime_>
<ng-container *ngIf="berkasType.toLowerCase().includes('dorama_'); then dorama_; else notDorama_;"></ng-container>
<ng-template #dorama_>
<mat-form-field appearance="outline" class="p-3 w-100" [color]="'accent'">
<mat-label>Dorama Terkait</mat-label>
<input matInput formControlName="dorama_id" placeholder="Flying Colors" [matAutocomplete]="autoCompleteDorama" (keyup)="resetSelectedDorama()" />
<mat-icon fontIcon="short_text" matSuffix></mat-icon>
<mat-autocomplete #autoCompleteDorama="matAutocomplete">
<mat-option *ngIf="isLoading" class="is-loading">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</mat-option>
<ng-container *ngIf="!isLoading">
<mat-option *ngFor="let d of filteredDorama" [value]="d.mdl_id" class="px-1" (click)="filterDoramaSelected(d)">
<img src="{{ d.image_url }}" style="height: 40px; width: 30px; object-fit: cover;" class="me-1" />
<span class="ms-1">{{ d.mdl_id }} :: {{ d.title }}</span>
</mat-option>
</ng-container>
</mat-autocomplete>
<small *ngIf="fg.get('dorama_name').value" class="text-warning">{{ fg.get('dorama_name').value }}</small>
<mat-error>
<div *ngIf="fg.get('dorama_id').hasError('required')">ID Dorama Tidak Boleh Kosong</div>
<div *ngIf="fg.get('dorama_id').hasError('pattern')">ID Dorama Hanya Boleh Angka</div>
</mat-error>
</mat-form-field>
</ng-template>
<ng-template #notDorama_>
<mat-form-field appearance="outline" class="p-3 col-12" *ngIf="berkasType" [color]="'accent'">
<mat-label>Kode / Serial Number</mat-label>
<input matInput formControlName="sn_code" placeholder="XXX-999" required />
<mat-icon fontIcon="tag" matSuffix></mat-icon>
<mat-error>
<div *ngIf="fg.get('sn_code').hasError('required')">Kode Serial Tidak Boleh Kosong</div>
<div *ngIf="fg.get('sn_code').hasError('pattern')">Kode Serial Hanya Boleh Huruf Besar, Strip, Dan Angka</div>
</mat-error>
</mat-form-field>
</ng-template>
</ng-template>
<div class="col-12 p-3">
<mat-divider></mat-divider>
</div>
Expand Down
Loading

0 comments on commit af72b60

Please sign in to comment.