Skip to content

Commit

Permalink
lined work creation (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot authored May 6, 2024
1 parent b8ec9d7 commit e5389f9
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""create linked_work table
Revision ID: b724615d3fdf
Revises: c64aaa268112
Create Date: 2024-05-05 10:45:18.936600
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'b724615d3fdf'
down_revision = 'c64aaa268112'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('LinkedWorks',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('source_work_id', sa.Integer(), nullable=False),
sa.Column('linked_work_id', sa.Integer(), nullable=False),
sa.Column('source_event_id', sa.Integer(), nullable=False),
sa.Column('created_by', sa.String(length=255), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text("TIMEZONE('utc', CURRENT_TIMESTAMP)"), nullable=True),
sa.Column('updated_by', sa.String(length=255), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('is_active', sa.Boolean(), server_default='t', nullable=False),
sa.Column('is_deleted', sa.Boolean(), server_default='f', nullable=False),
sa.ForeignKeyConstraint(['linked_work_id'], ['works.id'], ),
sa.ForeignKeyConstraint(['source_event_id'], ['events.id'], ),
sa.ForeignKeyConstraint(['source_work_id'], ['works.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('LinkedWorks')
# ### end Alembic commands ###
12 changes: 11 additions & 1 deletion epictrack-api/src/api/actions/create_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pytz import timezone

from api.actions.base import ActionFactory
from api.models.linked_work import LinkedWork


class CreateWork(ActionFactory):
Expand Down Expand Up @@ -31,4 +32,13 @@ def run(self, source_event, params) -> None:
"eao_team_id": source_event.work.eao_team_id,
"decision_by_id": source_event.work.decision_by_id,
}
WorkService.create_work(new_work)
work = WorkService.create_work(new_work)
linked_work = LinkedWork(
**{
"source_work_id": source_event.work_id,
"linked_work_id": work.id,
"source_event_id": source_event.id,
"is_active": True,
}
)
linked_work.flush()
1 change: 1 addition & 0 deletions epictrack-api/src/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@
from .work_status import WorkStatus
from .work_type import WorkType
from .indigenous_consultation_levels import IndigenousConsultationLevel
from .linked_work import LinkedWork
33 changes: 33 additions & 0 deletions epictrack-api/src/api/models/linked_work.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright © 2019 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Model for linked works"""

from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from .base_model import BaseModel


class LinkedWork(BaseModel):
"""Model for linked works"""

__tablename__ = "LinkedWorks"

id = Column(Integer, primary_key=True, autoincrement=True)
source_work_id = Column(ForeignKey("works.id"), nullable=False)
linked_work_id = Column(ForeignKey("works.id"), nullable=False)
source_event_id = Column(ForeignKey("events.id"), nullable=False)

source_work = relationship('Work', foreign_keys=[source_work_id], lazy="select")
linked_work = relationship('Work', foreign_keys=[linked_work_id], lazy="select")
event = relationship('Event', foreign_keys=[source_event_id], lazy="select")
3 changes: 3 additions & 0 deletions epictrack-api/src/api/services/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
from api.utils.roles import Role as KeycloakRole


# pylint: disable=too-many-lines
class WorkService: # pylint: disable=too-many-public-methods
"""Service to manage work related operations."""

Expand Down Expand Up @@ -137,6 +138,7 @@ def _serialize_work(work, work_staffs, works_statuses, work_phase):
"id",
"work_state",
"work_type",
"current_work_phase_id",
"federal_involvement",
"eao_team",
"title",
Expand All @@ -153,6 +155,7 @@ def _serialize_work(work, work_staffs, works_statuses, work_phase):
"next_milestone",
"milestone_progress",
"days_left",
"work_phase.id",
"work_phase.phase.color",
"work_phase.start_date",
"work_phase.end_date",
Expand Down
27 changes: 18 additions & 9 deletions epictrack-web/src/components/myWorkplans/Card/CardBody.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from "react";
import { Grid, Stack } from "@mui/material";
import { Palette } from "../../../styles/theme";
import { ETCaption1, ETCaption2, ETHeading4, ETParagraph } from "../../shared";
Expand Down Expand Up @@ -28,6 +29,14 @@ const CardBody = ({ workplan }: CardProps) => {
workplan.simple_title ? ` - ${workplan.simple_title}` : ""
}`;

const currentWorkPhaseInfo = useMemo(() => {
const currentPhaseInfo = workplan.phase_info.filter(
(p) => p.work_phase.id === workplan.current_work_phase_id
);
return currentPhaseInfo[0];
}, [workplan]);
console.log("CURRENT WORKPHASE INFO", currentWorkPhaseInfo);

return (
<Grid
container
Expand Down Expand Up @@ -64,7 +73,7 @@ const CardBody = ({ workplan }: CardProps) => {
</Grid>

<Grid item container direction="row" spacing={1} sx={{ height: "26px" }}>
<When condition={"phase_info" in workplan}>
<When condition={Boolean(currentWorkPhaseInfo)}>
<Grid item xs={12}>
<Stack
direction={"row"}
Expand All @@ -85,11 +94,11 @@ const CardBody = ({ workplan }: CardProps) => {
textOverflow: "ellipsis",
}}
>
{workplan?.phase_info[0]?.work_phase.name}
{currentWorkPhaseInfo.work_phase.name}
</ETCaption2>
<ClockIcon
fill={
workplan?.phase_info[0]?.days_left > 0
currentWorkPhaseInfo?.days_left > 0
? Palette.neutral.main
: Palette.error.main
}
Expand All @@ -98,7 +107,7 @@ const CardBody = ({ workplan }: CardProps) => {
bold
enableEllipsis
color={
workplan?.phase_info[0]?.days_left > 0
currentWorkPhaseInfo?.days_left > 0
? Palette.neutral.main
: Palette.error.main
}
Expand All @@ -108,16 +117,16 @@ const CardBody = ({ workplan }: CardProps) => {
}}
>
{daysLeft(
workplan?.phase_info[0]?.days_left,
workplan?.phase_info[0]?.total_number_of_days
currentWorkPhaseInfo?.days_left,
currentWorkPhaseInfo?.total_number_of_days
)}
</ETCaption2>
</Stack>
</Grid>
</When>
</Grid>
<Grid container sx={{ height: "64px" }} spacing={1}>
<When condition={Boolean(workplan?.phase_info[0])}>
<When condition={Boolean(currentWorkPhaseInfo)}>
<Grid item container direction="row" spacing={1}>
<Grid
item
Expand All @@ -129,7 +138,7 @@ const CardBody = ({ workplan }: CardProps) => {
>
<ETCaption1 color={Palette.neutral.main}>
{`UPCOMING MILESTONE ${dayjs(new Date())
.add(workplan?.phase_info[0]?.days_left, "days")
.add(currentWorkPhaseInfo?.days_left, "days")
.format(MONTH_DAY_YEAR)
.toUpperCase()}`}
</ETCaption1>
Expand All @@ -146,7 +155,7 @@ const CardBody = ({ workplan }: CardProps) => {
whiteSpace: "nowrap",
}}
>
{workplan.phase_info[0]?.next_milestone}
{currentWorkPhaseInfo?.next_milestone}
</ETParagraph>
</Grid>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions epictrack-web/src/models/workplan.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { WorkPhase } from "./work";
import { WorkType } from "./workType";

export interface WorkPlan {
id: number;
title: string;
simple_title: string;
is_active: boolean;
current_work_phase_id: number;
work_type: WorkType;
work_state: string;

Expand All @@ -19,6 +21,7 @@ export interface WorkPlan {
total_number_of_days: number;
work_phase: {
name: string;
id: number;
phase: {
color: string;
};
Expand Down

0 comments on commit e5389f9

Please sign in to comment.