From 03365a1fc8991a4a105a92c1ccbd82eaa900e04a Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 27 May 2021 11:46:30 +0200 Subject: [PATCH] NEW FEATURE: overview of runs --- assets/job/view.js | 1 + assets/job/view.scss | 1 + config/routes.yaml | 3 ++- lib/Framework/Repository.php | 17 +++++++++++++ src/Controller/JobController.php | 7 ++++-- src/Repository/Job.php | 11 ++------- src/Repository/Run.php | 29 ++++++++++++++++++++++ src/Repository/User.php | 9 ++----- templates/job/view.html.twig | 41 ++++++++++++++++++++++++++++++++ webpack.config.js | 1 + 10 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 assets/job/view.js create mode 100644 assets/job/view.scss create mode 100644 lib/Framework/Repository.php create mode 100644 src/Repository/Run.php create mode 100644 templates/job/view.html.twig diff --git a/assets/job/view.js b/assets/job/view.js new file mode 100644 index 0000000..250f0ac --- /dev/null +++ b/assets/job/view.js @@ -0,0 +1 @@ +import 'bootstrap'; \ No newline at end of file diff --git a/assets/job/view.scss b/assets/job/view.scss new file mode 100644 index 0000000..3dc130c --- /dev/null +++ b/assets/job/view.scss @@ -0,0 +1 @@ +@import "~bootstrap/dist/css/bootstrap.css"; \ No newline at end of file diff --git a/config/routes.yaml b/config/routes.yaml index 75c2604..c86e30c 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -25,10 +25,11 @@ job_index: _controller: JeroenED\Webcron\Controller\JobController::defaultAction job_view: - path: '/job/{id}' + path: '/job/{id}/{all}' methods: [ 'GET' ] defaults: _controller: JeroenED\Webcron\Controller\JobController::jobAction + all: false requirements: id: \d+ diff --git a/lib/Framework/Repository.php b/lib/Framework/Repository.php new file mode 100644 index 0000000..eb1f1fd --- /dev/null +++ b/lib/Framework/Repository.php @@ -0,0 +1,17 @@ +dbcon = $dbcon; + } +} \ No newline at end of file diff --git a/src/Controller/JobController.php b/src/Controller/JobController.php index 0ccd183..2178bd8 100644 --- a/src/Controller/JobController.php +++ b/src/Controller/JobController.php @@ -5,6 +5,7 @@ namespace JeroenED\Webcron\Controller; use JeroenED\Framework\Controller; use JeroenED\Webcron\Repository\Job; +use JeroenED\Webcron\Repository\Run; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; @@ -21,16 +22,18 @@ class JobController extends Controller return $this->render('job/index.html.twig', ['jobs' => $jobs]); } - public function jobAction($id) + public function jobAction($id, $all = false) { if(!isset($_SESSION['isAuthenticated']) || !$_SESSION['isAuthenticated']) { return new RedirectResponse($this->generateRoute('login')); } $jobRepo = new Job($this->getDbCon()); + $runRepo = new Run($this->getDbCon()); if($this->getRequest()->getMethod() == 'GET') { $job = $jobRepo->getJob($id); - return new Response('Not implemented, yet', Response::HTTP_NOT_IMPLEMENTED); + $runs = $runRepo->getRunsForJob($id, $all != 'all' ? [$job['data']['response']] : []); + return $this->render('job/view.html.twig', ['job' => $job, 'runs' => $runs, 'allruns' => $all == 'all']); } elseif($this->getRequest()->getMethod() == 'DELETE') { $success = $jobRepo->deleteJob($id); $this->addFlash('success', $success['message']); diff --git a/src/Repository/Job.php b/src/Repository/Job.php index 95b19c0..00b0c55 100644 --- a/src/Repository/Job.php +++ b/src/Repository/Job.php @@ -5,20 +5,13 @@ namespace JeroenED\Webcron\Repository; use DateTime; -use Doctrine\DBAL\Connection; use GuzzleHttp\Client; +use JeroenED\Framework\Repository; use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Net\SSH2; -class Job +class Job extends Repository { - private Connection $dbcon; - - public function __construct(Connection $dbcon) - { - $this->dbcon = $dbcon; - } - public function getAllJobs() { $jobsSql = "SELECT * FROM job"; diff --git a/src/Repository/Run.php b/src/Repository/Run.php new file mode 100644 index 0000000..8dd3199 --- /dev/null +++ b/src/Repository/Run.php @@ -0,0 +1,29 @@ + $id]; + if (!empty($excludedexitcodes)) { + $runsSql .= ' AND exitcode NOT in ('; + foreach($excludedexitcodes as $key => $exitcode) { + $runsSql .= ':code' . $key; + $params[':code' . $key] = $exitcode; + } + $runsSql .= ')'; + } + if ($ordered) $runsSql .= ' ORDER by timestamp DESC'; + $runsStmt = $this->dbcon->prepare($runsSql); + $runsRslt = $runsStmt->executeQuery($params); + $runs = $runsRslt->fetchAllAssociative(); + return $runs; + } +} \ No newline at end of file diff --git a/src/Repository/User.php b/src/Repository/User.php index ada8125..dc65b1e 100644 --- a/src/Repository/User.php +++ b/src/Repository/User.php @@ -5,15 +5,10 @@ namespace JeroenED\Webcron\Repository; use Doctrine\DBAL\Connection; +use JeroenED\Framework\Repository; -class User +class User extends Repository { - private Connection $dbcon; - - public function __construct(Connection $dbcon) - { - $this->dbcon = $dbcon; - } /** * @param string $user diff --git a/templates/job/view.html.twig b/templates/job/view.html.twig new file mode 100644 index 0000000..f0b0eaa --- /dev/null +++ b/templates/job/view.html.twig @@ -0,0 +1,41 @@ +{% extends "base.html.twig" %} +{% block title %}Overview of run for {{ job.name }}{% endblock %} +{% block content %} +

Overview of runs for {{ job.name }}

+

+ Edit job + {% if allruns %} | Only show failed runs + {% elseif not allruns %} | Show all runs + {% endif %} +

+
+ {% for run in runs %} +
+
+

+ +

+
+
+
+
{{ run.output }}
+
+
+
+ {% else %} +

No {% if not allruns %}failed {% endif %}runs found

+

Show all runs

+ {% endfor %} +
+{% endblock %} + +{% block styles %} + {{ encore_entry_link_tags('job.view') }} +{% endblock %} + +{% block scripts %} + {{ encore_entry_script_tags('job.view') }} +{% endblock %} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index b9632a1..94edbc0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -25,6 +25,7 @@ Encore */ .addEntry('security.login', ['./assets/security/login.js', './assets/security/login.scss']) .addEntry('job.index', ['./assets/job/index.js', './assets/job/index.scss']) + .addEntry('job.view', ['./assets/job/view.js', './assets/job/view.scss']) .addEntry('job.add', ['./assets/job/add.js', './assets/job/add.scss']) //.addEntry('page1', './assets/page1.js') //.addEntry('page2', './assets/page2.js')