Update logic front + design

pull/11/head
ayshiff 2018-06-04 22:57:11 +02:00
commit 09c02d0bd8
16 changed files with 864 additions and 396 deletions

View File

@ -9,7 +9,7 @@
"private": true,
"scripts": {
"build": "react-scripts build",
"start": "cd client && node ../node_modules/react-scripts/scripts/start.js"
"start": "node node_modules/react-scripts/scripts/start.js"
},
"dependencies": {
"axios": "^0.18.0",

View File

@ -7,71 +7,75 @@ class App extends Component {
constructor(props) {
super(props);
this.state = {
currentOptionsState: ["test"],
pastOptions: [],
score: 0
currentResponses: ["zert","zert","zert","zert"],
currentQuestion: "zefzeezze",
currentResponsesContent: ["zert","zert","zert","zert"],
currentResponsesChild: [0,1,2,3],
pastQuestion: null,
pastResponse: null,
score: 0,
}
}
_handleClick(element) {
this.setState(prevState => ({
pastOptions: [...prevState.pastOptions, element]
_handleClick(event) {
}
fetchQuestion(id) {
axios.get('http://localhost:8000/questions/'+ id)
.then(((data) => {
this.setState({
currentResponses : data.responses,
currentQuestion: data.text
})
}))
}
fetchOptions(id) {
axios.get('http://localhost/questions/'+ id)
fetchResponses() {
this.state.currentResponses.forEach((element) => {
axios.get(element)
.then(((t) => {
this.setState(prevState => ({
currentOptionsState: [...prevState.currentOptionsState, t.data.responses]
currentResponsesContent: [...prevState.currentResponsesContent, t.text],
currentResponsesChild: [...prevState.currentResponsesChild, t.child]
}))
}))
})
}
componentWillMount(){
this.fetchOptions()
this.fetchQuestion(0);
this.fetchResponses();
}
headerRendering() {
let headerPast = [];
for(let i = 0; i<this.state.pastOptions-1; i++) {
headerPast.push (
<div className="headerPast">
<h3 className="currentOption">
{this.state.pastOptions[i]}
</h3>
<h4 className="currentOption">
{this.state.pastOptions[i+1]}
</h4>
</div>
)
}
return headerPast
}
render() {
let currentOptions = this.state.currentOptionsState.map(((element, index) => (
<div key={index} className="currentOption btn btn-default btn-lg btn-block text-left" onClick={this._handleClick.bind(this, element)}>
<h3 className="currentOption_element">
{element}
</h3>
</div>
let currentOptions = this.state.currentResponsesContent.map(((element, index) => (
<p key={index}><a class="btn btn-default btn-lg btn-block text-left" onClick={this._handleClick.bind(this, element)}>{element}</a></p>
)));
let header = () => (
<div class="jumbotron">
<h3>{this.state.pastQuestion}<br/>
<small> {this.state.pastResponse}</small></h3>
</div>
)
return (
<div className="App container">
<h1>Am I late ?</h1>
<header className="App_header">
{this.state.pastOptions ? this.headerRendering() : null}
{this.state.pastQuestion ? header : null}
</header>
<div className="jumbotron">
<div className="currentSection vertical-center container">
<h1 className="currentState">{}</h1>
<h1 className="currentState">{this.state.currentQuestion}</h1>
<h2 className="currentQuestion">Je fais quoi ?</h2>
<div className="currentOptions">
{this.state.currentOptionsState ? currentOptions : null}
{this.state.currentResponsesContent ? currentOptions : null}
</div>
</div>
</div>
</div>

View File

@ -11,6 +11,8 @@
"symfony/lts": "^4@dev",
"symfony/maker-bundle": "^1.4",
"symfony/orm-pack": "^1.0",
"symfony/profiler-pack": "^1.0",
"symfony/serializer": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {

839
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,4 +11,5 @@ return [
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
];

View File

@ -162,8 +162,8 @@ api_platform:
# The list of enabled formats. The first one will be the default.
formats:
jsonld:
mime_types: ['application/ld+json']
# jsonld:
# mime_types: ['application/ld+json']
json:
mime_types: ['application/json']
@ -178,7 +178,9 @@ api_platform:
jsonproblem:
mime_types: ['application/problem+json']
jsonld:
mime_types: ['application/ld+json']
# jsonld:
# mime_types: ['application/ld+json']
# ...
framework:
serializer: { enable_annotations: true }

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: true
intercept_redirects: false
framework:
profiler: { only_exceptions: false }

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: false
intercept_redirects: false
framework:
profiler: { collect: false }

View File

@ -0,0 +1,7 @@
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler

View File

@ -5,7 +5,7 @@ install:
npm install;
api-start:
bin/console server:start *:3000;
bin/console server:start *:8000;
api-stop:
bin/console server:stop;

View File

@ -2,18 +2,23 @@
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Query;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
/**
* Question
*
* @ApiResource()
* @ORM\Table("question")
* @ORM\Table(name="question")
* @ORM\Entity(repositoryClass="App\Repository\QuestionRepository")
*/
class Question
@ -26,49 +31,34 @@ class Question
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $text;
/**
* @var Collection<Service>
*
* @ORM\JoinColumn(nullable=true)
* @ORM\ManyToOne(targetEntity="Response")
* @ORM\JoinColumn(name="id", referencedColumnName="id")
* @ApiSubresource()
*/
private $response;
/**
* @var Collection<Service>
*
* @ORM\OneToMany(targetEntity="Response", mappedBy="id")
* @ORM\JoinColumn(name="id", referencedColumnName="id")
* @ApiSubresource()
*/
private $responses;
/**
* @ORM\Column(type="boolean")
*/
private $valided;
/**
* @ORM\Column(type="boolean")
*/
private $gameover;
/**
* @ORM\Column(type="datetime")
*/
private $date;
public function __construct()
/**
* @ORM\OneToMany(targetEntity="App\Entity\Response", mappedBy="question")
* @ORM\JoinTable(name="response")
* @ApiSubresource()
*/
private $responses;
public function __construct(TestSerializer $testSerializer)
{
$this->responses = new ArrayCollection();
$this->date = new \DateTime();
$this->testSerializer = $testSerializer;
}
public function __invoke(Question $question): Question
{
$this->testSerializer->test();
return $question;
}
public function getId()
@ -88,54 +78,6 @@ class Question
return $this;
}
public function getResponse()
{
return $this->response;
}
public function setResponse($response): self
{
$this->response = $response;
return $this;
}
public function getResponses()
{
return $this->responses;
}
public function setResponses($responses): self
{
$this->responses = $responses;
return $this;
}
public function getValided(): ?bool
{
return $this->valided;
}
public function setValided(bool $valided): self
{
$this->valided = $valided;
return $this;
}
public function getGameover(): ?bool
{
return $this->gameover;
}
public function setGameover(bool $gameover): self
{
$this->gameover = $gameover;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
@ -147,4 +89,35 @@ class Question
return $this;
}
/**
* @return Collection|Response[]
*/
public function getResponses(): Collection
{
return $this->responses;
}
public function addResponse(Response $response): self
{
if (!$this->responses->contains($response)) {
$this->responses[] = $response;
$response->setQuestion($this);
}
return $this;
}
public function removeResponse(Response $response): self
{
if ($this->responses->contains($response)) {
$this->responses->removeElement($response);
// set the owning side to null (unless already changed)
if ($response->getQuestion() === $this) {
$response->setQuestion(null);
}
}
return $this;
}
}

View File

@ -9,8 +9,6 @@ use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Annotation\ApiSubresource;
/**
* Response
*
* @ApiResource()
* @ORM\Table(name="response")
* @ORM\Entity(repositoryClass="App\Repository\ResponseRepository")
@ -30,15 +28,14 @@ class Response
private $text;
/**
* @ORM\ManyToOne(targetEntity="Question", inversedBy="reponses", cascade={"persist"})
* @ORM\JoinColumn(name="id", referencedColumnName="id", onDelete="SET NULL")
* @ApiSubresource()
* @ORM\ManyToOne(targetEntity="App\Entity\Question", inversedBy="responses")
* @ORM\JoinTable(name="question")
*/
private $question;
/**
* @ORM\OneToMany(targetEntity="Question", mappedBy="response")
* @ORM\Column(type="json_array")
* @ORM\OneToOne(targetEntity="App\Entity\Question", cascade={"persist", "remove"})
* @ORM\JoinTable(name="question")
*/
private $child;
@ -59,24 +56,24 @@ class Response
return $this;
}
public function getQuestion(): ?int
public function getQuestion(): ?Question
{
return $this->question;
}
public function setQuestion(int $question): self
public function setQuestion(?Question $question): self
{
$this->question = $question;
return $this;
}
public function getChild()
public function getChild(): ?Question
{
return $this->child;
}
public function setChild($child): self
public function setChild(?Question $child): self
{
$this->child = $child;

View File

@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20180529075445 extends AbstractMigration
{
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE response ADD question_id INT DEFAULT NULL, ADD child_id INT DEFAULT NULL, DROP child');
$this->addSql('ALTER TABLE response ADD CONSTRAINT FK_3E7B0BFB1E27F6BF FOREIGN KEY (question_id) REFERENCES question (id)');
$this->addSql('ALTER TABLE response ADD CONSTRAINT FK_3E7B0BFBDD62C21B FOREIGN KEY (child_id) REFERENCES question (id)');
$this->addSql('CREATE INDEX IDX_3E7B0BFB1E27F6BF ON response (question_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_3E7B0BFBDD62C21B ON response (child_id)');
$this->addSql('ALTER TABLE question DROP response, DROP responses, DROP valided, DROP gameover');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE question ADD response INT NOT NULL, ADD responses JSON DEFAULT NULL COMMENT \'(DC2Type:json_array)\', ADD valided TINYINT(1) NOT NULL, ADD gameover TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE response DROP FOREIGN KEY FK_3E7B0BFB1E27F6BF');
$this->addSql('ALTER TABLE response DROP FOREIGN KEY FK_3E7B0BFBDD62C21B');
$this->addSql('DROP INDEX IDX_3E7B0BFB1E27F6BF ON response');
$this->addSql('DROP INDEX UNIQ_3E7B0BFBDD62C21B ON response');
$this->addSql('ALTER TABLE response ADD child JSON NOT NULL COMMENT \'(DC2Type:json_array)\', DROP question_id, DROP child_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Created by PhpStorm.
* User: sundowndev
* Date: 30/05/18
* Time: 17:20
*/
namespace App\Service;
use App\Entity\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ResponseService
{
//private $object;
private $response;
public function __construct(Response $response)
{
$this->response = $response;
}
public function persistResponses(array $data, $question)
{
$entityManager = $this->getDoctrine()->getManager();
foreach ($data as $text) {
$entity = new Response();
$entity->setText($text);
$entity->setQuestion($question);
// tell Doctrine you want to (eventually) save the Product (no queries yet)
$entityManager->persist($entity);
// actually executes the queries (i.e. the INSERT query)
$entityManager->flush();
}
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Created by PhpStorm.
* User: sundowndev
* Date: 30/05/18
* Time: 16:31
*/
namespace App\Service;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class TestSerializer
{
public function test ($data, Serializer $serializer)
{
return $serializer->denormalize($data);
}
}

View File

@ -194,12 +194,21 @@
"symfony/orm-pack": {
"version": "v1.0.5"
},
"symfony/polyfill-ctype": {
"version": "v1.8.0"
},
"symfony/polyfill-mbstring": {
"version": "v1.8.0"
},
"symfony/polyfill-php72": {
"version": "v1.8.0"
},
"symfony/process": {
"version": "v4.0.9"
},
"symfony/profiler-pack": {
"version": "v1.0.3"
},
"symfony/property-access": {
"version": "v4.0.9"
},
@ -230,6 +239,9 @@
"symfony/serializer": {
"version": "v4.0.9"
},
"symfony/stopwatch": {
"version": "v4.0.11"
},
"symfony/translation": {
"version": "3.3",
"recipe": {
@ -254,6 +266,18 @@
"symfony/validator": {
"version": "v4.0.9"
},
"symfony/var-dumper": {
"version": "v4.0.11"
},
"symfony/web-profiler-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6"
}
},
"symfony/web-server-bundle": {
"version": "3.3",
"recipe": {