Skip to content

Commit cc1e362

Browse files
authored
Merge pull request #423 from martincaron/sort-by-aspect-ratio-399
Sorting option for aspect ratio (#399)
2 parents ce81e0e + 7bbeb27 commit cc1e362

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
"sortOptionTimesPlayedMoreInfo": "Show the times played order option in the sorting dropdown",
149149
"sortOptionYearDescription": "Year",
150150
"sortOptionYearMoreInfo": "Show the year order option in the sorting dropdown. Only affected by the year you manually set in the details view",
151+
"sortOptionAspectRatioDescription": "Aspect Ratio",
152+
"sortOptionAspectRatioMoreInfo": "Show the aspect ratio order option in the sorting dropdown",
151153
"sortOrderDescription": "Sort order",
152154
"sortOrderHint": "Sort order",
153155
"sortOrderMoreInfo": "Show the sort order filter",
@@ -294,6 +296,7 @@
294296
"sortTime": "Duration",
295297
"sortTimesPlayed": "Times played",
296298
"sortYear": "Year",
299+
"sortAspectRatio": "Aspect ratio",
297300
"tagExclusion": "tags do not have",
298301
"tagIntersection": "tags include",
299302
"tagUnion": "tags include any",

i18n/fr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
"sortOptionTimesPlayedMoreInfo": "Afficher l'option de commande des temps joués dans le menu déroulant de tri",
136136
"sortOptionYearDescription": "Année",
137137
"sortOptionYearMoreInfo": "Afficher l’option de l’année dans le menu déroulant de tri. Uniquement affecté par l'année que vous avez définie manuellement dans la vue Détails",
138+
"sortOptionAspectRatioDescription": "Ratio d'aspect",
139+
"sortOptionAspectRatioMoreInfo": "Afficher l'option de ratio d'aspect dans la liste déroulante de tri",
138140
"sortOrderDescription": "Ordre de tri",
139141
"sortOrderHint": "Ordre de tri",
140142
"sortOrderMoreInfo": "Afficher le filtre d'ordre de tri",
@@ -271,6 +273,7 @@
271273
"sortTime": "Durée",
272274
"sortTimesPlayed": "Fois joué",
273275
"sortYear": "Année",
276+
"sortAspectRatio": "Ratio d'aspect",
274277
"tagExclusion": "les balises n'ont pas",
275278
"tagIntersection": "les tags incluent",
276279
"tagUnion": "les tags incluent",

src/app/common/settings-buttons.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export const SettingsButtonsGroups: string[][] = [
3030
'sortOptionStar',
3131
'sortOptionYear',
3232
'sortOptionModified',
33-
'sortOptionTags'
33+
'sortOptionTags',
34+
'sortOptionAspectRatio'
3435
],
3536
[
3637
'duplicateLength',
@@ -629,6 +630,14 @@ export const SettingsButtons: { [s: string]: SettingsButton } = {
629630
title: '',
630631
toggled: false,
631632
},
633+
'sortOptionAspectRatio': {
634+
description: 'BUTTONS.sortOptionAspectRatioDescription',
635+
hidden: false,
636+
iconName: 'icon-checkmark', // this specific icon makes the button only appear in the Settings menu (not in ribbon)
637+
moreInfo: 'BUTTONS.sortOptionAspectRatioMoreInfo',
638+
title: '',
639+
toggled: false,
640+
},
632641
'sortOrder': {
633642
description: 'BUTTONS.sortOrderDescription',
634643
hidden: false,

src/app/components/sort-order/sort-order.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
<option *ngIf="settingsButtons['sortOptionTags'].toggled" value="tagsDesc">
6666
&#x25BC; {{ 'SIDEBAR.sortTags' | translate }}
6767
</option>
68+
<option *ngIf="settingsButtons['sortOptionAspectRatio'].toggled" value="aspectRatioAsc">
69+
&#x25B2; {{ 'SIDEBAR.sortAspectRatio' | translate }}
70+
</option>
71+
<option *ngIf="settingsButtons['sortOptionAspectRatio'].toggled" value="aspectRatioDesc">
72+
&#x25BC; {{ 'SIDEBAR.sortAspectRatio' | translate }}
73+
</option>
6874
<option value="random">
6975
{{ 'SIDEBAR.sortRandom' | translate }}
7076
</option>

src/app/pipes/sorting.pipe.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { randomizeArray } from '../../../utility';
55
export type SortType = 'default'
66
| 'alphabetAsc'
77
| 'alphabetDesc'
8+
| 'aspectRatioAsc'
9+
| 'aspectRatioDesc'
810
| 'hash' // only used by the duplicateFinderPipe
911
| 'modifiedAsc'
1012
| 'modifiedDesc'
@@ -99,6 +101,19 @@ export class SortingPipe implements PipeTransform {
99101
}
100102
}
101103

104+
if (property === 'aspectRatio') {
105+
var xAspectRatio = x.width / x.height;
106+
var yAspectRatio = y.width / y.height;
107+
108+
if (xAspectRatio < yAspectRatio) {
109+
if (decreasing) { return 1 } else { return -1;}
110+
} if (xAspectRatio > yAspectRatio) {
111+
if (decreasing) { return -1 } else { return 1;}
112+
} else {
113+
return 0;
114+
}
115+
}
116+
102117
if (decreasing) {
103118
return (x[property]) - (y[property]);
104119
} else {
@@ -205,6 +220,14 @@ export class SortingPipe implements PipeTransform {
205220
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
206221
return this.sortFunctionLol(x, y, 'tags', false);
207222
});
223+
} else if (sortingType === 'aspectRatioAsc') {
224+
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
225+
return this.sortFunctionLol(x, y, 'aspectRatio', false);
226+
});
227+
} else if (sortingType === 'aspectRatioDesc') {
228+
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
229+
return this.sortFunctionLol(x, y, 'aspectRatio', true);
230+
});
208231
} else {
209232
return galleryArray.slice().sort((x: ImageElement, y: ImageElement): any => {
210233
return this.sortFunctionLol(x, y, 'index', true);

0 commit comments

Comments
 (0)