Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/dinesh-aot/EPIC-FLOW int…
Browse files Browse the repository at this point in the history
…o 1390
  • Loading branch information
dinesh-aot committed Dec 14, 2023
2 parents 84ae0d0 + 25a2f48 commit 4f208d5
Show file tree
Hide file tree
Showing 30 changed files with 454 additions and 223 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)
6 changes: 6 additions & 0 deletions epictrack-api/src/api/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class Project(BaseModelVersioned):
proponent = relationship("Proponent", foreign_keys=[proponent_id], lazy="select")
region_env = relationship("Region", foreign_keys=[region_id_env], lazy="select")
region_flnro = relationship("Region", foreign_keys=[region_id_flnro], lazy="select")
works = relationship('Work', lazy='dynamic')

@classmethod
def find_all_with_works(cls):
"""Return all projects with works."""
return cls.query.filter(cls.works.any()).filter(cls.is_deleted.is_(False)).all()

@classmethod
def check_existence(cls, name, project_id=None):
Expand Down
3 changes: 2 additions & 1 deletion epictrack-api/src/api/models/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ def _filter_by_staff_id(cls, query, staff_id):
@classmethod
def _filter_by_search_text(cls, query, search_text):
if search_text:
query = query.filter(Work.title.ilike(f'%{search_text}%'))
subquery = exists().where(and_(Work.project_id == Project.id, Project.name == search_text))
query = query.filter(subquery)
return query

@classmethod
Expand Down
7 changes: 6 additions & 1 deletion epictrack-api/src/api/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ class Projects(Resource):
@profiletime
def get():
"""Return all projects."""
projects = ProjectService.find_all()
with_works = request.args.get(
'with_works',
default=False,
type=lambda v: v.lower() == 'true'
)
projects = ProjectService.find_all(with_works)
return_type = request.args.get("return_type", None)
if return_type == "list_type":
schema = res.ListTypeResponseSchema(many=True)
Expand Down
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
9 changes: 8 additions & 1 deletion epictrack-api/src/api/services/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ def find(cls, project_id):
return project

@classmethod
def find_all(cls):
def find_all(cls, with_works=False):
"""Find all projects"""
if with_works:
return Project.find_all_with_works()
return Project.find_all(default_filters=False)

@classmethod
def find_all_with_works(cls):
"""Find all projects"""
return Project.find_all_with_works()

@classmethod
def create_project(cls, payload: dict):
"""Create a new project."""
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
96 changes: 52 additions & 44 deletions epictrack-web/src/components/myWorkplans/Card/CardBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,31 @@ const CardBody = ({ workplan }: CardProps) => {
</ETCaption1>
</Grid>
</Grid>
<Grid item container direction="row" spacing={1}>
<Grid item container direction="row" spacing={1} sx={{ height: "26px" }}>
<When condition={"phase_info" in workplan}>
<Grid item xs={6}>
<Grid item xs={12}>
<Stack
direction={"row"}
spacing={1}
alignItems={"center"}
sx={{ overflow: "clip" }}
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
<DotIcon fill={phase_color} />
<ETCaption2
bold
enableEllipsis
color={phase_color}
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{workplan?.phase_info?.work_phase.name}
</ETCaption2>
</Stack>
</Grid>
<Grid item xs={6}>
<Stack
direction={"row"}
spacing={1}
alignItems={"center"}
sx={{ overflow: "clip" }}
>
<ClockIcon
fill={
workplan?.phase_info?.days_left > 0
Expand All @@ -105,6 +100,7 @@ const CardBody = ({ workplan }: CardProps) => {
/>
<ETCaption2
bold
enableEllipsis
color={
workplan?.phase_info?.days_left > 0
? Palette.neutral.main
Expand All @@ -113,7 +109,6 @@ const CardBody = ({ workplan }: CardProps) => {
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{daysLeft()}
Expand All @@ -122,40 +117,42 @@ const CardBody = ({ workplan }: CardProps) => {
</Grid>
</When>
</Grid>
<When condition={Boolean(workplan?.phase_info)}>
<Grid item container direction="row" spacing={1}>
<Grid
item
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
<ETCaption1 color={Palette.neutral.main}>
{`UPCOMING MILESTONE ${dayjs(new Date())
.add(workplan?.phase_info?.days_left, "days")
.format(MONTH_DAY_YEAR)
.toUpperCase()}`}
</ETCaption1>
</Grid>
</Grid>
<Grid item container direction="row" spacing={1}>
<Grid item sx={{ overflow: "hidden" }}>
<ETParagraph
bold
color={Palette.neutral.dark}
<Grid container sx={{ height: "64px" }} spacing={1}>
<When condition={Boolean(workplan?.phase_info)}>
<Grid item container direction="row" spacing={1}>
<Grid
item
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{workplan.phase_info?.next_milestone}
</ETParagraph>
<ETCaption1 color={Palette.neutral.main}>
{`UPCOMING MILESTONE ${dayjs(new Date())
.add(workplan?.phase_info?.days_left, "days")
.format(MONTH_DAY_YEAR)
.toUpperCase()}`}
</ETCaption1>
</Grid>
</Grid>
</Grid>
</When>
<Grid item container direction="row" spacing={1}>
<Grid item sx={{ overflow: "hidden" }}>
<ETParagraph
bold
color={Palette.neutral.dark}
sx={{
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{workplan.phase_info?.next_milestone}
</ETParagraph>
</Grid>
</Grid>
</When>
</Grid>

<Grid item container direction="row" spacing={1}>
<Grid item>
Expand All @@ -172,13 +169,24 @@ const CardBody = ({ workplan }: CardProps) => {
{statusOutOfDate && <IndicatorSmallIcon />}
</Grid>
</Grid>
<Grid item sx={{ height: "49px", width: "100%" }}>
<ETParagraph sx={{ height: "49px" }} enableEllipsis>
<Grid item>
<ETParagraph
sx={{
height: "50px",
overflow: "hidden",
textOverflow: "ellipsis",
display: "-webkit-box",
"-webkit-line-clamp": "2",
"-webkit-box-orient": "vertical",
}}
>
{workplan.status_info.description}
</ETParagraph>
</Grid>
<Grid item>
<ETCaption1 color={Palette.neutral.main}>IAAC INVOLVEMENT</ETCaption1>
<ETCaption1 color={Palette.neutral.main}>
FEDERAL INVOLVEMENT
</ETCaption1>
</Grid>
<Grid item>
<ETParagraph color={Palette.neutral.dark}>
Expand Down
Loading

0 comments on commit 4f208d5

Please sign in to comment.