Align dashboard user search with staff pattern
This commit is contained in:
@@ -38,9 +38,6 @@
|
||||
</td>
|
||||
</template>
|
||||
</v-data-table>
|
||||
<div class="text-xs-center mt-2">
|
||||
<v-pagination v-model="pageSync" :length="totalPages"></v-pagination>
|
||||
</div>
|
||||
</v-flex>
|
||||
</v-layout>
|
||||
</v-card>
|
||||
@@ -64,10 +61,6 @@ module.exports = {
|
||||
computed: {
|
||||
users() { return this.$store.state.dashboard_user.users },
|
||||
isLoading() { return this.$store.state.dashboard_user.search_status == 1 },
|
||||
totalPages() {
|
||||
let p = this.$store.state.dashboard_user.total_pages
|
||||
return p > 0 ? p : 1
|
||||
},
|
||||
username: {
|
||||
get() { return this.$store.state.dashboard_user.search_username },
|
||||
set(val) { this.$store.commit('dashboard_user/update_search_username', val) }
|
||||
@@ -89,24 +82,14 @@ module.exports = {
|
||||
return Object.assign({}, p, { label: p.project_number + ' - ' + p.project_name })
|
||||
})
|
||||
return base.concat(records)
|
||||
},
|
||||
pageSync: {
|
||||
get() { return this.$store.state.dashboard_user.page },
|
||||
set(val) {
|
||||
let nextPage = Number(val) || 1
|
||||
let currentPage = Number(this.$store.state.dashboard_user.page) || 1
|
||||
if (nextPage === currentPage) return
|
||||
this.$store.commit('dashboard_user/update_page', nextPage)
|
||||
this.doSearch(nextPage)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
doSearch(page) {
|
||||
doSearch() {
|
||||
this.$store.dispatch('dashboard_user/search', {
|
||||
username: this.username || '',
|
||||
project: this.project && this.project.mcu_id ? this.project.mcu_id : 'all',
|
||||
page: page || 1,
|
||||
page: 1,
|
||||
limit: this.$store.state.dashboard_user.limit
|
||||
})
|
||||
},
|
||||
|
||||
@@ -13,8 +13,6 @@ export default {
|
||||
limit: 20,
|
||||
total_rows: 0,
|
||||
total_pages: 0,
|
||||
last_search_signature: '',
|
||||
last_search_at: 0,
|
||||
search_status: 0,
|
||||
save_status: 0,
|
||||
save_error_message: '',
|
||||
@@ -32,8 +30,6 @@ export default {
|
||||
update_limit(state, val) { state.limit = val },
|
||||
update_total_rows(state, val) { state.total_rows = val },
|
||||
update_total_pages(state, val) { state.total_pages = val },
|
||||
update_last_search_signature(state, val) { state.last_search_signature = val },
|
||||
update_last_search_at(state, val) { state.last_search_at = val },
|
||||
update_search_status(state, val) { state.search_status = val },
|
||||
update_save_status(state, val) { state.save_status = val },
|
||||
update_save_error_message(state, val) { state.save_error_message = val },
|
||||
@@ -42,23 +38,10 @@ export default {
|
||||
},
|
||||
actions: {
|
||||
async search(context, prm) {
|
||||
let normalized = {
|
||||
username: (prm && prm.username ? prm.username : '').trim(),
|
||||
project: (prm && prm.project ? prm.project : 'all'),
|
||||
page: Number(prm && prm.page ? prm.page : context.state.page) || 1,
|
||||
limit: Number(prm && prm.limit ? prm.limit : context.state.limit) || 20
|
||||
}
|
||||
let signature = JSON.stringify(normalized)
|
||||
let now = Date.now()
|
||||
if (signature === context.state.last_search_signature && (now - context.state.last_search_at) < 1000) {
|
||||
return { status: 'SKIP' }
|
||||
}
|
||||
context.commit('update_last_search_signature', signature)
|
||||
context.commit('update_last_search_at', now)
|
||||
context.commit('update_search_status', 1)
|
||||
try {
|
||||
let payload = Object.assign({}, normalized, { token: one_token() })
|
||||
let resp = await api.search(payload)
|
||||
prm.token = one_token()
|
||||
let resp = await api.search(prm)
|
||||
if (resp.status != 'OK') {
|
||||
context.commit('update_search_status', 3)
|
||||
context.commit('update_save_error_message', resp.message)
|
||||
|
||||
Reference in New Issue
Block a user