Renamed AdminPanel to DeltaCMS

lot of changes :p
This commit is contained in:
Florian Bouillon 2019-04-25 17:13:02 +02:00
parent d73566086c
commit e4d320e5e7
45 changed files with 299 additions and 186 deletions

View File

@ -60,8 +60,8 @@ steps:
commands:
- chmod +x prepare.sh && ./prepare.sh
- php composer.phar install --no-dev --optimize-autoloader
- cat production.txt | zip AdminPanel.zip -r -@
- tar -cvzf AdminPanel.tar.gz -T production.txt
- cat production.txt | zip DeltaCMS.zip -r -@
- tar -cvzf DeltaCMS.tar.gz -T production.txt
when:
event: tag
@ -72,8 +72,8 @@ steps:
from_secret: gitea_token
base_url: https://git.delta-wings.net/
files:
- AdminPanel.zip
- AdminPanel.tar.gz
- DeltaCMS.zip
- DeltaCMS.tar.gz
checksum:
- md5
- sha1

View File

@ -54,14 +54,14 @@ _([ci.delta-wings.net](https://ci.delta-wings.net))_
### Coverage
_([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
_([Codacy](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard))_
![coverage](https://img.shields.io/codacy/coverage/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge)
`https://img.shields.io/codacy/coverage/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge`
### Code Quality
_([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
_([Codacy](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard))_
![Code Quality](https://img.shields.io/codacy/grade/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge)
`https://img.shields.io/codacy/grade/bf7f9ac73707426e9afc4b9daa950039.svg?style=for-the-badge`
@ -84,6 +84,6 @@ _([Codacy](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard))_
- [PHP Mess Detector](https://phpmd.org/)
- Hosting
- [Gitlab](https://gitlab.com/) _Project url [here](https://gitlab.com/delta-wings/adminpanel)_
- [Gitea](https://gitea.io/) _Current server [here](https://git.delta-wings.net/Avior/AdminPanel)_
- [Gitea](https://gitea.io/) _Current server [here](https://git.delta-wings.net/Avior/DeltaCMS)_
- [Drone](https://drone.io/) _Current server [here](https://ci.delta-wings.net/)_
- [Codacy](https://codacy.com/) _Project Dashboard [here](https://app.codacy.com/project/Aviorleking/AdminPanel/dashboard)_
- [Codacy](https://codacy.com/) _Project Dashboard [here](https://app.codacy.com/project/Aviorleking/DeltaCMS/dashboard)_

View File

@ -11,14 +11,14 @@
],
"autoload": {
"psr-4": {
"AdminPanel\\": "src/AdminPanel",
"DeltaCMS\\": "src/DeltaCMS",
"": "src/Modules"
},
"exclude-from-classmap": [
"src/Modules"
],
"files": [
"src/AdminPanel/Functions.php"
"src/DeltaCMS/Functions.php"
]
},
"require": {

View File

@ -24,7 +24,7 @@
"path": "cache/",
// driver to use with cache
"driver": "\\AdminPanel\\Cache\\FileCache",
"driver": "\\DeltaCMS\\Cache\\FileCache",
"options": {
"ttl": null
}

View File

@ -5,7 +5,7 @@
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<description>AdminPanel rules</description>
<description>DeltaCMS rules</description>
<!-- <rule ref="rulesets/cleancode.xml"/> -->
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/controversial.xml"/>

View File

@ -25,7 +25,7 @@
verbose="false">
<filter>
<whitelist>
<directory>src/AdminPanel</directory>
<directory>src/DeltaCMS</directory>
</whitelist>
</filter>
<testsuites>

View File

@ -1,6 +1,6 @@
<?php
use AdminPanel\AdminPanel;
use DeltaCMS\DeltaCMS;
session_start();
ini_set('display_errors', 'On');
@ -9,7 +9,7 @@ ini_set('display_errors', 'On');
$loader = require_once __DIR__ . "/../vendor/autoload.php";
//die;
$ap = AdminPanel::getInstance();
$ap = DeltaCMS::getInstance();
// dd($ap);
/*
1: get all the template folders
@ -94,7 +94,7 @@ foreach ($caches['routes'] as $key => $value) {
$loader->loadClass($value->controller);
$function = $value->function;
// dump($function);
/** @var AdminPanel\Classes\Controller $controller */
/** @var DeltaCMS\Classes\Controller $controller */
$controller = new $value->controller();
// dd(new $routeArgs->controller());
if ($composants) {

View File

@ -1,87 +0,0 @@
<?php
namespace AdminPanel;
use AdminPanel\Cache\SessionCache;
class Form
{
private $session = null;
private $formname = null;
private function isSubmitting($fields)
{
$entity = $this->session->get("form_" . $this->formname);
if (isset($entity)) {
foreach (array_keys((array) $fields) as $name) {
if (filter_input(INPUT_POST, $name) === null) {
return false;
}
}
return true;
}
return false;
}
private function addField($name, $settings)
{
// get class
if (strstr($settings->type, "\\") === false) {
$settings->type = "\\AdminPanel\\Form\\" . ucfirst($settings->type) . "Input";
}
/** @var \AdminPanel\Form\Input */
$field = new $settings->type();
$entity = $this->session->get("form_" . $this->formname);
// dd($entity);
$func = "get" . ucfirst($name);
$options = array(
'name' => $name,
'attr' => array(),
'label' => isset($settings->label) ? $settings->label : null,
'value' => $entity !== null && $entity->$func() !== null ? $entity->$func() : null
);
$fieldOptions = array_merge(
$field->getOptions(),
array_keys($options)
);
foreach ($settings as $opt => $value) {
if (in_array($opt, $fieldOptions)) {
$options = array_merge(
$options,
$field->processOption($opt, $value)
);
} else {
$options["attr"][$opt] = $value;
}
}
$this->$name = AdminPanel::getInstance()->getTwig()->render($field->getTemplate(), $options);
}
public function __construct(string $formname, $entity = null)
{
// dd($entity);
$cache = AdminPanel::getInstance()->getCache();
$forms = $cache->get("forms");
$this->session = new SessionCache();
if (isset($forms[$formname])) {
$this->formname = $formname;
$form = $forms[$formname];
if ($this->isSubmitting($form->fields)) {
dd("submitting");
}
dump("not submitting");
if (isset($form->entity) && (!isset($entity) || !($entity instanceof $form->entity))) {
$entity = new $form->entity();
}
$this->session->set("form_" . $this->formname, $entity);
foreach ($form->fields as $name => $settings) {
$this->addField($name, $settings);
}
}
}
}

View File

@ -1 +0,0 @@
{% extends "@AdminPanel/form/_default.twig" %}

View File

@ -1 +0,0 @@
{% extends "@AdminPanel/form/_default.twig" %}

View File

@ -1 +0,0 @@
{% extends "@AdminPanel/form/_default.twig" %}

View File

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ title }}</title>
{% block styles %}{% endblock %}
{% block scripts %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

View File

@ -5,18 +5,18 @@
* @since 1.0.0
*/
namespace AdminPanel;
namespace DeltaCMS;
use Twig\Loader\FilesystemLoader;
use Twig\Environment;
use AdminPanel\Cache\FileCache;
use DeltaCMS\Cache\FileCache;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use AdminPanel\Logger;
use DeltaCMS\Logger;
class AdminPanel
class DeltaCMS
{
/** @var AdminPanel $instance */
/** @var DeltaCMS $instance */
private static $instance = null;
/** @var string $root */
@ -25,12 +25,12 @@ class AdminPanel
private $settings = null;
/**
* Get actual AdminPanel instance
* Get actual DeltaCMS instance
*
* @param array $settings
* Settings to set to the software
*
* @return AdminPanel
* @return DeltaCMS
*/
public static function getInstance()
{
@ -40,7 +40,7 @@ class AdminPanel
$ap->root = dirname(__DIR__);
$ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false);
$ap->loader = new FilesystemLoader();
$ap->addLoaderFolder($ap->root . "/AdminPanel/Twig");
$ap->addLoaderFolder($ap->root . "/DeltaCMS/Twig");
// $ap->setLoader(new FilesystemLoader());
}
return self::$instance;
@ -60,7 +60,7 @@ class AdminPanel
// $this->loader = $loader;
// }
public function addLoaderFolder(string $path, string $prefix = "AdminPanel")
public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
{
$this->loader->addPath($path, $prefix);
}
@ -75,6 +75,12 @@ class AdminPanel
}
private $cache;
/**
* Get the cache object used Site-wide
*
* @return \Psr\SimpleCache\CacheInterface
*/
public function getCache()
{
if (!$this->cache) {

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel;
namespace DeltaCMS;
class Authentificator
{

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Cache;
namespace DeltaCMS\Cache;
use Psr\SimpleCache\CacheInterface;

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Cache;
namespace DeltaCMS\Cache;
use Exception;

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Cache;
namespace DeltaCMS\Cache;
class FileCache extends AbstractCache
{

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Cache;
namespace DeltaCMS\Cache;
class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException
{

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Cache;
namespace DeltaCMS\Cache;
/**
* Session Cache (different type of cache because is per-user cache)

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel;
namespace DeltaCMS;
class Controller
{
@ -8,13 +8,13 @@ class Controller
protected $urlArguments = array();
protected $moduleRoot = null;
/** @var \AdminPanel\Cache\FileCache */
/** @var \DeltaCMS\Cache\FileCache */
protected $cache;
public function __construct()
{
$this->cache = AdminPanel::getInstance()->getCache();
$this->cache = DeltaCMS::getInstance()->getCache();
}
public function setUrlArguments($args)
@ -53,12 +53,12 @@ class Controller
protected function render($template, $args)
{
return AdminPanel::getInstance()->getTwig()->render($template, $args);
return DeltaCMS::getInstance()->getTwig()->render($template, $args);
}
protected function getEM()
{
return AdminPanel::getInstance()->getEM();
return DeltaCMS::getInstance()->getEM();
}

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel;
namespace DeltaCMS;
abstract class Enum
{

107
src/DeltaCMS/Form.php Normal file
View File

@ -0,0 +1,107 @@
<?php
namespace DeltaCMS;
use DeltaCMS\Cache\SessionCache;
use DeltaCMS\Form\Input;
class Form
{
private $session = null;
private $formname = null;
private $fields = null;
/**
* Check if form was submitted
*
* @return boolean
*/
public function isSubmitting()
{
return false;
$entity = $this->session->get("form_" . $this->formname);
if (isset($entity)) {
foreach (array_keys((array) $this->fields) as $name) {
if (filter_input(INPUT_POST, $name) === null) {
return false;
}
}
return true;
}
return false;
}
private function putFieldsInEntity($entity, $fields)
{
foreach ($fields as $name => $settings) {
$setter = "set" . ucfirst($name);
$adder = "add" . ucfirst($name);
$value = filter_input(INPUT_POST, $name);
$field = $this->getField($settings->type);
$value = $field->processValue($value, $settings);
if (is_callable(array($entity, $setter))) {
$entity->$setter($value);
} elseif (is_callable(array($entity, $adder))) {
$entity->$adder($value);
}
}
}
private function getField(string $type): Input
{
if (strstr($type, "\\") === false) {
$type = "\\DeltaCMS\\Form\\" . ucfirst($type) . "Input";
}
return new $type();
}
private function addField($name, $settings)
{
/** @var \DeltaCMS\Form\Input */
$field = $this->getField($settings->type);
$entity = $this->session->get("form_" . $this->formname, null);
$func = "get" . ucfirst($name);
$field->setOption("name", $name);
$entity !== null && method_exists($entity, $func) ? $field->setOption("value", $entity->$func()) : null;
foreach ($settings as $settingName => $value) {
$field->setOption($settingName, $value);
}
// dump($_POST[$name]);
dump($name, $field->getValue());
$this->$name = $field->render();
}
public function __construct(string $formname, $entity = null)
{
// dd($entity);
$cache = DeltaCMS::getInstance()->getCache();
$forms = $cache->get("forms");
$this->session = new SessionCache();
if (isset($forms[$formname])) {
$this->formname = $formname;
$form = $forms[$formname];
$this->fields = $form->fields;
// dd($this->fields);
if ($this->isSubmitting($this->fields)) {
if ($entity !== null) {
$this->putFieldsInEntity(
$entity,
$this->fields
);
}
}
if (isset($form->entity) && (!isset($entity) || !($entity instanceof $form->entity))) {
$entity = new $form->entity();
}
// send entity to session cache
$this->session->set("form_" . $this->formname, $entity);
foreach ($this->fields as $name => $settings) {
$this->addField($name, $settings);
}
}
}
}

View File

@ -1,8 +1,8 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
use AdminPanel\AdminPanel;
use DeltaCMS\DeltaCMS;
/**
* this abstract class has default functionnality for all working
@ -79,6 +79,19 @@ abstract class AbstractInput implements Input
}
}
protected function getValueFromPost($name = null)
{
if ($name !== null) {
return filter_input_array(INPUT_POST)[$this->attributes["name"]][$name];
}
return filter_input(INPUT_POST, $this->attributes["name"]);
}
public function getValue($name = null)
{
return $this->getValueFromPost($name);
}
public function render(): string
{
$arr = explode('\\', get_class($this));
@ -90,7 +103,7 @@ abstract class AbstractInput implements Input
)
);
return $this->getTwig()->render(
"@AdminPanel/form/" . $tpName . ".twig",
"@DeltaCMS/form/" . $tpName . ".twig",
array(
'attributes' => $this->attributes,
'options' => $this->options
@ -100,6 +113,6 @@ abstract class AbstractInput implements Input
protected function getTwig()
{
return AdminPanel::getInstance()->getTwig();
return DeltaCMS::getInstance()->getTwig();
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
class ArrayInput extends AbstractInput
{
@ -49,6 +49,21 @@ class ArrayInput extends AbstractInput
parent::setOption($name, $value);
}
public function getValue($name = null)
{
if (!isset($_POST[$this->attributes["name"]]) || empty($_POST[$this->attributes["name"]])) {
return array();
}
$clas = $this->options["array_type"];
$arr = array();
foreach ($_POST[$this->attributes["name"]] as $name => $value) {
$input = new $clas();
$input->setOption("name", $this->attributes["name"]);
$arr[] = $input->getValue($name);
}
return $arr;
}
public function render(): string
{
if (array_key_exists("array_type", $this->options) &&

View File

@ -1,8 +1,8 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
use AdminPanel\AdminPanel;
use DeltaCMS\DeltaCMS;
class ChoiceInput extends AbstractInput
{

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
class DatalistInput extends AbstractInput
{

View File

@ -1,21 +1,11 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
use DateTime;
class DateInput extends AbstractInput
{
public function getOption(string $name)
{
if ($name === "value") {
return new DateTime($this->options["name"]);
} else {
return parent::getOption($name);
}
}
public function setOption($name, $value)
{
if ($name === "value") {
@ -24,4 +14,9 @@ class DateInput extends AbstractInput
parent::setOption($name, $value);
}
}
public function getValue($name = null)
{
return new DateTime($this->getValueFromPost($name));
}
}

View File

@ -1,8 +1,8 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
use AdminPanel\AdminPanel;
use DeltaCMS\DeltaCMS;
class EntityInput extends AbstractInput
{
@ -16,7 +16,8 @@ class EntityInput extends AbstractInput
return array_merge(
parent::getOptionsList(),
array(
'entity'
'entity',
'field'
)
);
}
@ -24,22 +25,18 @@ class EntityInput extends AbstractInput
public function setOption(string $name, $value)
{
if ($name === 'entity') {
$this->options["entities"] = AdminPanel::getInstance()->getEm()->getRepository($value)->findAll();
$this->options["entities"] = DeltaCMS::getInstance()->getEm()->getRepository($value)->findAll();
} elseif ($name === "name") {
$this->attributes["list"] = $value . "_list";
}
parent::setOption($name, $value);
}
public function getOption($name)
public function getValue($name = null)
{
if ($name === "value") {
$repo = AdminPanel::getInstance()->getEm()->getRepository($this->options["entity"]);
return $repo->findOneBy(array(
'name' => $this->options["value"]
));
} else {
return parent::getOption($name);
}
$repo = DeltaCMS::getInstance()->getEm()->getRepository($this->options["entity"]);
return $repo->findOneBy(array(
$this->options['field'] => $this->getValueFromPost($name)
));
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
interface Input
{
@ -55,6 +55,15 @@ interface Input
*/
public function setOption(string $name, $value);
/**
* Get the value from $_POST & transform it into the correct type
*
* @param mixed $name index used
*
* @return mixed
*/
public function getValue($name = null);
/**
* return the html to render the current input
*

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
class NumberInput extends AbstractInput
{
@ -14,4 +14,9 @@ class NumberInput extends AbstractInput
)
);
}
public function getValue($name = null)
{
return (float) $this->getValueFromPost($name);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel\Form;
namespace DeltaCMS\Form;
class TextInput extends AbstractInput
{

View File

@ -1,6 +1,6 @@
<?php
namespace AdminPanel;
namespace DeltaCMS;
use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;

View File

@ -1,4 +1,4 @@
{% extends "@AdminPanel/form/_default.twig" %}
{% extends "@DeltaCMS/form/_default.twig" %}
{% set name = "div" %}

View File

@ -1,4 +1,4 @@
{% extends "@AdminPanel/form/_default.twig" %}
{% extends "@DeltaCMS/form/_default.twig" %}
{% set name = "select" %}

View File

@ -1,4 +1,4 @@
{% extends "@AdminPanel/form/_default.twig" %}
{% extends "@DeltaCMS/form/_default.twig" %}
{% block after %}
<datalist id="{{ attributes.list }}">

View File

@ -0,0 +1 @@
{% extends "@DeltaCMS/form/_default.twig" %}

View File

@ -1,4 +1,4 @@
{% extends "@AdminPanel/form/_default.twig" %}
{% extends "@DeltaCMS/form/_default.twig" %}
{% block after %}
<datalist id="{{ attributes.list }}">

View File

@ -0,0 +1 @@
{% extends "@DeltaCMS/form/_default.twig" %}

View File

@ -0,0 +1 @@
{% extends "@DeltaCMS/form/_default.twig" %}

View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{{ title }}</title>
{% block styles %}{% endblock %}
{% block scripts %}{% endblock %}
<script>
const deleteClick = (ev) => {
console.log(ev);
let btn = ev.target;
console.log(btn.parentElement);
btn.parentElement.remove();
}
const addClick = (ev) => {
let btn = ev.target;
let content = document.getElementById(btn.getAttribute("data-for"));
if (!content.hasAttribute("data-length")) {
content.setAttribute("data-length", content.children.length);
}
let length = parseInt(content.getAttribute("data-length"));
let placeholder = content.getAttribute("data-element").replace(/__unique__/g, length + 1);
let el = document.createElement("div");
el.innerHTML = placeholder;
content.appendChild(el);
content.setAttribute("data-length", length + 1);
reloadDeleteBtns();
}
const reloadDeleteBtns = () => {
let ele = document.querySelectorAll("[data-element]");
ele.forEach(element => {
for (const child of element.children) {
if (child.children.item(1) === null) {
let deletebtn = document.createElement("button");
deletebtn.innerText = "Suprimmer";
deletebtn.type = "button";
deletebtn.addEventListener("click", deleteClick);
child.appendChild(deletebtn);
} else {
child.children.item(1).addEventListener("click", deleteClick);
}
}
});
}
function init() {
reloadDeleteBtns();
let fore = document.querySelectorAll("[data-for]");
fore.forEach(element => {
element.addEventListener("click", addClick);
});
}
</script>
</head>
<body>
{% block body %}{% endblock %}
</body>
<script>
init();
</script>
</html>

View File

@ -2,8 +2,8 @@
namespace ModuleName\Controller;
use AdminPanel\Controller;
use AdminPanel\Authentificator;
use DeltaCMS\Controller;
use DeltaCMS\Authentificator;
class ExampleController extends Controller
{

View File

@ -1,8 +1,8 @@
<?php
use PHPUnit\Framework\TestCase;
use AdminPanel\Cache\FileCache;
use AdminPanel\Logger;
use DeltaCMS\Cache\FileCache;
use DeltaCMS\Logger;
use Psr\Log\InvalidArgumentException;
final class LoggerTest extends TestCase

View File

@ -1,7 +1,7 @@
<?php
use PHPUnit\Framework\TestCase;
use AdminPanel\Cache\SessionCache;
use DeltaCMS\Cache\SessionCache;
final class SessionCacheTest extends TestCase
{