From 76c0eb28af238876489fe4d5eedc49e5e0054e76 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Fri, 17 Nov 2023 14:34:38 +0100 Subject: [PATCH 1/6] prepare front to persistable tactics --- front/components/editor/BasketCourt.tsx | 43 +++++++++++-------------- front/components/editor/CourtPlayer.tsx | 2 +- front/views/Editor.tsx | 34 ++++++++----------- 3 files changed, 32 insertions(+), 47 deletions(-) diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index 115c41b..ccdc382 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -1,35 +1,28 @@ -import CourtSvg from "../../assets/basketball_court.svg?react" -import "../../style/basket_court.css" -import { useRef } from "react" -import CourtPlayer from "./CourtPlayer" -import { Player } from "../../tactic/Player" +import CourtSvg from '../../assets/basketball_court.svg?react'; +import '../../style/basket_court.css'; +import {useRef} from "react"; +import CourtPlayer from "./CourtPlayer"; +import {Player} from "../../tactic/Player"; export interface BasketCourtProps { - players: Player[] - onPlayerRemove: (p: Player) => void + players: Player[], + onPlayerRemove: (p: Player) => void, onPlayerChange: (p: Player) => void } -export function BasketCourt({ - players, - onPlayerRemove, - onPlayerChange, -}: BasketCourtProps) { - const divRef = useRef(null) +export function BasketCourt({players, onPlayerRemove, onPlayerChange}: BasketCourtProps) { + const divRef = useRef(null); return ( -
- - {players.map((player) => { - return ( - onPlayerRemove(player)} - parentRef={divRef} - /> - ) +
+ + {players.map(player => { + return onPlayerRemove(player)} + parentRef={divRef} + /> })}
) diff --git a/front/components/editor/CourtPlayer.tsx b/front/components/editor/CourtPlayer.tsx index 12083d3..1709599 100644 --- a/front/components/editor/CourtPlayer.tsx +++ b/front/components/editor/CourtPlayer.tsx @@ -1,4 +1,4 @@ -import { RefObject, useRef, useState } from "react" +import { RefObject, useRef } from "react" import "../../style/player.css" import RemoveIcon from "../../assets/icon/remove.svg?react" import Draggable from "react-draggable" diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 04362b5..15bb5b2 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -1,27 +1,18 @@ -import { - CSSProperties, - Dispatch, - SetStateAction, - useCallback, - useRef, - useState, -} from "react" -import "../style/editor.css" -import TitleInput from "../components/TitleInput" -import { BasketCourt } from "../components/editor/BasketCourt" -import { Rack } from "../components/Rack" -import { PlayerPiece } from "../components/editor/PlayerPiece" +import { CSSProperties, Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from "react" +import "../style/editor.css"; +import TitleInput from "../components/TitleInput"; +import {BasketCourt} from "../components/editor/BasketCourt"; -import { Player } from "../tactic/Player" -import { Tactic, TacticContent } from "../tactic/Tactic" -import { fetchAPI } from "../Fetcher" -import { Team } from "../tactic/Team" +import {Rack} from "../components/Rack"; +import {PlayerPiece} from "../components/editor/PlayerPiece"; + +import {Player} from "../tactic/Player"; +import {Tactic, TacticContent} from "../tactic/Tactic"; +import {fetchAPI} from "../Fetcher"; +import {Team} from "../tactic/Team"; +import SavingState, { SaveState, SaveStates } from "../components/editor/SavingState" import { calculateRatio } from "../Utils" -import SavingState, { - SaveState, - SaveStates, -} from "../components/editor/SavingState" const ERROR_STYLE: CSSProperties = { borderColor: "red", @@ -103,6 +94,7 @@ function EditorView({ isInGuestMode ? SaveStates.Guest : SaveStates.Ok, onContentChange, ) + const [allies, setAllies] = useState( getRackPlayers(Team.Allies, content.players), ) -- 2.36.3 From ce832a8510ab26440c5add516af7b6fd63cebc15 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Mon, 20 Nov 2023 09:56:05 +0100 Subject: [PATCH 2/6] add save state information in topbar --- front/components/editor/BasketCourt.tsx | 22 +++++++++++++--------- front/components/editor/CourtPlayer.tsx | 2 +- front/views/Editor.tsx | 16 +++++++++------- sql/setup-tables.sql | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index ccdc382..23c4a3f 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -1,17 +1,21 @@ -import CourtSvg from '../../assets/basketball_court.svg?react'; -import '../../style/basket_court.css'; -import {useRef} from "react"; -import CourtPlayer from "./CourtPlayer"; -import {Player} from "../../tactic/Player"; +import CourtSvg from "../../assets/basketball_court.svg?react" +import "../../style/basket_court.css" +import { useRef } from "react" +import CourtPlayer from "./CourtPlayer" +import { Player } from "../../tactic/Player" export interface BasketCourtProps { - players: Player[], - onPlayerRemove: (p: Player) => void, + players: Player[] + onPlayerRemove: (p: Player) => void onPlayerChange: (p: Player) => void } -export function BasketCourt({players, onPlayerRemove, onPlayerChange}: BasketCourtProps) { - const divRef = useRef(null); +export function BasketCourt({ + players, + onPlayerRemove, + onPlayerChange, +}: BasketCourtProps) { + const divRef = useRef(null) return (
diff --git a/front/components/editor/CourtPlayer.tsx b/front/components/editor/CourtPlayer.tsx index 1709599..12083d3 100644 --- a/front/components/editor/CourtPlayer.tsx +++ b/front/components/editor/CourtPlayer.tsx @@ -1,4 +1,4 @@ -import { RefObject, useRef } from "react" +import { RefObject, useRef, useState } from "react" import "../../style/player.css" import RemoveIcon from "../../assets/icon/remove.svg?react" import Draggable from "react-draggable" diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 15bb5b2..380b024 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -4,15 +4,17 @@ import "../style/editor.css"; import TitleInput from "../components/TitleInput"; import {BasketCourt} from "../components/editor/BasketCourt"; -import {Rack} from "../components/Rack"; -import {PlayerPiece} from "../components/editor/PlayerPiece"; -import {Player} from "../tactic/Player"; -import {Tactic, TacticContent} from "../tactic/Tactic"; -import {fetchAPI} from "../Fetcher"; -import {Team} from "../tactic/Team"; -import SavingState, { SaveState, SaveStates } from "../components/editor/SavingState" +import { Rack } from "../components/Rack" +import { PlayerPiece } from "../components/editor/PlayerPiece" + + +import { Player } from "../tactic/Player" +import { Tactic, TacticContent } from "../tactic/Tactic" +import { fetchAPI } from "../Fetcher" +import { Team } from "../tactic/Team" import { calculateRatio } from "../Utils" +import SavingState, { SaveState, SaveStates } from "../components/editor/SavingState" const ERROR_STYLE: CSSProperties = { borderColor: "red", diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index eb74877..7c012eb 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -46,5 +46,5 @@ CREATE TABLE Member id_user integer, role text CHECK (role IN ('Coach', 'Player')), FOREIGN KEY (id_team) REFERENCES Team (id), - FOREIGN KEY (id_user) REFERENCES User (id) + FOREIGN KEY (id_user) REFERENCES Account (id) ); -- 2.36.3 From 8546206bc19ae705b9aacf783233d73c3f422b27 Mon Sep 17 00:00:00 2001 From: Override-6 Date: Sun, 26 Nov 2023 21:35:23 +0100 Subject: [PATCH 3/6] add view to select between half and plain court --- .../{basketball_court.svg => court/court.svg} | 1 + front/assets/court/half_court.svg | 22 ++++ front/components/editor/BasketCourt.tsx | 24 ++-- front/style/basket_court.css | 8 +- front/style/colors.css | 11 -- front/style/editor.css | 5 +- front/style/new_tactic_panel.css | 117 ++++++++++++++++++ front/style/theme/default.css | 21 ++++ front/views/Editor.tsx | 42 +++++-- front/views/NewTacticPanel.tsx | 63 ++++++++++ front/views/Visualizer.tsx | 2 +- public/index.php | 5 +- sql/setup-tables.sql | 29 ++--- src/App/Controller/EditorController.php | 17 +-- src/Core/Data/CourtType.php | 61 +++++++++ src/Core/Data/MemberRole.php | 8 +- src/Core/Data/TacticInfo.php | 10 +- src/Core/Gateway/TacticInfoGateway.php | 10 +- src/Core/Model/TacticModel.php | 11 +- 19 files changed, 397 insertions(+), 70 deletions(-) rename front/assets/{basketball_court.svg => court/court.svg} (99%) create mode 100644 front/assets/court/half_court.svg delete mode 100644 front/style/colors.css create mode 100644 front/style/new_tactic_panel.css create mode 100644 front/style/theme/default.css create mode 100644 front/views/NewTacticPanel.tsx create mode 100755 src/Core/Data/CourtType.php diff --git a/front/assets/basketball_court.svg b/front/assets/court/court.svg similarity index 99% rename from front/assets/basketball_court.svg rename to front/assets/court/court.svg index e0df003..476a96f 100644 --- a/front/assets/basketball_court.svg +++ b/front/assets/court/court.svg @@ -2,6 +2,7 @@ xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" + height="100%" viewBox="7.5 18.5 85.5 56" style="enable-background:new 7.5 18.5 85.5 56;" xml:space="preserve"> diff --git a/front/assets/court/half_court.svg b/front/assets/court/half_court.svg new file mode 100644 index 0000000..8c06d6d --- /dev/null +++ b/front/assets/court/half_court.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index 23c4a3f..5305f6f 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -1,4 +1,3 @@ -import CourtSvg from "../../assets/basketball_court.svg?react" import "../../style/basket_court.css" import { useRef } from "react" import CourtPlayer from "./CourtPlayer" @@ -8,25 +7,30 @@ export interface BasketCourtProps { players: Player[] onPlayerRemove: (p: Player) => void onPlayerChange: (p: Player) => void + courtImage: string, } export function BasketCourt({ players, onPlayerRemove, onPlayerChange, + courtImage }: BasketCourtProps) { const divRef = useRef(null) return ( -
- - {players.map(player => { - return onPlayerRemove(player)} - parentRef={divRef} - /> +
+ {"court"} + {players.map((player) => { + return ( + onPlayerRemove(player)} + parentRef={divRef} + /> + ) })}
) diff --git a/front/style/basket_court.css b/front/style/basket_court.css index c001cc0..353d519 100644 --- a/front/style/basket_court.css +++ b/front/style/basket_court.css @@ -1,11 +1,17 @@ #court-container { display: flex; + align-content: center; + align-items: center; + justify-content: center; + height: 100%; + + padding: 20px 40px 20px 40px; background-color: var(--main-color); } #court-svg { - margin: 5%; + height: 100%; user-select: none; -webkit-user-drag: none; } diff --git a/front/style/colors.css b/front/style/colors.css deleted file mode 100644 index 3c17a25..0000000 --- a/front/style/colors.css +++ /dev/null @@ -1,11 +0,0 @@ -:root { - --main-color: #ffffff; - --second-color: #ccde54; - - --background-color: #d2cdd3; - - --selected-team-primarycolor: #ffffff; - --selected-team-secondarycolor: #000000; - - --selection-color: #3f7fc4; -} diff --git a/front/style/editor.css b/front/style/editor.css index eefa561..45ce43d 100644 --- a/front/style/editor.css +++ b/front/style/editor.css @@ -1,4 +1,4 @@ -@import "colors.css"; +@import "theme/default.css"; #main-div { display: flex; @@ -63,7 +63,8 @@ } #court-div-bounds { - width: 60%; + padding: 20px 20px 20px 20px; + height: 75%; } .react-draggable { diff --git a/front/style/new_tactic_panel.css b/front/style/new_tactic_panel.css new file mode 100644 index 0000000..e5640b6 --- /dev/null +++ b/front/style/new_tactic_panel.css @@ -0,0 +1,117 @@ + +#panel-root { + width: 100%; + height: 100%; + + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + align-content: center; +} + +#panel-top { + font-family: var(--text-main-font); +} + +#panel-choices { + width: 100%; + height: 100%; + + display: flex; + justify-content: center; + align-items: center; + align-content: center; + + background-color: var(--editor-court-selection-background); +} + +#panel-buttons { + width: 75%; + height: 30%; + display: flex; + justify-content: space-evenly; + align-items: stretch; + align-content: center; +} + +.court-kind-button { + position: relative; + + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + align-content: center; + + cursor: pointer; + + transition: scale 1s; +} + +.court-kind-button-bottom, .court-kind-button-top { + width: 100%; + height: 100%; + border: solid; + border-color: var(--border-color); +} + +.court-kind-button-bottom { + display: flex; + justify-content: center; + align-items: center; + align-content: center; + + height: 25%; + background-color: var(--editor-court-selection-buttons); + border-radius: 0 0 20px 20px; + border-width: 3px; +} + +.court-kind-button-top { + height: 75%; + overflow: hidden; + background-color: var(--main-color); + border-radius: 20px 20px 0 0; + border-width: 3px 3px 0 3px; +} + +.court-kind-button:hover { + scale: 1.1; +} + +.court-kind-button-top, .court-kind-button-image-div { + display: flex; + justify-content: center; + align-items: stretch; + align-content: stretch; +} + +.court-kind-button-image { + height: 100%; + user-select: none; + -webkit-user-drag: none; +} + +.court-kind-button-image-div { + width: 100%; + height: 100%; + padding: 0 10px 0 10px; + background-color: var(--second-color); +} + +.court-kind-button-name, .court-kind-button-details { + user-select: none; + font-family: var(--text-main-font); +} + +.court-kind-button-details { + position: absolute; + z-index: -1; + top: 0; + transition: top 1s; +} + +.court-kind-button:hover .court-kind-button-details { + top: -20px; +} \ No newline at end of file diff --git a/front/style/theme/default.css b/front/style/theme/default.css new file mode 100644 index 0000000..0baa9b9 --- /dev/null +++ b/front/style/theme/default.css @@ -0,0 +1,21 @@ +@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap'); +:root { + --main-color: #ffffff; + --second-color: #e8e8e8; + + --background-color: #d2cdd3; + + --selected-team-primarycolor: #ffffff; + --selected-team-secondarycolor: #000000; + + --buttons-shadow-color: #a8a8a8; + + --selection-color: #3f7fc4; + + --border-color: #FFFFFF; + + --editor-court-selection-background: #5f8fee; + --editor-court-selection-buttons: #acc4f3; + + --text-main-font: 'Roboto', sans-serif; +} diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 380b024..4c4c725 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -1,20 +1,30 @@ +import { + CSSProperties, + Dispatch, + SetStateAction, + useCallback, + useRef, + useState, +} from "react" +import "../style/editor.css" +import TitleInput from "../components/TitleInput" +import { BasketCourt } from "../components/editor/BasketCourt" -import { CSSProperties, Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from "react" -import "../style/editor.css"; -import TitleInput from "../components/TitleInput"; -import {BasketCourt} from "../components/editor/BasketCourt"; - +import plainCourt from "../assets/court/court.svg" +import halfCourt from "../assets/court/half_court.svg" import { Rack } from "../components/Rack" import { PlayerPiece } from "../components/editor/PlayerPiece" - import { Player } from "../tactic/Player" import { Tactic, TacticContent } from "../tactic/Tactic" import { fetchAPI } from "../Fetcher" import { Team } from "../tactic/Team" import { calculateRatio } from "../Utils" -import SavingState, { SaveState, SaveStates } from "../components/editor/SavingState" +import SavingState, { + SaveState, + SaveStates, +} from "../components/editor/SavingState" const ERROR_STYLE: CSSProperties = { borderColor: "red", @@ -27,6 +37,14 @@ export interface EditorViewProps { tactic: Tactic onContentChange: (tactic: TacticContent) => Promise onNameChange: (name: string) => Promise + courtType: string +} + +export interface EditorProps { + id: number + name: string + content: string + courtType: string } /** @@ -87,10 +105,11 @@ function EditorView({ tactic: { id, name, content: initialContent }, onContentChange, onNameChange, + courtType, }: EditorViewProps) { const isInGuestMode = id == -1 - const [style, setStyle] = useState({}) + const [titleStyle, setTitleStyle] = useState({}) const [content, setContent, saveState] = useContentState( initialContent, isInGuestMode ? SaveStates.Guest : SaveStates.Ok, @@ -149,11 +168,11 @@ function EditorView({
{ onNameChange(new_name).then((success) => { - setStyle(success ? {} : ERROR_STYLE) + setTitleStyle(success ? {} : ERROR_STYLE) }) }} /> @@ -187,6 +206,9 @@ function EditorView({
{ setContent((content) => ({ players: toSplicedPlayers( diff --git a/front/views/NewTacticPanel.tsx b/front/views/NewTacticPanel.tsx new file mode 100644 index 0000000..0f72c37 --- /dev/null +++ b/front/views/NewTacticPanel.tsx @@ -0,0 +1,63 @@ +import "../style/theme/default.css" +import "../style/new_tactic_panel.css" + +import plainCourt from "../assets/court/court.svg" +import halfCourt from "../assets/court/half_court.svg" + +export default function NewTacticPanel() { + return ( +
+
+

Select a basket court

+
+
+
+ + +
+
+
+ ) +} + +function CourtKindButton({ + name, + image, + details, + redirect, +}: { + name: string + image: string + details: string + redirect: string +}) { + return ( +
location.href = redirect} + > +
{details}
+
+
+ {name} +
+
+
+

{name}

+
+
+ ) +} diff --git a/front/views/Visualizer.tsx b/front/views/Visualizer.tsx index 541da09..5b09115 100644 --- a/front/views/Visualizer.tsx +++ b/front/views/Visualizer.tsx @@ -1,6 +1,6 @@ import React, { CSSProperties, useState } from "react" import "../style/visualizer.css" -import Court from "../assets/basketball_court.svg" +import Court from "../assets/court/court.svg" export default function Visualizer({ id, name }: { id: number; name: string }) { const [style, setStyle] = useState({}) diff --git a/public/index.php b/public/index.php index 78ee4d6..cd777ab 100644 --- a/public/index.php +++ b/public/index.php @@ -19,6 +19,7 @@ use IQBall\App\Session\SessionHandle; use IQBall\App\ViewHttpResponse; use IQBall\Core\Action; use IQBall\Core\Connection; +use IQBall\Core\Data\CourtType; use IQBall\Core\Gateway\AccountGateway; use IQBall\Core\Gateway\MemberGateway; use IQBall\Core\Gateway\TacticInfoGateway; @@ -90,7 +91,9 @@ function getRoutes(): AltoRouter { $ar->map("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->openEditor($id, $s))); // don't require an authentication to run this action. // If the user is not connected, the tactic will never save. - $ar->map("GET", "/tactic/new", Action::noAuth(fn(SessionHandle $s) => getEditorController()->createNew($s))); + $ar->map("GET", "/tactic/new", Action::noAuth(fn() => getEditorController()->createNew())); + $ar->map("GET", "/tactic/new/plain", Action::noAuth(fn(SessionHandle $s) => getEditorController()->createNewOfKind(CourtType::plain(), $s))); + $ar->map("GET", "/tactic/new/half", Action::noAuth(fn(SessionHandle $s) => getEditorController()->createNewOfKind(CourtType::half(), $s))); //team-related $ar->map("GET", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->displayCreateTeam($s))); diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 7c012eb..efb20c6 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -16,35 +16,36 @@ CREATE TABLE Account CREATE TABLE Tactic ( id integer PRIMARY KEY AUTOINCREMENT, - name varchar NOT NULL, - creation_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, - owner integer NOT NULL, - content varchar DEFAULT '{"players": []}' NOT NULL, + name varchar NOT NULL, + creation_date timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, + owner integer NOT NULL, + content varchar DEFAULT '{"players": []}' NOT NULL, + court_type varchar CHECK ( court_type IN ('HALF', 'PLAIN')) NOT NULL, FOREIGN KEY (owner) REFERENCES Account ); CREATE TABLE FormEntries ( - name varchar, - description varchar + name varchar NOT NULL, + description varchar NOT NULL ); CREATE TABLE Team ( - id integer PRIMARY KEY AUTOINCREMENT, - name varchar, - picture varchar, - main_color varchar, - second_color varchar + id integer PRIMARY KEY AUTOINCREMENT NOT NULL, + name varchar NOT NULL, + picture varchar NOT NULL, + main_color varchar NOT NULL, + second_color varchar NOT NULL ); CREATE TABLE Member ( - id_team integer, - id_user integer, - role text CHECK (role IN ('Coach', 'Player')), + id_team integer NOT NULL, + id_user integer NOT NULL, + role text CHECK (role IN ('COACH', 'PLAYER')) NOT NULL, FOREIGN KEY (id_team) REFERENCES Team (id), FOREIGN KEY (id_user) REFERENCES Account (id) ); diff --git a/src/App/Controller/EditorController.php b/src/App/Controller/EditorController.php index 3994093..238ae83 100644 --- a/src/App/Controller/EditorController.php +++ b/src/App/Controller/EditorController.php @@ -5,9 +5,11 @@ namespace IQBall\App\Controller; use IQBall\App\Session\SessionHandle; use IQBall\App\Validator\TacticValidator; use IQBall\App\ViewHttpResponse; +use IQBall\Core\Data\CourtType; use IQBall\Core\Data\TacticInfo; use IQBall\Core\Http\HttpCodes; use IQBall\Core\Model\TacticModel; +use IQBall\Core\Validation\ValidationFail; class EditorController { private TacticModel $model; @@ -25,9 +27,14 @@ class EditorController { "id" => $tactic->getId(), "name" => $tactic->getName(), "content" => $tactic->getContent(), + "courtType" => $tactic->getCourtType()->name() ]); } + public function createNew(): ViewHttpResponse { + return ViewHttpResponse::react("views/NewTacticPanel.tsx", []); + } + /** * @return ViewHttpResponse the editor view for a test tactic. */ @@ -44,15 +51,11 @@ class EditorController { * If the given session does not contain a connected account, * open a test editor. * @param SessionHandle $session + * @param CourtType $type * @return ViewHttpResponse the editor view */ - public function createNew(SessionHandle $session): ViewHttpResponse { - $account = $session->getAccount(); - - if ($account == null) { - return $this->openTestEditor(); - } - $tactic = $this->model->makeNewDefault($account->getId()); + public function createNewOfKind(CourtType $type, SessionHandle $session): ViewHttpResponse { + $tactic = $this->model->makeNewDefault($session->getAccount()->getId(), $type); return $this->openEditorFor($tactic); } diff --git a/src/Core/Data/CourtType.php b/src/Core/Data/CourtType.php new file mode 100755 index 0000000..caad45c --- /dev/null +++ b/src/Core/Data/CourtType.php @@ -0,0 +1,61 @@ + self::COURT_HALF) { + throw new InvalidArgumentException("Valeur du rĂ´le invalide"); + } + $this->value = $val; + } + + public static function plain(): CourtType { + return new CourtType(CourtType::COURT_PLAIN); + } + + public static function half(): CourtType { + return new CourtType(CourtType::COURT_HALF); + } + + public function name(): string { + switch ($this->value) { + case self::COURT_HALF: + return "HALF"; + case self::COURT_PLAIN: + return "PLAIN"; + } + die("unreachable"); + } + + public static function fromName(string $name): ?CourtType { + switch ($name) { + case "HALF": + return CourtType::half(); + case "PLAIN": + return CourtType::plain(); + default: + return null; + } + } + + public function isPlain(): bool { + return ($this->value == self::COURT_PLAIN); + } + + public function isHalf(): bool { + return ($this->value == self::COURT_HALF); + } + +} diff --git a/src/Core/Data/MemberRole.php b/src/Core/Data/MemberRole.php index 41b6b71..9606c0b 100755 --- a/src/Core/Data/MemberRole.php +++ b/src/Core/Data/MemberRole.php @@ -35,18 +35,18 @@ final class MemberRole { public function name(): string { switch ($this->value) { case self::ROLE_COACH: - return "Coach"; + return "COACH"; case self::ROLE_PLAYER: - return "Player"; + return "PLAYER"; } die("unreachable"); } public static function fromName(string $name): ?MemberRole { switch ($name) { - case "Coach": + case "COACH": return MemberRole::coach(); - case "Player": + case "PLAYER": return MemberRole::player(); default: return null; diff --git a/src/Core/Data/TacticInfo.php b/src/Core/Data/TacticInfo.php index 2565f93..c3b8667 100644 --- a/src/Core/Data/TacticInfo.php +++ b/src/Core/Data/TacticInfo.php @@ -7,7 +7,7 @@ class TacticInfo { private string $name; private int $creationDate; private int $ownerId; - + private CourtType $courtType; private string $content; /** @@ -15,13 +15,15 @@ class TacticInfo { * @param string $name * @param int $creationDate * @param int $ownerId + * @param CourtType $type * @param string $content */ - public function __construct(int $id, string $name, int $creationDate, int $ownerId, string $content) { + public function __construct(int $id, string $name, int $creationDate, int $ownerId, CourtType $type, string $content) { $this->id = $id; $this->name = $name; $this->ownerId = $ownerId; $this->creationDate = $creationDate; + $this->courtType = $type; $this->content = $content; } @@ -47,6 +49,10 @@ class TacticInfo { return $this->ownerId; } + public function getCourtType(): CourtType { + return $this->courtType; + } + /** * @return int */ diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 447c7a5..abd0541 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -3,6 +3,7 @@ namespace IQBall\Core\Gateway; use IQBall\Core\Connection; +use IQBall\Core\Data\CourtType; use IQBall\Core\Data\TacticInfo; use PDO; @@ -33,7 +34,8 @@ class TacticInfoGateway { $row = $res[0]; - return new TacticInfo($id, $row["name"], strtotime($row["creation_date"]), $row["owner"], $row['content']); + $type = CourtType::fromName($row['court_type']); + return new TacticInfo($id, $row["name"], strtotime($row["creation_date"]), $row["owner"], $type, $row['content']); } @@ -57,14 +59,16 @@ class TacticInfoGateway { /** * @param string $name * @param int $owner + * @param CourtType $type * @return int inserted tactic id */ - public function insert(string $name, int $owner): int { + public function insert(string $name, int $owner, CourtType $type): int { $this->con->exec( - "INSERT INTO Tactic(name, owner) VALUES(:name, :owner)", + "INSERT INTO Tactic(name, owner, court_type) VALUES(:name, :owner, :court_type)", [ ":name" => [$name, PDO::PARAM_STR], ":owner" => [$owner, PDO::PARAM_INT], + ":court_type" => [$type->name(), PDO::PARAM_STR] ] ); return intval($this->con->lastInsertId()); diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 136b27d..51e5eb8 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -2,6 +2,7 @@ namespace IQBall\Core\Model; +use IQBall\Core\Data\CourtType; use IQBall\Core\Data\TacticInfo; use IQBall\Core\Gateway\TacticInfoGateway; use IQBall\Core\Validation\ValidationFail; @@ -23,20 +24,22 @@ class TacticModel { * creates a new empty tactic, with given name * @param string $name * @param int $ownerId + * @param CourtType $type * @return TacticInfo */ - public function makeNew(string $name, int $ownerId): TacticInfo { - $id = $this->tactics->insert($name, $ownerId); + public function makeNew(string $name, int $ownerId, CourtType $type): TacticInfo { + $id = $this->tactics->insert($name, $ownerId, $type); return $this->tactics->get($id); } /** * creates a new empty tactic, with a default name * @param int $ownerId + * @param CourtType $type * @return TacticInfo|null */ - public function makeNewDefault(int $ownerId): ?TacticInfo { - return $this->makeNew(self::TACTIC_DEFAULT_NAME, $ownerId); + public function makeNewDefault(int $ownerId, CourtType $type): ?TacticInfo { + return $this->makeNew(self::TACTIC_DEFAULT_NAME, $ownerId, $type); } /** -- 2.36.3 From 208d835a1f05139b7c9a4a99e275a280740022d2 Mon Sep 17 00:00:00 2001 From: Override-6 Date: Sun, 26 Nov 2023 21:46:31 +0100 Subject: [PATCH 4/6] fix BasketCourt margins --- front/components/editor/BasketCourt.tsx | 19 +++++++++++-------- front/style/basket_court.css | 5 ++--- front/style/new_tactic_panel.css | 12 +++++++----- front/style/player.css | 5 ++--- front/style/theme/default.css | 6 +++--- front/views/Editor.tsx | 3 ++- front/views/NewTacticPanel.tsx | 3 +-- src/App/Controller/EditorController.php | 2 +- src/Core/Gateway/TacticInfoGateway.php | 2 +- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index 5305f6f..cd4774e 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -1,5 +1,5 @@ import "../../style/basket_court.css" -import { useRef } from "react" +import { RefObject, useRef } from "react" import CourtPlayer from "./CourtPlayer" import { Player } from "../../tactic/Player" @@ -7,20 +7,23 @@ export interface BasketCourtProps { players: Player[] onPlayerRemove: (p: Player) => void onPlayerChange: (p: Player) => void - courtImage: string, + courtImage: string + courtRef: RefObject } export function BasketCourt({ players, onPlayerRemove, onPlayerChange, - courtImage + courtImage, + courtRef, }: BasketCourtProps) { - const divRef = useRef(null) - return ( -
- {"court"} +
+ {"court"} {players.map((player) => { return ( onPlayerRemove(player)} - parentRef={divRef} + parentRef={courtRef} /> ) })} diff --git a/front/style/basket_court.css b/front/style/basket_court.css index 353d519..859d00f 100644 --- a/front/style/basket_court.css +++ b/front/style/basket_court.css @@ -5,13 +5,12 @@ justify-content: center; height: 100%; - padding: 20px 40px 20px 40px; - background-color: var(--main-color); } #court-svg { - height: 100%; + margin: 35px; + height: 87%; user-select: none; -webkit-user-drag: none; } diff --git a/front/style/new_tactic_panel.css b/front/style/new_tactic_panel.css index e5640b6..5f151d9 100644 --- a/front/style/new_tactic_panel.css +++ b/front/style/new_tactic_panel.css @@ -1,4 +1,3 @@ - #panel-root { width: 100%; height: 100%; @@ -49,7 +48,8 @@ transition: scale 1s; } -.court-kind-button-bottom, .court-kind-button-top { +.court-kind-button-bottom, +.court-kind-button-top { width: 100%; height: 100%; border: solid; @@ -80,7 +80,8 @@ scale: 1.1; } -.court-kind-button-top, .court-kind-button-image-div { +.court-kind-button-top, +.court-kind-button-image-div { display: flex; justify-content: center; align-items: stretch; @@ -100,7 +101,8 @@ background-color: var(--second-color); } -.court-kind-button-name, .court-kind-button-details { +.court-kind-button-name, +.court-kind-button-details { user-select: none; font-family: var(--text-main-font); } @@ -114,4 +116,4 @@ .court-kind-button:hover .court-kind-button-details { top: -20px; -} \ No newline at end of file +} diff --git a/front/style/player.css b/front/style/player.css index 7bea36e..71baddb 100644 --- a/front/style/player.css +++ b/front/style/player.css @@ -39,12 +39,11 @@ on the court. } .player-selection-tab { - display: flex; + display: none; position: absolute; margin-bottom: 10%; justify-content: center; - visibility: hidden; width: 100%; transform: translateY(-20px); @@ -67,7 +66,7 @@ on the court. } .player:focus-within .player-selection-tab { - visibility: visible; + display: flex; } .player:focus-within .player-piece { diff --git a/front/style/theme/default.css b/front/style/theme/default.css index 0baa9b9..a2894ee 100644 --- a/front/style/theme/default.css +++ b/front/style/theme/default.css @@ -1,4 +1,4 @@ -@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap'); +@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400&display=swap"); :root { --main-color: #ffffff; --second-color: #e8e8e8; @@ -12,10 +12,10 @@ --selection-color: #3f7fc4; - --border-color: #FFFFFF; + --border-color: #ffffff; --editor-court-selection-background: #5f8fee; --editor-court-selection-buttons: #acc4f3; - --text-main-font: 'Roboto', sans-serif; + --text-main-font: "Roboto", sans-serif; } diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 4c4c725..6b5dbd7 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -203,12 +203,13 @@ function EditorView({ />
-
+
{ setContent((content) => ({ players: toSplicedPlayers( diff --git a/front/views/NewTacticPanel.tsx b/front/views/NewTacticPanel.tsx index 0f72c37..2b7165b 100644 --- a/front/views/NewTacticPanel.tsx +++ b/front/views/NewTacticPanel.tsx @@ -44,8 +44,7 @@ function CourtKindButton({ return (
location.href = redirect} - > + onClick={() => (location.href = redirect)}>
{details}
diff --git a/src/App/Controller/EditorController.php b/src/App/Controller/EditorController.php index 238ae83..64de063 100644 --- a/src/App/Controller/EditorController.php +++ b/src/App/Controller/EditorController.php @@ -27,7 +27,7 @@ class EditorController { "id" => $tactic->getId(), "name" => $tactic->getName(), "content" => $tactic->getContent(), - "courtType" => $tactic->getCourtType()->name() + "courtType" => $tactic->getCourtType()->name(), ]); } diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index abd0541..67cffc4 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -68,7 +68,7 @@ class TacticInfoGateway { [ ":name" => [$name, PDO::PARAM_STR], ":owner" => [$owner, PDO::PARAM_INT], - ":court_type" => [$type->name(), PDO::PARAM_STR] + ":court_type" => [$type->name(), PDO::PARAM_STR], ] ); return intval($this->con->lastInsertId()); -- 2.36.3 From 4c684e27a8e2daba8554dee965a95fffee331ec1 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Thu, 30 Nov 2023 08:50:06 +0100 Subject: [PATCH 5/6] fix staging server --- .env | 3 ++- ci/.drone.yml | 1 + ci/build_react.msh | 2 -- front/Constants.ts | 5 +++++ front/views/Editor.tsx | 4 ++-- front/views/NewTacticPanel.tsx | 15 ++++++++------- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.env b/.env index 951db6b..98ae12d 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -VITE_API_ENDPOINT=/api \ No newline at end of file +VITE_API_ENDPOINT=/api +VITE_BASE= \ No newline at end of file diff --git a/ci/.drone.yml b/ci/.drone.yml index 8b7058d..a282766 100644 --- a/ci/.drone.yml +++ b/ci/.drone.yml @@ -36,6 +36,7 @@ steps: - chmod +x /tmp/moshell_setup.sh - echo n | /tmp/moshell_setup.sh - echo "VITE_API_ENDPOINT=/IQBall/$DRONE_BRANCH/public/api" >> .env.PROD + - echo "VITE_BASE=/IQBall/$DRONE_BRANCH/public" >> .env.PROD - - /root/.local/bin/moshell ci/build_react.msh diff --git a/ci/build_react.msh b/ci/build_react.msh index 32a5923..3d3a8f0 100755 --- a/ci/build_react.msh +++ b/ci/build_react.msh @@ -9,8 +9,6 @@ val drone_branch = std::env("DRONE_BRANCH").unwrap() val base = "/IQBall/$drone_branch/public" npm run build -- --base=$base --mode PROD -npm run build -- --base=/IQBall/public --mode PROD - // Read generated mappings from build val result = $(jq -r 'to_entries|map(.key + " " +.value.file)|.[]' dist/manifest.json) val mappings = $result.split('\n') diff --git a/front/Constants.ts b/front/Constants.ts index 76b37c2..013db50 100644 --- a/front/Constants.ts +++ b/front/Constants.ts @@ -2,3 +2,8 @@ * This constant defines the API endpoint. */ export const API = import.meta.env.VITE_API_ENDPOINT + +/** + * This constant defines the base app's endpoint. + */ +export const BASE = import.meta.env.VITE_BASE diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 6b5dbd7..3b6ad4f 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -37,14 +37,14 @@ export interface EditorViewProps { tactic: Tactic onContentChange: (tactic: TacticContent) => Promise onNameChange: (name: string) => Promise - courtType: string + courtType: "PLAIN" | "HALF" } export interface EditorProps { id: number name: string content: string - courtType: string + courtType: "PLAIN" | "HALF" } /** diff --git a/front/views/NewTacticPanel.tsx b/front/views/NewTacticPanel.tsx index 2b7165b..9733c91 100644 --- a/front/views/NewTacticPanel.tsx +++ b/front/views/NewTacticPanel.tsx @@ -3,6 +3,7 @@ import "../style/new_tactic_panel.css" import plainCourt from "../assets/court/court.svg" import halfCourt from "../assets/court/half_court.svg" +import {BASE} from "../Constants"; export default function NewTacticPanel() { return ( @@ -31,11 +32,11 @@ export default function NewTacticPanel() { } function CourtKindButton({ - name, - image, - details, - redirect, -}: { + name, + image, + details, + redirect, + }: { name: string image: string details: string @@ -44,14 +45,14 @@ function CourtKindButton({ return (
(location.href = redirect)}> + onClick={() => location.href = BASE + redirect}>
{details}
{name} + className="court-kind-button-image"/>
-- 2.36.3 From 940d87930adb17917b1fe38cb19b7de8183859ba Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Mon, 4 Dec 2023 14:28:20 +0100 Subject: [PATCH 6/6] fix new tactic panel --- front/assets/court/court.svg | 4 ++-- front/assets/court/half_court.svg | 2 +- front/style/basket_court.css | 2 +- front/style/new_tactic_panel.css | 23 +++++++++++++---------- front/views/Editor.tsx | 9 +++------ front/views/NewTacticPanel.tsx | 2 +- src/App/Controller/EditorController.php | 12 ++++++++++-- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/front/assets/court/court.svg b/front/assets/court/court.svg index 476a96f..e01fd58 100644 --- a/front/assets/court/court.svg +++ b/front/assets/court/court.svg @@ -1,8 +1,8 @@ diff --git a/front/assets/court/half_court.svg b/front/assets/court/half_court.svg index 8c06d6d..8e7640e 100644 --- a/front/assets/court/half_court.svg +++ b/front/assets/court/half_court.svg @@ -1,4 +1,4 @@ - + diff --git a/front/style/basket_court.css b/front/style/basket_court.css index 859d00f..92a520c 100644 --- a/front/style/basket_court.css +++ b/front/style/basket_court.css @@ -9,7 +9,7 @@ } #court-svg { - margin: 35px; + margin: 35px 0 35px 0; height: 87%; user-select: none; -webkit-user-drag: none; diff --git a/front/style/new_tactic_panel.css b/front/style/new_tactic_panel.css index 5f151d9..ff6a07e 100644 --- a/front/style/new_tactic_panel.css +++ b/front/style/new_tactic_panel.css @@ -27,7 +27,7 @@ #panel-buttons { width: 75%; - height: 30%; + height: 20%; display: flex; justify-content: space-evenly; align-items: stretch; @@ -45,17 +45,15 @@ cursor: pointer; - transition: scale 1s; + transition: scale 0.5s ease-out; + width: auto; } .court-kind-button-bottom, .court-kind-button-top { - width: 100%; - height: 100%; border: solid; border-color: var(--border-color); } - .court-kind-button-bottom { display: flex; justify-content: center; @@ -63,14 +61,15 @@ align-content: center; height: 25%; + width: 100%; + background-color: var(--editor-court-selection-buttons); border-radius: 0 0 20px 20px; border-width: 3px; } .court-kind-button-top { - height: 75%; - overflow: hidden; + height: 30%; background-color: var(--main-color); border-radius: 20px 20px 0 0; border-width: 3px 3px 0 3px; @@ -82,21 +81,25 @@ .court-kind-button-top, .court-kind-button-image-div { + overflow: hidden; display: flex; + height: 100%; + width: 100%; justify-content: center; - align-items: stretch; - align-content: stretch; + align-items: center; + align-content: center; } .court-kind-button-image { height: 100%; + width: 150px; user-select: none; -webkit-user-drag: none; } .court-kind-button-image-div { - width: 100%; height: 100%; + padding: 0 10px 0 10px; background-color: var(--second-color); } diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 3b6ad4f..14ebbf6 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -58,12 +58,9 @@ interface RackedPlayer { export default function Editor({ id, name, + courtType, content, -}: { - id: number - name: string - content: string -}) { +}: EditorProps) { const isInGuestMode = id == -1 const storage_content = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY) @@ -97,7 +94,7 @@ export default function Editor({ (r) => r.ok, ) }} - /> + courtType={courtType}/> ) } diff --git a/front/views/NewTacticPanel.tsx b/front/views/NewTacticPanel.tsx index 9733c91..d3d5528 100644 --- a/front/views/NewTacticPanel.tsx +++ b/front/views/NewTacticPanel.tsx @@ -56,7 +56,7 @@ function CourtKindButton({
-

{name}

+

{name}

) diff --git a/src/App/Controller/EditorController.php b/src/App/Controller/EditorController.php index 64de063..855d8d9 100644 --- a/src/App/Controller/EditorController.php +++ b/src/App/Controller/EditorController.php @@ -38,11 +38,12 @@ class EditorController { /** * @return ViewHttpResponse the editor view for a test tactic. */ - private function openTestEditor(): ViewHttpResponse { + private function openTestEditor(CourtType $courtType): ViewHttpResponse { return ViewHttpResponse::react("views/Editor.tsx", [ "id" => -1, //-1 id means that the editor will not support saves - "content" => '{"players": []}', "name" => TacticModel::TACTIC_DEFAULT_NAME, + "content" => '{"players": []}', + "courtType" => $courtType->name() ]); } @@ -55,6 +56,13 @@ class EditorController { * @return ViewHttpResponse the editor view */ public function createNewOfKind(CourtType $type, SessionHandle $session): ViewHttpResponse { + + $action = $session->getAccount(); + + if ($action == null) { + return $this->openTestEditor($type); + } + $tactic = $this->model->makeNewDefault($session->getAccount()->getId(), $type); return $this->openEditorFor($tactic); } -- 2.36.3