Added ability to generate RSS feed URLs from the UI

Moved property sorting into its own component
This commit is contained in:
Tzahi12345
2023-01-05 02:38:44 -05:00
parent 2a3017972a
commit 121f5586a6
16 changed files with 314 additions and 70 deletions

View File

@@ -2,20 +2,7 @@
<div class="row">
<!-- Sorting -->
<div class="col-12 order-2 col-sm-4 order-sm-1 d-flex justify-content-center">
<div>
<div style="display: inline-block;">
<mat-form-field appearance="outline" style="width: 165px;">
<mat-select [(ngModel)]="this.sortProperty" (selectionChange)="filterOptionChanged($event.value)">
<mat-option *ngFor="let sortOption of sortProperties | keyvalue" [value]="sortOption.value">
{{sortOption['value']['label']}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="sort-dir-div">
<button (click)="toggleModeChange()" mat-icon-button><mat-icon>{{descendingMode ? 'arrow_downward' : 'arrow_upward'}}</mat-icon></button>
</div>
</div>
<app-sort-property [(sortProperty)]="sortProperty" [(descendingMode)]="descendingMode" (sortOptionChanged)="sortOptionChanged($event)"></app-sort-property>
</div>
<!-- Files title -->
<div class="col-12 order-1 col-sm-4 order-sm-2 d-flex justify-content-center">

View File

@@ -41,12 +41,6 @@
display: inline-block;
}
.sort-dir-div {
display: inline-block;
position: absolute;
top: 4px;
}
.paginator {
margin-top: 5px;
}

View File

@@ -1,7 +1,7 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { PostsService } from 'app/posts.services';
import { Router } from '@angular/router';
import { DatabaseFile, FileType, FileTypeFilter } from '../../../api-types';
import { DatabaseFile, FileType, FileTypeFilter, Sort } from '../../../api-types';
import { MatPaginator } from '@angular/material/paginator';
import { Subject } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
@@ -47,33 +47,6 @@ export class RecentVideosComponent implements OnInit {
search_text = '';
searchIsFocused = false;
descendingMode = true;
sortProperties = {
'registered': {
'key': 'registered',
'label': $localize`Download Date`,
'property': 'registered'
},
'upload_date': {
'key': 'upload_date',
'label': $localize`Upload Date`,
'property': 'upload_date'
},
'name': {
'key': 'name',
'label': $localize`Name`,
'property': 'title'
},
'file_size': {
'key': 'file_size',
'label': $localize`File Size`,
'property': 'size'
},
'duration': {
'key': 'duration',
'label': $localize`Duration`,
'property': 'duration'
}
};
fileFilters = {
video_only: {
@@ -94,7 +67,7 @@ export class RecentVideosComponent implements OnInit {
selectedFilters = [];
sortProperty = this.sortProperties['upload_date'];
sortProperty = 'registered';
playlists = null;
@@ -109,8 +82,8 @@ export class RecentVideosComponent implements OnInit {
// set filter property to cached value
const cached_sort_property = localStorage.getItem('sort_property');
if (cached_sort_property && this.sortProperties[cached_sort_property]) {
this.sortProperty = this.sortProperties[cached_sort_property];
if (cached_sort_property) {
this.sortProperty = cached_sort_property;
}
// set file type filter to cached value
@@ -189,8 +162,12 @@ export class RecentVideosComponent implements OnInit {
this.searchChangedSubject.next(newvalue);
}
filterOptionChanged(value: string): void {
localStorage.setItem('filter_property', value['key']);
sortOptionChanged(value: Sort): void {
localStorage.setItem('sort_property', value['by']);
localStorage.setItem('recent_videos_sort_order', value['order'] === -1 ? 'descending' : 'ascending');
this.descendingMode = value['order'] === -1;
this.sortProperty = value['by'];
this.getAllFiles();
}
@@ -227,18 +204,13 @@ export class RecentVideosComponent implements OnInit {
return this.selectedFilters.includes('favorited');
}
toggleModeChange(): void {
this.descendingMode = !this.descendingMode;
localStorage.setItem('recent_videos_sort_order', this.descendingMode ? 'descending' : 'ascending');
this.getAllFiles();
}
// get files
getAllFiles(cache_mode = false): void {
this.normal_files_received = cache_mode;
const current_file_index = (this.paginator?.pageIndex ? this.paginator.pageIndex : 0)*this.pageSize;
const sort = {by: this.sortProperty['property'], order: this.descendingMode ? -1 : 1};
const sort = {by: this.sortProperty, order: this.descendingMode ? -1 : 1};
const range = [current_file_index, current_file_index + this.pageSize];
const fileTypeFilter = this.getFileTypeFilter();
const favoriteFilter = this.getFavoriteFilter();

View File

@@ -0,0 +1,14 @@
<div>
<div style="display: inline-block;">
<mat-form-field appearance="outline" style="width: 165px;">
<mat-select [(ngModel)]="this.sortProperty" (selectionChange)="emitSortOptionChanged()">
<mat-option *ngFor="let sortOption of sortProperties | keyvalue" [value]="sortOption.key">
{{sortOption['value']['label']}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="sort-dir-div">
<button (click)="toggleModeChange()" mat-icon-button><mat-icon>{{descendingMode ? 'arrow_downward' : 'arrow_upward'}}</mat-icon></button>
</div>
</div>

View File

@@ -0,0 +1,5 @@
.sort-dir-div {
display: inline-block;
position: absolute;
top: 4px;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SortPropertyComponent } from './sort-property.component';
describe('SortPropertyComponent', () => {
let component: SortPropertyComponent;
let fixture: ComponentFixture<SortPropertyComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SortPropertyComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(SortPropertyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,54 @@
import { Component, Input, EventEmitter, Output } from '@angular/core';
import { Sort } from 'api-types';
@Component({
selector: 'app-sort-property',
templateUrl: './sort-property.component.html',
styleUrls: ['./sort-property.component.scss']
})
export class SortPropertyComponent {
sortProperties = {
'registered': {
'key': 'registered',
'label': $localize`Download Date`
},
'upload_date': {
'key': 'upload_date',
'label': $localize`Upload Date`
},
'title': {
'key': 'title',
'label': $localize`Name`
},
'size': {
'key': 'size',
'label': $localize`File Size`
},
'duration': {
'key': 'duration',
'label': $localize`Duration`
}
};
@Input() sortProperty = 'registered';
@Input() descendingMode = true;
@Output() sortPropertyChange = new EventEmitter<unknown>();
@Output() descendingModeChange = new EventEmitter<number>();
@Output() sortOptionChanged = new EventEmitter<Sort>();
toggleModeChange(): void {
this.descendingMode = !this.descendingMode;
this.emitSortOptionChanged();
}
emitSortOptionChanged(): void {
if (!this.sortProperty || !this.sortProperties[this.sortProperty]) {
return;
}
this.sortOptionChanged.emit({
by: this.sortProperty,
order: this.descendingMode ? -1 : 1
});
}
}