Skip to content

Commit

Permalink
devonfw-forge#41: store finalValue in TaskStore + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahffm committed Dec 20, 2022
1 parent bf47f34 commit 6d72991
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,21 +22,21 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
const columns = new Array<String>();

const [doVote, setDoVote] = useState<boolean>(true);
// delete line?
const [averageExists, setAverageExists] = useState<boolean>(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);
Expand All @@ -48,28 +45,21 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ 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";
Expand All @@ -85,25 +75,24 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ 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";

Expand All @@ -113,56 +102,58 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ 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 = () => (

<div>
<>
Average Complexity for the task &nbsp;
<div>
<>
Average Complexity for the task &nbsp;
&apos;{findEvaluatedTask()?.title}&apos;: &nbsp;
</>
<strong>
{averageComplexity}
</strong>
<>
{renderFinalValueChoice(task)}
</>
</div>

</>
<strong>
{averageComplexity}
</strong>
<>
{renderFinalValueChoice(task)}
</>
</div>
);

const renderEstimationForTask = (task: ITask) => (

<Center>
<>
<strong className={defaultPadding}>
Expand All @@ -186,6 +177,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
key={"estimationBar" + type}
// @ts-ignore
type={EstimationType[type] as EstimationType}
isFinal={false}
/>
</div>
))}
Expand All @@ -196,88 +188,56 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
"border-b-blue-700 bg-blue-500 hover:bg-blue-700 text-white font-bold m-2 p-2 rounded "
}
>
Submit
Submit
</button>
</div>
</>
</>
</Center>

);

const renderVoting = () => {

if (task) {
if (doVote) {
return(
renderEstimationForTask(task)
)
}
else {
return (
renderVoteAgainButton()
)
}
}
else if ( evaluatedTaskExists ) {
return (
renderComplexityAverageAndFinalValueChoice()
)
}

else {
return (
renderWaitForLobbyhostMessage()
)
}

};

const renderFinalValueChoice = (task: ITask) => (


<Center>
<>
<strong className={defaultPadding}>
Choose final value for the Complexity
</strong>
<>
<div
key={"estimationColumn" + "Complexity"}
className={
"flex flex-row justify-between items-center " + defaultPadding
}
style={{
background:"#f1f4f6",
}}
>
<p style={{ color: "#404b56" }}>
Complexity :
</p>
<EstimationBar
key={"estimationBar" + "Complexity"}
// @ts-ignore
type={EstimationType["Complexity"] as EstimationType}
/>
</div>
<div className="flex justify-center">
<button
onClick={() => submitFinalResultToRestApi(task)} //submitfinalresulto...
className={
"border-b-blue-700 bg-blue-500 hover:bg-blue-700 text-white font-bold m-2 p-2 rounded "
}
>
Submit
</button>
</div>
</>
</>
</Center>

<Center>
<>
<strong className={defaultPadding}>
Choose final value for the Complexity
</strong>
<>
<div
key={"estimationColumn" + "Complexity"}
className={
"flex flex-row justify-between items-center " + defaultPadding
}
style={{
background: "#f1f4f6",
}}
>
<p style={{ color: "#404b56" }}>
Complexity:
</p>
<EstimationBar
key={"estimationBar" + "Complexity"}
// @ts-ignore
type={EstimationType["Complexity"] as EstimationType}
isFinal={true}
/>
</div>
<div className="flex justify-center">
<button
onClick={() => submitFinalResultToRestApi()}
className={
"border-b-blue-700 bg-blue-500 hover:bg-blue-700 text-white font-bold m-2 p-2 rounded "
}
>
Submit
</button>
</div>
</>
</>
</Center>
);

const renderVoteAgainButton = () => (

<div className="flex justify-center">
<button
onClick={() => {
Expand All @@ -287,28 +247,18 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
"border-b-blue-700 bg-blue-500 hover:bg-blue-700 text-white font-bold m-2 p-2 rounded "
}
>

I want to vote again
I want to vote again
</button>
</div>

);

const renderWaitForLobbyhostMessage = () => (

<strong className={defaultPadding}>

Please wait for your lobby host to create a task!
</strong>

);


</div>
);

const renderWaitForLobbyhostMessage = () => (
<strong className={defaultPadding}>
Please wait for your lobby host to create a task!
</strong>
);

return renderVoting();



/*
return userHasAlreadyVoted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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}
/>
);
})}
Expand Down
Loading

0 comments on commit 6d72991

Please sign in to comment.