[TR-22] - Fix department filter issue

This commit is contained in:
Ivan Diaz 2019-07-26 12:49:43 +02:00
parent 59413434b0
commit b81a28114f
6 changed files with 56 additions and 20 deletions

View File

@ -12,22 +12,22 @@ export default {
};
},
retrieveMyTickets(page, closed = 0) {
retrieveMyTickets(page, closed = 0, departmentId = 0) {
return {
type: 'MY_TICKETS',
payload: API.call({
path: '/staff/get-tickets',
data: {page, closed}
data: {page, closed, departmentId}
})
};
},
retrieveNewTickets(page = 1) {
retrieveNewTickets(page = 1, departmentId = 0) {
return {
type: 'NEW_TICKETS',
payload: API.call({
path: '/staff/get-new-tickets',
data: {page}
data: {page, departmentId}
})
};
},

View File

@ -26,7 +26,8 @@ class TicketList extends React.Component {
'secondary'
]),
closedTicketsShown: React.PropTypes.bool,
onClosedTicketsShownChange: React.PropTypes.func
onClosedTicketsShownChange: React.PropTypes.func,
onDepartmentChange: React.PropTypes.func,
};
static defaultProps = {
@ -72,9 +73,13 @@ class TicketList extends React.Component {
return {
departments: this.getDepartments(),
onChange: (event) => {
const departmentId = event.index && this.props.departments[event.index - 1].id;
this.setState({
selectedDepartment: event.index && this.props.departments[event.index - 1].id
selectedDepartment: departmentId
});
if(this.props.onDepartmentChange) {
this.props.onDepartmentChange(departmentId || null);
}
},
size: 'medium'
};

View File

@ -25,10 +25,11 @@ class AdminPanelMyTickets extends React.Component {
state = {
closedTicketsShown: false,
departmentId: null,
};
componentDidMount() {
this.retrieveMyTickets()
this.retrieveMyTickets();
}
render() {
@ -57,7 +58,11 @@ class AdminPanelMyTickets extends React.Component {
onClosedTicketsShownChange: this.onClosedTicketsShownChange.bind(this),
pages: this.props.pages,
page: this.props.page,
onPageChange: event => this.retrieveMyTickets(event.target.value)
onPageChange: event => this.retrieveMyTickets(event.target.value),
onDepartmentChange: departmentId => {
this.setState({departmentId});
this.retrieveMyTickets(1, this.state.closedTicketsShown, departmentId);
},
};
}
@ -85,8 +90,8 @@ class AdminPanelMyTickets extends React.Component {
this.retrieveMyTickets();
}
retrieveMyTickets(page = this.props.page, closed = this.state.closedTicketsShown) {
this.props.dispatch(AdminDataAction.retrieveMyTickets(page, closed * 1));
retrieveMyTickets(page = this.props.page, closed = this.state.closedTicketsShown, departmentId = this.state.departmentId) {
this.props.dispatch(AdminDataAction.retrieveMyTickets(page, closed * 1, departmentId));
}
}

View File

@ -15,7 +15,11 @@ class AdminPanelNewTickets extends React.Component {
page: 1,
userId: 0,
departments: [],
tickets: []
tickets: [],
};
state = {
departmentId: null,
};
componentDidMount() {
@ -43,12 +47,16 @@ class AdminPanelNewTickets extends React.Component {
ticketPath: '/admin/panel/tickets/view-ticket/',
page: this.props.page,
pages: this.props.pages,
onPageChange: event => this.retrieveNewTickets(event.target.value)
onPageChange: event => this.retrieveNewTickets(event.target.value),
onDepartmentChange: departmentId => {
this.setState({departmentId});
this.retrieveNewTickets(1, departmentId);
},
};
}
retrieveNewTickets(page = this.props.page) {
this.props.dispatch(AdminDataAction.retrieveNewTickets(page));
retrieveNewTickets(page = this.props.page, departmentId = this.state.departmentId) {
this.props.dispatch(AdminDataAction.retrieveNewTickets(page, departmentId));
}
}

View File

@ -43,6 +43,7 @@ class GetNewTicketsStaffController extends Controller {
}
public function handler() {
$page = Controller::request('page');
$departmentId = Controller::request('departmentId');
if (Ticket::isTableEmpty()) {
Response::respondSuccess([
@ -68,6 +69,10 @@ class GetNewTicketsStaffController extends Controller {
$query .= 'FALSE) AND closed = 0';
}
if($departmentId) {
$query .= ' AND department_id=' . $departmentId;
}
$countTotal = Ticket::count($query);
$query .= ' ORDER BY unread_staff DESC';

View File

@ -46,16 +46,29 @@ class GetTicketStaffController extends Controller {
$user = Controller::getLoggedUser();
$closed = Controller::request('closed');
$page = Controller::request('page');
$departmentId = Controller::request('departmentId');
$offset = ($page-1)*10;
if ($closed) {
$tickets = $user->withCondition(' TRUE LIMIT 10 OFFSET ?', [$offset])->sharedTicketList->toArray(true);
$countTotal = $user->countShared('ticket');
} else {
$tickets = $user->withCondition(' closed = ? LIMIT 10 OFFSET ?', ['0', $offset])->sharedTicketList->toArray(true);
$countTotal = $user->withCondition(' closed = ?', ['0'])->countShared('ticket');
$condition = 'TRUE';
$bindings = [];
if($departmentId) {
$condition .= ' AND department_id = ?';
$bindings[] = $departmentId;
}
if(!$closed) {
$condition .= ' AND closed = ?';
$bindings[] = '0';
}
$countTotal = $user->withCondition($condition, $bindings)->countShared('ticket');
$condition .= ' LIMIT 10 OFFSET ?';
$bindings[] = $offset;
$tickets = $user->withCondition($condition, $bindings)->sharedTicketList->toArray(true);
Response::respondSuccess([
'tickets' => $tickets,
'page' => $page,