Skip to content

Commit

Permalink
deactivate task event (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot authored Dec 14, 2023
1 parent 8e30645 commit 0f3d680
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
28 changes: 28 additions & 0 deletions epictrack-api/src/api/actions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import datetime
from api.models import Event, EventConfiguration, WorkPhase, db
from api.models.phase_code import PhaseCode, PhaseVisibilityEnum
from api.models.work_calendar_event import WorkCalendarEvent
from api.models.calendar_event import CalendarEvent


def find_configuration(source_event: Event, params) -> int:
Expand Down Expand Up @@ -42,3 +44,29 @@ def find_event_date(source_event: Event) -> datetime:
if source_event.actual_date
else source_event.anticipated_date
)


def deactivate_calendar_events_by_configuration_ids(configuration_ids: [int]):
"""Make the calendar events inactive based on the source event configuration ids"""
if len(configuration_ids) > 0:
events_result = (
db.session.query(Event)
.filter(Event.event_configuration_id.in_(configuration_ids))
.all()
)
source_event_ids = list(map(lambda x: x.id, events_result))
work_calendar_events = (
db.session.query(WorkCalendarEvent)
.filter(WorkCalendarEvent.source_event_id.in_(source_event_ids))
.all()
)
work_calendar_event_ids = list(map(lambda x: x.id, work_calendar_events))
calendar_event_ids = list(
map(lambda x: x.calendar_event_id, work_calendar_events)
)
db.session.query(WorkCalendarEvent).filter(
WorkCalendarEvent.id.in_(work_calendar_event_ids)
).update({WorkCalendarEvent.is_active: False})
db.session.query(CalendarEvent).filter(
CalendarEvent.id.in_(calendar_event_ids)
).update({CalendarEvent.is_active: False})
6 changes: 5 additions & 1 deletion epictrack-api/src/api/actions/set_events_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
from api.models import db
from api.models.event import Event

from .common import find_configuration
from .common import find_configuration, deactivate_calendar_events_by_configuration_ids


class SetEventsStatus(ActionFactory):
"""Set events status action"""

def run(self, source_event, params):
"""Sets all future events to INACTIVE"""
event_configuration_ids = []
if isinstance(params, list):
for event_params in params:
event_configuration = find_configuration(source_event, event_params)
event_configuration_ids.append(event_configuration.id)
db.session.query(Event).filter(
Event.event_configuration_id == event_configuration.id
).update({Event.is_active: event_params.get("is_active")})
# Deactivate all child events (Calendar events at this point) of the main event
deactivate_calendar_events_by_configuration_ids(event_configuration_ids)
29 changes: 29 additions & 0 deletions epictrack-api/src/api/actions/set_phases_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from api.models.event_configuration import EventConfiguration
from api.models.phase_code import PhaseCode, PhaseVisibilityEnum
from api.models.work_phase import WorkPhase
from api.models.work_calendar_event import WorkCalendarEvent
from api.models.calendar_event import CalendarEvent
from api.models.task_event import TaskEvent

from .common import deactivate_calendar_events_by_configuration_ids


class SetPhasesStatus(ActionFactory):
Expand Down Expand Up @@ -48,8 +53,30 @@ def run(self, source_event: Event, params):
db.session.query(WorkPhase).filter(
WorkPhase.id == source_event.event_configuration.work_phase_id
).update({WorkPhase.is_completed: True})
source_event_ids = list(map(lambda x: x.id, events_to_be_updated))
self.deactivate_calendar_events(source_event_ids)
self._deactivate_phases_and_events(work_phase_ids)

def deactivate_calendar_events(self, source_event_ids: [int]) -> None:
"""Deactivate calendar events by source event ids"""
work_calendar_events = db.session.query(WorkCalendarEvent).filter(
WorkCalendarEvent.source_event_id.in_(source_event_ids)
)
work_calendar_events_ids = list(map(lambda x: x.id, work_calendar_events))
calendar_event_ids = list(
map(lambda x: x.calendar_event_id, work_calendar_events)
)
db.session.query(WorkCalendarEvent).filter(
WorkCalendarEvent.id.in_(work_calendar_events_ids)
).update({WorkCalendarEvent.is_active: False})
db.session.query(CalendarEvent).filter(CalendarEvent.id.in_(calendar_event_ids))

def deactivate_task_events(self, work_phase_ids: [int]) -> None:
"""Deactivate task events by work phase ids"""
db.session.query(TaskEvent).filter(
TaskEvent.work_phase_id.in_(work_phase_ids)
).update({TaskEvent.is_active: False})

def get_additional_params(self, source_event: Event, params) -> int:
"""Returns additional parameter"""
work_phase = (
Expand Down Expand Up @@ -81,3 +108,5 @@ def _deactivate_phases_and_events(self, work_phase_ids: [int]) -> None:
db.session.query(Event).filter(
Event.event_configuration_id.in_(event_configuration_ids)
).update({Event.is_active: False})
deactivate_calendar_events_by_configuration_ids(event_configuration_ids)
self.deactivate_task_events(work_phase_ids)
1 change: 1 addition & 0 deletions epictrack-api/src/api/schemas/response/work_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class WorkPhaseAdditionalInfoResponseSchema(Schema):
)
next_milestone = fields.Str(metadata={"description": "Next milestone in the phase"})
milestone_progress = fields.Number(metadata={"description": "Milestone progress"})
is_last_phase = fields.Number(metadata={"description": "Indicate if this the last phase of the work"})
days_left = fields.Number(
metadata={"description": "Number of days left in the phase"}
)
Expand Down
11 changes: 7 additions & 4 deletions epictrack-api/src/api/services/work_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ def find_multiple_works_phases_status(
result_dict = {}
work_ids = list(work_params_dict.keys())

work_phases_dict = cls._query_work_phases(work_ids)
work_phases_dict, total_work_phases = cls._query_work_phases(work_ids)

index = 1
for work_id, work_phase_id in work_params_dict.items():
result_dict[work_id] = cls._find_work_phase_status(
work_id, work_phase_id, work_phases_dict.get(work_id, [])
)
result_dict["is_last_phase"] = index == total_work_phases
index = index + 1

return result_dict

Expand All @@ -126,19 +129,19 @@ def _query_work_phases(cls, work_ids):
.join(PhaseCode, WorkPhase.phase_id == PhaseCode.id)
.filter(
WorkPhase.work_id.in_(work_ids),
WorkPhase.is_active.is_(True),
WorkPhase.is_deleted.is_(False),
WorkPhase.visibility != PhaseVisibilityEnum.HIDDEN.value,
)
.order_by(WorkPhase.sort_order)
.all()
)

total_work_phases = len(work_phases_dict)
work_phases_dict = list(filter(lambda x: x[1].is_active is True, work_phases_dict))
result_dict = defaultdict(list)
for work_id, work_phase in work_phases_dict:
result_dict[work_id].append(work_phase)

return result_dict
return result_dict, total_work_phases

@classmethod
def _find_work_phase_status(cls, work_id, work_phase_id, work_phases):
Expand Down
8 changes: 4 additions & 4 deletions epictrack-web/src/components/workPlan/event/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ const EventForm = ({
}, [selectedConfiguration, event]);

const decisionMakerPositionIds = useMemo<number[]>(() => {
const workPhaseIndex = ctx.workPhases.findIndex(
(p) => p.work_phase.id === ctx.selectedWorkPhase?.work_phase.id
);
// const workPhaseIndex = ctx.workPhases.findIndex(
// (p) => p.work_phase.id === ctx.selectedWorkPhase?.work_phase.id
// );
const lastDecisionIndex = milestoneEvents.findLastIndex(
(p: EventsGridModel) =>
p.event_configuration.event_category_id === EventCategory.DECISION
Expand All @@ -164,7 +164,7 @@ const EventForm = ({
(p: EventsGridModel) => p.id === event?.id
);
if (
workPhaseIndex === ctx.workPhases.length - 1 &&
ctx.selectedWorkPhase?.is_last_phase &&
lastDecisionIndex === currentEventIndex
) {
return [Number(ctx.work?.decision_maker_position_id)];
Expand Down
1 change: 1 addition & 0 deletions epictrack-web/src/models/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface WorkPhaseAdditionalInfo {
next_milestone: string;
milestone_progress: number;
days_left: number;
is_last_phase: boolean;
}

export interface TemplateStatus extends MasterBase {
Expand Down

0 comments on commit 0f3d680

Please sign in to comment.