Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
giovanni-orciuolo committed Feb 4, 2024
2 parents 210b7f3 + f307e96 commit 7d26b3c
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 198 deletions.
101 changes: 80 additions & 21 deletions IT/codekatabattle-frontend/src/components/BattleEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {useParams} from "react-router-dom";
import {useEffect, useState} from "react";
import {Battle, BattleEntry, BattleService, BattleTestResult} from "../services/openapi";
import { BattleEntry, BattleService, BattleTestResult} from "../services/openapi";
import {NavBar} from "./NavBar.tsx";

export const BattleEntries= () => {
const params = useParams();
const [battle, setBattle] = useState<Battle | null>(null);
const [error, setError] = useState<Error | null>(null);
const [entries, setEntries] = useState<Array<BattleEntry >| undefined>(undefined);

Expand All @@ -27,8 +26,7 @@ export const BattleEntries= () => {
async function fetchBattle(){
try {
const tbattle = await BattleService.findById1(+params.bId!);
setBattle(tbattle);
const entryList = battle?.entries;
const entryList = tbattle.entries;
setEntries(entryList?.filter((entry) => participantRight(entry)));
} catch (error1) {
setError(error as Error);
Expand Down Expand Up @@ -57,19 +55,19 @@ export const BattleEntries= () => {
</th>

<th>
{score.exitCode}
{score.exitCode.toString()}
</th>

<th>
{score.timeout}
{score.timeout.toString()}
</th>

<th>
{score.error}
{score.error?.toString()}
</th>

<th>
{score.passed}
{score.passed.toString()}
</th>

</tr>
Expand All @@ -79,18 +77,62 @@ export const BattleEntries= () => {

function testScoreListModal(testScores: Array<BattleTestResult>) {
return (

<dialog id="my_modal_3" className="modal">
{testScoreList(testScores)}
<div style={{padding:"1%"}} className="bg bg-base-100 rounded-box">
<h1 className="text-2xl font-bold" style={{paddingTop: "1.5%", paddingLeft: "0.5%"}}>
Test results
</h1>
<table>
<div style={{height: "fit-content"}} className="boxx">
<div className="boxx-inner">
<thead>
<th>Name</th>
<th>Input</th>
<th>Output</th>
<th>Score</th>
<th>Exit code</th>
<th>Timeout</th>
<th>Error</th>
<th>Passed</th>
</thead>
<tbody>
{testScoreList(testScores)}
</tbody>
</div>
</div>

</table>

<div style={{padding: "2%"}} className="modal-action">
<form method="dialog">

<button className="btn">Close</button>
</form>
</div>
</div>


</dialog>


)
}

function seeModal(lenght: number) {
if (lenght == 0) {
alert("No tests")
return
}
(document.getElementById('my_modal_3') as HTMLDialogElement).showModal()
}

function entryList() {
return (
entries?.map((entry, index) => (
<tr>
<tr className=" bg bg-base-200">
<th className="font-bold" style={{alignItems: "center"}}>
{index}
{index + 1}
</th>

<th>
Expand All @@ -101,18 +143,28 @@ export const BattleEntries= () => {
{entry.score}
</th>


<th>
{(entry.processResult?.satResult?.satName ?? "-").toString()}
</th>

<th>
{(entry.processResult?.satResult?.score ?? "-").toString()}
</th>

<th>
{(entry.processResult?.satResult?.warnings ?? "-").toString()}
</th>
<th>
<div style={{paddingLeft: "1.5%"}}>
<p className="badge badge-primary badge-outline"
onClick={() => (document.getElementById('my_modal_3') as HTMLDialogElement).showModal()}>
<p className="badge badge-info badge-outline"
onClick={() => seeModal((entry.processResult?.testResults.length ?? 0))}>
See test results
</p>
</div>
{testScoreListModal((entry.processResult?.testResults ?? []))}
</th>
<th>
{(entry.processResult?.satResult ?? "").toString()}
</th>

</tr>
)
)
Expand All @@ -121,16 +173,23 @@ export const BattleEntries= () => {

return (
<>
<div style={{alignSelf: "end", top: "8%", width: "100%"}}>
<div className="overflow-x-auto">
<table className="table">
{/* head */}

<div className="" style={{alignSelf: "end", position: "fixed", top: "8%", width: "100%"}}>
<h1 className="text-3xl font-bold" style={{paddingTop: "2%", paddingLeft: "4%"}}>
{params.username?.toString() + "'s entries"}
</h1>
<div style={{paddingLeft: "3%", paddingRight: "3%", paddingTop: "2%"}} className="overflow-x-auto ">
<table className="table bg bg-base-300">
{/* head */}
<thead>
<tr>
<th></th>
<th>Status</th>
<th>Score</th>
<th>r</th>
<th>Executed SAT</th>
<th>SAT score</th>
<th>SAT warnings</th>
<th></th>
</tr>
</thead>
<tbody>
Expand Down
3 changes: 1 addition & 2 deletions IT/codekatabattle-frontend/src/components/CreateBattle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export default function CreateBattle() {


</div>
{/*botton close*/
}

<div className="modal-action">
<form method="dialog">

Expand Down
24 changes: 1 addition & 23 deletions IT/codekatabattle-frontend/src/components/ImageCreator.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
import {useEffect, useState} from "react";
import {AuthService, GHUser} from "../services/openapi";


export const ImageCreator= ({username}: {username :string}) => {
const [user,setUser]=useState<GHUser>();

useEffect(() => {
fetchUser()
}, []);
async function fetchUser(){
const ghuser=await AuthService.getUserInfo(username);
setUser(ghuser);
}

if(user){
return(
<><img src={user.avatar_url}/></>

)
}
return(
<>
<span className="loading loading-ring loading-lg"></span>
</>)
return(<><img src={`https://github.com/${username}.png`}/></>)
}
10 changes: 5 additions & 5 deletions IT/codekatabattle-frontend/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const NavBar= () => {
className="drawer-overlay"></label>
<ul className="menu p-4 w-80 min-h-full bg-base-200 text-base-content">
<li><Link to={"/all/tournaments/view/0"}>All Tournaments</Link></li>
<li><Link to={"/joined/tournaments/view/0"}>Joined Tournaments</Link></li>
<li><Link to={"/created/tournaments/view/0"}>Created Tournaments</Link></li>
<li><Link to={"/coordinated/tournaments/view/0"}>Coordinated Tournaments</Link></li>
<li><Link to={"/joined/tournaments/view/"+user?.login+"/0"}>Joined Tournaments</Link></li>
<li><Link to={"/created/tournaments/view/"+user?.login+"/0"}>Created Tournaments</Link></li>
<li><Link to={"/coordinated/tournaments/view/"+user?.login+"/0"}>Coordinated Tournaments</Link></li>
<li><Link to="/tournament/create">Create Tournaments</Link></li>
<li><Link to={"/profile/" + user?.login?.toString()}>My Profile</Link></li>

Expand All @@ -66,9 +66,9 @@ export const NavBar= () => {
<div className="navbar-end">
<form className="input input-bordered ">
<ul className="menu menu-vertical lg:menu-horizontal">
<input type="text" placeholder="Type here..." style={{height:"5%",paddingTop:"4%"}} className="bg-base-100 "
<input type="text" placeholder="Search user..." style={{height:"5%",paddingTop:"4%"}} className="bg-base-100 "
onChange={event => setUsername(event.target.value)}/>
<button className="btm btn-sm btn-ghost btn-circle" style={{right:"70%"}} onClick={()=>navigate("/"+username)}>
<button className="btm btn-sm btn-ghost btn-circle" style={{right:"70%"}} onClick={()=>navigate("/profile/"+username)}>
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import {Link, useParams} from "react-router-dom";
import {Link, useNavigate, useParams} from "react-router-dom";
import {useContext, useEffect, useState} from "react";
import {AuthContext} from "../context/AuthContext.ts";
import {Battle, BattleParticipant, BattleParticipantUpdateDTO, BattleService} from "../services/openapi";
import {
Battle,
BattleParticipant,
BattleParticipantUpdateDTO,
BattleService,
BattleUpdateDTO
} from "../services/openapi";
import {NavBar} from "./NavBar.tsx";
import nunchaku from "../assets/nunchaku.png";

export const PerformeOME= () => {
export const PerformOME= () => {
const params = useParams();
const {user}=useContext(AuthContext);
const [battle, setBattle] = useState<Battle | null>(null);
const [error, setError] = useState<Error | null>(null);
const navigate=useNavigate();
const [OMEs] = useState(
new Array(battle?.participants?.length).fill(0)
);
Expand Down Expand Up @@ -78,7 +85,7 @@ export const PerformeOME= () => {
</td>
<td>
<label className="btn btn-primary"
onClick={() => performOME(index, participantId)}>Edit</label>
onClick={() => performOME(index, participantId)}>Save</label>
</td>
</>
)
Expand All @@ -105,12 +112,27 @@ export const PerformeOME= () => {
)
}

async function editBattle(){
(document.getElementById('my_modal_2') as HTMLDialogElement).showModal();
if(!battle)return;
const updateBattle:BattleUpdateDTO={startsAt: battle.startsAt, endsAt: battle.endsAt, enableManualEvaluation: false};
if(battle.id!=undefined){
try{
await BattleService.updateById1(battle.id,updateBattle);
navigate("/tournaments/"+params.tId+"/battles/"+params.bId);
} catch (e) {
setError(e as Error);
if(error?.message)alert(error.message);
}
}
}

return (
<>
<div style={{top: "8%", width: "100%", position: "absolute"}}>

<div className="navbar bg-base-200" style={{width: "100%"}}>
<div className="navbar-start"></div>
<div className="navbar-start"></div>
<div className="navbar-center">
<div className="w-10 h-10 rounded-full">
<img src={nunchaku}/>
Expand Down Expand Up @@ -139,6 +161,11 @@ export const PerformeOME= () => {
</tbody>
</table>
</div>
<div style={{padding:"1%"}}>
<label style={{width: "100%"}} className="btn btn-error" onClick={() => editBattle()}>Terminate OME
and BATTLE!!</label>

</div>
</div>
<div style={{top: "0%", position: "fixed", width: "100%", height: "10%"}}><NavBar/></div>

Expand Down
Loading

0 comments on commit 7d26b3c

Please sign in to comment.