Search in sources :

Example 1 with Timer

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);
}
Also used : Timer(com.axelor.apps.base.db.Timer)

Example 2 with 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;
}
Also used : Ticket(com.axelor.apps.helpdesk.db.Ticket) User(com.axelor.auth.db.User) Timer(com.axelor.apps.base.db.Timer)

Example 3 with Timer

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);
    }
}
Also used : Ticket(com.axelor.apps.helpdesk.db.Ticket) Timer(com.axelor.apps.base.db.Timer) TimerTicketService(com.axelor.apps.helpdesk.service.TimerTicketService)

Example 4 with Timer

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);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Timer(com.axelor.apps.base.db.Timer) Transactional(com.google.inject.persist.Transactional)

Example 5 with 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);
    }
}
Also used : TimerProjectTaskService(com.axelor.apps.project.service.TimerProjectTaskService) Timer(com.axelor.apps.base.db.Timer) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Aggregations

Timer (com.axelor.apps.base.db.Timer)7 Ticket (com.axelor.apps.helpdesk.db.Ticket)2 ProjectTask (com.axelor.apps.project.db.ProjectTask)2 User (com.axelor.auth.db.User)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 TimerHistory (com.axelor.apps.base.db.TimerHistory)1 TimerHistoryRepository (com.axelor.apps.base.db.repo.TimerHistoryRepository)1 TimerRepository (com.axelor.apps.base.db.repo.TimerRepository)1 AbstractTimerService (com.axelor.apps.base.service.timer.AbstractTimerService)1 UserService (com.axelor.apps.base.service.user.UserService)1 TimerTicketService (com.axelor.apps.helpdesk.service.TimerTicketService)1 TimerProjectTaskService (com.axelor.apps.project.service.TimerProjectTaskService)1 Model (com.axelor.db.Model)1 Inject (com.google.inject.Inject)1 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1