Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/hotosm/fmtm into dev…
Browse files Browse the repository at this point in the history
…elopment
  • Loading branch information
spwoodcock committed Dec 7, 2023
2 parents d521980 + 36221cc commit fab0202
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
17 changes: 14 additions & 3 deletions src/backend/app/tasks/tasks_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from geojson_pydantic import Feature
from loguru import logger as log
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo
from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, validator
from pydantic.functional_validators import field_validator

from app.db.postgis_utils import geometry_to_geojson, get_centroid
Expand Down Expand Up @@ -70,6 +70,17 @@ class TaskBase(BaseModel):
locked_by_username: Optional[str] = None
task_history: Optional[List[TaskHistoryBase]] = None

@validator("task_status", pre=False, always=True)
def get_enum_name(cls, value, values):
if isinstance(value, int):
try:
return TaskStatus(value).name
except ValueError as e:
raise ValueError(
f"Invalid integer value for task_status: {value}"
) from e
return value

@field_validator("outline_geojson", mode="before")
@classmethod
def get_geojson_from_outline(cls, v: Any, info: ValidationInfo) -> str:
Expand Down Expand Up @@ -103,15 +114,15 @@ def get_centroid_from_outline(cls, v: Any, info: ValidationInfo) -> str:
def get_lock_uid(cls, v: int, info: ValidationInfo) -> str:
"""Get lock uid from lock_holder details."""
if lock_holder := info.data.get("lock_holder"):
return lock_holder.get("id")
return lock_holder.id
return None

@field_validator("locked_by_username", mode="before")
@classmethod
def get_lock_username(cls, v: str, info: ValidationInfo) -> str:
"""Get lock username from lock_holder details."""
if lock_holder := info.data.get("lock_holder"):
return lock_holder.get("username")
return lock_holder.username
return None


Expand Down
10 changes: 5 additions & 5 deletions src/frontend/src/components/DialogTaskActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Dialog({ taskId, feature, map, view }) {
const token = CoreModules.useAppSelector((state) => state.login.loginToken);
const loading = CoreModules.useAppSelector((state) => state.common.loading);
const [list_of_task_status, set_list_of_task_status] = useState([]);
const [task_status, set_task_status] = useState(task_priority_str['READY']);
const [task_status, set_task_status] = useState('READY');

const geojsonStyles = MapStyles();
const dispatch = CoreModules.useAppDispatch();
Expand All @@ -34,11 +34,11 @@ export default function Dialog({ taskId, feature, map, view }) {
})[0],
};
const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex(
(data) => data.label == task_priority_str[currentStatus.task_status],
(data) => data.label == currentStatus.task_status,
);
const tasksStatus =
feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : '';
set_task_status(task_priority_str[tasksStatus]);
set_task_status(tasksStatus);
const tasksStatusList =
feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['action'] : [];

Expand All @@ -53,7 +53,7 @@ export default function Dialog({ taskId, feature, map, view }) {
const handleOnClick = (event) => {
const status = task_priority_str[event.target.id];
const body = token != null ? { ...token } : {};
const geoStyle = geojsonStyles[status];
const geoStyle = geojsonStyles[event.target.id];
if (event.target.id != undefined) {
if (body.hasOwnProperty('id')) {
dispatch(
Expand Down Expand Up @@ -103,7 +103,7 @@ export default function Dialog({ taskId, feature, map, view }) {
<CoreModules.Stack direction={'row'} pl={1}>
<CoreModules.Typography variant="h3">
{/* {`STATUS : ${task_status?.toString()?.replaceAll('_', ' ')}`} */}
{`STATUS : ${task_priority_str[task_status]}`}
{`STATUS : ${task_status}`}
</CoreModules.Typography>
</CoreModules.Stack>
<CoreModules.Link
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const btnStyle = (btnType, className) => {
case 'other':
return `fmtm-py-1 fmtm-px-5 fmtm-bg-red-500 fmtm-text-white fmtm-rounded-lg hover:fmtm-bg-red-600`;
case 'disabled':
return `fmtm-py-1 fmtm-px-5 fmtm-text-white fmtm-rounded-lg fmtm-bg-gray-400 fmtm-cursor-not-allowed`;
return `fmtm-py-1 fmtm-px-4 fmtm-text-white fmtm-rounded-lg fmtm-bg-gray-400 fmtm-cursor-not-allowed`;

default:
return 'fmtm-primary';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ const SplitTasks = ({ flag, geojsonFile, setGeojsonFile, customLineUpload, custo
onClick={generateTaskBasedOnSelection}
className=""
icon={<AssetModules.SettingsIcon className="fmtm-text-white" />}
disabled={formValues?.average_buildings_per_task ? false : true}
/>
{/* <Button
btnText="Stop generating"
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/src/components/home/ExploreProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ export default function ExploreProjectCard({ data }) {
>
{data.description}
</p>

<div className="fmtm-flex fmtm-items-start fmtm-mt-[1.63rem] fmtm-gap-2">
<AssetModules.LocationOn color="error" style={cardInnerStyles.location.icon} />
<p className="fmtm-capitalize fmtm-line-clamp-1 fmtm-text-[#7A7676]" title={data.description}>
{data.description}
<p className="fmtm-capitalize fmtm-line-clamp-1 fmtm-text-[#7A7676]" title={data?.location_str}>
{data?.location_str}
</p>
</div>
</CoreModules.Stack>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/utilfunctions/getTaskStatusStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const strokeColor = 'rgb(0,0,0,0.5)';

const getTaskStatusStyle = (feature, mapTheme) => {
let id = feature.getId().toString().replace('_', ',');
const status = task_priority_str[id.split(',')[1]];
const status = id.split(',')[1];
const lockedPolygonStyle = createPolygonStyle(mapTheme.palette.mapFeatureColors.locked_for_mapping_rgb, strokeColor);
const lockedValidationStyle = createPolygonStyle(
mapTheme.palette.mapFeatureColors.locked_for_validation_rgb,
Expand Down

0 comments on commit fab0202

Please sign in to comment.