diff --git a/src/api.js b/src/api.js new file mode 100644 index 0000000000000000000000000000000000000000..402b5844486d6536ee88b6725707a314f27c535d --- /dev/null +++ b/src/api.js @@ -0,0 +1,230 @@ +export const api = { + async search (name, tags, param, sort, size, page) { + var url = this.$serverurl + 'search' + const params = new URLSearchParams() + + if (name != null) params.append('name', name) + if (tags != null) params.append('tags', tags) + if (param != null) params.append('param', param) + if (sort != null) params.append('sort', sort) + + params.append('size', size) + params.append('page', page) + + console.log('get models ' + this.paramSearch + ' + ' + this.paramPerf + ' + ' + this.paramTags) + + url += '?' + params + const response = await fetch(url) + try { + return await response.json() + } catch (error) { + return null + } + }, + async getTags () { + const url = this.$serverurl + 'tags' + const response = await fetch(url) + try { + return await response.json() + } catch (error) { + return null + } + }, + async getUser () { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'user' + try { + const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } }) + return await response.json() + } catch (error) { + return null + } + }, + async addNewCategory (name) { + const url = this.$serverurl + 'tags/category' + const token = await localStorage.getItem('token') + try { + const response = await fetch( + url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + token + }, + body: JSON.stringify({ + name: name + }) + } + ) + return await response.json() + } catch (error) { + return null + } + }, + async addNewTag (tag, categoryId) { + const url = this.$serverurl + 'tags' + const token = await localStorage.getItem('token') + try { + const response = await fetch( + url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + token + }, + body: JSON.stringify({ + name: tag, + categoryId: categoryId + }) + } + ) + return await response.json() + } catch (error) { + return null + } + }, + async getUserList () { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'user/list' + try { + const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } }) + return await response.json() + } catch (error) { + return null + } + }, + async getModelList () { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'models/list' + try { + const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } }) + return await response.json() + } catch (error) { + return null + } + }, + async getUserModels () { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'models' + try { + const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } }) + return await response.json() + } catch (error) { + return null + } + }, + async getModel (id) { + const url = this.$serverurl + 'models' + '?id=' + id + const response = await fetch(url) + try { + return await response.json() + } catch (error) { + return null + } + }, + async removeModel (id) { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'models' + '?id=' + id + try { + await fetch(url, { + method: 'DELETE', + headers: { + Authorization: 'Bearer ' + token + } + }) + return true + } catch (error) { + return false + } + }, + async removeTag (id) { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'tags' + '?id=' + id + try { + await fetch(url, { + method: 'DELETE', + headers: { + Authorization: 'Bearer ' + token + } + }) + return true + } catch (error) { + return false + } + }, + async removeCategory (id) { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'tags/category' + '?id=' + id + try { + await fetch(url, { + method: 'DELETE', + headers: { + Authorization: 'Bearer ' + token + } + }) + return true + } catch (error) { + return false + } + }, + async removeUser (id) { + const token = await localStorage.getItem('token') + const url = this.$serverurl + 'user' + '?id=' + id + try { + await fetch(url, { + method: 'DELETE', + headers: { + Authorization: 'Bearer ' + token + } + }) + return true + } catch (error) { + return false + } + }, + async login (username, password) { + const url = this.$serverurl + 'login' + try { + const response = await fetch( + url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + username: username, + password: password + }) + } + ) + return await response.json() + } catch (error) { + return null + } + }, + async register (username, email, password) { + const url = this.$serverurl + 'user/signup' + try { + const response = await fetch( + url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + email: email, + username: username, + password: password + }) + } + ) + return await response.json() + } catch (error) { + return null + } + } +} diff --git a/src/components/Filters.vue b/src/components/Filters.vue index 07d21b79452501672718b164afd2349f262ef871..4e771972de03da52b935aa101769ca88fc0fdbce 100644 --- a/src/components/Filters.vue +++ b/src/components/Filters.vue @@ -2,7 +2,7 @@ <b-menu> <div> <b-menu-list v-for="category in tags" v-bind:key="category.name" :label="category.name"> - <div v-for="tag in category.tags" v-bind:key="tag" class="field"> + <div v-for="tag in category.tags" v-bind:key="tag.name" class="field"> <b-checkbox :native-value="tag.name" v-model="checkboxGroup" diff --git a/src/components/ModelCard.vue b/src/components/ModelCard.vue index 26263a236477a60991eb52dac8e5baec6503bad2..7c8a1f74a536038e501345d76d48535fdc85db97 100644 --- a/src/components/ModelCard.vue +++ b/src/components/ModelCard.vue @@ -7,7 +7,7 @@ <p> <strong>{{model.name}}</strong> <br> - <small>{{model.author.username}}</small> - <small>{{new Date(model.modificationDate).toLocaleDateString()}}</small> + <small>{{model.author.username}}</small> - <small>{{new Date(model.lastModified).toLocaleDateString()}}</small> <br> {{model.shortDescription}} </p> diff --git a/src/components/ModelTable.vue b/src/components/ModelTable.vue index f080a5eb9bde06b222c3f4c5be549738f48f1480..a5701f3ea50e1348f36df936d310e0be59bccdfe 100644 --- a/src/components/ModelTable.vue +++ b/src/components/ModelTable.vue @@ -10,11 +10,11 @@ </b-table-column> <b-table-column field="date" label="Last modification" centered sortable> - {{ new Date(props.row.modificationDate).toLocaleDateString() }} + {{ new Date(props.row.lastModified).toLocaleDateString() }} </b-table-column> <b-table-column field="date" label="Added" centered sortable> - {{ new Date(props.row.addedDate).toLocaleDateString() }} + {{ new Date(props.row.added).toLocaleDateString() }} </b-table-column> <b-table-column label="" centered> diff --git a/src/main.js b/src/main.js index 75cf15283d3c8b8e606ae7ad1fcf159c835c6c43..aeaa0a34ddcfb7f26ab87c459650cf5b6a1a9c62 100644 --- a/src/main.js +++ b/src/main.js @@ -9,7 +9,7 @@ Vue.use(Buefy) Vue.config.productionTip = false // Vue.prototype.$serverurl = process.env.VUE_APP_SERVER_URL -Vue.prototype.$serverurl = '/' +Vue.prototype.$serverurl = 'https://mozen.gltronic.ovh/' new Vue({ router, diff --git a/src/views/Model.vue b/src/views/Model.vue index 7b15081bde338de0ee14162b0f8f9635fbd7a319..fec946b73b293d55e0eb2b7ec89090df203aefa3 100644 --- a/src/views/Model.vue +++ b/src/views/Model.vue @@ -22,9 +22,9 @@ <h1 class="title is-4">{{model.votes}} votes <b-button size="is-small" icon-left="heart-outline" style="top:-2px"/></h1> <small>Author: </small><strong>{{model.author.username}}</strong> <br> - <small>Added: </small><strong>{{new Date(model.addedDate).toLocaleDateString()}}</strong> + <small>Added: </small><strong>{{new Date(model.added).toLocaleDateString()}}</strong> <br> - <small>Last modification: </small><strong>{{new Date(model.modificationDate).toLocaleDateString()}}</strong> + <small>Last modification: </small><strong>{{new Date(model.lastModified).toLocaleDateString()}}</strong> <br> <br> <b-button type="is-primary" size="is-medium" icon-left="download">