Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "times played" slider filter #612

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
"sizeFilterDescription": "Size",
"sizeFilterHint": "Size filter",
"sizeFilterMoreInfo": "Show the size filter",
"timesPlayedDescription": "Times Played",
"timesPlayedHint": "Times Played filter",
"timesPlayedMoreInfo": "Show the times played filter",
"sortOptionAlphabeticalDescription": "Alphabetical",
"sortOptionAlphabeticalDescription2": "Alphabetical 2",
"sortOptionAlphabeticalMoreInfo": "Show the alphabetical order option in the sorting dropdown",
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import { DeleteFilePipe } from './pipes/delete-file.pipe';
import { DuplicateFinderPipe } from './pipes/duplicateFinder.pipe';
import { FileSearchPipe } from './pipes/file-search.pipe';
import { FileSizeFilterPipe } from './pipes/file-size-filter.pipe';
import { TimesPlayedFilterPipe } from './pipes/times-played-filter.pipe';
import { FileSizePipe } from './pipes/file-size.pipe';
import { FolderArrowsPipe } from './pipes/folder-arrows.pipe';
import { FolderViewPipe } from './pipes/folder-view.pipe';
Expand All @@ -99,6 +100,7 @@ import { TagFilterPipe } from './components/tags-auto/tag-filter.pipe';
import { TagFrequencyPipe } from './components/tags-auto/tag-frequency.pipe';
import { TagMatchPipe } from './components/tags-auto/tag-match.pipe';
import { TagsDisplayPipe } from './components/tags-auto/tag-display.pipe';
import { TimesPlayedPipe } from './pipes/times-played.pipe';
import { WordFrequencyPipe } from './pipes/word-frequency.pipe';
import { WrapperPipe } from './pipes/wrapper.pipe';

Expand Down Expand Up @@ -163,6 +165,8 @@ import { WrapperPipe } from './pipes/wrapper.pipe';
TagTrayComponent,
TagsComponent,
TagsDisplayPipe,
TimesPlayedPipe,
TimesPlayedFilterPipe,
ThumbnailComponent,
TitleBarComponent,
TopComponent,
Expand Down
9 changes: 9 additions & 0 deletions src/app/common/settings-buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type SettingsButtonKey = 'autoFileTags'
| 'tagExclusion'
| 'tagIntersection'
| 'tagUnion'
| 'timesPlayedFilter'
| 'thumbAutoAdvance'
| 'videoNotes';

Expand All @@ -102,6 +103,7 @@ export const SettingsButtonsGroups: SettingsButtonKey[][] = [
[ // 2 - Filters & sorting options
'durationFilter',
'sizeFilter',
'timesPlayedFilter',
'resolutionFilter',
'starFilter',
'sortOrder',
Expand Down Expand Up @@ -818,6 +820,13 @@ export const SettingsButtons: SettingsButtonsType = {
moreInfo: 'BUTTONS.tagUnionMoreInfo',
title: 'BUTTONS.tagUnionHint',
toggled: false
}, 'timesPlayedFilter': {
description: 'BUTTONS.timesPlayedDescription',
hidden: false,
iconName: 'icon-res-filter',
moreInfo: 'BUTTONS.timesPlayedMoreInfo',
title: 'BUTTONS.timesPlayedHint',
toggled: false
},
'thumbAutoAdvance': {
description: 'BUTTONS.thumbAutoAdvanceDescription',
Expand Down
18 changes: 18 additions & 0 deletions src/app/components/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,20 @@
></app-slider-filter>
</div>

<!-- timesPlayedFilter -->
<div *ngIf="settingsButtons['timesPlayedFilter'].toggled">

<app-slider-filter
(newSliderFilterSelected)="newTimesPlayedFilterSelected($event)"
[darkMode]="settingsButtons['darkMode'].toggled"
[labelFormatPipe]="'timesPlayedPipe'"
[maximumValue]="timesPlayedCutoff"
[minimumValue]="-1"
[timesPlayed]="true"
[steps]="50"
></app-slider-filter>
</div>

<!-- resolution filter & its frequency histogram -->
<app-resolution-filter
(newResFilterSelected)="newResFilterSelected($event)"
Expand Down Expand Up @@ -713,6 +727,10 @@
: sizeLeftBound
: sizeRightBound

| timesPlayedFilterPipe : settingsButtons['timesPlayedFilter'].toggled
: timesPlayedLeftBound
: timesPlayedRightBound

| resolutionFilterPipe : settingsButtons['resolutionFilter'].toggled
: freqLeftBound
: freqRightBound
Expand Down
22 changes: 22 additions & 0 deletions src/app/components/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export class HomeComponent implements OnInit, AfterViewInit {
sizeLeftBound: number = 0;
sizeRightBound: number = Infinity;

// ========================================================================
// Times Played filter
// ------------------------------------------------------------------------

timesPlayedLeftBound: number = 0;
timesPlayedRightBound: number = Infinity;

// ========================================================================
// Frequency / histogram
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -274,6 +281,7 @@ export class HomeComponent implements OnInit, AfterViewInit {

durationOutlierCutoff: number = 0; // for the duration filter to cut off outliers
sizeOutlierCutoff: number = 0; // for the size filter to cut off outliers
timesPlayedCutoff: number = 0; // for the times played filter max value

timeExtractionStarted; // time remaining calculator
timeExtractionRemaining; // time remaining calculator
Expand Down Expand Up @@ -717,6 +725,7 @@ export class HomeComponent implements OnInit, AfterViewInit {

this.setUpDurationFilterValues(this.imageElementService.imageElements);
this.setUpSizeFilterValues(this.imageElementService.imageElements);
this.setUpTimesPlayedFilterValues(this.imageElementService.imageElements);

if (this.sortOrderRef.sortFilterElement) {
this.sortOrderRef.sortFilterElement.nativeElement.value = this.sortType;
Expand Down Expand Up @@ -2192,6 +2201,13 @@ export class HomeComponent implements OnInit, AfterViewInit {

}

newTimesPlayedFilterSelected(selection: number[]): void {

this.timesPlayedLeftBound = selection[0];
this.timesPlayedRightBound = selection[1];

}

setUpDurationFilterValues(finalArray: ImageElement[]): void {
const durations: number[] = finalArray.map((element) => { return element.duration; });

Expand All @@ -2206,6 +2222,12 @@ export class HomeComponent implements OnInit, AfterViewInit {
this.sizeOutlierCutoff = Math.max(...fileSizes);
}

setUpTimesPlayedFilterValues(finalArray: ImageElement[]): void {
const timesPlayed: number[] = finalArray.map((element) => { return element.timesPlayed; });

this.timesPlayedCutoff = Math.max(...timesPlayed);
}

/**
* Given an array of numbers
* returns the cutoff for outliers
Expand Down
17 changes: 17 additions & 0 deletions src/app/components/slider-filter/slider-filter.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
>
{{ convertToIndex(currentXleft) | wrapperPipe : labelFormatPipe }}
</span>
<span
*ngIf="timesPlayed"
class="left-label"
[ngStyle]="{ left: ((currentXleft > 10) ? currentXleft - 10 : 0) + 'px' }"
>
{{ convertToIndex(currentXleft) | wrapperPipe : labelFormatPipe}}
</span>
<span
*ngIf="lengthFilter"
class="right-label"
Expand All @@ -69,8 +76,18 @@
>
{{ convertToIndex(currentXright) | wrapperPipe : labelFormatPipe }}
</span>

<span
*ngIf="timesPlayed"
class="right-label"
[ngStyle]="{ right: 160 - ((currentXright < 125) ? currentXright + 50 : 160) + 'px' }"
>
{{ convertToIndex(currentXright) | wrapperPipe : labelFormatPipe}}
</span>
<span *ngIf="lengthFilter" class="minLabel">0 min</span>
<span *ngIf="lengthFilter" class="maxLabel">∞</span>
<span *ngIf="sizeFilter" class="minLabel">0 MB</span>
<span *ngIf="sizeFilter" class="maxLabel">∞</span>
<span *ngIf="timesPlayed" class="minLabel">0</span>
<span *ngIf="timesPlayed" class="maxLabel">∞</span>
</div>
3 changes: 2 additions & 1 deletion src/app/components/slider-filter/slider-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class SliderFilterComponent implements OnInit, OnDestroy {
@Input() steps: number;
@Input() lengthFilter?: boolean = false;
@Input() sizeFilter?: boolean = false;
@Input() timesPlayed?: boolean = false;
@Input() labelFormatPipe?: string;

@Output() newSliderFilterSelected = new EventEmitter<number[]>();
Expand Down Expand Up @@ -85,7 +86,7 @@ export class SliderFilterComponent implements OnInit, OnDestroy {

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

if ((this.lengthFilter || this.sizeFilter) && cutoff > this.maximumValue) {
if ((this.lengthFilter || this.sizeFilter || this.timesPlayed) && cutoff > this.maximumValue) {
return Infinity;
} else {
return cutoff;
Expand Down
31 changes: 31 additions & 0 deletions src/app/pipes/times-played-filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Pipe, PipeTransform } from '@angular/core';

import { ImageElement } from '../../../interfaces/final-object.interface';

@Pipe({
name: 'timesPlayedFilterPipe'
})
export class TimesPlayedFilterPipe implements PipeTransform {

/**
* Filter and show only videos that are within the fileSize bounds
* @param finalArray
* @param render
* @param leftBound
* @param rightBound
*/
transform(finalArray: ImageElement[], render?: boolean, leftBound?: number, rightBound?: number): ImageElement[] {

if (render && finalArray.length > 0) {
return finalArray.filter((element) => {
const timesPlayed = element.timesPlayed;
if ( timesPlayed > leftBound && timesPlayed < rightBound) {
return true;
} else {
return false;
}
});
}
return finalArray;
}
}
23 changes: 23 additions & 0 deletions src/app/pipes/times-played.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'timesPlayedPipe'
})
export class TimesPlayedPipe implements PipeTransform {

/**
* Return times played of file as int
* add 1 to result because min value needs to be -1 in order to include files with 0 times played
* @param timesPlayed -- times played value
*/
transform(timesPlayed: number): string {
if (timesPlayed) {
const rounded = Math.floor(timesPlayed+1)

return rounded.toString(10);
} else {
return '0';
}
}

}
6 changes: 6 additions & 0 deletions src/app/pipes/wrapper.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Pipe, PipeTransform } from '@angular/core';
import { LengthPipe } from './length.pipe';
import { FileSizePipe } from './file-size.pipe';
import { TimesPlayedPipe } from './times-played.pipe';

@Pipe({
name: 'wrapperPipe'
Expand All @@ -14,6 +15,11 @@ export class WrapperPipe implements PipeTransform {
if (pipe === 'fileSizePipe') {
return new FileSizePipe().transform(value, true);
}

if (pipe === 'timesPlayedPipe') {
return new TimesPlayedPipe().transform(value);
}

return value;
}
}