Moves filtering functionality to backend and adapts frontend

This commit is contained in:
Maxi Redigonda 2018-10-17 11:26:11 -03:00
parent a2d3908c4d
commit 73b92bba86
8 changed files with 18 additions and 11 deletions

Binary file not shown.

View File

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

View File

@ -44,17 +44,11 @@ class AdminPanelMyTickets extends React.Component {
); );
} }
filterOpenedTickets(tickets){
return _.filter(tickets, (ticket) => {
return !ticket.closed
});
}
getProps() { getProps() {
return { return {
userId: this.props.userId, userId: this.props.userId,
departments: this.props.departments, departments: this.props.departments,
tickets: this.state.closedTicketsShown ? this.props.tickets : this.filterOpenedTickets(this.props.tickets), tickets: this.props.tickets,
type: 'secondary', type: 'secondary',
loading: this.props.loading, loading: this.props.loading,
ticketPath: '/admin/panel/tickets/view-ticket/', ticketPath: '/admin/panel/tickets/view-ticket/',
@ -68,6 +62,8 @@ class AdminPanelMyTickets extends React.Component {
return { return {
closedTicketsShown: !state.closedTicketsShown closedTicketsShown: !state.closedTicketsShown
}; };
}, () => {
this.props.dispatch(AdminDataAction.retrieveMyTickets(this.state.closedTicketsShown * 1));
}); });
} }

Binary file not shown.

Binary file not shown.

View File

@ -13,6 +13,8 @@ use Respect\Validation\Validator as DataValidator;
* *
* @apiPermission staff1 * @apiPermission staff1
* *
* @apiParam {bool} closed Include closed tickets in the response.
*
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
* *
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data Array of tickets assigned to the staff * @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data Array of tickets assigned to the staff
@ -32,6 +34,11 @@ class GetTicketStaffController extends Controller {
public function handler() { public function handler() {
$user = Controller::getLoggedUser(); $user = Controller::getLoggedUser();
Response::respondSuccess($user->sharedTicketList->toArray()); $closed = Controller::request('closed');
if ($closed) {
Response::respondSuccess($user->sharedTicketList->toArray());
} else {
Response::respondSuccess($user->withCondition('closed = ?', ['0'])->sharedTicketList->toArray());
}
} }
} }

View File

@ -150,6 +150,10 @@ abstract class DataStore {
} }
} }
public function withCondition($condition, $values) {
return new static($this->_bean->withCondition($condition, $values));
}
private function updateBeanProp($key, $value) { private function updateBeanProp($key, $value) {
if ($value instanceof DataStoreList) { if ($value instanceof DataStoreList) {
$this->_bean[$key] = $value->toBeanList(); $this->_bean[$key] = $value->toBeanList();