diff --git a/app/Http/Controllers/AlbumController.php b/app/Http/Controllers/AlbumController.php
index 12f7c66..151ebcd 100644
--- a/app/Http/Controllers/AlbumController.php
+++ b/app/Http/Controllers/AlbumController.php
@@ -17,8 +17,12 @@ class AlbumController extends Controller
*/
public function index()
{
+ $total = Album::count();
+ $pageSize = 12;
+ $page = 1;
return Inertia::render('Album/Index', [
- "albums" => Album::orderBy("created_at", "DESC")->get()->jsonSerialize(),
+ "lastPage" => ceil($total / $pageSize),
+ "albums" => Album::orderBy("created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize(),
]);
}
@@ -28,18 +32,56 @@ public function index()
public function show(string $id)
{
$album = Album::where("uuid", $id)->first();
+ $total = $album->photos()->count();
+ $pageSize = 12;
+ $page = 1;
return Inertia::render('Album/Show', [
"album" => $album->jsonSerialize(),
- "photos" => $album->photos->jsonSerialize()
+ "lastPage" => ceil($total / $pageSize),
+ "photos" => $album->photos()->orderBy("album_photo.created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize()
]);
}
- /**
- * Show the form for creating a new resource.
- */
- public function create()
+ public function pages(Request $request)
{
- //
+ $total = Album::count();
+ $pageSize = 12;
+ $page = $request->page ?? 2;
+ $page = $request->page <= ceil($total / $pageSize) ? $page : ceil($total / $pageSize);
+ return response()->json([
+ "lastPage" => ceil($total / $pageSize),
+ "albums" => Album::orderBy("created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize(),
+ ]);
+ }
+
+ public function photoUuids(Request $request)
+ {
+ $album = Album::where("uuid", $request->id)->first();
+ $uuids = [];
+ foreach($album->photos as $photo) array_push($uuids, $photo->uuid);
+ return response()->json([
+ "uuids" => $uuids,
+ ]);
+ }
+
+ public function photoPages(Request $request)
+ {
+ $album = Album::where("uuid", $request->id)->first();
+ $total = $album->photos()->count();
+ $pageSize = 12;
+ $page = $request->page ?? 2;
+ $page = $request->page <= ceil($total / $pageSize) ? $page : ceil($total / $pageSize);
+ return response()->json([
+ "lastPage" => ceil($total / $pageSize),
+ "photos" => $album->photos()->orderBy("album_photo.created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize(),
+ ]);
+ }
+
+ public function photoRemove(Request $request)
+ {
+ $album = Album::where("uuid", $request->id)->first();
+ $total = $album->photos()->detach(Photo::where("uuid", $request->photoId)->first());
+ return redirect(route("album.show", [ "id" => $album->uuid ]))->with(["message" => "Photo supprimée avec success"]);
}
/**
@@ -67,21 +109,15 @@ public function store(Request $request)
return redirect(route("album.index"))->with(["message" => "Photo ajouté avec success"]);
}
- /**
- * Update the specified resource in storage.
- */
- public function update(Request $request, string $id)
- {
- //
- }
-
- public function addPhoto(Request $request)
+ public function addPhotos(Request $request)
{
$album = Album::where("uuid", $request->id)->first();
- $photo = Photo::where("uuid", $request->uuid)->first();
- if(!$photo) redirect()->back()->withErrors(["uuid" => "Photo introuvable" ]);
if(!$album) redirect()->back()->withErrors(["uuid" => "Album introuvable" ]);
- $album->photos()->attach($photo);
+ foreach($request->uuids as $uuid) {
+ $photo = Photo::where("uuid", $uuid)->first();
+ if(!$photo) redirect()->back()->withErrors(["uuid" => "Photo introuvable" ]);
+ $album->photos()->attach($photo);
+ }
return redirect()->back();
}
diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php
index 093a9c5..e5b07dd 100644
--- a/app/Http/Controllers/PhotoController.php
+++ b/app/Http/Controllers/PhotoController.php
@@ -14,13 +14,28 @@ class PhotoController extends Controller
/**
* Display a listing of the resource.
*/
- public function index()
+ public function index(Request $request)
{
+ $total = Photo::count();
+ $pageSize = 12;
+ $page = 1;
return Inertia::render('Photo/Index', [
- "photos" => Photo::orderBy("created_at", "DESC")->get()->jsonSerialize(),
+ "lastPage" => ceil($total / $pageSize),
+ "photos" => Photo::orderBy("created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize(),
]);
}
+ public function pages(Request $request)
+ {
+ $pageSize = 12;
+ $total = Photo::count();
+ $page = $request->page ?? 2;
+ $page = $request->page <= ceil($total / $pageSize) ? $page : ceil($total / $pageSize);
+ return response()->json([
+ "lastPage" => ceil($total / $pageSize),
+ "photos" => Photo::orderBy("created_at", "DESC")->offset($page * $pageSize - $pageSize)->limit($pageSize)->get()->jsonSerialize(),
+ ]);
+ }
/**
* Show the form for creating a new resource.
*/
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index f75c113..bd47f20 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -46,25 +46,4 @@ public function update(ProfileUpdateRequest $request): RedirectResponse
return redirect(route('profile.edit'));
}
-
- /**
- * Delete the user's account.
- */
- public function destroy(Request $request): RedirectResponse
- {
- $request->validate([
- 'password' => ['required', 'current_password'],
- ]);
-
- $user = $request->user();
-
- Auth::logout();
-
- $user->delete();
-
- $request->session()->invalidate();
- $request->session()->regenerateToken();
-
- return Redirect::to('/');
- }
}
diff --git a/app/Models/Album.php b/app/Models/Album.php
index ad64767..677aa5f 100644
--- a/app/Models/Album.php
+++ b/app/Models/Album.php
@@ -33,11 +33,11 @@ public function user()
public function photos()
{
- return $this->belongsToMany(Photo::class);
+ return $this->belongsToMany(Photo::class)->withTimestamps();
}
public function tags()
{
- return $this->belongsToMany(Tag::class);
+ return $this->belongsToMany(Tag::class)->withTimestamps();
}
}
diff --git a/app/Models/Photo.php b/app/Models/Photo.php
index 63d4e42..bf487b6 100644
--- a/app/Models/Photo.php
+++ b/app/Models/Photo.php
@@ -33,7 +33,7 @@ public function user()
public function albums()
{
- return $this->belongsToMany(Album::class);
+ return $this->belongsToMany(Album::class)->withTimestamps();
}
}
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index c048d52..e6139af 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -13,6 +13,6 @@ class Tag extends Model
public function albums()
{
- return $this->belongsToMany(Album::class);
+ return $this->belongsToMany(Album::class)->withTimestamps();
}
}
diff --git a/database/migrations/2025_01_26_015737_add_created_at.php b/database/migrations/2025_01_26_015737_add_created_at.php
new file mode 100644
index 0000000..15bb249
--- /dev/null
+++ b/database/migrations/2025_01_26_015737_add_created_at.php
@@ -0,0 +1,31 @@
+get();
+ foreach($aps as $ap) {
+ $photo = DB::table("photos")->where("id", $ap->photo_id)->first();
+ DB::table("album_photo")->where("id", $ap->id)->update([
+ "created_at" => $photo->created_at
+ ]);
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ //
+ }
+};
diff --git a/resources/js/Pages/Album/Partials/Edit.vue b/resources/js/Pages/Album/Partials/Edit.vue
index 1cb55d2..b23ef80 100644
--- a/resources/js/Pages/Album/Partials/Edit.vue
+++ b/resources/js/Pages/Album/Partials/Edit.vue
@@ -3,7 +3,7 @@ import TextInput from '@/Components/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
const props = defineProps({
- photo: {
+ album: {
type: Object,
required: true,
}
diff --git a/resources/js/Pages/Album/Show.vue b/resources/js/Pages/Album/Show.vue
index eab86dd..59e6d5d 100644
--- a/resources/js/Pages/Album/Show.vue
+++ b/resources/js/Pages/Album/Show.vue
@@ -5,6 +5,7 @@ import Create from '@/Pages/Photo/Partials/Create.vue';
import Show from'@/Pages/Photo/Partials/Show.vue';
import Modal from '@/Pages/Photo/Partials/Modal.vue';
import { reactive, ref } from 'vue';
+import Panel from '../Photo/Partials/Panel.vue';
const props = defineProps({
album: {
@@ -15,19 +16,23 @@ const props = defineProps({
type: Array,
default: []
},
+ lastPage: {
+ type: Number,
+ default: 1,
+ }
});
-const form = useForm({ uuid: "" });
+const form = useForm({ uuids: [] });
const create = reactive({ active: false });
const fullScreenState = reactive({ photo: {}, active: false });
-const viewState = reactive({ square: true, list: false });
+const photoState = reactive({ square: true, list: false, pageCount: 1, photos: props.photos });
const fullScreen = (photo) => {
fullScreenState.photo = photo;
fullScreenState.active = true;
- viewState.square = false;
- viewState.list = false;
+ photoState.square = false;
+ photoState.list = false;
}
const gridState = reactive({ columns: 3 });
@@ -35,26 +40,50 @@ const gridState = reactive({ columns: 3 });
const squareView = () => {
gridState.columns = 3;
fullScreenState.active = false;
- viewState.square = true;
- viewState.list = false;
+ photoState.square = true;
+ photoState.list = false;
}
const listView = () => {
gridState.columns = 1;
fullScreenState.active = false;
- viewState.square = false;
- viewState.list = true;
+ photoState.square = false;
+ photoState.list = true;
}
-const addPhoto = (uuid) => {
+const addPhotos = (uuids) => {
console.log("uuid");
- form.uuid = uuid;
+ form.uuids = uuids;
form.post("/album/" + props.album.uuid + "/add",{
headers: {
"X-CSRF-Token": document.querySelector('input[name=_token]').value,
},
+ onSuccess: () => window.location.reload()
});
}
+
+const loadPhotos = async () => {
+ photoState.pageCount++;
+ const res = await axios.get(route("album.photo.page", {
+ id: props.album.uuid,
+ page: photoState.pageCount
+ }));
+ photoState.photos = photoState.photos.concat(res.data.photos)
+ console.log("hello", res.data.photos, photoState.photos, props.lastPage)
+}
+
+const deletePhoto = (uuid) => {
+ if(confirm("Voulez-vous vraiment retirer cette photo de l'album")){
+ form.delete(route("album.photo.remove", {id: props.album.uuid, photoId: uuid}), {
+ headers: {
+ "X-CSRF-Token": document.querySelector('input[name=_token]').value,
+ },
+ onSuccess: () => {
+ photoState.photos = photoState.photos.filter(photo => photo.uuid != uuid);
+ }
+ });
+ }
+}
@@ -65,15 +94,15 @@ const addPhoto = (uuid) => {
Affichage
Affichage
Photothèque
+{{ album.name }}
+plus d'album
+{{ props.photo.name }}
+publier par {{ props.photo.user.name }}
+- Once your account is deleted, all of its resources and data will - be permanently deleted. Before deleting your account, please - download any data or information that you wish to retain. -
-- Once your account is deleted, all of its resources and data - will be permanently deleted. Please enter your password to - confirm you would like to permanently delete your account. -
- -