From 8806bb5f857502eec2ad9132757458d714fff442 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 4 Oct 2022 20:55:04 +0200 Subject: Add search --- store/models.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'store') diff --git a/store/models.js b/store/models.js index 890ba8c..c884aa6 100644 --- a/store/models.js +++ b/store/models.js @@ -49,6 +49,36 @@ export const actions = { return res; }, + // Filter models + async filter({ commit }, data) { + commit("loadingStatus", true, { root: true }); + let res = { status: 0, data: null }; + let api = this.$config.api; + + const page = data.page ? data.page : 0; + + await fetch(`${api}/v1/models/filter?page=${page}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ q: data.q }), + }) + .then(async (response) => { + res.data = await response.json(); + res.status = response.status; + if (res.status == 200) { + commit("saveModels", res.data); + } + }) + .catch((e) => { + res.status = e.status; + }); + + commit("loadingStatus", false, { root: true }); + + return res; + }, // Find a model by its id async findModel({ commit }, id) { commit("loadingStatus", true, { root: true }); -- cgit v1.2.3-18-g5258