mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-27 05:35:16 +00:00
Merge pull request #1137 from ae-utbm/fix-user-pictures
fix: user pictures ordering
This commit is contained in:
commit
c7087c6e7e
2
package-lock.json
generated
2
package-lock.json
generated
@ -48,6 +48,7 @@
|
|||||||
"@types/cytoscape-cxtmenu": "^3.4.4",
|
"@types/cytoscape-cxtmenu": "^3.4.4",
|
||||||
"@types/cytoscape-klay": "^3.1.4",
|
"@types/cytoscape-klay": "^3.1.4",
|
||||||
"@types/jquery": "^3.5.31",
|
"@types/jquery": "^3.5.31",
|
||||||
|
"typescript": "^5.8.3",
|
||||||
"vite": "^6.2.5",
|
"vite": "^6.2.5",
|
||||||
"vite-bundle-visualizer": "^1.2.1",
|
"vite-bundle-visualizer": "^1.2.1",
|
||||||
"vite-plugin-static-copy": "^3.0.2"
|
"vite-plugin-static-copy": "^3.0.2"
|
||||||
@ -5587,7 +5588,6 @@
|
|||||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"peer": true,
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
"@types/jquery": "^3.5.31",
|
"@types/jquery": "^3.5.31",
|
||||||
"@types/cytoscape-cxtmenu": "^3.4.4",
|
"@types/cytoscape-cxtmenu": "^3.4.4",
|
||||||
"@types/cytoscape-klay": "^3.1.4",
|
"@types/cytoscape-klay": "^3.1.4",
|
||||||
|
"typescript": "^5.8.3",
|
||||||
"vite": "^6.2.5",
|
"vite": "^6.2.5",
|
||||||
"vite-bundle-visualizer": "^1.2.1",
|
"vite-bundle-visualizer": "^1.2.1",
|
||||||
"vite-plugin-static-copy": "^3.0.2"
|
"vite-plugin-static-copy": "^3.0.2"
|
||||||
|
@ -9,28 +9,35 @@ interface PagePictureConfig {
|
|||||||
userId: number;
|
userId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Album {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
pictures: PictureSchema[];
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("alpine:init", () => {
|
document.addEventListener("alpine:init", () => {
|
||||||
Alpine.data("user_pictures", (config: PagePictureConfig) => ({
|
Alpine.data("user_pictures", (config: PagePictureConfig) => ({
|
||||||
loading: true,
|
loading: true,
|
||||||
pictures: [] as PictureSchema[],
|
albums: [] as Album[],
|
||||||
albums: {} as Record<string, PictureSchema[]>,
|
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
this.pictures = await paginated(picturesFetchPictures, {
|
const pictures = await paginated(picturesFetchPictures, {
|
||||||
// biome-ignore lint/style/useNamingConvention: from python api
|
// biome-ignore lint/style/useNamingConvention: from python api
|
||||||
query: { users_identified: [config.userId] },
|
query: { users_identified: [config.userId] },
|
||||||
} as PicturesFetchPicturesData);
|
} as PicturesFetchPicturesData);
|
||||||
|
const groupedAlbums = Object.groupBy(pictures, (i: PictureSchema) => i.album.id);
|
||||||
this.albums = this.pictures.reduce(
|
this.albums = Object.values(groupedAlbums).map((pictures: PictureSchema[]) => {
|
||||||
(acc: Record<number, PictureSchema[]>, picture: PictureSchema) => {
|
return {
|
||||||
if (!acc[picture.album.id]) {
|
id: pictures[0].album.id,
|
||||||
acc[picture.album.id] = [];
|
name: pictures[0].album.name,
|
||||||
|
pictures: pictures,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
this.albums.sort((a: Album, b: Album) => b.id - a.id);
|
||||||
|
const hash = document.location.hash.replace("#", "");
|
||||||
|
if (hash.startsWith("album-")) {
|
||||||
|
this.$nextTick(() => document.getElementById(hash)?.scrollIntoView()).then();
|
||||||
}
|
}
|
||||||
acc[picture.album.id].push(picture);
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{},
|
|
||||||
);
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
#}
|
#}
|
||||||
{% macro download_button(name) %}
|
{% macro download_button(name) %}
|
||||||
<div x-data="pictures_download">
|
<div x-data="pictures_download">
|
||||||
<div x-show="pictures.length > 0" x-cloak>
|
<div x-show="albums.length > 0" x-cloak>
|
||||||
<button
|
<button
|
||||||
:disabled="isDownloading"
|
:disabled="isDownloading"
|
||||||
class="btn btn-blue {% if name == "" %}btn-no-text{% endif %}"
|
class="btn btn-blue {% if name == "" %}btn-no-text{% endif %}"
|
||||||
|
@ -20,17 +20,17 @@
|
|||||||
{{ download_button(_("Download all my pictures")) }}
|
{{ download_button(_("Download all my pictures")) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<template x-for="[album_id, pictures] in Object.entries(albums)" x-cloak>
|
<template x-for="album in albums" x-cloak>
|
||||||
<section>
|
<section>
|
||||||
<br />
|
<br />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h4 x-text="pictures[0].album.name" :id="`album-${album_id}`"></h4>
|
<h4 x-text="album.name" :id="`album-${album.id}`"></h4>
|
||||||
{% if user.id == object.id %}
|
{% if user.id == object.id %}
|
||||||
{{ download_button("") }}
|
{{ download_button("") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="photos">
|
<div class="photos">
|
||||||
<template x-for="picture in pictures">
|
<template x-for="picture in album.pictures">
|
||||||
<a :href="picture.sas_url">
|
<a :href="picture.sas_url">
|
||||||
<div
|
<div
|
||||||
class="photo"
|
class="photo"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"target": "es2022",
|
"target": "es2024",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user