Add theme change to /design page
This commit is contained in:
parent
149155fbda
commit
a5757497e5
|
@ -1,4 +1,4 @@
|
||||||
{% set theme = user.settings.theme|default(config('theme')) %}
|
{% set theme = theme|default(user.settings.theme|default(config('theme'))) %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ session_get('locale')|split('_')[0]|escape('html_attr') }}">
|
<html lang="{{ session_get('locale')|split('_')[0]|escape('html_attr') }}">
|
||||||
<head>
|
<head>
|
||||||
|
|
|
@ -8,21 +8,53 @@
|
||||||
{% set types=['default', 'primary', 'success', 'info', 'warning', 'danger'] %}
|
{% set types=['default', 'primary', 'success', 'info', 'warning', 'danger'] %}
|
||||||
{% set types_buttons=types|merge(['link']) %}
|
{% set types_buttons=types|merge(['link']) %}
|
||||||
{% set lipsum='Lorem ipsum dolor sit amet, consectetur adipisici elit…' %}
|
{% set lipsum='Lorem ipsum dolor sit amet, consectetur adipisici elit…' %}
|
||||||
{% set linksum='Lorem ipsum dolor <a href="#">link</a> amet, consectetur adipisici elit!' %}
|
{% set linksum='Lorem ipsum! Dolor <a href="#">link</a> amet, consectetur adipisici elit!' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }} <small>{{ themes[theme] }}</small></h1>
|
||||||
|
|
||||||
|
|
||||||
<h2>Elements</h2>
|
<h2>Elements <small>small</small></h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-2">
|
||||||
<h3>Headings</h3>
|
<h3>Headings <small>small</small></h3>
|
||||||
<h4>H4</h4>
|
<h4>H4 <small>small</small></h4>
|
||||||
<h5>H5</h5>
|
<h5>H5 <small>small</small></h5>
|
||||||
<h6>H6</h6>
|
<h6>H6 <small>small</small></h6>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h3>Lists</h3>
|
||||||
|
<p>
|
||||||
|
This page should be used when creating and testing new designs to find usability and/or design issues.
|
||||||
|
{{ lipsum|replace({'…': '.'}) }}
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>Unordered</li>
|
||||||
|
<li>List</li>
|
||||||
|
<li>Items</li>
|
||||||
|
</ul>
|
||||||
|
<ol>
|
||||||
|
<li>Ordered</li>
|
||||||
|
<li>List</li>
|
||||||
|
<li>Items</li>
|
||||||
|
</ol>
|
||||||
|
<p>{{ linksum|raw }} {{ lipsum }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h3>Themes</h3>
|
||||||
|
<ul>
|
||||||
|
{% for id,theme in themes|sort %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ url('design', {'theme': id}) }}">
|
||||||
|
{{ theme }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h3>Tables</h3>
|
<h3>Tables</h3>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
@ -43,6 +75,22 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<h3>Navigation Tabs</h3>
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
<li class="active"><a href="#">Lorem</a></li>
|
||||||
|
<li><a href="#">Ipsum</a></li>
|
||||||
|
<li><a href="#">Dolor</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 settings-menu">
|
||||||
|
<h3>Navigation Pills</h3>
|
||||||
|
<ul class="nav nav-pills nav-stacked">
|
||||||
|
<li class="active"><a href="#">Some</a></li>
|
||||||
|
<li><a href="#">Test</a></li>
|
||||||
|
<li><a href="#">Menu</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Engelsystem\Controllers;
|
namespace Engelsystem\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
|
use Engelsystem\Http\Request;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
use Engelsystem\Models\User\State;
|
use Engelsystem\Models\User\State;
|
||||||
use Engelsystem\Models\User\User;
|
use Engelsystem\Models\User\User;
|
||||||
|
@ -11,23 +13,30 @@ class DesignController extends BaseController
|
||||||
/** @var Response */
|
/** @var Response */
|
||||||
protected $response;
|
protected $response;
|
||||||
|
|
||||||
|
/** @var Config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
|
* @param Config $config
|
||||||
*/
|
*/
|
||||||
public function __construct(Response $response)
|
public function __construct(Response $response, Config $config)
|
||||||
{
|
{
|
||||||
|
$this->config = $config;
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the design overview page
|
* Show the design overview page
|
||||||
*
|
*
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$demoUser = (new User())->forceFill([
|
$demoUser = (new User())->forceFill([
|
||||||
'id' => 42,
|
'id' => 42,
|
||||||
'name' => 'test',
|
'name' => 'test',
|
||||||
]);
|
]);
|
||||||
$demoUser->__set('state', (new State())->forceFill([
|
$demoUser->__set('state', (new State())->forceFill([
|
||||||
|
@ -35,7 +44,7 @@ class DesignController extends BaseController
|
||||||
'arrived' => true,
|
'arrived' => true,
|
||||||
]));
|
]));
|
||||||
$demoUser2 = (new User())->forceFill([
|
$demoUser2 = (new User())->forceFill([
|
||||||
'id' => 1337,
|
'id' => 1337,
|
||||||
'name' => 'test2',
|
'name' => 'test2',
|
||||||
]);
|
]);
|
||||||
$demoUser2->__set('state', (new State())->forceFill([
|
$demoUser2->__set('state', (new State())->forceFill([
|
||||||
|
@ -43,12 +52,22 @@ class DesignController extends BaseController
|
||||||
'arrived' => false,
|
'arrived' => false,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
$themes = $this->config->get('available_themes');
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'demo_user' => $demoUser,
|
||||||
|
'demo_user_2' => $demoUser2,
|
||||||
|
'themes' => $themes,
|
||||||
|
];
|
||||||
|
|
||||||
|
$theme = $request->get('theme');
|
||||||
|
if (isset($themes[$theme])) {
|
||||||
|
$data['theme'] = $theme;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->response->withView(
|
return $this->response->withView(
|
||||||
'pages/design',
|
'pages/design',
|
||||||
[
|
$data
|
||||||
'demo_user' => $demoUser,
|
|
||||||
'demo_user_2' => $demoUser2,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
namespace Engelsystem\Test\Unit\Controllers;
|
namespace Engelsystem\Test\Unit\Controllers;
|
||||||
|
|
||||||
|
use Engelsystem\Config\Config;
|
||||||
use Engelsystem\Controllers\DesignController;
|
use Engelsystem\Controllers\DesignController;
|
||||||
|
use Engelsystem\Http\Request;
|
||||||
use Engelsystem\Http\Response;
|
use Engelsystem\Http\Response;
|
||||||
use Engelsystem\Test\Unit\TestCase;
|
use Engelsystem\Test\Unit\TestCase;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
@ -21,10 +23,35 @@ class DesignControllerTest extends TestCase
|
||||||
->method('withView')
|
->method('withView')
|
||||||
->with('pages/design')
|
->with('pages/design')
|
||||||
->willReturn($response);
|
->willReturn($response);
|
||||||
|
$request = new Request(['theme' => 42]);
|
||||||
|
$config = new Config();
|
||||||
|
|
||||||
$controller = new DesignController($response);
|
$controller = new DesignController($response, $config);
|
||||||
$return = $controller->index();
|
$return = $controller->index($request);
|
||||||
|
|
||||||
$this->assertEquals($response, $return);
|
$this->assertEquals($response, $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \Engelsystem\Controllers\DesignController::index
|
||||||
|
*/
|
||||||
|
public function testIndexSetTheme()
|
||||||
|
{
|
||||||
|
/** @var Response|MockObject $response */
|
||||||
|
$response = $this->createMock(Response::class);
|
||||||
|
$response->expects($this->once())
|
||||||
|
->method('withView')
|
||||||
|
->willReturnCallback(function (string $view, array $data) use ($response) {
|
||||||
|
$this->assertTrue(isset($data['theme']));
|
||||||
|
$this->assertEquals('42', $data['theme']);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
});
|
||||||
|
$request = new Request();
|
||||||
|
$request->attributes->set('theme', '42');
|
||||||
|
$config = new Config(['available_themes' => ['42' => 'Meaning of Live']]);
|
||||||
|
|
||||||
|
$controller = new DesignController($response, $config);
|
||||||
|
$controller->index($request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue