From e8f528574a794a20744bde6e96f0ca9c6b1d6c67 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 3 Jan 2023 10:50:07 +0100 Subject: [PATCH] fake afnor --- .env | 13 ++++---- .gitignore | 1 + assets/js/app.js | 11 +++++++ config/services.yaml | 1 + docker-compose.yml | 28 ++-------------- src/Controller/HomeController.php | 32 ++++++++++++++++++- src/Form/AfnorType.php | 53 +++++++++++++++++++++++++++++++ src/Service/SftpService.php | 2 -- templates/Home/home.html.twig | 46 +++++++++++++++++++++++++++ 9 files changed, 152 insertions(+), 35 deletions(-) create mode 100644 src/Form/AfnorType.php diff --git a/.env b/.env index 9e3b01b..063f757 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -APP_ENV=prod +APP_ENV=dev APP_SECRET=changeme MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 @@ -10,9 +10,10 @@ MERCURE_URL=https://example.com/.well-known/mercure MERCURE_PUBLIC_URL=https://example.com/.well-known/mercure MERCURE_JWT_SECRET="!ChangeThisMercureHubJWTSecretKey!" -SFTP_HOST=localhost -SFTP_PORT=2222 -SFTP_USER=user -SFTP_PASSWORD=changeme -SFTP_FOLDER=upload +SFTP_HOST=$SFTP_HOST +SFTP_PORT=$SFTP_PORT +SFTP_USER=$SFTP_USER +SFTP_PASSWORD=$SFTP_PASSWORD +SFTP_FOLDER=$SFTP_FOLDER +FAKE_FILES=$FAKE_FILES diff --git a/.gitignore b/.gitignore index b072513..add0e7d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /public/bundles/ /var/ /vendor/ +/sftp/ ###< symfony/framework-bundle ### ###> symfony/webpack-encore-bundle ### diff --git a/assets/js/app.js b/assets/js/app.js index 924fbc2..f35f2dd 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -30,6 +30,17 @@ $(document).ready(function() { $("#"+$(this).data("modalid")).modal("show"); }); + $('.add-another-collection-widget').click(function (e) { + var list = $($(this).attr('data-list-selector')); + var counter = list.data('widget-counter') || list.children().length; + var newWidget = list.attr('data-prototype'); + newWidget = newWidget.replace(/__name__/g, counter); + counter++; + list.data('widget-counter', counter); + var newElem = $(list.attr('data-widget-tags')).html(newWidget); + newElem.appendTo(list); + }); + // Resize resize(); diff --git a/config/services.yaml b/config/services.yaml index f91afe6..3b8bdb1 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -4,6 +4,7 @@ parameters: sftpUser: '%env(resolve:SFTP_USER)%' sftpPassword: '%env(resolve:SFTP_PASSWORD)%' sftpFolder: '%env(resolve:SFTP_FOLDER)%' + fakeFiles: '%env(json:FAKE_FILES)%' services: _defaults: diff --git a/docker-compose.yml b/docker-compose.yml index 4f69d27..5b1e6f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,31 +5,7 @@ services: image: atmoz/sftp container_name: sftp volumes: - - ./sftp:/home/efs/upload + - ./sftp:/home/user/upload ports: - "2222:22" - command: efs:changeme:1000 - -###> symfony/mercure-bundle ### - mercure: - image: dunglas/mercure - restart: unless-stopped - environment: - SERVER_NAME: ':80' - MERCURE_PUBLISHER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!' - MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeThisMercureHubJWTSecretKey!' - # Set the URL of your Symfony project (without trailing slash!) as value of the cors_origins directive - MERCURE_EXTRA_DIRECTIVES: | - cors_origins http://127.0.0.1:8000 - # Comment the following line to disable the development mode - command: /usr/bin/caddy run -config /etc/caddy/Caddyfile.dev - volumes: - - mercure_data:/data - - mercure_config:/config -###< symfony/mercure-bundle ### - -volumes: -###> symfony/mercure-bundle ### - mercure_data: - mercure_config: -###< symfony/mercure-bundle ### + command: user:changeme:::upload \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 83aac07..40876bc 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -4,12 +4,14 @@ namespace App\Controller; use App\Form\FolderType; use App\Form\FileType; +use App\Form\AfnorType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use App\Service\SftpService; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\ResponseHeaderBag; +use Symfony\Component\Filesystem\Filesystem; class HomeController extends AbstractController { @@ -42,6 +44,31 @@ class HomeController extends AbstractController $this->sftp->rename($folder."/".$oldname,$folder."/".$name); } + // Fake AFNOR + $formAfnor = $this->createForm(AfnorType::class); + $formAfnor->handleRequest($request); + if ($formAfnor->get('submit')->isClicked()) { + $id = $formAfnor->get("id")->getData(); + $codeproduct = $formAfnor->get("codeproduct")->getData(); + $codequalifications = $formAfnor->get("codequalifications")->getData(); + + $filesystem = new Filesystem(); + $dir = $this->getParameter('kernel.project_dir').'/var/tmp'; + + $file ="gc,".$id."\n"; + $file.="ph\n"; + $file.="pj,".$codeproduct."\n"; + + foreach($codequalifications as $codequalification) { + $file.="qa\n"; + $file.="qh,".$codequalification."\n"; + } + + $filesystem->dumpFile($dir.'/DEL-'.$id.'.AFN', $file); + $return=$this->sftp->uploadFile($dir.'/DEL-'.$id.'.AFN', $folder); + + } + // Lister les fichiers $ls=$this->sftp->ls($folder); @@ -65,8 +92,11 @@ class HomeController extends AbstractController 'infolder' => $folder, 'folders' => $ls["folders"], 'files' => $ls["files"], + 'fakeAfnor'=>in_array("AFNOR",$this->getParameter("fakeFiles")), 'formfolder'=>$formFolder->createView(), 'formfile'=>$formFile->createView(), + 'formafnor'=>$formAfnor->createView(), + ]); } @@ -78,7 +108,7 @@ class HomeController extends AbstractController throw new \Exception('Erreur de téléchargement'); } - if (str_starts_with(mime_content_type($tmpfile), 'image/') || 'application/pdf' == mime_content_type($tmpfile)) { + if (str_starts_with(mime_content_type($tmpfile), 'image/') || 'application/pdf' == mime_content_type($tmpfile) || 'text/plain' == mime_content_type($tmpfile)) { $response = new BinaryFileResponse($tmpfile); $response->headers->set('Content-Type', mime_content_type($tmpfile)); } else { diff --git a/src/Form/AfnorType.php b/src/Form/AfnorType.php new file mode 100644 index 0000000..1ce225d --- /dev/null +++ b/src/Form/AfnorType.php @@ -0,0 +1,53 @@ +add('submit', + SubmitType::class, [ + 'label' => 'Valider', + 'attr' => ['class' => 'btn btn-success mb-5'], + ] + ); + + $builder->add('id', + TextType::class, [ + 'mapped' => false, + 'label' => 'ID Déliverance', + 'required' => true, + ] + ); + + + $builder->add('codeproduct', + TextType::class, [ + 'mapped' => false, + 'label' => 'Code Produit', + 'required' => true, + ] + ); + + $builder->add('codequalifications', CollectionType::class, [ + 'entry_type' => TextType::class, + 'label' => 'Codes Qualification', + 'allow_add' => true, + 'required' => false, + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + ]); + } +} diff --git a/src/Service/SftpService.php b/src/Service/SftpService.php index 4100575..148d30a 100644 --- a/src/Service/SftpService.php +++ b/src/Service/SftpService.php @@ -71,10 +71,8 @@ class SftpService $sftp = $this->sftp; $remotePath = 'ssh2.sftp://'.join(DIRECTORY_SEPARATOR, [$sftp, $this->folder.$remoteFolder."/".$baseName]); - echo($remotePath); $stream = @fopen($remotePath, 'w'); if (!$stream) { - echo "here"; return false; } $localStream = fopen($localFile, 'r'); diff --git a/templates/Home/home.html.twig b/templates/Home/home.html.twig index 0d6d899..511037a 100644 --- a/templates/Home/home.html.twig +++ b/templates/Home/home.html.twig @@ -2,6 +2,12 @@ {% block body %}
+ {% if fakeAfnor %} + + {% endif %} + @@ -77,6 +83,38 @@
+ + {% endblock %} {% block localscript %} @@ -92,5 +130,13 @@ $('#file_name').val(file); $('#file_name').focus(); } + + function showAfnor() { + $('#afnor').modal('show'); + } + + + + {% endblock %} \ No newline at end of file