Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

act sections in extension input #1108

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions epictrack-api/src/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from .event_configuration import API as EVENT_CONFIGURATION_API
from .responsibility import API as RESPONSIBILITY_API
from .outcome_configuration import API as OUTCOME_CONFIGURATION_API
from .act_section import API as ACT_SECTION_API


__all__ = ("API_BLUEPRINT", "OPS_BLUEPRINT")
Expand Down Expand Up @@ -103,3 +104,4 @@
API.add_namespace(EVENT_CONFIGURATION_API, path="/event-configurations")
API.add_namespace(RESPONSIBILITY_API, path="/responsibilities")
API.add_namespace(OUTCOME_CONFIGURATION_API, path="/outcome-configurations")
API.add_namespace(ACT_SECTION_API, path="/act-sections")
45 changes: 45 additions & 0 deletions epictrack-api/src/api/resources/act_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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.
"""Resource for Act Section endpoints."""
from http import HTTPStatus

from flask import jsonify, request
from flask_restx import Namespace, Resource, cors

from api.services import ActSectionService
from api.utils import auth, constants, profiletime
from api.utils.caching import AppCache
from api.utils.util import cors_preflight

from api.schemas import request as req
from api.schemas import response as res

API = Namespace("act-sections", description="ActSections")


@cors_preflight("GET")
@API.route("", methods=["GET", "OPTIONS"])
class ActSections(Resource):
"""Endpoint resource to return sub types based on type id"""

@staticmethod
@cors.crossdomain(origin="*")
@auth.require
@profiletime
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT, query_string=True)
def get():
"""Return all sub_types based on type_id."""
args = req.ActSectionQueryParameterSchema().load(request.args)
act_sections = ActSectionService.find_by_ea_act(args)
return jsonify(res.ActSectionResponseSchema(many=True).dump(act_sections)), HTTPStatus.OK
1 change: 1 addition & 0 deletions epictrack-api/src/api/schemas/request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
WorkBodyParameterSchema, WorkExistenceQueryParamSchema, WorkFirstNationImportBodyParamSchema,
WorkFirstNationNotesBodySchema, WorkIdPathParameterSchema, WorkIdPhaseIdPathParameterSchema,
WorkPlanDownloadQueryParamSchema, WorkTypeIdQueryParamSchema)
from .act_section_request import ActSectionQueryParameterSchema
26 changes: 26 additions & 0 deletions epictrack-api/src/api/schemas/request/act_section_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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.
"""Act Sections resource's input validations"""
from marshmallow import fields, validate

from .base import BasicRequestQueryParameterSchema


class ActSectionQueryParameterSchema(BasicRequestQueryParameterSchema):
"""Type id path parameter schema"""

ea_act_id = fields.Int(
metadata={"description": "The id of the EA Act"},
validate=validate.Range(min=1)
)
1 change: 1 addition & 0 deletions epictrack-api/src/api/schemas/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
WorkPhaseResponseSchema, WorkPhaseSkeletonResponseSchema, WorkPhaseTemplateAvailableResponse,
WorkResourceResponseSchema, WorkResponseSchema, WorkStaffRoleReponseSchema)
from .outcome_configuration_response import OutcomeConfigurationResponseSchema
from .act_section_response import ActSectionResponseSchema
17 changes: 17 additions & 0 deletions epictrack-api/src/api/schemas/response/act_section_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""ActSection model schema"""
from marshmallow import EXCLUDE

from api.models import ActSection
from api.schemas.base import AutoSchemaBase


class ActSectionResponseSchema(
AutoSchemaBase
): # pylint: disable=too-many-ancestors,too-few-public-methods
"""Type model schema class"""

class Meta(AutoSchemaBase.Meta):
"""Meta information"""

model = ActSection
unknown = EXCLUDE
1 change: 1 addition & 0 deletions epictrack-api/src/api/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
from .work import WorkService
from .work_phase import WorkPhaseService
from .action_template import ActionTemplateService
from .act_section import ActSectionService
28 changes: 28 additions & 0 deletions epictrack-api/src/api/services/act_section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.
"""Service to manage ActSection."""
from flask import current_app

from api.models import ActSection


class ActSectionService: # pylint:disable=too-few-public-methods
"""Service to manage sub type related operations"""

@classmethod
def find_by_ea_act(cls, args: dict):
"""Find sub types by type_id"""
current_app.logger.debug(f"find act sections by params {args}")
act_sections = ActSection.find_by_params(args)
return act_sections
4 changes: 2 additions & 2 deletions epictrack-api/src/api/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import wraps
from http import HTTPStatus

from flask import current_app, g, request
from flask import g, request
from flask_jwt_oidc import JwtManager

from ..exceptions import BusinessError
Expand All @@ -22,7 +22,7 @@ def require(cls, f):
@wraps(f)
def decorated(*args, **kwargs):
g.authorization_header = request.headers.get("Authorization", None)
current_app.logger.info(f"AUTH HEADER {g.authorization_header}")
# current_app.logger.info(f"AUTH HEADER {g.authorization_header}")
g.token_info = g.jwt_oidc_token_info

return f(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import ControlledSelectV2 from "../../../shared/controlledInputComponents/Contro
import { Controller, useFormContext } from "react-hook-form";
import { ListType } from "../../../../models/code";
import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
import { DATE_FORMAT } from "../../../../constants/application-constant";
import {
COMMON_ERROR_MESSAGE,
DATE_FORMAT,
} from "../../../../constants/application-constant";
import { WorkplanContext } from "../../WorkPlanContext";
import { dateUtils } from "../../../../utils";
import { SyntheticEvent } from "react-draft-wysiwyg";
import actSectionService from "../../../../services/actSectionService/actSectionService";
import { showNotification } from "../../../shared/notificationProvider";

interface ExtensionInputProps {
isFormFieldsLocked: boolean;
Expand Down Expand Up @@ -49,9 +54,24 @@ const ExtensionInput = (props: ExtensionInputProps) => {
"phase_end_date",
Moment(ctx.selectedWorkPhase?.end_date).add(numberOfDays, "days").format()
);
getActSections();
}, []);
const numberOfDaysRef = React.useRef();
const endDateRef = React.useRef();
const getActSections = async () => {
try {
const result = await actSectionService.getActSectionsByEaAct(
ctx.work?.ea_act_id
);
if (result.status === 200) {
setActSections(result.data as ListType[]);
}
} catch (e) {
showNotification(COMMON_ERROR_MESSAGE, {
type: "error",
});
}
};
const onDayChange = (event: SyntheticEvent) => {
if (endDateRef.current as any) {
setValue(
Expand Down Expand Up @@ -140,8 +160,8 @@ const ExtensionInput = (props: ExtensionInputProps) => {
disabled={props.isFormFieldsLocked}
helperText={errors?.act_section_id?.message?.toString()}
options={actSections || []}
getOptionValue={(o: ListType) => o.id.toString()}
getOptionLabel={(o: ListType) => o.name}
getOptionValue={(o: ListType) => o?.id.toString()}
getOptionLabel={(o: ListType) => o?.name}
{...register("act_section_id")}
></ControlledSelectV2>
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion epictrack-web/src/components/workPlan/task/TaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const TaskForm = ({
start_date: Moment(data.start_date).format(),
number_of_days:
data.number_of_days.toString() === "" ? 0 : data.number_of_days,
notes: notes,
notes: notes ?? "",
};

await saveTask(dataToSave);
Expand Down
3 changes: 3 additions & 0 deletions epictrack-web/src/constants/api-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ const Endpoints = {
OutcomeConfigurations: {
CONFIGURATIONS: "/outcome-configurations",
},
ActSections: {
ACT_SECTIONS: "/act-sections",
},
};
export default Endpoints;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Endpoints from "../../constants/api-endpoint";
import http from "../../apiManager/http-request-handler";

class ActSectionService {
async getActSectionsByEaAct(eaActId?: number) {
return await http.GetRequest(
Endpoints.ActSections.ACT_SECTIONS + `?ea_act_id=${eaActId}`
);
}
}

export default new ActSectionService();
Loading