new table form html, css

This commit is contained in:
2018-07-21 18:06:37 +02:00
parent ba721592cd
commit 3242ae9cbe
26 changed files with 749 additions and 148 deletions
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
use App\View\WidgetFactory;
/** Facade for easy widget rendering in View */
class WidgetFacade extends Facade
{
protected static function getFacadeAccessor()
{
return WidgetFactory::class;
}
}
-10
View File
@@ -6,16 +6,6 @@ use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
+17 -3
View File
@@ -14,9 +14,9 @@ class TableController extends Controller
public function create()
{
$exampleColSpec =
"string, latin, Latin Name\n".
"string, common, Common Name\n".
"int, lifespan, Lifespan";
"latin, string, Latin Name\n".
"common, string, Common Name\n".
"lifespan, int, Lifespan (years)";
$exampleData =
"Mercenaria mercenaria, hard clam, 40\n" .
@@ -27,4 +27,18 @@ class TableController extends Controller
compact('exampleColSpec', 'exampleData')
);
}
public function storeNew(Request $request)
{
$this->validate($request, [
'table-name' => 'required',
'table-descr' => 'string|nullable',
'license' => 'string|nullable',
'upstream' => 'string|nullable',
'col-spec' => 'required',
'row-data' => 'string|nullable',
]);
return "Ok.";
}
}
+4 -1
View File
@@ -2,6 +2,7 @@
namespace App\Providers;
use App\View\WidgetFactory;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -25,6 +26,8 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
//
$this->app->singleton(WidgetFactory::class, function () {
return new WidgetFactory();
});
}
}
+5 -1
View File
@@ -53,7 +53,11 @@ class RouteServiceProvider extends ServiceProvider
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
->group(base_path('routes/public.php'));
Route::middleware(['web', 'auth'])
->namespace($this->namespace)
->group(base_path('routes/user.php'));
}
/**
+108
View File
@@ -0,0 +1,108 @@
<?php
namespace App\View;
/**
* Widget
*
* @property-read string $name
* @property-read string $id
* @property-read string $label
* @property-read string|null $help
* @property-read string|null $value
* @property-read string $attributes
*/
class Widget
{
private $attributes = [],
$id, $name, $label, $value,
$viewName,
$help,
$style = [];
public function __construct($viewName, $name, $label)
{
$this->id = 'field-'.$name;
$this->name = $name;
$this->label = $label;
$this->viewName = $viewName;
}
// setting attributes via magic method
public function __call($method, $args)
{
static $cssProps = [
'height', 'minHeight', 'maxHeight'
];
if (empty($args)) $args = [''];
$arg = $args[0];
// css
$lccamel = $method;
if (in_array($lccamel, $cssProps)) {
return $this->css(kebab_case($lccamel), $arg);
}
if (property_exists($this, $method)) {
$this->$method = $arg;
}
else {
$this->attributes[$method] = $arg;
}
return $this;
}
public function css($prop, $val)
{
$this->style[$prop] = $val;
return $this;
}
public function __get($name)
{
if ($name == 'attributes') {
return $this->compileAttribs();
}
if ($name == 'value') {
return old($this->name, $this->value);
}
if (property_exists($this, $name)) {
return $this->$name;
}
return null;
}
public function compileAttribs()
{
// compile attribs string
$attribs_s = array_reduce(array_keys($this->attributes), function ($carry, $key) {
return $carry . ' ' . $key . '="' . e($this->attributes[$key]) . '"';
}, '');
// add a compiled list of styles
if (!empty($this->style)) {
$attribs_s .= 'style="'.trim(e(array_reduce(array_keys($this->style), function ($carry, $key) {
return $carry . $key . ': ' . $this->style[$key] . '; ';
}, ''))).'"';
}
return trim($attribs_s);
}
public function render()
{
return view('form.'.$this->viewName)->with(['w' => $this]);
}
public function __toString()
{
return (string) $this->render();
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace App\View;
class WidgetFactory
{
public function text($name, $label)
{
return new Widget('input', $name, $label);
}
public function number($name, $label)
{
return new Widget('number', $name, $label);
}
public function email($name, $label)
{
return new Widget('email', $name, $label);
}
public function textarea($name, $label)
{
return (new Widget('textarea', $name, $label))->minHeight('4em');
}
}