show number of tag usage
This commit is contained in:
parent
38dc23d57b
commit
22585b92fe
8 changed files with 47 additions and 7 deletions
File diff suppressed because one or more lines are too long
1
build/public/assets/index.e2df6757.js
Normal file
1
build/public/assets/index.e2df6757.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
||||||
<title>🧩 jigsaw.hyottoko.club</title>
|
<title>🧩 jigsaw.hyottoko.club</title>
|
||||||
<script type="module" crossorigin src="/assets/index.a4bac37f.js"></script>
|
<script type="module" crossorigin src="/assets/index.e2df6757.js"></script>
|
||||||
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
<link rel="modulepreload" href="/assets/vendor.684f7bc8.js">
|
||||||
<link rel="stylesheet" href="/assets/index.6748df9f.css">
|
<link rel="stylesheet" href="/assets/index.6748df9f.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -1315,15 +1315,28 @@ async function getExifOrientation(imagePath) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const getAllTags = (db) => {
|
||||||
|
const query = `
|
||||||
|
select c.id, c.slug, c.title, count(*) as total from categories c
|
||||||
|
inner join image_x_category ixc on c.id = ixc.category_id
|
||||||
|
group by c.id order by total desc;`;
|
||||||
|
return db._getMany(query).map(row => ({
|
||||||
|
id: parseInt(row.id, 10) || 0,
|
||||||
|
slug: row.slug,
|
||||||
|
title: row.title,
|
||||||
|
total: parseInt(row.total, 10) || 0,
|
||||||
|
}));
|
||||||
|
};
|
||||||
const getTags = (db, imageId) => {
|
const getTags = (db, imageId) => {
|
||||||
const query = `
|
const query = `
|
||||||
select * from categories c
|
select * from categories c
|
||||||
inner join image_x_category ixc on c.id = ixc.category_id
|
inner join image_x_category ixc on c.id = ixc.category_id
|
||||||
where ixc.image_id = ?`;
|
where ixc.image_id = ?`;
|
||||||
return db._getMany(query, [imageId]).map(row => ({
|
return db._getMany(query, [imageId]).map(row => ({
|
||||||
id: parseInt(row.number, 10) || 0,
|
id: parseInt(row.id, 10) || 0,
|
||||||
slug: row.slug,
|
slug: row.slug,
|
||||||
title: row.title,
|
title: row.title,
|
||||||
|
total: 0,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const imageFromDb = (db, imageId) => {
|
const imageFromDb = (db, imageId) => {
|
||||||
|
|
@ -1432,6 +1445,7 @@ var Images = {
|
||||||
allImagesFromDisk,
|
allImagesFromDisk,
|
||||||
imageFromDb,
|
imageFromDb,
|
||||||
allImagesFromDb,
|
allImagesFromDb,
|
||||||
|
getAllTags,
|
||||||
resizeImage,
|
resizeImage,
|
||||||
getDimensions,
|
getDimensions,
|
||||||
};
|
};
|
||||||
|
|
@ -2008,7 +2022,7 @@ app.get('/api/newgame-data', (req, res) => {
|
||||||
const tagSlugs = q.tags ? q.tags.split(',') : [];
|
const tagSlugs = q.tags ? q.tags.split(',') : [];
|
||||||
res.send({
|
res.send({
|
||||||
images: Images.allImagesFromDb(db, tagSlugs, q.sort),
|
images: Images.allImagesFromDb(db, tagSlugs, q.sort),
|
||||||
tags: db.getMany('categories', {}, [{ title: 1 }]),
|
tags: Images.getAllTags(db),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.get('/api/index-data', (req, res) => {
|
app.get('/api/index-data', (req, res) => {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ export interface Tag {
|
||||||
id: number
|
id: number
|
||||||
slug: string
|
slug: string
|
||||||
title: string
|
title: string
|
||||||
|
total: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GameRng {
|
interface GameRng {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@ in jigsawpuzzles.io
|
||||||
<div>
|
<div>
|
||||||
<label v-if="tags.length > 0">
|
<label v-if="tags.length > 0">
|
||||||
Tags:
|
Tags:
|
||||||
<span class="bit" v-for="(t,idx) in tags" :key="idx" @click="toggleTag(t)" :class="{on: filters.tags.includes(t.slug)}">{{t.title}}</span>
|
<span
|
||||||
|
class="bit"
|
||||||
|
v-for="(t,idx) in relevantTags"
|
||||||
|
:key="idx"
|
||||||
|
@click="toggleTag(t)"
|
||||||
|
:class="{on: filters.tags.includes(t.slug)}">{{t.title}} ({{t.total}})</span>
|
||||||
<!-- <select v-model="filters.tags" @change="filtersChanged">
|
<!-- <select v-model="filters.tags" @change="filtersChanged">
|
||||||
<option value="">All</option>
|
<option value="">All</option>
|
||||||
<option v-for="(c, idx) in tags" :key="idx" :value="c.slug">{{c.title}}</option>
|
<option v-for="(c, idx) in tags" :key="idx" :value="c.slug">{{c.title}}</option>
|
||||||
|
|
@ -97,6 +102,11 @@ export default defineComponent({
|
||||||
async created() {
|
async created() {
|
||||||
await this.loadImages()
|
await this.loadImages()
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
relevantTags (): Tag[] {
|
||||||
|
return this.tags.filter((tag: Tag) => tag.total > 0)
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
autocompleteTags (input: string, exclude: string[]): string[] {
|
autocompleteTags (input: string, exclude: string[]): string[] {
|
||||||
return this.tags
|
return this.tags
|
||||||
|
|
|
||||||
|
|
@ -72,15 +72,29 @@ async function getExifOrientation(imagePath: string): Promise<number> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAllTags = (db: Db): Tag[] => {
|
||||||
|
const query = `
|
||||||
|
select c.id, c.slug, c.title, count(*) as total from categories c
|
||||||
|
inner join image_x_category ixc on c.id = ixc.category_id
|
||||||
|
group by c.id order by total desc;`
|
||||||
|
return db._getMany(query).map(row => ({
|
||||||
|
id: parseInt(row.id, 10) || 0,
|
||||||
|
slug: row.slug,
|
||||||
|
title: row.title,
|
||||||
|
total: parseInt(row.total, 10) || 0,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
const getTags = (db: Db, imageId: number): Tag[] => {
|
const getTags = (db: Db, imageId: number): Tag[] => {
|
||||||
const query = `
|
const query = `
|
||||||
select * from categories c
|
select * from categories c
|
||||||
inner join image_x_category ixc on c.id = ixc.category_id
|
inner join image_x_category ixc on c.id = ixc.category_id
|
||||||
where ixc.image_id = ?`
|
where ixc.image_id = ?`
|
||||||
return db._getMany(query, [imageId]).map(row => ({
|
return db._getMany(query, [imageId]).map(row => ({
|
||||||
id: parseInt(row.number, 10) || 0,
|
id: parseInt(row.id, 10) || 0,
|
||||||
slug: row.slug,
|
slug: row.slug,
|
||||||
title: row.title,
|
title: row.title,
|
||||||
|
total: 0,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,6 +221,7 @@ export default {
|
||||||
allImagesFromDisk,
|
allImagesFromDisk,
|
||||||
imageFromDb,
|
imageFromDb,
|
||||||
allImagesFromDb,
|
allImagesFromDb,
|
||||||
|
getAllTags,
|
||||||
resizeImage,
|
resizeImage,
|
||||||
getDimensions,
|
getDimensions,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ app.get('/api/newgame-data', (req, res): void => {
|
||||||
const tagSlugs: string[] = q.tags ? q.tags.split(',') : []
|
const tagSlugs: string[] = q.tags ? q.tags.split(',') : []
|
||||||
res.send({
|
res.send({
|
||||||
images: Images.allImagesFromDb(db, tagSlugs, q.sort),
|
images: Images.allImagesFromDb(db, tagSlugs, q.sort),
|
||||||
tags: db.getMany('categories', {}, [{ title: 1 }]),
|
tags: Images.getAllTags(db),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue