diff --git a/ui/easydiffusion/bucket_manager.py b/ui/easydiffusion/bucket_manager.py
index e8d65a48..41bf09b6 100644
--- a/ui/easydiffusion/bucket_manager.py
+++ b/ui/easydiffusion/bucket_manager.py
@@ -100,14 +100,14 @@ def init():
raise HTTPException(status_code=404, detail="Image not found")
@server_api.get("/all_images")
- def get_all_images(prompt: str = "", model: str = "", page = 0, db: Session = Depends(get_db)):
+ def get_all_images(prompt: str = "", model: str = "", page: int = 0, images_per_page: int = 50, db: Session = Depends(get_db)):
from easydiffusion.easydb.mappings import GalleryImage
- images = db.query(GalleryImage)
+ images = db.query(GalleryImage).order_by(GalleryImage.time_created.desc())
if prompt != "":
images = images.filter(GalleryImage.path.like("%"+prompt+"%"))
if model != "":
images = images.filter(GalleryImage.use_stable_diffusion_model.like("%"+model+"%"))
- images = images.offset(page*50).limit(50)
+ images = images.offset(page*images_per_page).limit(images_per_page)
return images.all()
@server_api.get("/single_image")
diff --git a/ui/index.html b/ui/index.html
index 5676ab5c..40beed92 100644
--- a/ui/index.html
+++ b/ui/index.html
@@ -518,10 +518,13 @@
+
-
-
+
+
+
+
diff --git a/ui/media/js/main.js b/ui/media/js/main.js
index 34f84399..edacd977 100644
--- a/ui/media/js/main.js
+++ b/ui/media/js/main.js
@@ -3110,20 +3110,36 @@ function galleryImage(item) {
function refreshGallery() {
let container = document.getElementById("imagecontainer")
- params = new URLSearchParams({
+ let params = new URLSearchParams({
prompt: document.getElementById("gallery-prompt-search").value,
model: document.getElementById("gallery-model-search").value,
page: document.getElementById("gallery-page").value
})
- container.innerHTML=""
+ container.innerHTML = ""
fetch('/all_images?' + params)
.then(response => response.json())
.then(json => {
- console.log(json)
- json.forEach( item => {
+ if (document.getElementById("gallery-page").value > 0 && json.length == 0) {
+ decrementGalleryPage()
+ alert("No more images")
+ return
+ }
+ json.forEach(item => {
container.appendChild(galleryImage(item))
})
- })
+ })
+ document.getElementById("gallery-refresh").innerText = "Refresh"
+}
+
+function decrementGalleryPage() {
+ let page = Math.max(document.getElementById("gallery-page").value - 1, 0)
+ document.getElementById("gallery-page").value = page
+ refreshGallery()
+}
+
+function incrementGalleryPage() {
+ document.getElementById("gallery-page").value++
+ refreshGallery()
}
function gallery_keyDown_handler(event) {