Skip to content

Commit

Permalink
feat: filter training results when dropdown is used (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Sep 7, 2021
1 parent e4c48d0 commit 81232aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 11 additions & 5 deletions api/src/controllers/train.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ const { tryParseJSON } = require('../util/validators.util');
module.exports.get = async (req, res) => {
const token = AUTH ? jwt.sign({ route: 'storage' }) : null;
const db = database.connect();
let files = db
.prepare(
'SELECT id, name, filename, createdAt FROM file WHERE isActive = 1 ORDER BY name ASC, id DESC'
)
.all();
let files = req.query.name
? db
.prepare(
'SELECT id, name, filename, createdAt FROM file WHERE name = ? AND isActive = 1 ORDER BY name ASC, id DESC'
)
.all(req.query.name)
: db
.prepare(
'SELECT id, name, filename, createdAt FROM file WHERE isActive = 1 ORDER BY name ASC, id DESC'
)
.all();

files.forEach((file) => {
file.results = [];
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/views/Train.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export default {
},
created() {
this.emitter.on('trainingFolder', (value) => {
let shouldRefresh = false;
if (value !== 'add new' && value !== null) shouldRefresh = true;
if (value === null && this.trainingFolder !== 'add new') shouldRefresh = true;
this.trainingFolder = value;
if (shouldRefresh) this.get().status();
});
this.emitter.on('folders', (value) => {
Expand Down Expand Up @@ -94,7 +98,9 @@ export default {
async files() {
try {
$this.loading.files = true;
const { data } = await ApiService.get('train');
const { data } = $this.trainingFolder
? await ApiService.get(`train?name=${$this.trainingFolder}`)
: await ApiService.get('train');
$this.matches.source = data;
$this.loading.files = false;
} catch (error) {
Expand Down

0 comments on commit 81232aa

Please sign in to comment.