Skip to content

Commit

Permalink
default show own tickets and support show all for admin (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
QSummerY authored Jul 5, 2024
1 parent 46f1c59 commit d1961c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
37 changes: 24 additions & 13 deletions frontend/pages/ticket/index.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<template>
<a-layout>
<a-form layout="inline">
<div style="margin-top: 16px;margin-bottom: 16px">
<a-form-item label="Query key">
<!-- <a-input v-model="queryKey" placeholder="input query key" style="width:300px"></a-input> -->
<a-select v-model="queryKey" allow-clear placeholder="select a search key" style="width: 300px">
<a-select-option v-for="item in queryKeyMap" :key="item.name" :value="item.value" >{{ item.name }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="Query value">
<a-input v-model="queryValue" placeholder="input query value" style="width:300px"></a-input>
</a-form-item>
<a-button type="link" icon="search" @click="handleSearch"></a-button>
</div>
</a-form>
<div style="margin-top: 16px;margin-bottom: 16px">
<a-checkbox v-if="$store.getters.isAdmin" v-model="showAll">Show All</a-checkbox>
<a-form-item label="Query key">
<a-select v-model="queryKey" allow-clear placeholder="select a search key" style="width: 300px">
<a-select-option v-for="item in queryKeyMap" :key="item.name" :value="item.value" >{{ item.name }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="Query value">
<a-input v-model="queryValue" placeholder="input query value" style="width:300px"></a-input>
</a-form-item>
<a-button type="link" icon="search" @click="handleSearch"></a-button>
</div>
</a-form>
<a-table
:columns="columns"
:data-source="tableData"
Expand Down Expand Up @@ -137,6 +137,7 @@ export default {
{"name": "Submitter", "value": "submitter"},
{"name": "By", "value": "confirmed_by"},
],
showAll: false,
queryKey: undefined,
queryValue: undefined,
}
Expand Down Expand Up @@ -231,6 +232,13 @@ export default {
]
}
},
watch: {
showAll () {
const queryParams = {page: 1, pagesize: 10}
this.loading = true
this.loadTickets(queryParams)
}
},
mounted () {
const queryParams = this.$route.query
if (queryParams.page === undefined) {
Expand Down Expand Up @@ -279,6 +287,9 @@ export default {
loadTickets (params) {
this.pagination.current = params.page
this.loading = true
if (this.showAll) {
params.show_all = true
}
this.$axios.get('/api/ticket', {params}).then(
(response) => {
this.handleTicketList(response)
Expand Down
6 changes: 3 additions & 3 deletions helpdesk/views/api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def extra_dict(d):
@router.get('/ticket')
async def list_ticket(page: Optional[str] = None, pagesize: Optional[str] = None,
order_by: Optional[str] = None, desc: bool = False, current_user: User = Depends(get_current_user),
query_key: Optional[QeuryKey] = None, query_value: Optional[str] = None):
query_key: Optional[QeuryKey] = None, query_value: Optional[str] = None, show_all: Optional[bool] = False):
query_params={'page': page, 'page_size': pagesize, 'order_by': order_by, 'desc': desc}
if query_key and query_value:
query_params[query_key] = query_value
Expand All @@ -237,11 +237,11 @@ async def list_ticket(page: Optional[str] = None, pagesize: Optional[str] = None
desc = True
kw = dict(filter_=filter_, order_by=order_by, desc=desc, limit=pagesize, offset=(page - 1) * pagesize)

if current_user.is_admin:
if current_user.is_admin and show_all:
tickets = await Ticket.get_all(**kw)
total = await Ticket.count(filter_=filter_)
else:
# only show self tickets if not admin
# only show self tickets if not admin or admin without show_all
tickets = await Ticket.get_all_by_submitter(submitter=current_user.name, **kw)
total = await Ticket.count_by_submitter(submitter=current_user.name, filter_=filter_)

Expand Down

0 comments on commit d1961c5

Please sign in to comment.