diff --git a/client/app/Components/Features/Session/Estimation/Components/Estimation.tsx b/client/app/Components/Features/Session/Estimation/Components/Estimation.tsx index deb3d32..335b735 100644 --- a/client/app/Components/Features/Session/Estimation/Components/Estimation.tsx +++ b/client/app/Components/Features/Session/Estimation/Components/Estimation.tsx @@ -9,10 +9,7 @@ import { Type } from "../../../../../Types/Type"; import { Center } from "../../../../Globals/Center"; import { useTaskStore } from "../../Tasks/Stores/TaskStore"; import { useEstimationStore, useFinalValueStore } from "../Stores/EstimationStore"; -import {EstimationBar} from "./EstimationBar"; -//import {ITaskresultDto} from "/Interfaces/ITaskResultDto"; -import { requestStatusChange} from "../../Tasks/Components/TaskCard"; - +import { EstimationBar } from "./EstimationBar"; interface EstimationProps { id: String; @@ -25,21 +22,21 @@ export const Estimation: FunctionComponent = ({ id }) => { const columns = new Array(); const [doVote, setDoVote] = useState(true); + // delete line? const [averageExists, setAverageExists] = useState(false); const task = findOpenTask(); + // delete line and function? const closedTask = findClosedTask(); //check if an evaluated task existst const evaluatedTaskExists = findEvaluatedTask(); - let alreadyVoted = false; - - //averageComplexity value of the current evaluated task + // averageComplexity value of the current evaluated task let averageComplexity = findEvaluatedTask()?.complexityAverage; - + let alreadyVoted = false; if (task) { alreadyVoted = userAlreadyVoted("me", task.id); @@ -48,28 +45,21 @@ export const Estimation: FunctionComponent = ({ id }) => { useEffect(() => { if (alreadyVoted === true) { setDoVote(false); - } else { setDoVote(true); - } - - - if(averageComplexity===undefined||averageComplexity===null) { - setAverageExists(false); + + if (averageComplexity === undefined || averageComplexity === null) { + setAverageExists(false); } else { - setAverageExists(true); + setAverageExists(true); } - - }, [alreadyVoted, averageComplexity]); - for (const type in EstimationType) { columns.push(type); - console.log(type); } const defaultPadding = "p-4"; @@ -85,25 +75,24 @@ export const Estimation: FunctionComponent = ({ id }) => { url: url, data: rating, }); - - if (result.status == 201 ) { - // finally remove task from store + + if (result.status == 201) { // setDoVote to render the correct button after giving an estimation setDoVote(false); + // finally remove task from store resetStore(); } - }; - - const submitFinalResultToRestApi = async (taskId: String) => { - let res = { amountOfVotes: 0, complexityAverage: averageComplexity , finalValue: 5 }; //averageComplexity, finalValue + + const submitFinalResultToRestApi = async () => { + // TODO: finalValue + let res = { amountOfVotes: 0, complexityAverage: averageComplexity, finalValue: 5 }; console.log(res); - console.log("STATUSSS" + findEvaluatedTask()?.status); - const rating = { id: findEvaluatedTask().id, status: Status.Ended , result: res }; // fehler wg. namen finalComplVal? - - console.log("rating object :" + JSON.stringify(rating)); + const rating = { id: findEvaluatedTask().id, status: Status.Ended, result: res }; + + console.log("rating object: " + JSON.stringify(rating)); const url = baseUrl + serviceUrl + id + "/task/status"; @@ -113,56 +102,58 @@ export const Estimation: FunctionComponent = ({ id }) => { data: rating, }); - if (result.status == 201 ) { + if (result.status == 201) { resetStore(); - console.log("YOYOOYOYOYOOY"); } } - - - /* - const requestStatusChange = async () => { - const url = baseUrl + serviceUrl + id + "/task/status"; - - - // const result = newStatus === Status.Ended ? finalResult : null; - const result = { amoutOfVotes: 0, complexityAverage: 0, finalValue: 5 } ; - console.log("Final Result: " + result); - - await axios({ - method: "put", - url: url, - data: { id: findEvaluatedTask().id, status: Status.Ended , result: result }, - }); - }; - */ if (tasks == undefined) { return <>; - } + } - const user = "me"; + const user = "me"; + const renderVoting = () => { + if (task) { + if (doVote) { + return ( + renderEstimationForTask(task) + ) + } + else { + return ( + renderVoteAgainButton() + ) + } + } + else if (evaluatedTaskExists) { + return ( + renderComplexityAverageAndFinalValueChoice() + ) + } + else { + return ( + renderWaitForLobbyhostMessage() + ) + } + }; const renderComplexityAverageAndFinalValueChoice = () => ( - -
- <> - Average Complexity for the task   +
+ <> + Average Complexity for the task   '{findEvaluatedTask()?.title}':   - - - {averageComplexity} - - <> - {renderFinalValueChoice(task)} - -
- + + + {averageComplexity} + + <> + {renderFinalValueChoice(task)} + +
); const renderEstimationForTask = (task: ITask) => ( -
<> @@ -186,6 +177,7 @@ export const Estimation: FunctionComponent = ({ id }) => { key={"estimationBar" + type} // @ts-ignore type={EstimationType[type] as EstimationType} + isFinal={false} /> ))} @@ -196,88 +188,56 @@ export const Estimation: FunctionComponent = ({ id }) => { "border-b-blue-700 bg-blue-500 hover:bg-blue-700 text-white font-bold m-2 p-2 rounded " } > - Submit + Submit
- ); - const renderVoting = () => { - - if (task) { - if (doVote) { - return( - renderEstimationForTask(task) - ) - } - else { - return ( - renderVoteAgainButton() - ) - } - } - else if ( evaluatedTaskExists ) { - return ( - renderComplexityAverageAndFinalValueChoice() - ) - } - - else { - return ( - renderWaitForLobbyhostMessage() - ) - } - - }; - const renderFinalValueChoice = (task: ITask) => ( - - -
- <> - - Choose final value for the Complexity - - <> -
-

- Complexity : -

- -
-
- -
- - -
- +
+ <> + + Choose final value for the Complexity + + <> +
+

+ Complexity: +

+ +
+
+ +
+ + +
); const renderVoteAgainButton = () => ( -
-
- -); - -const renderWaitForLobbyhostMessage = () => ( - - - - Please wait for your lobby host to create a task! - - -); - - + + ); + const renderWaitForLobbyhostMessage = () => ( + + Please wait for your lobby host to create a task! + + ); return renderVoting(); - - /* return userHasAlreadyVoted diff --git a/client/app/Components/Features/Session/Estimation/Components/EstimationBar.tsx b/client/app/Components/Features/Session/Estimation/Components/EstimationBar.tsx index 1d05448..c0877b7 100644 --- a/client/app/Components/Features/Session/Estimation/Components/EstimationBar.tsx +++ b/client/app/Components/Features/Session/Estimation/Components/EstimationBar.tsx @@ -3,8 +3,8 @@ import { EstimationValue } from "./EstimationButton"; import { useEstimationStore } from "../Stores/EstimationStore"; import { EstimationType } from "../../../../../Types/EstimationType"; -export const EstimationBar: FunctionComponent<{ type: EstimationType }> = ({ - type, +export const EstimationBar: FunctionComponent<{ type: EstimationType; isFinal: boolean }> = ({ + type, isFinal }) => { const state = useEstimationStore(); @@ -28,6 +28,7 @@ export const EstimationBar: FunctionComponent<{ type: EstimationType }> = ({ gridColumn={validValues.indexOf(item) * 2 + 2} isActive={item == state[type] ? true : false} parentType={type} + isFinal={isFinal} /> ); })} diff --git a/client/app/Components/Features/Session/Estimation/Components/EstimationButton.tsx b/client/app/Components/Features/Session/Estimation/Components/EstimationButton.tsx index 1e3718d..04fff81 100644 --- a/client/app/Components/Features/Session/Estimation/Components/EstimationButton.tsx +++ b/client/app/Components/Features/Session/Estimation/Components/EstimationButton.tsx @@ -3,6 +3,7 @@ import { convertTypeToColorIfActive, EstimationType, } from "../../../../../Types/EstimationType"; +import { useTaskStore } from "../../Tasks/Stores/TaskStore"; import { useEstimationStore } from "../Stores/EstimationStore"; export const EstimationValue: FunctionComponent<{ @@ -10,8 +11,10 @@ export const EstimationValue: FunctionComponent<{ gridColumn: number; isActive: boolean; parentType: EstimationType; -}> = ({ value, gridColumn, isActive, parentType }) => { + isFinal: boolean; +}> = ({ value, gridColumn, isActive, parentType, isFinal }) => { const { setValue } = useEstimationStore(); + const { setFinalComplexity } = useTaskStore(); return ( <> @@ -26,6 +29,10 @@ export const EstimationValue: FunctionComponent<{ background: convertTypeToColorIfActive(parentType, isActive), }} onClick={() => { + if (isFinal) { + console.log("Setting final value: " + value); + setFinalComplexity(value); + } setValue(parentType, value); }} > diff --git a/client/app/Components/Features/Session/Tasks/Components/TaskCard.tsx b/client/app/Components/Features/Session/Tasks/Components/TaskCard.tsx index 61ab070..047733c 100644 --- a/client/app/Components/Features/Session/Tasks/Components/TaskCard.tsx +++ b/client/app/Components/Features/Session/Tasks/Components/TaskCard.tsx @@ -24,14 +24,10 @@ export const TaskCard: FunctionComponent<{ const requestStatusChange = async (newStatus: Status) => { const url = baseUrl + serviceUrl + parentSession + "/task/status"; - // const result = newStatus === Status.Ended ? finalResult : null; - const result = newStatus === Status.Ended ? { amoutOfVotes: 0, complexityAverage: 0, finalValue: 5 } : null; - console.log("Final Result: " + result); - await axios({ method: "put", url: url, - data: { id: id, status: convertStatusToNumber(newStatus), result: result }, + data: { id: id, status: convertStatusToNumber(newStatus) }, }); }; diff --git a/client/app/Components/Features/Session/Tasks/Stores/TaskStore.ts b/client/app/Components/Features/Session/Tasks/Stores/TaskStore.ts index 93ac175..c5101ba 100644 --- a/client/app/Components/Features/Session/Tasks/Stores/TaskStore.ts +++ b/client/app/Components/Features/Session/Tasks/Stores/TaskStore.ts @@ -18,9 +18,10 @@ interface ISessionTaskState { findOpenTask: () => ITask | undefined; upsertEstimationToTask: (estimation: IEstimationDto) => void; setAverageComplexity: (taskResultDto: ITaskResultDto) => void; - findEvaluatedTask: () => ITask|undefined; - findClosedTask: () => ITask|undefined; -} + setFinalComplexity: (finalValue: number) => void; + findEvaluatedTask: () => ITask | undefined; + findClosedTask: () => ITask | undefined; +} export const useTaskStore = create()((set, get) => ({ tasks: [], @@ -114,25 +115,33 @@ export const useTaskStore = create()((set, get) => ({ }, //sets the averageComplexity value for each task setAverageComplexity: (taskResultDto: ITaskResultDto) => { - set( - produce((draft: ISessionTaskState) => - { - draft.tasks.forEach((task) => - { - //taskId ging nicht - if (task.id == taskResultDto.id) { //Task mit complexityAv. erweitern und darin speichern? - task.complexityAverage = taskResultDto.complexityAverage; - task.status=Status.Evaluated; - console.log(task.complexityAverage); - - } - }); - }) - ); + set( + produce((draft: ISessionTaskState) => { + draft.tasks.forEach((task) => { + if (task.id == taskResultDto.id) { + task.complexityAverage = taskResultDto.complexityAverage; + task.status = Status.Evaluated; + } + }); + }) + ); + }, + setFinalComplexity: (finalValue: Number) => { + set( + produce((draft: ISessionTaskState) => { + const evaluatedTask = get().tasks.find((task) => task.status == Status.Evaluated); + draft.tasks.forEach((task) => { + if (task.id == evaluatedTask.id) { + task.finalValue = finalValue; + console.log("finalValue updated: " + task.finalValue); + } + }); + }) + ); }, //returns the task thats currently in evaluation findEvaluatedTask: () => { - return get().tasks.find((task) => task.status == Status.Evaluated); + return get().tasks.find((task) => task.status == Status.Evaluated); }, findClosedTask: () => { return get().tasks.find((task) => task.status == Status.Ended); diff --git a/client/pages/session/[id].tsx b/client/pages/session/[id].tsx index b6ea525..f4a0ae0 100644 --- a/client/pages/session/[id].tsx +++ b/client/pages/session/[id].tsx @@ -78,9 +78,9 @@ export default function Session({ id, data }: any) { } case Type.TaskAverageAdded: { let { payload } = parsed as IMessage; - console.log("TaskResultAdded received."); - - setAverageComplexity(payload); //implement setAverageComplexity + console.log("TaskAverageAdded received."); + + setAverageComplexity(payload); } case Type.TaskFinalValueAdded: { let { payload } = parsed as IMessage; @@ -93,7 +93,7 @@ export default function Session({ id, data }: any) { } }; - const { upsertTask, changeStatusOfTask, deleteTask, upsertEstimationToTask, setAverageComplexity } = + const { upsertTask, changeStatusOfTask, deleteTask, upsertEstimationToTask, setAverageComplexity } = useTaskStore(); const { sendMessage, getWebSocket } = useWebSocket( diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs index 5974928..2f0857c 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs @@ -311,7 +311,6 @@ private string generateInviteToken() } session.Tasks.ToList().Find(item => item.Id == id).Result.FinalValue = statusChange.Result.FinalValue; - Console.WriteLine("StatusChange Final Value is: " + session.Tasks.ToList().Find(item => item.Id == id).Result.FinalValue); } var finished = _sessionRepository.Update(session); @@ -331,7 +330,6 @@ private string generateInviteToken() if (status == Status.Ended) { converted.Find(item => item.Id == id).Result = session.Tasks.ToList().Find(item => item.Id == id).Result; - Console.WriteLine("DTO Final Value is: " + converted.Find(item => item.Id == id).Result.FinalValue); } return (true, converted);