From 023fef6a70ea710374b4df3a9250b69f1a8f3dbc Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 14 Jan 2018 01:36:07 +0100 Subject: [PATCH] added control sidebar #10 (#87) - added configurable sidebar #10 - added language switch in sidebar preferences tab #10 - added sidebar tab with kimai beta-info message #10 - use trait for repositories - improved README --- .env.dist | 4 +- README.md | 41 ++++++++++---- config/packages/avanzu_admin_theme.yml | 2 +- config/packages/kimai.yml | 7 +++ config/packages/twig.yaml | 7 --- public/css/kimai.css | 5 ++ src/Controller/SidebarController.php | 34 ++++++++++++ src/Repository/AbstractRepository.php | 29 +--------- src/Repository/RepositoryTrait.php | 55 +++++++++++++++++++ templates/base.html.twig | 10 ---- .../Partials/_control-sidebar.html.twig | 23 ++++++++ templates/sidebar/home.html.twig | 40 ++++++++++++++ templates/sidebar/settings.html.twig | 11 ++++ translations/sidebar.de.xliff | 34 ++++++++++++ translations/sidebar.en.xliff | 34 ++++++++++++ 15 files changed, 277 insertions(+), 59 deletions(-) create mode 100644 src/Controller/SidebarController.php create mode 100644 src/Repository/RepositoryTrait.php create mode 100644 templates/bundles/AvanzuAdminThemeBundle/Partials/_control-sidebar.html.twig create mode 100644 templates/sidebar/home.html.twig create mode 100644 templates/sidebar/settings.html.twig create mode 100644 translations/sidebar.de.xliff create mode 100644 translations/sidebar.en.xliff diff --git a/.env.dist b/.env.dist index 0d7c35c0..8ed50a77 100644 --- a/.env.dist +++ b/.env.dist @@ -5,7 +5,6 @@ # KIMAI DEFAULT ENV VARS DATABASE_PREFIX=kimai2_ DATABASE_ENGINE=sqlite -DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite ###> symfony/framework-bundle ### APP_ENV=dev @@ -18,7 +17,8 @@ APP_SECRET=c88c14fa70a424e7a12d459b9dd9df7f # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data/kimai.sqlite" # Configure your db driver and server_version in config/packages/doctrine.yaml -#DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name +# DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name +DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite ###< doctrine/doctrine-bundle ### ###> symfony/swiftmailer-bundle ### diff --git a/README.md b/README.md index 5cce5265..8dde2299 100644 --- a/README.md +++ b/README.md @@ -44,16 +44,6 @@ The next command will create the database, the schema and install all web assets $ bin/console kimai:install --relative ``` -### Installation (live) - -All thats left to do is to create your first user: - -```bash -$ bin/console kimai:create-user username admin@example.com password en ROLE_SUPER_ADMIN -``` - -For available roles, please refer to [the user documentation](var/docs/users.md). - ### Installation (development / demo) Lets boostrap your environment by executing this commands (which is only available in dev environment): @@ -82,8 +72,37 @@ $ bin/console doctrine:schema:drop --force $ bin/console doctrine:schema:create ``` -The `kimai:reset-dev` command can always be executed later on to reset your dev database and cache. I use it very frequently. +The `kimai:reset-dev` command can always be executed later on to reset your dev database and cache. +### Installation (live) + +The default installation uses a SQLite database, which is not recommended for production usage. +You can configure your database through your environment (e.g. Webserver, Cloud-Provider) or in your `.env file: +```bash +$ cp .env.dist .env +``` + +You have to adjust the following ENV values to your needs: +``` +DATABASE_PREFIX=kimai2_ +DATABASE_ENGINE=sqlite +DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai.sqlite +APP_ENV=dev +APP_SECRET=some_random_secret_string_for_your_installation +``` + +Now create the database schemas: +```bash +$ bin/console doctrine:schema:create +``` + +And finally create your first user: + +```bash +$ bin/console kimai:create-user username admin@example.com password en ROLE_SUPER_ADMIN +``` + +For available roles, please refer to [the user documentation](var/docs/users.md). ## Usage diff --git a/config/packages/avanzu_admin_theme.yml b/config/packages/avanzu_admin_theme.yml index 829ebdff..eb9940b0 100644 --- a/config/packages/avanzu_admin_theme.yml +++ b/config/packages/avanzu_admin_theme.yml @@ -9,6 +9,6 @@ avanzu_admin_theme: boxed_layout: false collapsed_sidebar: true mini_sidebar: true - control_sidebar: false + control_sidebar: true knp_menu: enable: false diff --git a/config/packages/kimai.yml b/config/packages/kimai.yml index 69a5043a..ebdec234 100644 --- a/config/packages/kimai.yml +++ b/config/packages/kimai.yml @@ -7,3 +7,10 @@ twig: date_1: "d.m.Y" # used for display in timesheets box_color: "green" # a color for ??? active_warning: 3 # display a warning color if the user has at least X active recordings + control_sidebar: + settings: + icon: gears + controller: 'App\Controller\SidebarController::settingsAction' + home: + icon: question-circle-o + template: sidebar/home.html.twig diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index c83bdca1..165c4344 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -2,10 +2,3 @@ twig: #paths: ['%kernel.project_dir%/templates'] debug: '%kernel.debug%' strict_variables: '%kernel.debug%' - # TODO move me to kimai config - globals: - kimai_context: - date_1: "d.m.Y" # used for display in timesheets - box_color: "green" # a color for ??? - active_warning: 3 # display a warning color if the user has at least X active recordings - diff --git a/public/css/kimai.css b/public/css/kimai.css index dde2850a..3a929c72 100644 --- a/public/css/kimai.css +++ b/public/css/kimai.css @@ -39,6 +39,11 @@ li.open .ticktac i.running{ /* ================================ TOOLBAR ================================ */ +.control-sidebar select { + color: #000; +} +/* ================================ TOOLBAR ================================ */ + .data_table .box-header>.box-tools { top: 3px; } diff --git a/src/Controller/SidebarController.php b/src/Controller/SidebarController.php new file mode 100644 index 00000000..e608e76d --- /dev/null +++ b/src/Controller/SidebarController.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\Controller; + +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; + +/** + * Sidebar controller + * + * @Security("has_role('ROLE_USER')") + * + * @author Kevin Papst + */ +class SidebarController extends AbstractController +{ + public function homeAction() + { + return $this->render('sidebar/home.html.twig', []); + } + + public function settingsAction() + { + return $this->render('sidebar/settings.html.twig', []); + } +} diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php index e70afc74..d94d7efc 100644 --- a/src/Repository/AbstractRepository.php +++ b/src/Repository/AbstractRepository.php @@ -25,32 +25,5 @@ use Pagerfanta\Pagerfanta; */ abstract class AbstractRepository extends EntityRepository { - /** - * @param QueryBuilder $qb - * @param BaseQuery $query - * @return QueryBuilder|Pagerfanta - */ - protected function getBaseQueryResult(QueryBuilder $qb, BaseQuery $query) - { - if ($query->getResultType() == BaseQuery::RESULT_TYPE_PAGER) { - return $this->getPager($qb->getQuery(), $query->getPage(), $query->getPageSize()); - } - - return $qb; - } - - /** - * @param Query $query - * @param int $page - * @param int $maxPerPage - * @return Pagerfanta - */ - protected function getPager(Query $query, $page = 1, $maxPerPage = 25) - { - $paginator = new Pagerfanta(new DoctrineORMAdapter($query, false)); - $paginator->setMaxPerPage($maxPerPage); - $paginator->setCurrentPage($page); - - return $paginator; - } + use RepositoryTrait; } diff --git a/src/Repository/RepositoryTrait.php b/src/Repository/RepositoryTrait.php new file mode 100644 index 00000000..a9b193fe --- /dev/null +++ b/src/Repository/RepositoryTrait.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace App\Repository; + +use App\Repository\Query\BaseQuery; +use Doctrine\ORM\Query; +use Doctrine\ORM\QueryBuilder; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; + +/** + * Trait RepositoryTrait + * + * @author Kevin Papst + */ +trait RepositoryTrait +{ + /** + * @param QueryBuilder $qb + * @param BaseQuery $query + * @return QueryBuilder|Pagerfanta + */ + protected function getBaseQueryResult(QueryBuilder $qb, BaseQuery $query) + { + if ($query->getResultType() == BaseQuery::RESULT_TYPE_PAGER) { + return $this->getPager($qb->getQuery(), $query->getPage(), $query->getPageSize()); + } + + return $qb; + } + + /** + * @param Query $query + * @param int $page + * @param int $maxPerPage + * @return Pagerfanta + */ + protected function getPager(Query $query, $page = 1, $maxPerPage = 25) + { + $paginator = new Pagerfanta(new DoctrineORMAdapter($query, false)); + $paginator->setMaxPerPage($maxPerPage); + $paginator->setCurrentPage($page); + + return $paginator; + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index b34b7519..c2a40d75 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -57,16 +57,6 @@ {% if app.user is not null and is_granted('IS_AUTHENTICATED_FULLY') %} {{ render(controller('App\\Controller\\ActivityController::recentActivitiesAction')) }} {% endif %} - {# - - #} {% endblock %} {% block avanzu_navbar_toggle %}{{ parent() }}{% endblock %} diff --git a/templates/bundles/AvanzuAdminThemeBundle/Partials/_control-sidebar.html.twig b/templates/bundles/AvanzuAdminThemeBundle/Partials/_control-sidebar.html.twig new file mode 100644 index 00000000..9a768684 --- /dev/null +++ b/templates/bundles/AvanzuAdminThemeBundle/Partials/_control-sidebar.html.twig @@ -0,0 +1,23 @@ + +
\ No newline at end of file diff --git a/templates/sidebar/home.html.twig b/templates/sidebar/home.html.twig new file mode 100644 index 00000000..ae5c4a10 --- /dev/null +++ b/templates/sidebar/home.html.twig @@ -0,0 +1,40 @@ +

{{ 'home.title'|trans({}, 'sidebar') }}

+
+ {{ 'home.betainfo'|trans({}, 'sidebar')|raw|nl2br }} + +
+{# + + +

{{ 'Tasks Progress'|trans({}, 'AvanzuAdminTheme') }}

+ +#} \ No newline at end of file diff --git a/templates/sidebar/settings.html.twig b/templates/sidebar/settings.html.twig new file mode 100644 index 00000000..1ef193c6 --- /dev/null +++ b/templates/sidebar/settings.html.twig @@ -0,0 +1,11 @@ +

{{ 'preferences.title'|trans({}, 'sidebar') }}

+
+ +
diff --git a/translations/sidebar.de.xliff b/translations/sidebar.de.xliff new file mode 100644 index 00000000..d851c762 --- /dev/null +++ b/translations/sidebar.de.xliff @@ -0,0 +1,34 @@ + + + + + + home.title + Kimai v2 - Vorab Version + + + home.betainfo + Kimai. + + Diese neue Version 2 ist aktuell noch in einer frühen Phase der Entwicklung und wurde vorab veröffentlicht, um frühzeitig Rückmeldungen ihrer Benutzer zu sammeln und deren Ideen in die weitere Planung zu integrieren. + + Um bei der Verbesserung von Kimai zu helfen, schicken Sie mir bitte eine Nachricht auf der verlinkten Webseite. Egal ob Fragen, Fehlermeldungen oder Ideen für Erweiterungen, Ihr Feedback ist wertvoll! + + Weitere Informationen auf der: + ]]> + + + home.link.issues + GitHub Projekt-Webseite + + + preferences.title + Deine Einstellungen + + + preferences.label.language + Sprache + + + + diff --git a/translations/sidebar.en.xliff b/translations/sidebar.en.xliff new file mode 100644 index 00000000..bd8cfba6 --- /dev/null +++ b/translations/sidebar.en.xliff @@ -0,0 +1,34 @@ + + + + + + home.title + Kimai v2 - Pre-Version + + + home.betainfo + Kimai. + + This new version 2 is currently in an early stage of development and has been published in advance to collect feedback from its users and integrate their ideas into further planning. + + To help me improve Kimai, please send your message on the linked website. Whether you have questions, error messages or ideas for enhancements, your feedback is valuable! + + Further information on the: + ]]> + + + home.link.issues + GitHub Project-Website + + + preferences.title + Your preferences + + + preferences.label.language + Language + + + +