#19, added tags, and tags filtering

This commit is contained in:
2026-02-13 22:02:31 +02:00
parent 5c934e0ad2
commit b11e763fd9
11 changed files with 90 additions and 23 deletions
+1
View File
@@ -31,6 +31,7 @@ class Db {
await dbo.createCollection(c); await dbo.createCollection(c);
}catch(err){} }catch(err){}
} }
await dbo.collection('assets').createIndex({ name: 'text', 'description': 'text', tags: 'text' }, {name:'fts', default_language: "none" });
}finally{ }finally{
} }
} }
+7
View File
@@ -9,6 +9,8 @@ const execFile = util.promisify(npExecFile);
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import Utils from "../Utils.js";
const collection = 'assets'; const collection = 'assets';
/** /**
@@ -144,6 +146,11 @@ class GameObjectsManager{
project: { name:1, id:1, type:1, asset:1} project: { name:1, id:1, type:1, asset:1}
}); });
} }
this.getTags = async function(q){
let objects = await db.distinct(collection, 'tags', q ? {tags: {$regex: Utils.escapeRegExp(q), $options: 'i'}} : {});
return objects;
}
} }
/** /**
@@ -16,7 +16,7 @@ class GameObjectsController{
* @param {App} app The application instance, апликация * @param {App} app The application instance, апликация
*/ */
init(app){ init(app){
const { gameObject, am } = app; const { gameObject, am, db } = app;
const router = express.Router(); const router = express.Router();
/** /**
@@ -26,7 +26,7 @@ class GameObjectsController{
*/ */
router.put('/', multipartMiddleware, async (req, res)=>{ router.put('/', multipartMiddleware, async (req, res)=>{
try{ try{
let data = req.body; let data = JSON.parse(req.body.object);
let action = data.id ? 'update' : 'create'; let action = data.id ? 'update' : 'create';
let object = await gameObject[action](req, data) let object = await gameObject[action](req, data)
res.json({status: 'OK', object}); res.json({status: 'OK', object});
@@ -45,11 +45,16 @@ class GameObjectsController{
* @memberof GameObjectsController * @memberof GameObjectsController
*/ */
router.post('/', async (req, res)=>{ router.post('/', async (req, res)=>{
let result = await gameObject.list(req.body); let result = await gameObject.list(db.sanitizeQuery(req.body));
res.json(result); res.json(result);
am.audit(req, `game-object-list`, null, {q: req.body}); am.audit(req, `game-object-list`, null, {q: req.body});
}) })
router.post('/tags', async (req, res)=>{
let tags = await gameObject.getTags(req.body.q);
res.json(tags);
})
/** /**
* API: GET /api/game-object/:id Retrieve game object by ID, извличане на обект по идентификатор * API: GET /api/game-object/:id Retrieve game object by ID, извличане на обект по идентификатор
* @function read * @function read
@@ -1,7 +1,14 @@
<template> <template>
<v-chip-group variant="flat" v-if="!hideFilter" class="pa-4" multiple column v-model="selectedTypes"> <v-container fluid class="d-flex flex-wrap">
<v-chip v-for="(f,i) in $p.objectTypes" :key="i" :text="l[f.value]" :value="f.value" :color="f.color" filter></v-chip> <v-chip :text="'All'" class="mt-2 mr-2" @click="selectedTypes = selectedTypes.length ? [] : $p.objectTypes.map(f => f.value)" filter></v-chip>
</v-chip-group> <v-chip-group variant="flat" v-if="!hideFilter" multiple column v-model="selectedTypes">
<v-chip v-for="(f, i) in $p.objectTypes" :key="i" :text="l[f.value]" :value="f.value" :color="f.color"
filter></v-chip>
</v-chip-group>
<v-text-field :loading="loading" append-inner-icon="mdi-magnify" density="compact" :label="l.search"
hide-details @update:model-value="debounce(load, 500, true);" rounded v-model="textSearch"></v-text-field>
</v-container>
<v-container class="asset-browser"> <v-container class="asset-browser">
<v-row> <v-row>
<v-col v-for="(v, i) in items" :key="i" cols="12" xs="6" sm="4" md="3" xl="2" class="position-relative img-preview"> <v-col v-for="(v, i) in items" :key="i" cols="12" xs="6" sm="4" md="3" xl="2" class="position-relative img-preview">
@@ -26,7 +33,7 @@
</template> </template>
<script> <script>
import Utils from '#/app/Utils';
export default { export default {
props:[ props:[
'modelValue', 'query', 'hideFilter' 'modelValue', 'query', 'hideFilter'
@@ -39,6 +46,9 @@ export default {
selectedTypes: this.$p.objectTypes.map(f=>f.value), selectedTypes: this.$p.objectTypes.map(f=>f.value),
previewObject: null, previewObject: null,
previewDialog: false, previewDialog: false,
loading: false,
textSearch: '',
tags: []
} }
}, },
@@ -48,20 +58,32 @@ export default {
watch:{ watch:{
async selectedTypes(n){ async selectedTypes(n){
this.q.type = { $in: n }; this.q.type = { '*in': n };
await this.load(); await this.load();
} }
}, },
methods:{ methods:{
async load(){ async load(){
this.loading = true;
Object.assign(this.q, this.query || {}); Object.assign(this.q, this.query || {});
if (this.textSearch) {
this.q['*or'] = [
{ name: { '*regex': Utils.escapeRegExp(this.textSearch), '*options': 'i' } },
{ tags: { '*regex': Utils.escapeRegExp(this.textSearch), '*options': 'i' } },
{ description: { '*regex': Utils.escapeRegExp(this.textSearch), '*options': 'i' } }
];
}else{
delete this.q['*or'];
}
this.items = (await this.$api.gameObject.search(this.q)).data.data; this.items = (await this.$api.gameObject.search(this.q)).data.data;
this.loading = false;
this.tags = await this.$api.gameObject.getTags(this.textSearch || null);
}, },
preview(v){ preview(v){
this.previewObject = v; this.previewObject = v;
this.previewDialog = true; this.previewDialog = true;
} },
} }
} }
</script> </script>
+1
View File
@@ -39,6 +39,7 @@ export default {
engine.clearScene(); engine.clearScene();
engine.stop(); engine.stop();
engine.tm?.setGame(null); engine.tm?.setGame(null);
engine.destroy();
}, },
computed:{ computed:{
+13 -1
View File
@@ -1,5 +1,7 @@
import { useAppStore } from '@/stores/app'; import { useAppStore } from '@/stores/app';
const debounceData = [];
export default { export default {
data(){ data(){
return { return {
@@ -56,6 +58,16 @@ export default {
if (this.store?.prefs?.debug){ if (this.store?.prefs?.debug){
console.log(...args); console.log(...args);
} }
} },
debounce(fn){
let f = debounceData.find(f=>f.fn == fn);
if (f){
clearTimeout(f.to);
}else{
f = {fn};
debounceData.push(f);
}
f.to = setTimeout(...arguments);
},
} }
} }
+19 -11
View File
@@ -16,8 +16,17 @@
<v-textarea :label="l.description" v-model="object.description"></v-textarea> <v-textarea :label="l.description" v-model="object.description"></v-textarea>
<v-select :label="l.objectType" v-model="object.type" :items="$p.objectTypes.map(ot=>({title:l[ot.value], value:ot.value}))" tit :rules="[rules.required]"> <v-select :label="l.objectType" v-model="object.type" :items="$p.objectTypes.map(ot=>({title:l[ot.value], value:ot.value}))" tit :rules="[rules.required]">
</v-select> </v-select>
<v-file-input :label="l.objectFile" v-model="object.file" :rules="[rules.requiredFile]"></v-file-input> <v-file-input :label="l.objectFile" v-model="file" :rules="[rules.requiredFile]"></v-file-input>
<div v-if="object.asset">{{ object.asset.name }} | {{ object.asset.ofn }}</div> <v-combobox clearable chips multiple :label="l.tags" v-model="object.tags" :items="tagList">
<template v-slot:chip="{ props, item }">
<v-chip v-bind="props" label>
<template v-slot:close>
<v-icon icon="$close" size="14"></v-icon>
</template>
</v-chip>
</template>
</v-combobox>
<div v-if="object.asset" closable-chips deletable-chips :delimiters="[',']">{{ object.asset.name }} | {{ object.asset.ofn }}</div>
</v-form> </v-form>
<v-card-actions> <v-card-actions>
<v-btn @click="save" :loading="loading" prepend-icon="mdi-content-save" color="success" <v-btn @click="save" :loading="loading" prepend-icon="mdi-content-save" color="success"
@@ -54,6 +63,8 @@ export default {
return { return {
panel: this.$route.query?.tab || 'edit', panel: this.$route.query?.tab || 'edit',
object: {}, object: {},
tagList: [],
file: null,
valid: false, valid: false,
rules: { rules: {
required: v => v ? true : this.l.fieldRequired, required: v => v ? true : this.l.fieldRequired,
@@ -66,11 +77,9 @@ export default {
if (this.id && this.id != 'add') { if (this.id && this.id != 'add') {
this.object = (await this.$api.gameObject.load(this.id)).data; this.object = (await this.$api.gameObject.load(this.id)).data;
} }
this.tagList = (await this.$api.gameObject.getTags()).data;
}, },
computed: { computed: {
fileToUpload() {
return this.object?.file instanceof File
},
id() { id() {
return this.$route.params?.id; return this.$route.params?.id;
}, },
@@ -83,17 +92,16 @@ export default {
this.loading = true; this.loading = true;
try { try {
let fd = new FormData(); let fd = new FormData();
let keys = ['name', 'type']; if (this.file) {
if (this.fileToUpload) keys.push('file'); fd.append('file', this.file)
if (this.id != 'add') keys.push('id'); }
if (this.object.thumb) keys.push('thumb'); fd.append('object', JSON.stringify(this.object));
keys.forEach(e => fd.append(e, this.object[e]))
let result = await this.$api.gameObject.save(fd); let result = await this.$api.gameObject.save(fd);
Object.assign(this.object, result.data.object); Object.assign(this.object, result.data.object);
if (this.id == 'add') { if (this.id == 'add') {
this.$router.replace({ params: { id: this.object.id }, query:{ tab:'preview' } }); this.$router.replace({ params: { id: this.object.id }, query:{ tab:'preview' } });
} }
this.debug(this.object)
// await this.$nextTick(); // await this.$nextTick();
// this.panel = 'preview'; // this.panel = 'preview';
// if (!params?.thumbOnly) await this.$refs.assetPreview.loadAsset(); // if (!params?.thumbOnly) await this.$refs.assetPreview.loadAsset();
+3
View File
@@ -33,6 +33,9 @@ export default {
}, },
async remove(id){ async remove(id){
return await $ax.delete(`/game-object/${id}`) return await $ax.delete(`/game-object/${id}`)
},
async getTags(q){
return await $ax.post('/game-object/tags', {q});
} }
}, },
scenario:{ scenario:{
+4
View File
@@ -10,6 +10,8 @@ const lang = {
name: 'Name', name: 'Name',
id: 'Identifier', id: 'Identifier',
description: 'Description', description: 'Description',
tags: 'Tags',
search: 'Search',
fieldRequired: 'Field is required', fieldRequired: 'Field is required',
objectType: 'Object type', objectType: 'Object type',
objectFile: 'File', objectFile: 'File',
@@ -163,6 +165,8 @@ const lang = {
name: 'Име', name: 'Име',
id: 'Идентификатор', id: 'Идентификатор',
description: 'Описание', description: 'Описание',
tags: 'Етикети',
search: 'Търсене',
fieldRequired: 'Полето е задължително', fieldRequired: 'Полето е задължително',
objectType: 'Тип обект', objectType: 'Тип обект',
objectFile: 'Файл', objectFile: 'Файл',
+3
View File
@@ -24,6 +24,9 @@ export default createVuetify({
VSelect: { VSelect: {
variant: 'outlined' variant: 'outlined'
}, },
VCombobox: {
variant: 'outlined'
},
VTextField: { VTextField: {
variant: 'outlined' variant: 'outlined'
}, },
+3 -2
View File
@@ -115,7 +115,7 @@ video{
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;
max-width: 100vw; max-width: 100vw;
height: calc(100vh - 244px); height: calc(100vh - 277px);
&.pan { &.pan {
cursor: grab; cursor: grab;
} }
@@ -144,4 +144,5 @@ audio {
left:unset !important; left:unset !important;
bottom: 0 !important; bottom: 0 !important;
right: 0 !important; right: 0 !important;
} }