diff options
Diffstat (limited to 'viewer/src/services')
-rw-r--r-- | viewer/src/services/indexfactory.ts | 13 | ||||
-rw-r--r-- | viewer/src/services/indexsearch.ts | 17 | ||||
-rw-r--r-- | viewer/src/services/itemComparators.ts | 13 | ||||
-rw-r--r-- | viewer/src/services/ldzoom.ts | 7 | ||||
-rw-r--r-- | viewer/src/services/navigation.ts | 15 |
5 files changed, 35 insertions, 30 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 4b28a60..0c5fdc5 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts | |||
@@ -17,19 +17,20 @@ | |||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { Operation } from "@/@types/Operation"; | 20 | import { Item, RawTag } from "@/@types/gallery"; |
21 | import { ItemType } from "@/@types/ItemType"; | 21 | import { ItemType } from "@/@types/ItemType"; |
22 | import { Operation } from "@/@types/Operation"; | ||
22 | import Navigation from "@/services/navigation"; | 23 | import Navigation from "@/services/navigation"; |
23 | 24 | ||
24 | export default class IndexFactory { | 25 | export default class IndexFactory { |
25 | public static generateTags(root: Gallery.Item | null): Tag.Index { | 26 | public static generateTags(root: Item | null): Tag.Index { |
26 | const tagsIndex: Tag.Index = {}; | 27 | const tagsIndex: Tag.Index = {}; |
27 | if (root) IndexFactory.pushTagsForItem(tagsIndex, root); | 28 | if (root) IndexFactory.pushTagsForItem(tagsIndex, root); |
28 | return tagsIndex; | 29 | return tagsIndex; |
29 | } | 30 | } |
30 | 31 | ||
31 | // Pushes all tags for a root item (and its children) to the index | 32 | // Pushes all tags for a root item (and its children) to the index |
32 | private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { | 33 | private static pushTagsForItem(tagsIndex: Tag.Index, item: Item): void { |
33 | if (item.properties.type === ItemType.DIRECTORY) { | 34 | if (item.properties.type === ItemType.DIRECTORY) { |
34 | item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); | 35 | item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); |
35 | return; // Directories are not indexed | 36 | return; // Directories are not indexed |
@@ -49,7 +50,7 @@ export default class IndexFactory { | |||
49 | } | 50 | } |
50 | } | 51 | } |
51 | 52 | ||
52 | private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { | 53 | private static pushPartToIndex(index: Tag.Node, part: string, item: Item, rootPart: boolean): Tag.Node { |
53 | if (!index) | 54 | if (!index) |
54 | index = { | 55 | index = { |
55 | tag: part, | 56 | tag: part, |
@@ -131,7 +132,7 @@ export default class IndexFactory { | |||
131 | 132 | ||
132 | // --- | 133 | // --- |
133 | 134 | ||
134 | public static generateCategories(tagsIndex: Tag.Index, categoryTags?: Gallery.RawTag[]): Tag.Category[] { | 135 | public static generateCategories(tagsIndex: Tag.Index, categoryTags?: RawTag[]): Tag.Category[] { |
135 | if (!categoryTags?.length) return [{ tag: "", index: tagsIndex }]; | 136 | if (!categoryTags?.length) return [{ tag: "", index: tagsIndex }]; |
136 | 137 | ||
137 | const tagsCategories: Tag.Category[] = []; | 138 | const tagsCategories: Tag.Category[] = []; |
@@ -149,7 +150,7 @@ export default class IndexFactory { | |||
149 | return tagsCategories; | 150 | return tagsCategories; |
150 | } | 151 | } |
151 | 152 | ||
152 | private static isDiscriminantTagOnly(tags: Gallery.RawTag[], node: Tag.Node): boolean { | 153 | private static isDiscriminantTagOnly(tags: RawTag[], node: Tag.Node): boolean { |
153 | return !tags.includes(node.tag) || !node.childPart; | 154 | return !tags.includes(node.tag) || !node.childPart; |
154 | } | 155 | } |
155 | } | 156 | } |
diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts index 00f8cfc..eda1b27 100644 --- a/viewer/src/services/indexsearch.ts +++ b/viewer/src/services/indexsearch.ts | |||
@@ -17,11 +17,12 @@ | |||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { Item } from "@/@types/gallery"; | ||
20 | import { Operation } from "@/@types/Operation"; | 21 | import { Operation } from "@/@types/Operation"; |
21 | 22 | ||
22 | export default class IndexSearch { | 23 | export default class IndexSearch { |
23 | // Results of the search (by tags) | 24 | // Results of the search (by tags) |
24 | public static search(searchTags: Tag.Search[]): Gallery.Item[] { | 25 | public static search(searchTags: Tag.Search[]): Item[] { |
25 | const byOperation = this.extractTagsByOperation(searchTags); | 26 | const byOperation = this.extractTagsByOperation(searchTags); |
26 | const intersection = this.extractIntersection(byOperation); | 27 | const intersection = this.extractIntersection(byOperation); |
27 | const substraction = this.extractSubstraction(byOperation); | 28 | const substraction = this.extractSubstraction(byOperation); |
@@ -36,8 +37,8 @@ export default class IndexSearch { | |||
36 | return byOperation; | 37 | return byOperation; |
37 | } | 38 | } |
38 | 39 | ||
39 | private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { | 40 | private static extractIntersection(byOperation: Tag.SearchByOperation): Set<Item> { |
40 | const intersection = new Set<Gallery.Item>(); | 41 | const intersection = new Set<Item>(); |
41 | if (byOperation[Operation.INTERSECTION].length > 0) { | 42 | if (byOperation[Operation.INTERSECTION].length > 0) { |
42 | byOperation[Operation.INTERSECTION] | 43 | byOperation[Operation.INTERSECTION] |
43 | .map(tag => tag.items) | 44 | .map(tag => tag.items) |
@@ -48,8 +49,8 @@ export default class IndexSearch { | |||
48 | return intersection; | 49 | return intersection; |
49 | } | 50 | } |
50 | 51 | ||
51 | private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> { | 52 | private static extractSubstraction(byOperation: Tag.SearchByOperation): Set<Item> { |
52 | const substraction = new Set<Gallery.Item>(); | 53 | const substraction = new Set<Item>(); |
53 | if (byOperation[Operation.SUBSTRACTION].length > 0) { | 54 | if (byOperation[Operation.SUBSTRACTION].length > 0) { |
54 | byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); | 55 | byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item)); |
55 | } | 56 | } |
@@ -58,9 +59,9 @@ export default class IndexSearch { | |||
58 | 59 | ||
59 | private static aggregateAll( | 60 | private static aggregateAll( |
60 | byOperation: Tag.SearchByOperation, | 61 | byOperation: Tag.SearchByOperation, |
61 | intersection: Set<Gallery.Item>, | 62 | intersection: Set<Item>, |
62 | substraction: Set<Gallery.Item> | 63 | substraction: Set<Item> |
63 | ): Gallery.Item[] { | 64 | ): Item[] { |
64 | byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item)); | 65 | byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item)); |
65 | substraction.forEach(item => intersection.delete(item)); | 66 | substraction.forEach(item => intersection.delete(item)); |
66 | return [...intersection]; | 67 | return [...intersection]; |
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts index bd9accb..aceff79 100644 --- a/viewer/src/services/itemComparators.ts +++ b/viewer/src/services/itemComparators.ts | |||
@@ -16,14 +16,15 @@ | |||
16 | -- You should have received a copy of the GNU Affero General Public License | 16 | -- You should have received a copy of the GNU Affero General Public License |
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | import { TranslateResult } from "vue-i18n"; | 19 | import { Item, ItemSortStr } from "@/@types/gallery"; |
20 | import i18n from "@/plugins/i18n"; | 20 | import i18n from "@/plugins/i18n"; |
21 | import { TranslateResult } from "vue-i18n"; | ||
21 | 22 | ||
22 | export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; | 23 | export type ItemComparator = (left: Item, right: Item) => number; |
23 | export type ItemSort = { text: TranslateResult; fn: ItemComparator }; | 24 | export type ItemSort = { text: TranslateResult; fn: ItemComparator }; |
24 | 25 | ||
25 | export default class ItemComparators { | 26 | export default class ItemComparators { |
26 | static readonly ITEM_SORTS: Record<Gallery.ItemSortStr, ItemSort> = { | 27 | static readonly ITEM_SORTS: Record<ItemSortStr, ItemSort> = { |
27 | title_asc: { | 28 | title_asc: { |
28 | text: i18n.t("command.sort.byTitleAsc"), | 29 | text: i18n.t("command.sort.byTitleAsc"), |
29 | fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), | 30 | fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), |
@@ -40,7 +41,7 @@ export default class ItemComparators { | |||
40 | 41 | ||
41 | static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; | 42 | static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; |
42 | 43 | ||
43 | static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { | 44 | static sortByPathAsc(left: Item, right: Item): number { |
44 | return left.path.localeCompare(right.path, undefined, { | 45 | return left.path.localeCompare(right.path, undefined, { |
45 | sensitivity: "base", | 46 | sensitivity: "base", |
46 | ignorePunctuation: true, | 47 | ignorePunctuation: true, |
@@ -48,7 +49,7 @@ export default class ItemComparators { | |||
48 | }); | 49 | }); |
49 | } | 50 | } |
50 | 51 | ||
51 | static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number { | 52 | static sortByTitleAsc(left: Item, right: Item): number { |
52 | return left.title.localeCompare(right.title, undefined, { | 53 | return left.title.localeCompare(right.title, undefined, { |
53 | sensitivity: "base", | 54 | sensitivity: "base", |
54 | ignorePunctuation: true, | 55 | ignorePunctuation: true, |
@@ -56,7 +57,7 @@ export default class ItemComparators { | |||
56 | }); | 57 | }); |
57 | } | 58 | } |
58 | 59 | ||
59 | static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number { | 60 | static sortByDateAsc(left: Item, right: Item): number { |
60 | return left.datetime.localeCompare(right.datetime); // TODO: handle timezones | 61 | return left.datetime.localeCompare(right.datetime); // TODO: handle timezones |
61 | } | 62 | } |
62 | 63 | ||
diff --git a/viewer/src/services/ldzoom.ts b/viewer/src/services/ldzoom.ts index 0fb0848..33a64c8 100644 --- a/viewer/src/services/ldzoom.ts +++ b/viewer/src/services/ldzoom.ts | |||
@@ -17,6 +17,7 @@ | |||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { PictureProperties, Resolution } from "@/@types/gallery"; | ||
20 | import "hammerjs"; | 21 | import "hammerjs"; |
21 | 22 | ||
22 | /** | 23 | /** |
@@ -25,7 +26,7 @@ import "hammerjs"; | |||
25 | export default class LdZoom { | 26 | export default class LdZoom { |
26 | readonly containerElement: HTMLDivElement; | 27 | readonly containerElement: HTMLDivElement; |
27 | readonly imageElement: HTMLImageElement; | 28 | readonly imageElement: HTMLImageElement; |
28 | readonly pictureProperties: Gallery.PictureProperties; | 29 | readonly pictureProperties: PictureProperties; |
29 | readonly maxScaleFactor: number; | 30 | readonly maxScaleFactor: number; |
30 | readonly scrollZoomSpeed: number; | 31 | readonly scrollZoomSpeed: number; |
31 | scaleFactor: number = 0.0; | 32 | scaleFactor: number = 0.0; |
@@ -33,7 +34,7 @@ export default class LdZoom { | |||
33 | constructor( | 34 | constructor( |
34 | containerElement: HTMLDivElement, | 35 | containerElement: HTMLDivElement, |
35 | imageElement: HTMLImageElement, | 36 | imageElement: HTMLImageElement, |
36 | pictureProperties: Gallery.PictureProperties, | 37 | pictureProperties: PictureProperties, |
37 | maxScaleFactor: num |