Skip to content

Commit 051014b

Browse files
authored
Add Year filter (#677)
* Add times played slider filter * yearFilter initial commit * move button to filter section * year filter progress
1 parent 41310a6 commit 051014b

File tree

10 files changed

+144
-5
lines changed

10 files changed

+144
-5
lines changed

i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@
202202
"thumbAutoAdvanceDescription": "Cycle on hover",
203203
"thumbAutoAdvanceHint": "Enable thumbnail auto advance",
204204
"thumbAutoAdvanceMoreInfo": "Hovering over thumbnails cycles through screenshots",
205+
"yearSliderDescription": "Filter by Year",
206+
"yearSliderHint": "Year Filter",
207+
"yearSliderMoreInfo": "Show the year slider filter",
205208
"videoNotesDescription": "Notes search",
206209
"videoNotesHint": "Notes search",
207210
"videoNotesMoreInfo": "Search through the notes you have added to your videos. Enable notes in the Tags settings",

src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { DuplicateFinderPipe } from './pipes/duplicateFinder.pipe';
8080
import { FileSearchPipe } from './pipes/file-search.pipe';
8181
import { FileSizeFilterPipe } from './pipes/file-size-filter.pipe';
8282
import { TimesPlayedFilterPipe } from './pipes/times-played-filter.pipe';
83+
import { YearFilterPipe } from './pipes/year-filter.pipe';
8384
import { FileSizePipe } from './pipes/file-size.pipe';
8485
import { FolderArrowsPipe } from './pipes/folder-arrows.pipe';
8586
import { FolderViewPipe } from './pipes/folder-view.pipe';
@@ -104,6 +105,8 @@ import { TagsDisplayPipe } from './components/tags-auto/tag-display.pipe';
104105
import { TimesPlayedPipe } from './pipes/times-played.pipe';
105106
import { WordFrequencyPipe } from './pipes/word-frequency.pipe';
106107
import { WrapperPipe } from './pipes/wrapper.pipe';
108+
import { YearPipe } from './pipes/year.pipe';
109+
107110

108111
@NgModule({
109112
declarations: [
@@ -175,7 +178,9 @@ import { WrapperPipe } from './pipes/wrapper.pipe';
175178
WelcomeComponent,
176179
WizardComponent,
177180
WordFrequencyPipe,
178-
WrapperPipe
181+
WrapperPipe,
182+
YearPipe,
183+
YearFilterPipe
179184
],
180185
imports: [
181186
AnQrcodeModule,

src/app/common/settings-buttons.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ export type SettingsButtonKey = 'autoFileTags'
7777
| 'tagExclusion'
7878
| 'tagIntersection'
7979
| 'tagUnion'
80-
| 'thumbAutoAdvance'
8180
| 'timesPlayedFilter'
81+
| 'thumbAutoAdvance'
82+
| 'yearFilter'
8283
| 'videoNotes';
8384

8485
// Add `SettingsButtons` items here so they show up in the buttons ribbon and in the settings
@@ -106,6 +107,7 @@ export const SettingsButtonsGroups: SettingsButtonKey[][] = [
106107
'sizeFilter',
107108
'timesPlayedFilter',
108109
'resolutionFilter',
110+
'yearFilter',
109111
'starFilter',
110112
'sortOrder',
111113
'hideOffline',
@@ -122,7 +124,6 @@ export const SettingsButtonsGroups: SettingsButtonKey[][] = [
122124
'sortOptionAspectRatio',
123125
'sortOptionFps',
124126
'sortOptionFolderSize',
125-
126127
],
127128
[ // 3 - Find duplicates
128129
'duplicateLength',
@@ -847,6 +848,14 @@ export const SettingsButtons: SettingsButtonsType = {
847848
title: 'BUTTONS.thumbAutoAdvanceHint',
848849
toggled: false
849850
},
851+
'yearFilter': {
852+
description: 'BUTTONS.yearSliderDescription',
853+
hidden: false,
854+
iconName: 'icon-times-played',
855+
moreInfo: 'BUTTONS.yearSliderMoreInfo',
856+
title: 'BUTTONS.yearSliderHint',
857+
toggled: false
858+
},
850859
'videoNotes': {
851860
description: 'BUTTONS.videoNotesDescription',
852861
hidden: true,

src/app/components/home.component.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,20 @@
543543
></app-slider-filter>
544544
</div>
545545

546+
<!-- yearFilter -->
547+
<div *ngIf="settingsButtons['yearFilter'].toggled">
548+
549+
<app-slider-filter
550+
(newSliderFilterSelected)="newYearFilterSelected($event)"
551+
[darkMode]="settingsButtons['darkMode'].toggled"
552+
[labelFormatPipe]="'yearPipe'"
553+
[maximumValue]="yearCutoff"
554+
[minimumValue]="yearMinCutoff"
555+
[yearFilter]="true"
556+
[steps]="50"
557+
></app-slider-filter>
558+
</div>
559+
546560
<!-- resolution filter & its frequency histogram -->
547561
<app-resolution-filter
548562
(newResFilterSelected)="newResFilterSelected($event)"
@@ -731,6 +745,10 @@
731745
: timesPlayedLeftBound
732746
: timesPlayedRightBound
733747
748+
| yearFilterPipe : settingsButtons['yearFilter'].toggled
749+
: yearLeftBound
750+
: yearRightBound
751+
734752
| resolutionFilterPipe : settingsButtons['resolutionFilter'].toggled
735753
: freqLeftBound
736754
: freqRightBound

src/app/components/home.component.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ export class HomeComponent implements OnInit, AfterViewInit {
185185
timesPlayedLeftBound: number = 0;
186186
timesPlayedRightBound: number = Infinity;
187187

188+
// ========================================================================
189+
// Year filter
190+
// ------------------------------------------------------------------------
191+
192+
yearMinCutoff: number = 0;
193+
yearCutoff: number = 0;
194+
yearLeftBound: number = 0;
195+
yearRightBound: number = Infinity;
196+
188197
// ========================================================================
189198
// Frequency / histogram
190199
// ------------------------------------------------------------------------
@@ -719,6 +728,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
719728
this.setUpDurationFilterValues(this.imageElementService.imageElements);
720729
this.setUpSizeFilterValues(this.imageElementService.imageElements);
721730
this.setUpTimesPlayedFilterValues(this.imageElementService.imageElements);
731+
this.setUpYearFilterValues(this.imageElementService.imageElements);
722732

723733
if (this.sortOrderRef.sortFilterElement) {
724734
this.sortOrderRef.sortFilterElement.nativeElement.value = this.sortType;
@@ -2205,6 +2215,13 @@ export class HomeComponent implements OnInit, AfterViewInit {
22052215

22062216
}
22072217

2218+
newYearFilterSelected(selection: number[]): void {
2219+
2220+
this.yearLeftBound = selection[0];
2221+
this.yearRightBound = selection[1];
2222+
2223+
}
2224+
22082225
setUpDurationFilterValues(finalArray: ImageElement[]): void {
22092226
const durations: number[] = finalArray.map((element) => { return element.duration; });
22102227

@@ -2225,6 +2242,14 @@ export class HomeComponent implements OnInit, AfterViewInit {
22252242
this.timesPlayedCutoff = Math.max(...timesPlayed);
22262243
}
22272244

2245+
//need to filter otherwise cutoff will be NaN
2246+
setUpYearFilterValues(finalArray: ImageElement[]): void {
2247+
const year: number[] = finalArray.map((element) => { return element.year; });
2248+
const filtrate = el => Number.isInteger(el) && el > 0;
2249+
const yearFiltered = year.filter(filtrate)
2250+
this.yearMinCutoff = Math.min(...yearFiltered) - 1
2251+
this.yearCutoff = Math.max(...yearFiltered);
2252+
}
22282253
/**
22292254
* Given an array of numbers
22302255
* returns the cutoff for outliers

src/app/components/slider-filter/slider-filter.component.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@
6565
>
6666
{{ convertToIndex(currentXleft) | wrapperPipe : labelFormatPipe}}
6767
</span>
68+
<span
69+
*ngIf="yearFilter"
70+
class="left-label"
71+
[ngStyle]="{ left: ((currentXleft > 10) ? currentXleft - 10 : 0) + 'px', width: 6 + 'px' }"
72+
>
73+
{{ convertToIndex(currentXleft) | wrapperPipe : labelFormatPipe}}
74+
</span>
6875
<span
6976
*ngIf="lengthFilter"
7077
class="right-label"
@@ -82,15 +89,25 @@
8289
<span
8390
*ngIf="timesPlayed"
8491
class="right-label"
85-
[ngStyle]="{ right: 160 - ((currentXright < 160) ? currentXright + 11 : 160) + 'px', width: 11 + 'px' }"
92+
[ngStyle]="{ right: 160 - ((currentXright < 160) ? currentXright + 11 : 160) + 'px'}"
8693
>
8794
{{ convertToIndex(currentXright) | wrapperPipe : labelFormatPipe}}
8895
</span>
96+
<span
97+
*ngIf="yearFilter"
98+
class="right-label"
99+
[ngStyle]="{ right: 160 - ((currentXright < 125) ? currentXright + 35 : 160) + 'px'}"
100+
>
101+
{{ convertToIndex(currentXright) | wrapperPipe : labelFormatPipe}}
102+
</span>
89103

90104
<span *ngIf="lengthFilter" class="minLabel">0 min</span>
91105
<span *ngIf="lengthFilter" class="maxLabel"></span>
92106
<span *ngIf="sizeFilter" class="minLabel">0 MB</span>
93107
<span *ngIf="sizeFilter" class="maxLabel"></span>
94108
<span *ngIf="timesPlayed" class="minLabel">0</span>
95109
<span *ngIf="timesPlayed" class="maxLabel"></span>
110+
<span *ngIf="yearFilter" class="minLabel">0</span>
111+
<span *ngIf="yearFilter" class="maxLabel"></span>
112+
96113
</div>

src/app/components/slider-filter/slider-filter.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class SliderFilterComponent implements OnInit, OnDestroy {
1414
@Input() lengthFilter?: boolean = false;
1515
@Input() sizeFilter?: boolean = false;
1616
@Input() timesPlayed?: boolean = false;
17+
@Input() yearFilter?: boolean = false;
1718
@Input() labelFormatPipe?: string;
1819

1920
@Output() newSliderFilterSelected = new EventEmitter<number[]>();
@@ -86,7 +87,7 @@ export class SliderFilterComponent implements OnInit, OnDestroy {
8687

8788
const cutoff = (value / this.width) * (this.maximumValue - this.minimumValue) + this.minimumValue;
8889

89-
if ((this.lengthFilter || this.sizeFilter || this.timesPlayed) && cutoff > this.maximumValue) {
90+
if ((this.lengthFilter || this.sizeFilter || this.timesPlayed || this.yearFilter) && cutoff > this.maximumValue) {
9091
return Infinity;
9192
} else {
9293
return cutoff;

src/app/pipes/wrapper.pipe.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core';
22
import { LengthPipe } from './length.pipe';
33
import { FileSizePipe } from './file-size.pipe';
44
import { TimesPlayedPipe } from './times-played.pipe';
5+
import { YearPipe } from './year.pipe';
56

67
@Pipe({
78
name: 'wrapperPipe'
@@ -20,6 +21,10 @@ export class WrapperPipe implements PipeTransform {
2021
return new TimesPlayedPipe().transform(value);
2122
}
2223

24+
if (pipe === 'yearPipe') {
25+
return new YearPipe().transform(value);
26+
}
27+
2328
return value;
2429
}
2530
}

src/app/pipes/year-filter.pipe.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
import { ImageElement } from '../../../interfaces/final-object.interface';
4+
5+
@Pipe({
6+
name: 'yearFilterPipe'
7+
})
8+
export class YearFilterPipe implements PipeTransform {
9+
10+
/**
11+
* Filter and show only videos that are within the year bounds
12+
* @param finalArray
13+
* @param render
14+
* @param leftBound
15+
* @param rightBound
16+
*/
17+
transform(finalArray: ImageElement[], render?: boolean, leftBound?: number, rightBound?: number): ImageElement[] {
18+
19+
if (render && finalArray.length > 0) {
20+
return finalArray.filter((element) => {
21+
const year = element.year;
22+
if ( year > leftBound && year < rightBound) {
23+
return true;
24+
} else {
25+
return false;
26+
}
27+
});
28+
}
29+
return finalArray;
30+
}
31+
}

src/app/pipes/year.pipe.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'yearPipe'
5+
})
6+
export class YearPipe implements PipeTransform {
7+
8+
/**
9+
* Return year value of file
10+
* @param year
11+
*/
12+
transform(year: number): string {
13+
if (year) {
14+
const rounded = Math.floor(year)
15+
if (!isFinite(rounded)) {
16+
return "∞"
17+
}
18+
19+
return rounded.toString(10);
20+
} else {
21+
return '0';
22+
}
23+
}
24+
25+
}

0 commit comments

Comments
 (0)