Skip to content

Commit

Permalink
devonfw-forge#41: fixed elements shown to wrong user + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahffm committed Dec 27, 2022
1 parent df2905e commit a549aea
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FunctionComponent, useEffect, useState } from "react";
import { baseUrl, serviceUrl } from "../../../../../Constants/url";
import { ITask } from "../../../../../Interfaces/ITask";
import { EstimationType } from "../../../../../Types/EstimationType";
import { Role } from "../../../../../Types/Role";
import { Status } from "../../../../../Types/Status";
import { Center } from "../../../../Globals/Center";
import { useAuthStore } from "../../../Authentication/Stores/AuthStore";
Expand All @@ -17,17 +18,14 @@ interface EstimationProps {
export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
const { findOpenTask, tasks, userAlreadyVoted, findEvaluatedTask } = useTaskStore();
const { complexity, effort, risk, resetStore } = useEstimationStore();
const { userId, token } = useAuthStore();
const { userId, token, role } = useAuthStore();

const columns = new Array<String>();

const [doVote, setDoVote] = useState<boolean>(true);

const task = findOpenTask();

const evaluatedTaskExists = findEvaluatedTask();

// averageComplexity value of the current evaluated task
let averageComplexity = findEvaluatedTask()?.result?.complexityAverage;

let alreadyVoted = false;
Expand Down Expand Up @@ -148,9 +146,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
<strong>
{averageComplexity}
</strong>
<>
{renderFinalValueChoice(task)}
</>
{role === Role.Admin ? renderFinalValueChoice(task) : <></>}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ export const TaskCard: FunctionComponent<{
Evaluate!
</button>
);
case Status.Evaluated:
return (
<button
className={
"py-2 px-4 rounded " + convertStatusToColor(status)
}
onClick={() => requestStatusChange(Status.Ended)}
>
Close!
</button>
);
case Status.Suspended:
return (
<button
Expand All @@ -94,9 +83,6 @@ export const TaskCard: FunctionComponent<{
case Status.Ended:
return (
<>
<>
{renderFinalValueOnClosedTasks()}
</>
<button
className={
"bg-orange-500 p-2 mb-2 bg-warning font-bold p-1 mt-2 rounded"
Expand Down Expand Up @@ -124,40 +110,23 @@ export const TaskCard: FunctionComponent<{
};

const colorStyle = {
color: '#253EEA',
color: '#0DA65A',
fontWeight: 'bold',
};

/*
function UseUpdateFinalValue() {
const [value, setValue] = useState(0);
return () => setValue(value => value + 1)
}
const forceUpdate = UseUpdateFinalValue()
*/

const renderFinalValueOnClosedTasks = () => (
<>
<>
{renderCheckmark()}
</>
<div style={colorStyle}>
Rated: {finalValue}
</div>
</>
);

const renderCheckmark = () => {
return (
<div className="inline-flex flex-row space-x-2">
<Checkbox
key={"checkbox"}
size={"25px"}
backgroundColor={"#0DA65A"}
accentColor={" #FFFFFF"}
/>
)
}
<div style={colorStyle}>
{`Rated: ${finalValue}`}
</div>
</div>
);

return (
<>
Expand All @@ -167,6 +136,7 @@ export const TaskCard: FunctionComponent<{
convertStatusToBorderColor(status)
}
>
{status === Status.Ended ? renderFinalValueOnClosedTasks() : <></>}
{isAdmin() ? renderAdministrativeView() : <></>}
<div className="flex flex-row justify-between py-2">
<strong className={convertStatusToTextColor(status)}>{title}</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export const useTaskStore = create<ISessionTaskState>()((set, get) => ({
draft.tasks.forEach((task) => {
if (task.id == taskResultDto.id) {
task.result = { amountOfVotes: 0, complexityAverage: taskResultDto.complexityAverage };
// task.result.complexityAverage = taskResultDto.complexityAverage;
task.status = Status.Evaluated;
}
});
Expand Down
1 change: 0 additions & 1 deletion client/pages/session/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default function Session({ id, tasks, users, auth, inviteToken }: any) {

useEffect(() => {
setCurrentTasks(tasks);

setCurrentUsers(users);
const { role, username, userId, token } = auth;
login(username, token, userId, role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Devon4Net.Application.WebAPI.Implementation.Domain.Entities;
using Newtonsoft.Json.Serialization;
using Devon4Net.Authorization;
using Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Converters;

namespace Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Controllers
{
Expand Down Expand Up @@ -272,12 +273,7 @@ public async Task<IActionResult> ChangeTaskStatus(long sessionId, [FromBody] Tas
{
var evaluatedTask = modifiedTasks.Find(item => item.Id == statusChange.Id);

var taskResult = new TaskResultDto()
{
Id = statusChange.Id,
AmountOfVotes = evaluatedTask.Result.AmountOfVotes,
ComplexityAverage = evaluatedTask.Result.ComplexityAverage,
};
var taskResult = TaskResultConverter.ModelToDto(evaluatedTask);

await _webSocketHandler.Send(new Message<TaskResultDto> { Type = MessageType.TaskAverageAdded, Payload = taskResult }, sessionId);
}
Expand All @@ -286,13 +282,7 @@ public async Task<IActionResult> ChangeTaskStatus(long sessionId, [FromBody] Tas
{
var endedTask = modifiedTasks.Find(item => item.Id == statusChange.Id);

var taskResult = new TaskResultDto()
{
Id = statusChange.Id,
AmountOfVotes = endedTask.Result.AmountOfVotes,
ComplexityAverage = endedTask.Result.ComplexityAverage,
FinalValue = endedTask.Result.FinalValue
};
var taskResult = TaskResultConverter.ModelToDto(endedTask);

await _webSocketHandler.Send(new Message<TaskResultDto> { Type = MessageType.TaskFinalValueAdded, Payload = taskResult }, sessionId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Dtos;

namespace Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Converters
{
public class TaskResultConverter
{
public static TaskResultDto ModelToDto(TaskStatusChangeDto task)
{
return new TaskResultDto
{
Id = task.Id,
AmountOfVotes = task.Result.AmountOfVotes,
ComplexityAverage = task.Result.ComplexityAverage,
FinalValue = task.Result.FinalValue
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,6 @@ private string generateInviteToken()

var (id, status) = statusChange;

// debug print
if (statusChange.Result is not null)
{
if (statusChange.Result.FinalValue is not null) Console.WriteLine("Received Final Value: " + statusChange.Result.FinalValue);
}

// if the session could be found and is valid
if (session is not null && session.IsValid())
{
Expand All @@ -383,41 +377,37 @@ private string generateInviteToken()
return (false, new List<TaskStatusChangeDto>());
}

var task = session.Tasks.ToList().Find(item => item.Id == id);

// calculate the voting result if the task is evaluated
if (status == Status.Evaluated)
{
session.Tasks.ToList().Find(item => item.Id == id).calculateResult();
task.calculateResult();
}

// store the final estimation value if the task is ended
if (status == Status.Ended)
{
if (statusChange.Result.FinalValue is null)
{
Console.WriteLine("StatusChange FinalValue is null.");
return (false, new List<TaskStatusChangeDto>());
}

session.Tasks.ToList().Find(item => item.Id == id).Result.FinalValue = statusChange.Result.FinalValue;
task.Result.FinalValue = statusChange.Result.FinalValue;
}

var finished = _sessionRepository.Update(session);

// and we could properly update the database
// if we could properly update the database
if (finished)
{
var converted = taskChanges.Select<(String id, Status status), TaskStatusChangeDto>(item => new TaskStatusChangeDto { Id = item.id, Status = item.status }).ToList();

// add the result to the DTO if task is evaluated
if (status == Status.Evaluated)
{
converted.Find(item => item.Id == id).Result = session.Tasks.ToList().Find(item => item.Id == id).Result;
}

// add the final value to the DTO if task is ended
if (status == Status.Ended)
// add the result to the DTO if task is evaluated or ended
if (status == Status.Evaluated || status == Status.Ended)
{
converted.Find(item => item.Id == id).Result = session.Tasks.ToList().Find(item => item.Id == id).Result;
var convertedTask = converted.Find(item => item.Id == id);
convertedTask.Result = task.Result;
}

return (true, converted);
Expand Down

0 comments on commit a549aea

Please sign in to comment.