Added page for viewing a single image, tracking number of images a tag has.
This commit is contained in:
parent
ca567b2e60
commit
c4c44ad4da
@ -8,6 +8,7 @@ import org.springframework.stereotype.Controller
|
||||
import org.springframework.ui.Model
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.ModelAttribute
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
@ -36,6 +37,15 @@ class BaseController
|
||||
return "login"
|
||||
}
|
||||
|
||||
@GetMapping("/view/{id}")
|
||||
fun viewSingleImage(@PathVariable id: Long, model: Model) : String {
|
||||
val image = imageRepository.findById(id).get()
|
||||
val tagData = image.tags.sortedBy { it.tag }
|
||||
model.addAttribute("image", image)
|
||||
model.addAttribute("tags", tagData)
|
||||
model.addAttribute("title", tagData.joinToString { it.tag })
|
||||
return "single"
|
||||
}
|
||||
}
|
||||
|
||||
@Controller
|
||||
@ -137,6 +147,7 @@ class UploadController
|
||||
val user = memberRepository.findByName(userDetails.username)!!
|
||||
val hash: String = generateFileHash(file)
|
||||
val tagData = tags.split(" ").map { tagRepository.findByTagIs(it) ?: tagRepository.save(Tag(tag = it)) }.toMutableSet()
|
||||
tagData.map { it.amount = it.amount + 1 }
|
||||
storage.addImageFile(hash, extension, file.bytes)
|
||||
imageRepository.save(Image("$hash.$extension", user, tagData))
|
||||
return "upload" // TODO: Show success on page
|
||||
|
@ -72,6 +72,7 @@ open class Tag(
|
||||
@Column(unique = true)
|
||||
@Pattern(regexp = "[a-zA-Z0-9_]*") // Only allow alphanumeric and underscores
|
||||
open var tag: String = "",
|
||||
open var amount: Long = 0,
|
||||
@Id
|
||||
@SequenceGenerator(name="tag_id_seq", sequenceName = "tag_id_seq", allocationSize = 1)
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "tag_id_seq")
|
||||
|
@ -21,6 +21,10 @@ interface ImageRepository : JpaRepository<Image, Long> {
|
||||
fun findByTagsOrderById(tagIDs: List<Tag>, tagCount: Long, pageable: Pageable): Page<Image>
|
||||
|
||||
fun findAllByTagsContainingOrderById(tag: Tag, pageable: Pageable): Page<Image>
|
||||
|
||||
@Suppress("SqlResolve")
|
||||
@Query(value = "DELETE FROM BOORU.TAG_IMAGE WHERE IMAGE_ID = ?1", nativeQuery = true)
|
||||
fun deleteTagAssociations(imagesID: Long)
|
||||
}
|
||||
|
||||
interface TagRepository : CrudRepository<Tag, Long> {
|
||||
|
@ -9,4 +9,9 @@ data class DisplayUser(
|
||||
val email: String,
|
||||
val password: String,
|
||||
@field:NotBlank val oldPassword: String
|
||||
)
|
||||
|
||||
data class TagWithCount(
|
||||
val tagName: String,
|
||||
val count: Int
|
||||
)
|
@ -28,7 +28,8 @@ CREATE TABLE booru.role
|
||||
CREATE TABLE booru.tag
|
||||
(
|
||||
id bigserial NOT NULL PRIMARY KEY,
|
||||
tag varchar NOT NULL UNIQUE
|
||||
tag varchar NOT NULL UNIQUE,
|
||||
amount bigint NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE booru.tag_image
|
||||
|
@ -24,8 +24,9 @@
|
||||
</div>
|
||||
<div class="row" th:if="${imagePage != null}">
|
||||
<div class="col-2" th:each="image : ${imagePage.content}">
|
||||
<!--/*@thymesVar id="image" type="uk.co.neviyn.booru.Image"*/-->
|
||||
<img alt="" class="img-thumbnail" th:src="'/i/thumbnail.' + ${image.filename}"/>
|
||||
<a th:href="'/view/' + ${image.id}">
|
||||
<img alt="" class="img-thumbnail" th:src="'/i/thumbnail.' + ${image.filename}"/>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" th:if="${imagePage == null}">
|
||||
|
37
src/main/resources/templates/single.html
Normal file
37
src/main/resources/templates/single.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta th:replace="fragments :: header"/>
|
||||
<title th:text="${title}">Image</title>
|
||||
</head>
|
||||
<body>
|
||||
<div th:replace="fragments :: navbar"></div>
|
||||
<div class="container">
|
||||
<form action="/gallery" class="text-center row row-cols-auto align-items-center mt-2">
|
||||
<div class="col-10">
|
||||
<!--suppress HtmlFormInputWithoutLabel -->
|
||||
<input class="form-control" id="imageSearch"
|
||||
name="tags"
|
||||
pattern="[a-zA-Z0-9\s_]*"
|
||||
placeholder="Ex: blue_eyes smile"
|
||||
th:value="${#request.getParameter('tags')}"
|
||||
type="search">
|
||||
</div>
|
||||
<div class="col-2 d-grid">
|
||||
<button class="btn btn-primary" type="submit">Search</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col-2">
|
||||
<ul>
|
||||
<li th:each="tag : ${tags}"><a class="text-decoration-none" th:href="${#mvc.url('IC#getGalleryPage').arg(1, tag.tag).build()}" th:text="${tag.tag} + ' ' + ${tag.amount}">tag</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<img th:src="'/i/' + ${image.filename}" th:alt="${image.filename}" class="w-100">
|
||||
</div>
|
||||
<div class="col-2"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user