mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-22 04:17:33 +00:00
feat: tag autocomplete
This commit is contained in:
parent
a420b50877
commit
45d4278a52
@ -11,6 +11,7 @@ func InitializeTagRoutes(g *gin.Engine) {
|
|||||||
unprotected := g.Group("/api/tag")
|
unprotected := g.Group("/api/tag")
|
||||||
{
|
{
|
||||||
unprotected.GET("/", tagGet)
|
unprotected.GET("/", tagGet)
|
||||||
|
unprotected.GET("/autocomplete", tagAutocomplete)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,3 +19,8 @@ func tagGet(c *gin.Context) {
|
|||||||
tags := services.GetTagAll()
|
tags := services.GetTagAll()
|
||||||
c.JSON(http.StatusOK, tags)
|
c.JSON(http.StatusOK, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tagAutocomplete(c *gin.Context) {
|
||||||
|
tags := services.GetTagAutocomplete()
|
||||||
|
c.JSON(http.StatusOK, tags)
|
||||||
|
}
|
||||||
|
@ -12,6 +12,10 @@ type TagListItem struct {
|
|||||||
PostCount int `json:"postCount"`
|
PostCount int `json:"postCount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TagAutocompleteListItem struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
type PostListItem struct {
|
type PostListItem struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ImagePath string `json:"image_path"`
|
ImagePath string `json:"image_path"`
|
||||||
|
@ -21,6 +21,18 @@ func GetTagAll() []models.TagListItem {
|
|||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTagAutocomplete() []models.TagAutocompleteListItem {
|
||||||
|
var tags []models.TagAutocompleteListItem
|
||||||
|
result := database.DB.Model(&database.Tag{}).
|
||||||
|
Joins("join tag_types on tag_types.id = tags.tag_type_id").
|
||||||
|
Select("concat(tag_types.name,':',tags.name) as name").
|
||||||
|
Find(&tags)
|
||||||
|
if result.Error != nil {
|
||||||
|
return []models.TagAutocompleteListItem{}
|
||||||
|
}
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
func FindTagGeneric(tagName string) (*database.Tag, error) {
|
func FindTagGeneric(tagName string) (*database.Tag, error) {
|
||||||
var tag database.Tag
|
var tag database.Tag
|
||||||
result := database.DB.Where("name = ?", tagName).First(&tag)
|
result := database.DB.Where("name = ?", tagName).First(&tag)
|
||||||
|
@ -49,4 +49,13 @@
|
|||||||
font-size: 13.3333px;
|
font-size: 13.3333px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#tags .svelte-tags-input-matchs {
|
||||||
|
z-index: 200;
|
||||||
|
&-parent {
|
||||||
|
z-index: 200;
|
||||||
|
}
|
||||||
|
& li:hover {
|
||||||
|
background: $primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -41,6 +41,11 @@ export async function getTags() {
|
|||||||
const response = await axios.get(endpoint);
|
const response = await axios.get(endpoint);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
export async function getTagAutocomplete() {
|
||||||
|
const endpoint = url + "/api/tag/autocomplete";
|
||||||
|
const response = await axios.get(endpoint);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
export async function getPosts({ page }) {
|
export async function getPosts({ page }) {
|
||||||
const endpoint = url + "/api/post?page=" + page;
|
const endpoint = url + "/api/post?page=" + page;
|
||||||
const response = await axios.get(endpoint);
|
const response = await axios.get(endpoint);
|
||||||
|
@ -11,3 +11,6 @@
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.svelte-tags-input-matchs-parent {
|
||||||
|
z-index: 200;
|
||||||
|
}
|
@ -51,6 +51,11 @@
|
|||||||
searchTerms = value.detail.tags;
|
searchTerms = value.detail.tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onAutocomplete = async () => {
|
||||||
|
const list = await getTagAutocomplete();
|
||||||
|
return list;
|
||||||
|
};
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
queryParams = queryString.parse(location.search);
|
queryParams = queryString.parse(location.search);
|
||||||
if (queryParams.tags) {
|
if (queryParams.tags) {
|
||||||
@ -88,6 +93,8 @@
|
|||||||
tags={searchTerms}
|
tags={searchTerms}
|
||||||
addKeys={[9, 32]}
|
addKeys={[9, 32]}
|
||||||
on:tags={onTagChange}
|
on:tags={onTagChange}
|
||||||
|
autoComplete={onAutocomplete}
|
||||||
|
autoCompleteKey={"name"}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
import { uploadBlob, postCreate } from "../api.js";
|
import { uploadBlob, postCreate, getTagAutocomplete } from "../api.js";
|
||||||
import { navigate, Link } from "svelte-routing";
|
import { navigate, Link } from "svelte-routing";
|
||||||
import Tags from "svelte-tags-input";
|
import Tags from "svelte-tags-input";
|
||||||
import AuthRequired from "../AuthRequired.svelte";
|
import AuthRequired from "../AuthRequired.svelte";
|
||||||
@ -38,6 +38,11 @@
|
|||||||
form.tags = value.detail.tags;
|
form.tags = value.detail.tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onAutocomplete = async () => {
|
||||||
|
const list = await getTagAutocomplete();
|
||||||
|
return list;
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async () => {
|
const onSubmit = async () => {
|
||||||
const response = await postCreate(form);
|
const response = await postCreate(form);
|
||||||
navigate(`/post/${response.id}`);
|
navigate(`/post/${response.id}`);
|
||||||
@ -107,7 +112,7 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="tags" class="label">Tags</label>
|
<label for="tags" class="label">Tags</label>
|
||||||
<div class="control" id="tags">
|
<div class="control" id="tags">
|
||||||
<Tags addKeys={[9, 32]} on:tags={onTagChange} />
|
<Tags addKeys={[9, 32]} on:tags={onTagChange} autoComplete={onAutocomplete} autoCompleteKey={"name"} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
Loading…
Reference in New Issue
Block a user