Refactored retrieval of categories and improved runtime search of files in category

Fixed issue with editing/saving categories

Database queries can now handle nested object paths

Code cleanup
This commit is contained in:
Isaac Abadi
2022-06-17 19:43:32 -04:00
parent c810d4d878
commit b56c66f705
10 changed files with 50 additions and 30 deletions

View File

@@ -35,7 +35,7 @@ export class CustomPlaylistsComponent implements OnInit {
getAllPlaylists() {
this.playlists_received = false;
// must call getAllFiles as we need to get category playlists as well
this.postsService.getPlaylists().subscribe(res => {
this.postsService.getPlaylists(true).subscribe(res => {
this.playlists = res['playlists'];
this.playlists_received = true;
});

View File

@@ -28,12 +28,12 @@
<mat-form-field class="info-field">
<input [(ngModel)]="new_file.thumbnailURL" matInput placeholder="Thumbnail URL" i18n-placeholder="Thumbnail URL" [disabled]="!editing || new_file.thumbnailPath">
</mat-form-field>
<mat-form-field class="info-field">
<mat-select placeholder="Category" i18n-placeholder="Category" [value]="category" (valueChange)="categoryChanged($event)" [compareWith]="categoryComparisonFunction" [disabled]="!editing">
<mat-form-field *ngIf="initialized && postsService.categories" class="info-field">
<mat-select placeholder="Category" i18n-placeholder="Category" [value]="category" (selectionChange)="categoryChanged($event)" [compareWith]="categoryComparisonFunction" [disabled]="!editing">
<mat-option [value]="{}">
N/A
</mat-option>
<mat-option *ngFor="let available_category of postsService.categories | keyvalue" [value]="available_category">
<mat-option *ngFor="let available_category of postsService.categories | keyvalue" [value]="available_category.value">
{{available_category.value.name}}
</mat-option>
</mat-select>

View File

@@ -18,6 +18,7 @@ export class VideoInfoDialogComponent implements OnInit {
upload_date: Date;
category: Category;
editing = false;
initialized = false;
constructor(@Inject(MAT_DIALOG_DATA) public data: any, public postsService: PostsService, private datePipe: DatePipe) { }
@@ -37,15 +38,16 @@ export class VideoInfoDialogComponent implements OnInit {
this.upload_date = new Date(this.new_file.upload_date);
this.upload_date.setMinutes( this.upload_date.getMinutes() + this.upload_date.getTimezoneOffset() );
this.category = this.file.category ? this.category : {};
this.category = this.file.category ? this.file.category : {};
// we need to align whether missing category is null or undefined. this line helps with that.
if (!this.file.category) { this.new_file.category = null; this.file.category = null; }
this.initialized = true;
}
saveChanges(): void {
const change_obj = {};
const keys = Object.keys(this.file);
const keys = Object.keys(this.new_file);
keys.forEach(key => {
if (this.file[key] !== this.new_file[key]) change_obj[key] = this.new_file[key];
});
@@ -67,7 +69,8 @@ export class VideoInfoDialogComponent implements OnInit {
}
categoryChanged(event): void {
this.new_file.category = Object.keys(event).length ? {uid: event.uid, name: event.name} : null;
const new_category = event.value;
this.new_file.category = Object.keys(new_category).length ? {uid: new_category.uid, name: new_category.name} : null;
}
categoryComparisonFunction(option: Category, value: Category): boolean {

View File

@@ -457,15 +457,15 @@ export class PostsService implements CanActivate {
return this.http.post<GetPlaylistResponse>(this.path + 'getPlaylist', body, this.httpOptions);
}
getPlaylists(include_categories = false) {
return this.http.post<GetPlaylistsRequest>(this.path + 'getPlaylists', {include_categories: include_categories}, this.httpOptions);
}
incrementViewCount(file_uid, sub_id, uuid) {
const body: IncrementViewCountRequest = {file_uid: file_uid, sub_id: sub_id, uuid: uuid};
return this.http.post<SuccessObject>(this.path + 'incrementViewCount', body, this.httpOptions);
}
getPlaylists() {
return this.http.post<GetPlaylistsRequest>(this.path + 'getPlaylists', {}, this.httpOptions);
}
updatePlaylist(playlist: Playlist) {
const body: UpdatePlaylistRequest = {playlist: playlist};
return this.http.post<SuccessObject>(this.path + 'updatePlaylist', body, this.httpOptions);