use of com.axelor.apps.base.db.Timer in project axelor-open-suite by axelor.
the class TimerTicketServiceImpl method cancel.
@Override
public void cancel(Ticket task) throws AxelorException {
Timer timer = find(task);
cancel(timer);
}
use of com.axelor.apps.base.db.Timer in project axelor-open-suite by axelor.
the class TimerTicketServiceImpl method find.
@Override
public Timer find(Model model) throws AxelorException {
User user = userService.getUser();
Ticket ticket = (Ticket) model;
List<Timer> timerList = ticket.getTimerList();
if (timerList != null && !timerList.isEmpty()) {
return timerList.stream().filter(t -> t.getAssignedToUser() == user).findFirst().orElse(null);
}
return null;
}
use of com.axelor.apps.base.db.Timer in project axelor-open-suite by axelor.
the class TicketController method manageTimerButtons.
public void manageTimerButtons(ActionRequest request, ActionResponse response) {
try {
Ticket ticket = request.getContext().asType(Ticket.class);
TimerTicketService service = Beans.get(TimerTicketService.class);
Timer timer = service.find(ticket);
boolean hideStart = false;
boolean hideCancel = true;
if (timer != null) {
hideStart = timer.getStatusSelect() == TimerRepository.TIMER_STARTED;
hideCancel = timer.getTimerHistoryList().isEmpty() || timer.getStatusSelect().equals(TimerRepository.TIMER_STOPPED);
}
response.setAttr("startTimerBtn", HIDDEN_ATTR, hideStart);
response.setAttr("stopTimerBtn", HIDDEN_ATTR, !hideStart);
response.setAttr("cancelTimerBtn", HIDDEN_ATTR, hideCancel);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.Timer in project axelor-open-suite by axelor.
the class AbstractTimerService method tryStartOrCreate.
@Transactional(rollbackOn = { Exception.class })
protected Timer tryStartOrCreate(Timer timer) throws AxelorException {
if (timer == null) {
timer = new Timer();
timer.setAssignedToUser(userService.getUser());
} else if (timer.getStatusSelect().equals(TimerRepository.TIMER_STARTED)) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.TIMER_IS_NOT_STOPPED));
}
timer.setStatusSelect(TimerRepository.TIMER_STARTED);
return timerRepository.save(timer);
}
use of com.axelor.apps.base.db.Timer in project axelor-open-suite by axelor.
the class ProjectTaskController method manageTimerButtons.
public void manageTimerButtons(ActionRequest request, ActionResponse response) {
try {
ProjectTask task = request.getContext().asType(ProjectTask.class);
TimerProjectTaskService service = Beans.get(TimerProjectTaskService.class);
if (task.getId() == null) {
return;
}
Timer timer = service.find(task);
boolean hideStart = false;
boolean hideCancel = true;
if (timer != null) {
hideStart = timer.getStatusSelect() == TimerRepository.TIMER_STARTED;
hideCancel = timer.getTimerHistoryList().isEmpty();
}
response.setAttr("startTimerBtn", HIDDEN_ATTR, hideStart);
response.setAttr("stopTimerBtn", HIDDEN_ATTR, !hideStart);
response.setAttr("cancelTimerBtn", HIDDEN_ATTR, hideCancel);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations