Skip to content

Commit 64487bf

Browse files
committed
1 parent d5fc7f3 commit 64487bf

2 files changed

Lines changed: 53 additions & 57 deletions

File tree

src/main/malewicz/src/components/ObjectsTablePanel.vue

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<v-data-table
6969
:headers="defaultMeta"
7070
:items="items"
71-
:pagination.sync="pagination"
71+
:pagination.sync="uirPagination"
7272
:loading="isLoading"
7373
hide-actions
7474
class="elevation-1">
@@ -112,34 +112,11 @@ export default {
112112
return {
113113
meta: [],
114114
items: [],
115-
pagination: {
116-
rowsPerPage: -1,
117-
sortBy: ''
118-
},
119115
dialog: false,
120116
dialog2: false,
121117
isLoading: false
122118
}
123119
},
124-
created: function () {
125-
if (this.$store.state.uri.connections.length > 0) {
126-
this.isLoading = true
127-
this.$http.get(this.$store.getters.preparedTypeUri).then(
128-
response => {
129-
this.meta = response.body[0]
130-
}
131-
)
132-
this.$http.get(this.$store.getters.preparedUri).then(
133-
response => {
134-
this.items = response.body
135-
if (this.items.length >= 15 && this.message === this.getPageCount()) {
136-
this.increasePageCount()
137-
}
138-
this.isLoading = false
139-
}
140-
)
141-
}
142-
},
143120
computed: {
144121
getSort () {
145122
return this.pagination
@@ -161,42 +138,48 @@ export default {
161138
set (value) {
162139
return this.$store.commit('pageNumber', value)
163140
}
141+
},
142+
uirPagination: {
143+
get () {
144+
return this.$store.getters.getPagination
145+
},
146+
set (value) {
147+
return this.$store.commit('setPagination', value)
148+
}
164149
}
165150
},
166151
watch: {
167152
completeUri: {
168153
handler(newVal, oldVal) {
169-
this.meta = []
170-
// this.meta = this.$store.getters.getTypes.find( v => { return v.name === this.$store.getters.getUri.type } )
154+
this.meta = this.$store.getters.getTypes.find( v => { return v.name === this.$store.getters.getUri.type } )
171155
172-
this.$http.get(this.$store.getters.preparedTypeUri).then(
173-
response => {
174-
this.meta = response.body[0]
175-
176-
/* if (Object.keys(this.$store.getters.getUri.orderby).length === 0) {
177-
console.log("EMPTY!")
178-
this.pagination.sortBy = 'time'
179-
this.setSort('time')
180-
return
181-
}*/
182-
183-
this.items = []
184-
this.isLoading = true
185-
this.$http.get(this.$store.getters.preparedUri).then(
186-
response => {
187-
this.items = response.body
188-
if (this.items.length >= 15 && this.message === this.getPageCount()) {
189-
this.increasePageCount()
190-
}
191-
this.isLoading = false
192-
}, response => {
193-
this.$notify({ group: 'foo', type: 'error', title: 'Server error', text: response })
194-
this.isLoading = false
195-
}
196-
)
156+
console.log("URI_VAL = " + JSON.stringify(this.$store.getters.getUri))
157+
if (Object.keys(this.$store.getters.getUri.orderby).length === 0) {
158+
const defaultSort = this.meta.metadata.filter(v => { return v.properties.sort }).map(v => v.name)[0]
159+
console.log("defaultSort = " + defaultSort)
160+
if (defaultSort) {
161+
const sortType = this.meta.metadata.filter(v => { return v.properties.sort })[0].properties.sort
162+
console.log("sortType = " + sortType)
163+
this.setSort(defaultSort + '-' + sortType)
164+
return
165+
}
166+
}
197167
168+
this.items = []
169+
this.isLoading = true
170+
this.$http.get(this.$store.getters.preparedUri).then(
171+
response => {
172+
this.items = response.body
173+
if (this.items.length >= 15 && this.message === this.getPageCount()) {
174+
this.increasePageCount()
175+
}
176+
this.isLoading = false
177+
}, response => {
178+
this.$notify({ group: 'foo', type: 'error', title: 'Server error', text: response })
179+
this.isLoading = false
198180
}
199181
)
182+
200183
},
201184
deep: true,
202185
},
@@ -212,13 +195,8 @@ export default {
212195
},
213196
methods: {
214197
call () {
215-
this.meta = []
198+
this.meta = this.$store.getters.getTypes.find( v => { return v.name === this.$store.getters.getUri.type } )
216199
this.items = []
217-
this.$http.get(this.$store.getters.preparedTypeUri).then(
218-
response => {
219-
this.meta = response.body[0]
220-
}
221-
)
222200
this.$http.get(this.$store.getters.preparedUri).then(
223201
response => {
224202
this.items = response.body

src/main/malewicz/src/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ const store = new Vuex.Store({
8282
}
8383
},
8484
getters: {
85+
getPagination: state => {
86+
if (state.uri.orderby.ord === 'asc') {
87+
return { rowsPerPage: -1, sortBy: state.uri.orderby.field, descending: false, page: 1, totalItems: 0 }
88+
} else if (state.uri.orderby.ord === 'desc') {
89+
return { rowsPerPage: -1, sortBy: state.uri.orderby.field, descending: true, page: 1, totalItems: 0 }
90+
} else {
91+
return { rowsPerPage: -1, sortBy: state.uri.orderby.field, descending: null, page: 1, totalItems: 0 }
92+
}
93+
},
8594
getAllConnections: state => {
8695
return state.allConnections
8796
},
@@ -121,6 +130,15 @@ const store = new Vuex.Store({
121130
}
122131
},
123132
mutations: {
133+
setPagination (state, pagination) {
134+
if (pagination.descending === false) {
135+
state.uri.orderby = {field: pagination.sortBy, ord: "asc"}
136+
} else if (pagination.descending === true){
137+
state.uri.orderby = {field: pagination.sortBy, ord: "desc"}
138+
} else {
139+
state.uri.orderby = {}
140+
}
141+
},
124142
setAllConnections (state, connections) {
125143
state.allConnections = connections
126144
},

0 commit comments

Comments
 (0)