diff --git a/app/AppKernel.php b/app/AppKernel.php index 2c14036e..0948fef9 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -26,19 +26,19 @@ class AppKernel extends Kernel new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), - new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), - new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(), - new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), + new Avanzu\AdminThemeBundle\AvanzuAdminThemeBundle(), new AppBundle\AppBundle(), new TimesheetBundle\TimesheetBundle(), - new Avanzu\AdminThemeBundle\AvanzuAdminThemeBundle(), ]; // Bundles only used for development or unit and functional tests if (in_array($this->getEnvironment(), ['dev', 'test'])) { + //$bundles[] = new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(); + //$bundles[] = new Symfony\Bundle\AsseticBundle\AsseticBundle(); + $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(); $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); diff --git a/app/Resources/AvanzuAdminThemeBundle/views/Navbar/user.html.twig b/app/Resources/AvanzuAdminThemeBundle/views/Navbar/user.html.twig index e89d5475..b39a0cca 100644 --- a/app/Resources/AvanzuAdminThemeBundle/views/Navbar/user.html.twig +++ b/app/Resources/AvanzuAdminThemeBundle/views/Navbar/user.html.twig @@ -1,4 +1,4 @@ - +{# User Account: style can be found in dropdown.less #} {% import "AvanzuAdminThemeBundle:layout:macros.html.twig" as macro %}
  • {{ macro.avatar(user.avatar, user.username) }}

    - {{user.name}} - {{user.title}} - {{ 'Member since %date%'|trans({'%date%': user.memberSince|date('m.Y') }, 'AvanzuAdminTheme') }} + {{user.name}} + {{user.title}}

  • {# @@ -28,10 +28,10 @@ diff --git a/app/Resources/AvanzuAdminThemeBundle/views/Partials/_head.html.twig b/app/Resources/AvanzuAdminThemeBundle/views/Partials/_head.html.twig new file mode 100644 index 00000000..6f0e7d00 --- /dev/null +++ b/app/Resources/AvanzuAdminThemeBundle/views/Partials/_head.html.twig @@ -0,0 +1,20 @@ + + +{# Tell the browser to be responsive to screen width #} + +{# Bootstrap 3.3.6 #} + + +{# Ionicons #} +{##} + + +{# AdminLTE Skins. We have chosen the skin-blue for this starter page. However, you can choose + any other skin. Make sure you apply the skin class to the body tag so the changes take effect. #} + +{# HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries. + WARNING: Respond.js doesn't work if you view the page via file:// #} + diff --git a/app/Resources/translations/AvanzuAdminTheme.de.xliff b/app/Resources/translations/AvanzuAdminTheme.de.xliff deleted file mode 100644 index b076b38b..00000000 --- a/app/Resources/translations/AvanzuAdminTheme.de.xliff +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - Member since %date% - Mitglied seit %date% - - - Profile - Profil - - - Sign out - Abmelden - - - - diff --git a/app/Resources/translations/messages.de.xliff b/app/Resources/translations/messages.de.xliff index 4f235932..de271a82 100644 --- a/app/Resources/translations/messages.de.xliff +++ b/app/Resources/translations/messages.de.xliff @@ -25,10 +25,22 @@ security.label.password Passwort + + security.label.password_repeat + Passwort wiederholen + security.action.sign_in Los geht's + + label.logout + Abmelden + + + label.user_profile + Mein Profil + + + label.actions + Aktionen + + + action.edit + Bearbeiten + + + action.delete + Löschen + + + action.save + Speichern + + + action.updated_successfully + Änderungen erfolgreich gespeichert + + + month.1 + Januar + + + month.2 + Februar + + + month.3 + März + + + month.4 + April + + + month.5 + Mai + + + month.6 + Juni + + + month.7 + Juli + + + month.8 + August + + + month.9 + September + + + month.10 + Oktober + + + month.11 + November + + + month.12 + Dezember + diff --git a/app/Resources/views/admin/user.html.twig b/app/Resources/views/admin/user.html.twig index 3445eda2..03086bdc 100644 --- a/app/Resources/views/admin/user.html.twig +++ b/app/Resources/views/admin/user.html.twig @@ -16,17 +16,24 @@ 'label.title': 'graduation-cap', 'label.active': 'lock', 'label.roles': 'users', + 'label.actions': 'pencil-square-o', }) }} {% for entry in entries %} {{ entry.id }} - {{ entry.username }} + {{ entry.username }} {{ entry.alias }} {{ entry.email }} {{ entry.title }} {{ widgets.label_visible(entry.active) }} {{ entry.roles|join(',')|trans }} + + {{ widgets.button_group({ + 'edit': path('user_profile', {'username' : entry.username}), + 'trash': path('user_profile_delete', {'username' : entry.username}) + }) }} + {% endfor %} diff --git a/app/Resources/views/admin/user/_form.html.twig b/app/Resources/views/admin/user/_form.html.twig new file mode 100644 index 00000000..147fd73d --- /dev/null +++ b/app/Resources/views/admin/user/_form.html.twig @@ -0,0 +1,13 @@ +
    +
    +

    {{ user.username }}

    +
    + {{ form_start(form) }} +
    + {{ form_widget(form) }} +
    + + {{ form_end(form) }} +
    \ No newline at end of file diff --git a/app/Resources/views/admin/user/edit.html.twig b/app/Resources/views/admin/user/edit.html.twig new file mode 100644 index 00000000..526e2a6d --- /dev/null +++ b/app/Resources/views/admin/user/edit.html.twig @@ -0,0 +1,13 @@ +{% extends 'base.html.twig' %} + +{% block page_title %}{{ 'edit_profile.title'|trans }}{% endblock %} +{% block page_subtitle %}{{ 'edit_profile.subtitle'|trans({'%username%': user.username}) }}{% endblock %} + +{% block main %} + {{ include('default/_flash_messages.html.twig') }} + + {{ include('admin/user/_form.html.twig', { + user: user, + form: form, + }, with_context = false) }} +{% endblock %} diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 22a6a8ed..ec5a2538 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -38,11 +38,14 @@ {% block avanzu_head %} - + + + + + {% for year,yearStat in years %} +

    {{ year }}

    +
    + +
    + + {% endfor %} + + +
    + {{ form_start(form) }} + {{ form_widget(form) }} + + {{ form_end(form) }} +
    +
    + {{ form_start(form_password) }} + {{ form_widget(form_password) }} + + {{ form_end(form_password) }} +
    + + {% endblock %} -{% macro profile_list(user, items, color) %} +{% macro profile_infos(user, stats) %} +
    +
    +

    {{ 'profile.about_me'|trans }}

    +
    +
    + +
    +
    +{% endmacro %} + +{% macro profile_box(user, stats) %} + {% import "AvanzuAdminThemeBundle:layout:macros.html.twig" as macro %} + +
    +
    + {{ macro.avatar(user.avatar, user.username, 'profile-user-img img-responsive img-circle') }} +

    {{ user.alias }}

    + +

    {{ user.title }}

    + + + + {# Follow #} +
    + +
    +{% endmacro %} + +{# -------------------------------- UNUSED FOR NOW -------------------------------- #} +{% macro profile_list_unused(user, items, color) %} {% import "AvanzuAdminThemeBundle:layout:macros.html.twig" as macro %}
    @@ -37,11 +185,11 @@
    {% endmacro %} -{% macro profile_box(user, stats, color) %} +{# -------------------------------- UNUSED FOR NOW -------------------------------- #} +{% macro profile_box_unused(user, stats, color) %} {% import "AvanzuAdminThemeBundle:layout:macros.html.twig" as macro %}
    -

    {{ user.alias }} ({{ user.username }})

    {{ user.title }}
    @@ -78,4 +226,4 @@
    -{% endmacro %} +{% endmacro %} \ No newline at end of file diff --git a/app/config/config.yml b/app/config/config.yml index f7961394..a7a4f4bd 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -64,16 +64,16 @@ twig: table_icons: false # Assetic Configuration (used for managing web assets: CSS, JavaScript, Sass, etc.) -assetic: - debug: "%kernel.debug%" - use_controller: false - bundles: [ ] - filters: - cssrewrite: ~ - jsqueeze: ~ - scssphp: - # the formatter must be the FQCN (don't use the 'compressed' value) - formatter: "Leafo\\ScssPhp\\Formatter\\Compressed" +#assetic: +# debug: "%kernel.debug%" +# use_controller: false +# bundles: [ ] +# filters: +# cssrewrite: ~ +# jsqueeze: ~ +# scssphp: +# # the formatter must be the FQCN (don't use the 'compressed' value) +# formatter: "Leafo\\ScssPhp\\Formatter\\Compressed" # Doctrine Configuration (used to access databases and manipulate their information) doctrine: @@ -85,12 +85,12 @@ doctrine: auto_mapping: true # Swiftmailer Configuration (used to send emails) -swiftmailer: - transport: "%mailer_transport%" - host: "%mailer_host%" - username: "%mailer_user%" - password: "%mailer_password%" - spool: { type: memory } +#swiftmailer: +# transport: "%mailer_transport%" +# host: "%mailer_host%" +# username: "%mailer_user%" +# password: "%mailer_password%" +# spool: { type: memory } avanzu_admin_theme: use_twig : true diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index 19cd023c..dcee1614 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -29,8 +29,8 @@ monolog: # type: chromephp # level: info -assetic: - use_controller: true +#assetic: +# use_controller: true #swiftmailer: # delivery_address: me@example.com diff --git a/app/config/mysql.yml b/app/config/mysql.yml new file mode 100644 index 00000000..3006ff33 --- /dev/null +++ b/app/config/mysql.yml @@ -0,0 +1,86 @@ +doctrine: + orm: + dql: + datetime_functions: + convert_tz: DoctrineExtensions\Query\Mysql\ConvertTz + date: DoctrineExtensions\Query\Mysql\Date + date_format: DoctrineExtensions\Query\Mysql\DateFormat + dateadd: DoctrineExtensions\Query\Mysql\DateAdd + datesub: DoctrineExtensions\Query\Mysql\DateSub + datediff: DoctrineExtensions\Query\Mysql\DateDiff + day: DoctrineExtensions\Query\Mysql\Day + dayname: DoctrineExtensions\Query\Mysql\DayName + dayofweek: DoctrineExtensions\Query\Mysql\DayOfWeek + dayofyear: DoctrineExtensions\Query\Mysql\DayOfYear + div: DoctrineExtensions\Query\Mysql\Div + from_unixtime: DoctrineExtensions\Query\Mysql\FromUnixtime + last_day: DoctrineExtensions\Query\Mysql\LastDay + minute: DoctrineExtensions\Query\Mysql\Minute + now: DoctrineExtensions\Query\Mysql\Now + month: DoctrineExtensions\Query\Mysql\Month + monthname: DoctrineExtensions\Query\Mysql\MonthName + second: DoctrineExtensions\Query\Mysql\Second + strtodate: DoctrineExtensions\Query\Mysql\StrToDate + time: DoctrineExtensions\Query\Mysql\Time + timediff: DoctrineExtensions\Query\Mysql\TimeDiff + timestampadd: DoctrineExtensions\Query\Mysql\TimestampAdd + timestampdiff: DoctrineExtensions\Query\Mysql\TimestampDiff + timetosec: DoctrineExtensions\Query\Mysql\TimeToSec + week: DoctrineExtensions\Query\Mysql\Week + weekday: DoctrineExtensions\Query\Mysql\WeekDay + year: DoctrineExtensions\Query\Mysql\Year + yearweek: DoctrineExtensions\Query\Mysql\YearWeek + unix_timestamp: DoctrineExtensions\Query\Mysql\UnixTimestamp + + numeric_functions: + acos: DoctrineExtensions\Query\Mysql\Acos + asin: DoctrineExtensions\Query\Mysql\Asin + atan2: DoctrineExtensions\Query\Mysql\Atan2 + atan: DoctrineExtensions\Query\Mysql\Atan + bit_count: DoctrineExtensions\Query\Mysql\BitCount + bit_xor: DoctrineExtensions\Query\Mysql\BitXor + ceil: DoctrineExtensions\Query\Mysql\Ceil + cos: DoctrineExtensions\Query\Mysql\Cos + cot: DoctrineExtensions\Query\Mysql\Cot + floor: DoctrineExtensions\Query\Mysql\Floor + hour: DoctrineExtensions\Query\Mysql\Hour + pi: DoctrineExtensions\Query\Mysql\Pi + power: DoctrineExtensions\Query\Mysql\Power + quarter: DoctrineExtensions\Query\Mysql\Quarter + rand: DoctrineExtensions\Query\Mysql\Rand + round: DoctrineExtensions\Query\Mysql\Round + stddev: DoctrineExtensions\Query\Mysql\StdDev + sin: DoctrineExtensions\Query\Mysql\Sin + std: DoctrineExtensions\Query\Mysql\Std + tan: DoctrineExtensions\Query\Mysql\Tan + + string_functions: + ascii: DoctrineExtensions\Query\Mysql\Ascii + binary: DoctrineExtensions\Query\Mysql\Binary + char_length: DoctrineExtensions\Query\Mysql\CharLength + concat_ws: DoctrineExtensions\Query\Mysql\ConcatWs + countif: DoctrineExtensions\Query\Mysql\CountIf + crc32: DoctrineExtensions\Query\Mysql\Crc32 + degrees: DoctrineExtensions\Query\Mysql\Degrees + field: DoctrineExtensions\Query\Mysql\Field + find_in_set: DoctrineExtensions\Query\Mysql\FindInSet + greatest: DoctrineExtensions\Query\Mysql\Greatest + group_concat: DoctrineExtensions\Query\Mysql\GroupConcat + ifelse: DoctrineExtensions\Query\Mysql\IfElse + ifnull: DoctrineExtensions\Query\Mysql\IfNull + least: DoctrineExtensions\Query\Mysql\Least + lpad: DoctrineExtensions\Query\Mysql\Lpad + match_against: DoctrineExtensions\Query\Mysql\MatchAgainst + md5: DoctrineExtensions\Query\Mysql\Md5 + nullif: DoctrineExtensions\Query\Mysql\NullIf + radians: DoctrineExtensions\Query\Mysql\Radians + regexp: DoctrineExtensions\Query\Mysql\Regexp + replace: DoctrineExtensions\Query\Mysql\Replace + rpad: DoctrineExtensions\Query\Mysql\Rpad + sha1: DoctrineExtensions\Query\Mysql\Sha1 + sha2: DoctrineExtensions\Query\Mysql\Sha2 + soundex: DoctrineExtensions\Query\Mysql\Soundex + substring_index: DoctrineExtensions\Query\Mysql\SubstringIndex + uuid_short: DoctrineExtensions\Query\Mysql\UuidShort + hex: DoctrineExtensions\Query\Mysql\Hex + unhex: DoctrineExtensions\Query\Mysql\Unhex diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index fc9a044d..4a499479 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -4,6 +4,9 @@ # See http://symfony.com/doc/current/best_practices/configuration.html#canonical-parameters parameters: + # used to load additional doctrine functions (possible values: mysql, sqlite) + database_engine: sqlite + # Define the database connection string database_url: 'sqlite:///%kernel.root_dir%/data/timesheet.sqlite' # database_url: 'mysql://root:pass@127.0.0.1:3306/timesheet' diff --git a/app/config/routing.yml b/app/config/routing.yml index 230e6565..248dc744 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -34,6 +34,6 @@ homepage: permanent: true avanzu_admin_profile: - path: /{_locale}/profile/{ident}/ + path: /{_locale}/profile/{username} options: avanzu_admin_route: profile diff --git a/app/config/sqlite.yml b/app/config/sqlite.yml new file mode 100644 index 00000000..db315817 --- /dev/null +++ b/app/config/sqlite.yml @@ -0,0 +1,50 @@ +doctrine: + orm: + dql: + datetime_functions: + date: DoctrineExtensions\Query\Sqlite\Date + date_format: DoctrineExtensions\Query\Sqlite\DateFormat + #dateadd: DoctrineExtensions\Query\Sqlite\DateAdd + #datediff: DoctrineExtensions\Query\Sqlite\DateDiff + day: DoctrineExtensions\Query\Sqlite\Day + dayname: DoctrineExtensions\Query\Sqlite\DayName + minute: DoctrineExtensions\Query\Sqlite\Minute + #month: DoctrineExtensions\Query\Sqlite\Month + #monthname: DoctrineExtensions\Query\Sqlite\MonthName + second: DoctrineExtensions\Query\Sqlite\Second + month: DoctrineExtensions\Query\Sqlite\Month + strftime: DoctrineExtensions\Query\Sqlite\StrfTime + #strtodate: DoctrineExtensions\Query\Sqlite\StrToDate + #time: DoctrineExtensions\Query\Sqlite\Time + #timestampadd: DoctrineExtensions\Query\Sqlite\TimestampAdd + #timestampdiff: DoctrineExtensions\Query\Sqlite\TimestampDiff + week: DoctrineExtensions\Query\Sqlite\Week + weekday: DoctrineExtensions\Query\Sqlite\WeekDay + year: DoctrineExtensions\Query\Sqlite\Year + + + string_functions: +# binary: DoctrineExtensions\Query\Sqlite\Binary +# char_length: DoctrineExtensions\Query\Sqlite\CharLength + concat_ws: DoctrineExtensions\Query\Sqlite\ConcatWs +# countif: DoctrineExtensions\Query\Sqlite\CountIf +# crc32: DoctrineExtensions\Query\Sqlite\Crc32 +# degrees: DoctrineExtensions\Query\Sqlite\Degrees +# field: DoctrineExtensions\Query\Sqlite\Field +# find_in_set: DoctrineExtensions\Query\Sqlite\FindInSet +# group_concat: DoctrineExtensions\Query\Sqlite\GroupConcat +# ifelse: DoctrineExtensions\Query\Sqlite\IfElse + ifnull: DoctrineExtensions\Query\Sqlite\IfNull +# match_against: DoctrineExtensions\Query\Sqlite\MatchAgainst +# md5: DoctrineExtensions\Query\Sqlite\Md5 +# nullif: DoctrineExtensions\Query\Sqlite\NullIf +# radians: DoctrineExtensions\Query\Sqlite\Radians +# regexp: DoctrineExtensions\Query\Sqlite\Regexp + replace: DoctrineExtensions\Query\Sqlite\Replace +# sha1: DoctrineExtensions\Query\Sqlite\Sha1 +# sha2: DoctrineExtensions\Query\Sqlite\Sha2 +# soundex: DoctrineExtensions\Query\Sqlite\Soundex +# uuid_short: DoctrineExtensions\Query\Sqlite\UuidShort + + numeric_functions: + round: DoctrineExtensions\Query\Sqlite\Round diff --git a/composer.json b/composer.json index d2dd0062..2cc71d38 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "symfony/symfony": "^3.1", "twig/extensions": "^1.3", "white-october/pagerfanta-bundle": "^1.0", - "avanzu/admin-theme-bundle": "dev-feature/2.0" + "avanzu/admin-theme-bundle": "dev-feature/2.0", + "beberlei/DoctrineExtensions": "^1.0" }, "require-dev": { "sensio/generator-bundle": "~3.0", diff --git a/composer.lock b/composer.lock index 0446fd5a..e8a9e7d8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4987a4da3f291b8e0bb1b3af06a5cfa6", - "content-hash": "287d1663444888a10331136287c4269b", + "hash": "d5aa01779571420f9166199f60fa2a17", + "content-hash": "20dda7356ab7c685ada168dd7e9b7593", "packages": [ { "name": "almasaeed2010/adminlte", @@ -93,6 +93,68 @@ "description": "Admin Theme based on the AdminLTE Template for easy integration into symfony", "time": "2016-08-26 08:28:19" }, + { + "name": "beberlei/DoctrineExtensions", + "version": "v1.0.11", + "source": { + "type": "git", + "url": "https://github.com/beberlei/DoctrineExtensions.git", + "reference": "6dbe65e469e8bdcfe165ea16636b7049af479a24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/6dbe65e469e8bdcfe165ea16636b7049af479a24", + "reference": "6dbe65e469e8bdcfe165ea16636b7049af479a24", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/orm": "~2.1", + "nesbot/carbon": "*", + "phpunit/phpunit": "~4.5", + "symfony/yaml": "~2.6", + "zf1/zend-date": "~1.12", + "zf1/zend-registry": "~1.12" + }, + "suggest": { + "nesbot/carbon": "Alternative to DateTime", + "zf1/zend-date": "Alternative to DateTime" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "DoctrineExtensions\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Steve Lacey", + "email": "steve@stevelacey.net" + } + ], + "description": "A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL and Oracle.", + "keywords": [ + "database", + "doctrine", + "orm" + ], + "time": "2016-07-06 17:12:30" + }, { "name": "doctrine/annotations", "version": "v1.2.7", diff --git a/src/AppBundle/AppBundle.php b/src/AppBundle/AppBundle.php index 5bf996b4..a4a7f869 100644 --- a/src/AppBundle/AppBundle.php +++ b/src/AppBundle/AppBundle.php @@ -11,6 +11,10 @@ namespace AppBundle; +use AppBundle\DependencyInjection\AppBundleExtension; +use AppBundle\DependencyInjection\CompilerPass; +use Symfony\Component\DependencyInjection\Compiler\PassConfig; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -18,7 +22,15 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; * * @see http://symfony.com/doc/current/cookbook/bundles/best_practices.html * @see http://symfony.com/doc/current/best_practices/business-logic.html + * + * @author Kevin Papst */ class AppBundle extends Bundle { -} + public function build(ContainerBuilder $container) + { + parent::build($container); + + $container->addCompilerPass(new CompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000); + } +} \ No newline at end of file diff --git a/src/AppBundle/Controller/ProfileController.php b/src/AppBundle/Controller/ProfileController.php index cb663ffe..6cbcdfe1 100644 --- a/src/AppBundle/Controller/ProfileController.php +++ b/src/AppBundle/Controller/ProfileController.php @@ -11,12 +11,22 @@ namespace AppBundle\Controller; +use AppBundle\Entity\User; +use AppBundle\Form\UserEditType; +use AppBundle\Form\UserPasswordType; +use AppBundle\Repository\UserRepository; +use Symfony\Component\Form\Form; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use TimesheetBundle\Entity\Timesheet; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; +use TimesheetBundle\Model\TimesheetStatistic; +use TimesheetBundle\Repository\TimesheetRepository; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\HttpFoundation\Request; /** * User profile controller @@ -29,45 +39,189 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; class ProfileController extends Controller { /** - * @Route("/", defaults={"ident": null}, name="user_profile") - * @Route("/{ident}/", requirements={"ident": "[a-zA-Z0-9\-].*"}, name="user_profile_ident") + * @Route("/{username}", name="user_profile") * @Method("GET") */ - public function indexAction($ident) + public function indexAction($username) { - $user = $this->getUser(); + $user = $this->getUserByUsername($username); - $isAdmin = false; - if ($isAdmin) { - } else { - } + return $this->getProfileView($user); + } + /** + * @param User $user + * @param Form $editForm + * @param Form $pwdForm + * @param string $tab + * @return \Symfony\Component\HttpFoundation\Response + */ + protected function getProfileView(User $user, Form $editForm = null, Form $pwdForm = null, $tab = 'charts') + { + /* @var $timesheetRepo TimesheetRepository */ $timesheetRepo = $this->getDoctrine()->getRepository(Timesheet::class); $userStats = $timesheetRepo->getUserStatistics($user); + $monthlyStats = $timesheetRepo->getMonthlyStats($user); - // FIXME fetch values dynamically and add trans filter to macros - $items = [ - [ - 'title' => 'Stundenlohn', - 'url' => '#', - 'color' => 'blue', // aqua, red, green - 'value' => 70 - ], - [ - 'title' => 'Sprache', - 'url' => '#', - 'color' => 'green', // aqua, red, green - 'value' => 'deutsch' - ], - ]; + $editForm = $editForm !== null ? $editForm : $this->createEditForm($user); + $pwdForm = $pwdForm !== null ? $pwdForm : $this->createPasswordForm($user); return $this->render( 'user/profile.html.twig', [ - 'user' => $this->getUser(), - 'settings' => $items, - 'stats' => $userStats + 'tab' => $tab, + 'user' => $user, + 'stats' => $userStats, + 'years' => $monthlyStats, + 'form' => $editForm->createView(), + 'form_password' => $pwdForm->createView(), ] ); } + + /** + * @Route("/{username}/edit", name="user_profile_edit") + * @Method({"GET", "POST"}) + */ + public function editAction($username, Request $request) + { + $user = $this->getUserByUsername($username); + $editForm = $this->createEditForm($user); + + $editForm->handleRequest($request); + + if ($editForm->isSubmitted() && $editForm->isValid()) { + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($user); + $entityManager->flush(); + + $this->addFlash('success', 'action.updated_successfully'); + + return $this->redirectToRoute( + 'user_profile', ['username' => $user->getUsername()] + ); + } + + return $this->getProfileView($user, $editForm, null, 'profile'); + } + + /** + * @Route("/{username}/password", name="user_profile_password") + * @Method({"GET", "POST"}) + */ + public function passwordAction($username, Request $request) + { + $user = $this->getUserByUsername($username); + $pwdForm = $this->createPasswordForm($user); + + $pwdForm->handleRequest($request); + + if ($pwdForm->isSubmitted() && $pwdForm->isValid()) { + $password = $this->get('security.password_encoder') + ->encodePassword($user, $user->getPlainPassword()); + $user->setPassword($password); + + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->persist($user); + $entityManager->flush(); + + $this->addFlash('success', 'action.updated_successfully'); + + return $this->redirectToRoute( + 'user_profile', ['username' => $user->getUsername()] + ); + } + + return $this->getProfileView($user, null, $pwdForm, 'password'); + } + + /** + * FIXME + * @Route("/{username}/delete", name="user_profile_delete") + * @Method({"GET", "POST"}) + */ + public function deleteAction($username, Request $request) + { + $user = $this->getUserByUsername($username); + $deleteForm = $this->createDeleteForm($user); + + throw new \Exception('Delete not implemented yet'); + } + + /** + * @param $username + * @return User + * @throws NotFoundHttpException + */ + protected function getUserByUsername($username) + { + $user = $this->getUser(); + + // access to own profile always allowed + if (null === $username) { + $username = $user->getUsername(); + } + + if ($username !== $user->getUsername()) { + $this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page'); // TODO translation + } + + if ($username !== $user->getUsername()) { + /* @var $userRepo UserRepository */ + $userRepo = $this->getDoctrine()->getRepository(User::class); + $user = $userRepo->findByUsername($username); + if (null === $user) { + throw new NotFoundHttpException('User "'.$username.'" does not exist'); + } + } + + return $user; + } + + /** + * @param User $user + * @return \Symfony\Component\Form\Form + */ + private function createEditForm(User $user) + { + return $this->createForm( + UserEditType::class, + $user, + [ + 'action' => $this->generateUrl('user_profile_edit', ['username' => $user->getUsername()]), + 'method' => 'POST' + ] + ); + } + + /** + * @param User $user + * @return \Symfony\Component\Form\Form + */ + private function createPasswordForm(User $user) + { + return $this->createForm( + UserPasswordType::class, + $user, + [ + 'validation_groups' => array('passwordUpdate'), + 'action' => $this->generateUrl('user_profile_password', ['username' => $user->getUsername()]), + 'method' => 'POST' + ] + ); + } + + /** + * @param User $user + * + * @return \Symfony\Component\Form\Form The form + */ + private function createDeleteForm(User $user) + { + return $this->createFormBuilder() + ->setAction($this->generateUrl('user_profile_delete', ['username' => $user->getUsername()])) + ->setMethod('DELETE') + ->getForm() + ; + } } diff --git a/src/AppBundle/DataFixtures/ORM/LoadFixtures.php b/src/AppBundle/DataFixtures/ORM/LoadFixtures.php index 02053385..acd916f2 100644 --- a/src/AppBundle/DataFixtures/ORM/LoadFixtures.php +++ b/src/AppBundle/DataFixtures/ORM/LoadFixtures.php @@ -83,47 +83,6 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface $manager->flush(); } - /** - * FIXME CAN BE REMOVED - * - * @param ObjectManager $manager - */ - private function loadPosts(ObjectManager $manager) - { - $authors = [ - 'anna_admin@example.com', - 'tony_teamlead@example.com', - 'clara_customer@example.com', - 'john_user@example.com' - ]; - foreach (range(1, 30) as $i) { - $post = new Post(); - - $post->setTitle($this->getRandomPostTitle()); - $post->setSummary($this->getRandomPostSummary()); - $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); - $post->setContent($this->getPostContent()); - $post->setAuthorEmail($authors[array_rand($authors, 1)]); - $post->setPublishedAt(new \DateTime('now - '.$i.'days')); - - foreach (range(1, 5) as $j) { - $comment = new Comment(); - - $comment->setAuthorEmail($authors[array_rand($authors, 1)]); - $comment->setPublishedAt(new \DateTime('now + '.($i + $j).'seconds')); - $comment->setContent($this->getRandomCommentContent()); - $comment->setPost($post); - - $manager->persist($comment); - $post->addComment($comment); - } - - $manager->persist($post); - } - - $manager->flush(); - } - /** * {@inheritdoc} */ diff --git a/src/AppBundle/DependencyInjection/AppExtension.php b/src/AppBundle/DependencyInjection/AppExtension.php new file mode 100644 index 00000000..a5785b83 --- /dev/null +++ b/src/AppBundle/DependencyInjection/AppExtension.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 AppBundle\DependencyInjection; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use \Doctrine\Common\ClassLoader; + +/** + * Main extension class + * + * @author Kevin Papst + */ +class AppExtension extends Extension +{ + + public function load(array $configs, ContainerBuilder $container) + { + $rootDir = realpath($container->getParameter('kernel.root_dir')); + $extensionsDir = realpath($rootDir . '/../vendor/beberlei/DoctrineExtensions/src/'); + + $classLoader = new ClassLoader('DoctrineExtensions', $extensionsDir); + $classLoader->register(); + } +} \ No newline at end of file diff --git a/src/AppBundle/DependencyInjection/CompilerPass.php b/src/AppBundle/DependencyInjection/CompilerPass.php new file mode 100644 index 00000000..ab0cb6fb --- /dev/null +++ b/src/AppBundle/DependencyInjection/CompilerPass.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace AppBundle\DependencyInjection; + +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; +use Symfony\Component\Yaml\Yaml; + +/** + * Class Configuration + * + * @author Kevin Papst + */ +class CompilerPass implements CompilerPassInterface +{ + + /** + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + $engine = $container->getParameter('database_engine'); + if (null === $engine) { + throw new ParameterNotFoundException('database_engine'); + } + + $ormConfigDef = $container->getDefinition('doctrine.orm.default_configuration'); + + $configDir = realpath($container->getParameter('kernel.root_dir') . '/config/'); + $config = Yaml::parse(file_get_contents($configDir . '/' . $engine . '.yml')); + + if (!isset($config['doctrine']['orm']['dql'])) { + return; + } + + $sql = $config['doctrine']['orm']['dql']; + + if (!empty($sql)) { + foreach ($sql['string_functions'] as $name => $function) { + $ormConfigDef->addMethodCall('addCustomStringFunction', array($name, $function)); + } + foreach ($sql['numeric_functions'] as $name => $function) { + $ormConfigDef->addMethodCall('addCustomNumericFunction', array($name, $function)); + } + foreach ($sql['datetime_functions'] as $name => $function) { + $ormConfigDef->addMethodCall('addCustomDatetimeFunction', array($name, $function)); + } + } + } +} \ No newline at end of file diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php index 12f24d02..908d0325 100644 --- a/src/AppBundle/Entity/User.php +++ b/src/AppBundle/Entity/User.php @@ -4,7 +4,7 @@ namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; - +use Symfony\Component\Validator\Constraints as Assert; /** * User @@ -28,6 +28,8 @@ class User implements UserInterface * @var string * * @ORM\Column(name="name", type="string", length=160, nullable=false, unique=true) + * @Assert\NotBlank() + * @Assert\Length(min=6, max=160) */ private $username; @@ -35,6 +37,8 @@ class User implements UserInterface * @var string * * @ORM\Column(name="mail", type="string", length=160, nullable=false, unique=true) + * @Assert\NotBlank() + * @Assert\Email() */ private $email; @@ -45,6 +49,14 @@ class User implements UserInterface */ private $password; + /** + * @var string + * + * @Assert\NotBlank(groups={"registration", "passwordUpdate"}) + * @Assert\Length(min=6, max=4096, groups={"registration", "passwordUpdate"}) + */ + private $plainPassword; + /** * @var string * @@ -52,6 +64,13 @@ class User implements UserInterface */ private $alias; + /** + * @var string + * + * @ORM\Column(name="language", type="string", length=5, nullable=true) + */ + private $language = 'de'; + /** * @var boolean * @@ -62,16 +81,9 @@ class User implements UserInterface /** * @var \DateTime * - * @ORM\Column(name="start_timeframe", type="datetime", nullable=true) + * @ORM\Column(name="registration_date", type="datetime", nullable=true) */ - private $timeframeBegin; - - /** - * @var \DateTime - * - * @ORM\Column(name="end_timeframe", type="datetime", nullable=true) - */ - private $timeframeEnd; + private $registeredAt; /** * @var string @@ -94,6 +106,14 @@ class User implements UserInterface */ private $roles = []; + /** + * User constructor. + */ + public function __construct() + { + $this->registeredAt = new \DateTime(); + } + /** * @return int */ @@ -103,35 +123,22 @@ class User implements UserInterface } /** - * @return string + * @return \DateTime */ - public function getTimeframeBegin() + public function getRegisteredAt() { - return $this->timeframeBegin; + return $this->registeredAt; } /** - * @param string $timeframeBegin + * @param $registeredAt + * @return $this */ - public function setTimeframeBegin($timeframeBegin) + public function setRegisteredAt($registeredAt) { - $this->timeframeBegin = $timeframeBegin; - } + $this->registeredAt = $registeredAt; - /** - * @return string - */ - public function getTimeframeEnd() - { - return $this->timeframeEnd; - } - - /** - * @param string $timeframeEnd - */ - public function setTimeframeEnd($timeframeEnd) - { - $this->timeframeEnd = $timeframeEnd; + return $this; } /** @@ -193,6 +200,28 @@ class User implements UserInterface return $this->password; } + /** + * Only for form editing, you don't need this method! + * + * @return string + */ + public function getPlainPassword() + { + return $this->plainPassword; + } + + /** + * Only for form editing, you don't need this method! + * + * @param string $password + * @return $this + */ + public function setPlainPassword($password) + { + $this->plainPassword = $password; + return $this; + } + /** * @return string */ @@ -266,6 +295,22 @@ class User implements UserInterface return $this; } + /** + * @return string + */ + public function getLanguage() + { + return $this->language; + } + + /** + * @param string $language + */ + public function setLanguage($language) + { + $this->language = $language; + } + /** * Returns the roles or permissions granted to the user for security. * diff --git a/src/AppBundle/EventListener/NavbarShowUserListener.php b/src/AppBundle/EventListener/NavbarShowUserListener.php index 29b06c2c..89b5e4e6 100644 --- a/src/AppBundle/EventListener/NavbarShowUserListener.php +++ b/src/AppBundle/EventListener/NavbarShowUserListener.php @@ -29,11 +29,18 @@ class NavbarShowUserListener */ protected $storage; + /** + * NavbarShowUserListener constructor. + * @param TokenStorageInterface $tokenStorage + */ public function __construct(TokenStorageInterface $tokenStorage) { $this->storage = $tokenStorage; } + /** + * @param ShowUserEvent $event + */ public function onShowUser(ShowUserEvent $event) { /* @var $myUser User */ @@ -51,8 +58,7 @@ class NavbarShowUserListener ->setIsOnline(true) ->setTitle($myUser->getTitle()) ->setAvatar($myUser->getAvatar()) - ->setMemberSince(new \DateTime()) // FIXME add column to entity - ; + ->setMemberSince(new \DateTime()); $event->setUser($user); } diff --git a/src/AppBundle/Form/UserEditType.php b/src/AppBundle/Form/UserEditType.php new file mode 100644 index 00000000..98033b8f --- /dev/null +++ b/src/AppBundle/Form/UserEditType.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace AppBundle\Form; + +use AppBundle\Entity\User; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\LanguageType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; + +/** + * Defines the form used to create and manipulate Users. + * + * @author Kevin Papst + */ +class UserEditType extends AbstractType +{ + + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + // string - length 160 + ->add('alias', null, [ + 'label' => 'label.alias', + ]) + // string - length 50 + ->add('title', null, [ + //'attr' => ['autofocus' => true], + 'label' => 'label.title', + ]) + // string - length 160 + ->add('email', null, [ + 'label' => 'label.email', + ]) + // string - length 5 + ->add('language', LanguageType::class, [ + 'label' => 'label.language', + 'choices' => array('Deutsch' => 'de') // FIXME translation + ]) + ; + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class, + 'csrf_protection' => true, + 'csrf_field_name' => '_token', + 'csrf_token_id' => 'edit_user_profile', + ]); + } +} diff --git a/src/AppBundle/Form/UserPasswordType.php b/src/AppBundle/Form/UserPasswordType.php new file mode 100644 index 00000000..3046ed97 --- /dev/null +++ b/src/AppBundle/Form/UserPasswordType.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 AppBundle\Form; + +use AppBundle\Entity\User; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\RepeatedType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; + +/** + * Defines the form used to create and manipulate Users. + * + * @author Kevin Papst + */ +class UserPasswordType extends AbstractType +{ + + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('plainPassword', RepeatedType::class, [ + 'type' => PasswordType::class, + 'first_options' => array('label' => 'security.label.password'), + 'second_options' => array('label' => 'security.label.password_repeat'), + ]) + ; + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class, + 'csrf_protection' => true, + 'csrf_field_name' => '_token', + 'csrf_token_id' => 'edit_user_password', + ]); + } +} diff --git a/src/AppBundle/Repository/UserRepository.php b/src/AppBundle/Repository/UserRepository.php index 043e3fac..82e11bc3 100644 --- a/src/AppBundle/Repository/UserRepository.php +++ b/src/AppBundle/Repository/UserRepository.php @@ -57,7 +57,7 @@ class UserRepository extends EntityRepository public function findByUsername($username) { - return $this->findOneBy(['']); + return $this->findOneBy(['username' => $username]); } /** diff --git a/src/TimesheetBundle/Model/Statistic/Month.php b/src/TimesheetBundle/Model/Statistic/Month.php new file mode 100644 index 00000000..3f862358 --- /dev/null +++ b/src/TimesheetBundle/Model/Statistic/Month.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace TimesheetBundle\Model\Statistic; + +/** + * Yearly statistics + * + * @author Kevin Papst + */ +class Month +{ + /** + * @var string + */ + protected $month; + /** + * @var int + */ + protected $totalDuration = 0; + /** + * @var int + */ + protected $totalRate = 0; + + /** + * Month constructor. + * @param string $month + */ + public function __construct($month) + { + $this->month = $month; + } + + /** + * @return string + */ + public function getMonth() + { + return $this->month; + } + + /** + * @return int + */ + public function getTotalDuration() + { + return $this->totalDuration; + } + + /** + * @param $totalDuration + * @return $this + */ + public function setTotalDuration($totalDuration) + { + $this->totalDuration = $totalDuration; + return $this; + } + + /** + * @return int + */ + public function getTotalRate() + { + return $this->totalRate; + } + + /** + * @param $totalRate + * @return $this + */ + public function setTotalRate($totalRate) + { + $this->totalRate = $totalRate; + return $this; + } +} diff --git a/src/TimesheetBundle/Model/Statistic/Year.php b/src/TimesheetBundle/Model/Statistic/Year.php new file mode 100644 index 00000000..05551ca2 --- /dev/null +++ b/src/TimesheetBundle/Model/Statistic/Year.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace TimesheetBundle\Model\Statistic; + +/** + * Yearly statistics + * + * @author Kevin Papst + */ +class Year +{ + /** + * @var string + */ + protected $year; + /** + * @var Month[] + */ + protected $months; + + /** + * Year constructor. + * @param string $year + */ + public function __construct($year) + { + $this->year = $year; + } + + /** + * @return string + */ + public function getYear() + { + return $this->year; + } + + /** + * @param Month $month + * @return $this + */ + public function setMonth(Month $month) + { + $this->months[(int)$month->getMonth()] = $month; + + return $this; + } + + /** + * @param $month + * @return null|Month + */ + public function getMonth($month) + { + if (isset($this->months[$month])) { + return $this->months[$month]; + } + + return null; + } + + /** + * @return Month[] + */ + public function getMonths() + { + return array_values($this->months); + } +} diff --git a/src/TimesheetBundle/Model/TimesheetStatistic.php b/src/TimesheetBundle/Model/TimesheetStatistic.php index b2bc77f4..0aa56c82 100644 --- a/src/TimesheetBundle/Model/TimesheetStatistic.php +++ b/src/TimesheetBundle/Model/TimesheetStatistic.php @@ -11,6 +11,8 @@ namespace TimesheetBundle\Model; +use \DateTime; + /** * Timesheet statistics * @@ -34,6 +36,10 @@ class TimesheetStatistic * @var int */ protected $amountTotal = 0; + /** + * @var \DateTime + */ + protected $firstEntry; /** * @return int @@ -98,4 +104,20 @@ class TimesheetStatistic { $this->amountThisMonth = $amountThisMonth; } + + /** + * @return DateTime + */ + public function getFirstEntry() + { + return $this->firstEntry; + } + + /** + * @param DateTime $firstEntry + */ + public function setFirstEntry(DateTime $firstEntry) + { + $this->firstEntry = $firstEntry; + } } diff --git a/src/TimesheetBundle/Repository/TimesheetRepository.php b/src/TimesheetBundle/Repository/TimesheetRepository.php index ce7467a6..e8cdc81e 100644 --- a/src/TimesheetBundle/Repository/TimesheetRepository.php +++ b/src/TimesheetBundle/Repository/TimesheetRepository.php @@ -18,6 +18,8 @@ use Doctrine\ORM\Query; use Doctrine\DBAL\Types\Type; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Pagerfanta; +use TimesheetBundle\Model\Statistic\Month; +use TimesheetBundle\Model\Statistic\Year; use TimesheetBundle\Model\TimesheetGlobalStatistic; use TimesheetBundle\Model\TimesheetStatistic; use DateTime; @@ -30,13 +32,29 @@ use DateTime; class TimesheetRepository extends EntityRepository { + /** + * @param $select + * @param User|null $user + * @return \Doctrine\ORM\QueryBuilder + */ protected function queryThisMonth($select, User $user = null) { - $qb = $this->getEntityManager()->createQueryBuilder(); - - // FIXME $end = new DateTime(); - $begin = $end->sub(new \DateInterval("P30D")); + $begin = $end->sub(new \DateInterval("P30D")); // FIXME last month is not last 30 days + + return $this->queryTimeRange($select, $begin, $end, $user); + } + + /** + * @param $select + * @param DateTime $begin + * @param DateTime $end + * @param User|null $user + * @return \Doctrine\ORM\QueryBuilder + */ + protected function queryTimeRange($select, DateTime $begin, DateTime $end, User $user = null) + { + $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select($select) ->from('TimesheetBundle:Timesheet', 't') @@ -52,6 +70,7 @@ class TimesheetRepository extends EntityRepository return $qb; } + /** * Fetch statistic data for one user. * @@ -74,16 +93,67 @@ class TimesheetRepository extends EntityRepository $durationMonth = $this->queryThisMonth('SUM(t.duration)', $user) ->getQuery() ->getSingleScalarResult(); + $firstEntry = $this->getEntityManager() + ->createQuery('SELECT MIN(t.begin) FROM TimesheetBundle:Timesheet t WHERE t.user = :user') + ->setParameter('user', $user) + ->getSingleScalarResult(); $stats = new TimesheetStatistic(); $stats->setAmountTotal($rateTotal); $stats->setDurationTotal($durationTotal); $stats->setAmountThisMonth($amountMonth); $stats->setDurationThisMonth($durationMonth); + $stats->setFirstEntry(new DateTime($firstEntry)); return $stats; } + /** + * Returns an array of Year statistics. + * + * @param User|null $user + * @return Year[] + */ + public function getMonthlyStats(User $user = null) + { + $qb = $this->getEntityManager()->createQueryBuilder(); + + $qb->select('SUM(t.rate) as totalRate, SUM(t.duration) as totalDuration, MONTH(t.begin) as month, YEAR(t.begin) as year') + ->from('TimesheetBundle:Timesheet', 't') + ->where($qb->expr()->gt('t.begin', '0')) + ->andWhere($qb->expr()->isNotNull('t.end')) + ->orderBy('year', 'DESC') + ->addOrderBy('month', 'ASC') + ->groupBy('year') + ->addGroupBy('month'); + + if (null !== $user) { + $qb->where('t.user = :user') + ->setParameter('user', $user); + } + + $years = []; + foreach($qb->getQuery()->execute() as $statRow) { + $curYear = $statRow['year']; + + if (!isset($years[$curYear])) { + $year = new Year($curYear); + for ($i = 1; $i < 13; $i++) { + $month = $i < 10 ? '0' . $i : (string)$i; + $year->setMonth(new Month($month)); + } + $years[$curYear] = $year; + } + + $month = new Month($statRow['month']); + $month->setTotalDuration($statRow['totalDuration']) + ->setTotalRate($statRow['totalRate']); + $years[$curYear]->setMonth($month); + } + + return $years; + } + /** * Fetch statistic data for all user. * @@ -133,8 +203,8 @@ class TimesheetRepository extends EntityRepository $qb->select('t') ->from('TimesheetBundle:Timesheet', 't') - ->where('t.begin > 0') - ->andWhere('t.end is NULL'); + ->where($qb->expr()->gt('t.begin', '0')) + ->andWhere($qb->expr()->isNull('t.end')); $params = []; diff --git a/src/TimesheetBundle/Resources/views/admin/activity.html.twig b/src/TimesheetBundle/Resources/views/admin/activity.html.twig index fd86d027..1e4db236 100644 --- a/src/TimesheetBundle/Resources/views/admin/activity.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/activity.html.twig @@ -13,6 +13,7 @@ 'label.project': 'book', 'label.comment': 'comment-o', 'label.visible': 'eye', + 'label.actions': 'pencil-square-o', }) }} {% for entry in entries %} @@ -22,6 +23,9 @@ {{ entry.project }} {{ entry.comment }} {{ widgets.label_visible(entry.visible) }} + + {{ widgets.button_group({'edit': '#', 'trash': '#'}) }} + {% endfor %} diff --git a/src/TimesheetBundle/Resources/views/admin/project.html.twig b/src/TimesheetBundle/Resources/views/admin/project.html.twig index c536000b..b18086f0 100644 --- a/src/TimesheetBundle/Resources/views/admin/project.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/project.html.twig @@ -14,6 +14,7 @@ 'label.activity': 'tasks', 'label.budget': 'credit-card', 'label.visible': 'eye', + 'label.actions': 'pencil-square-o', }) }} {% for entry in entries %} @@ -24,6 +25,9 @@ {{ widgets.badge_counter(entry.activities.count) }} {{ entry.budget|money}} {{ widgets.label_visible(entry.visible) }} + + {{ widgets.button_group({'edit': '#', 'trash': '#'}) }} + {% endfor %} diff --git a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig index 8008b336..ed3495f4 100644 --- a/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig +++ b/src/TimesheetBundle/Resources/views/admin/timesheet.html.twig @@ -1,32 +1,45 @@ {% extends 'base.html.twig' %} -{% import "macros/datatables.html.twig" as widgets %} +{% import "macros/widgets.html.twig" as widgets %} +{% import "macros/datatables.html.twig" as datatables %} {% block page_title %}{{ 'admin_timesheet.title'|trans }}{% endblock %} {% block page_subtitle %}{{ 'admin_timesheet.subtitle'|trans }}{% endblock %} {% block main %} {% if entries.count > 0 %} - {{ widgets.data_table_header({ + {{ datatables.data_table_header({ 'label.date': 'calendar', 'label.starttime': 'hourglass-start', 'label.endtime': 'hourglass-end', 'label.duration': 'clock-o', + 'label.rate': 'money', 'label.username': 'user', - 'label.description': 'pencil-square-o', + 'label.description': 'comment-o', + 'label.actions': 'pencil-square-o', }) }} {% for entry in entries %} {{ entry.begin|date(kimai_context.date_1) }} {{ entry.begin|date("H:i") }} - {{ entry.end|date("H:i") }} - {{ entry.duration|duration }} - {{ entry.user.username }} + {% if entry.end %} + {{ entry.end|date("H:i") }} + {{ entry.duration|duration }} + {{ entry.rate|money }} + {% else %} + ‐ + ‐ + ‐ + {% endif %} + {{ entry.user.username }} {{ entry.description }} + + {{ widgets.button_group({'edit': '#', 'trash': '#'}) }} + {% endfor %} - {{ widgets.data_table_footer(entries, 'admin_timesheet_paginated') }} + {{ datatables.data_table_footer(entries, 'admin_timesheet_paginated') }} {% else %} {{ widgets.callout('warning', 'error.no_entries_found') }} {% endif %} diff --git a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig index 998bb027..1862fe99 100644 --- a/src/TimesheetBundle/Resources/views/timesheet/index.html.twig +++ b/src/TimesheetBundle/Resources/views/timesheet/index.html.twig @@ -1,30 +1,43 @@ {% extends 'base.html.twig' %} -{% import "macros/datatables.html.twig" as widgets %} +{% import "macros/widgets.html.twig" as widgets %} +{% import "macros/datatables.html.twig" as datatables %} {% block page_title %}{{ 'timesheet.title'|trans }}{% endblock %} {% block page_subtitle %}{{ 'timesheet.subtitle'|trans }}{% endblock %} {% block main %} {% if entries.count > 0 %} - {{ widgets.data_table_header({ + {{ datatables.data_table_header({ 'label.date': 'calendar', 'label.starttime': 'hourglass-start', 'label.endtime': 'hourglass-end', 'label.duration': 'clock-o', - 'label.description': 'pencil-square-o', + 'label.rate': 'money', + 'label.description': 'comment-o', + 'label.actions': 'pencil-square-o', }) }} {% for entry in entries %} {{ entry.begin|date(kimai_context.date_1) }} {{ entry.begin|date("H:i") }} - {{ entry.end|date("H:i") }} - {{ entry.duration|duration }} + {% if entry.end %} + {{ entry.end|date("H:i") }} + {{ entry.duration|duration }} + {{ entry.rate|money }} + {% else %} + ‐ + ‐ + ‐ + {% endif %} {{ entry.description }} + + {{ widgets.button_group({'repeat': '#', 'edit': '#', 'trash': '#'}) }} + {% endfor %} - {{ widgets.data_table_footer(entries, 'timesheet_paginated') }} + {{ datatables.data_table_footer(entries, 'timesheet_paginated') }} {% else %} {{ widgets.callout('warning', 'error.no_entries_found') }} {% endif %} diff --git a/src/TimesheetBundle/TimesheetBundle.php b/src/TimesheetBundle/TimesheetBundle.php index 5b251110..681d507f 100644 --- a/src/TimesheetBundle/TimesheetBundle.php +++ b/src/TimesheetBundle/TimesheetBundle.php @@ -12,7 +12,6 @@ namespace TimesheetBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; -use TimesheetBundle\EventListener\Menu as MenuListener; /** * This class defines the Bundle for all Timesheet related topics @@ -27,8 +26,5 @@ class TimesheetBundle extends Bundle */ public function boot() { - $listener = new MenuListener(); - /* @var $dispatcher \Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher */ - $dispatcher = $this->container->get('event_dispatcher'); } } diff --git a/web/css/kimai.css b/web/css/kimai.css index df8bc946..9d0f0478 100644 --- a/web/css/kimai.css +++ b/web/css/kimai.css @@ -2,6 +2,10 @@ width: 30px; } +.user-panel>.info { + left: 40px; + padding-top: 0px; +} /* #ticktac img { width: 100%; diff --git a/web/js/Chart.min.js b/web/js/Chart.min.js new file mode 100755 index 00000000..249ea639 --- /dev/null +++ b/web/js/Chart.min.js @@ -0,0 +1,11 @@ +/*! + * Chart.js + * http://chartjs.org/ + * Version: 1.1.1 + * + * Copyright 2015 Nick Downie + * Released under the MIT license + * https://github.com/nnnick/Chart.js/blob/master/LICENSE.md + */ +(function(){"use strict";var t=this,i=t.Chart,e=function(t){this.canvas=t.canvas,this.ctx=t;var i=function(t,i){return t["offset"+i]?t["offset"+i]:document.defaultView.getComputedStyle(t).getPropertyValue(i)};this.width=i(t.canvas,"Width")||t.canvas.width,this.height=i(t.canvas,"Height")||t.canvas.height;return this.aspectRatio=this.width/this.height,s.retinaScale(this),this};e.defaults={global:{animation:!0,animationSteps:60,animationEasing:"easeOutQuart",showScale:!0,scaleOverride:!1,scaleSteps:null,scaleStepWidth:null,scaleStartValue:null,scaleLineColor:"rgba(0,0,0,.1)",scaleLineWidth:1,scaleShowLabels:!0,scaleLabel:"<%=value%>",scaleIntegersOnly:!0,scaleBeginAtZero:!1,scaleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",scaleFontSize:12,scaleFontStyle:"normal",scaleFontColor:"#666",responsive:!1,maintainAspectRatio:!0,showTooltips:!0,customTooltips:!1,tooltipEvents:["mousemove","touchstart","touchmove","mouseout"],tooltipFillColor:"rgba(0,0,0,0.8)",tooltipFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",tooltipFontSize:14,tooltipFontStyle:"normal",tooltipFontColor:"#fff",tooltipTitleFontFamily:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",tooltipTitleFontSize:14,tooltipTitleFontStyle:"bold",tooltipTitleFontColor:"#fff",tooltipTitleTemplate:"<%= label%>",tooltipYPadding:6,tooltipXPadding:6,tooltipCaretSize:8,tooltipCornerRadius:6,tooltipXOffset:10,tooltipTemplate:"<%if (label){%><%=label%>: <%}%><%= value %>",multiTooltipTemplate:"<%= datasetLabel %>: <%= value %>",multiTooltipKeyBackground:"#fff",segmentColorDefault:["#A6CEE3","#1F78B4","#B2DF8A","#33A02C","#FB9A99","#E31A1C","#FDBF6F","#FF7F00","#CAB2D6","#6A3D9A","#B4B482","#B15928"],segmentHighlightColorDefaults:["#CEF6FF","#47A0DC","#DAFFB2","#5BC854","#FFC2C1","#FF4244","#FFE797","#FFA728","#F2DAFE","#9265C2","#DCDCAA","#D98150"],onAnimationProgress:function(){},onAnimationComplete:function(){}}},e.types={};var s=e.helpers={},n=s.each=function(t,i,e){var s=Array.prototype.slice.call(arguments,3);if(t)if(t.length===+t.length){var n;for(n=0;n=0;s--){var n=t[s];if(i(n))return n}},s.inherits=function(t){var i=this,e=t&&t.hasOwnProperty("constructor")?t.constructor:function(){return i.apply(this,arguments)},s=function(){this.constructor=e};return s.prototype=i.prototype,e.prototype=new s,e.extend=r,t&&a(e.prototype,t),e.__super__=i.prototype,e}),c=s.noop=function(){},u=s.uid=function(){var t=0;return function(){return"chart-"+t++}}(),d=s.warn=function(t){window.console&&"function"==typeof window.console.warn&&console.warn(t)},p=s.amd="function"==typeof define&&define.amd,f=s.isNumber=function(t){return!isNaN(parseFloat(t))&&isFinite(t)},g=s.max=function(t){return Math.max.apply(Math,t)},m=s.min=function(t){return Math.min.apply(Math,t)},v=(s.cap=function(t,i,e){if(f(i)){if(t>i)return i}else if(f(e)&&e>t)return e;return t},s.getDecimalPlaces=function(t){if(t%1!==0&&f(t)){var i=t.toString();if(i.indexOf("e-")<0)return i.split(".")[1].length;if(i.indexOf(".")<0)return parseInt(i.split("e-")[1]);var e=i.split(".")[1].split("e-");return e[0].length+parseInt(e[1])}return 0}),S=s.radians=function(t){return t*(Math.PI/180)},C=(s.getAngleFromPoint=function(t,i){var e=i.x-t.x,s=i.y-t.y,n=Math.sqrt(e*e+s*s),o=2*Math.PI+Math.atan2(s,e);return 0>e&&0>s&&(o+=2*Math.PI),{angle:o,distance:n}},s.aliasPixel=function(t){return t%2===0?0:.5}),x=(s.splineCurve=function(t,i,e,s){var n=Math.sqrt(Math.pow(i.x-t.x,2)+Math.pow(i.y-t.y,2)),o=Math.sqrt(Math.pow(e.x-i.x,2)+Math.pow(e.y-i.y,2)),a=s*n/(n+o),h=s*o/(n+o);return{inner:{x:i.x-a*(e.x-t.x),y:i.y-a*(e.y-t.y)},outer:{x:i.x+h*(e.x-t.x),y:i.y+h*(e.y-t.y)}}},s.calculateOrderOfMagnitude=function(t){return Math.floor(Math.log(t)/Math.LN10)}),y=(s.calculateScaleRange=function(t,i,e,s,o){var a=2,h=Math.floor(i/(1.5*e)),l=a>=h,r=[];n(t,function(t){null==t||r.push(t)});var c=m(r),u=g(r);u===c&&(u+=.5,c>=.5&&!s?c-=.5:u+=.5);for(var d=Math.abs(u-c),p=x(d),f=Math.ceil(u/(1*Math.pow(10,p)))*Math.pow(10,p),v=s?0:Math.floor(c/(1*Math.pow(10,p)))*Math.pow(10,p),S=f-v,C=Math.pow(10,p),y=Math.round(S/C);(y>h||h>2*y)&&!l;)if(y>h)C*=2,y=Math.round(S/C),y%1!==0&&(l=!0);else if(o&&p>=0){if(C/2%1!==0)break;C/=2,y=Math.round(S/C)}else C/=2,y=Math.round(S/C);return l&&(y=a,C=S/y),{steps:y,stepValue:C,min:v,max:v+y*C}},s.template=function(t,i){function e(t,i){var e=/\W/.test(t)?new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+t.replace(/[\r\t\n]/g," ").split("<%").join(" ").replace(/((^|%>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)%>/g,"',$1,'").split(" ").join("');").split("%>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');"):s[t]=s[t];return i?e(i):e}if(t instanceof Function)return t(i);var s={};return e(t,i)}),b=(s.generateLabels=function(t,i,e,s){var o=new Array(i);return t&&n(o,function(i,n){o[n]=y(t,{value:e+s*(n+1)})}),o},s.easingEffects={linear:function(t){return t},easeInQuad:function(t){return t*t},easeOutQuad:function(t){return-1*t*(t-2)},easeInOutQuad:function(t){return(t/=.5)<1?.5*t*t:-0.5*(--t*(t-2)-1)},easeInCubic:function(t){return t*t*t},easeOutCubic:function(t){return 1*((t=t/1-1)*t*t+1)},easeInOutCubic:function(t){return(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2)},easeInQuart:function(t){return t*t*t*t},easeOutQuart:function(t){return-1*((t=t/1-1)*t*t*t-1)},easeInOutQuart:function(t){return(t/=.5)<1?.5*t*t*t*t:-0.5*((t-=2)*t*t*t-2)},easeInQuint:function(t){return 1*(t/=1)*t*t*t*t},easeOutQuint:function(t){return 1*((t=t/1-1)*t*t*t*t+1)},easeInOutQuint:function(t){return(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)},easeInSine:function(t){return-1*Math.cos(t/1*(Math.PI/2))+1},easeOutSine:function(t){return 1*Math.sin(t/1*(Math.PI/2))},easeInOutSine:function(t){return-0.5*(Math.cos(Math.PI*t/1)-1)},easeInExpo:function(t){return 0===t?1:1*Math.pow(2,10*(t/1-1))},easeOutExpo:function(t){return 1===t?1:1*(-Math.pow(2,-10*t/1)+1)},easeInOutExpo:function(t){return 0===t?0:1===t?1:(t/=.5)<1?.5*Math.pow(2,10*(t-1)):.5*(-Math.pow(2,-10*--t)+2)},easeInCirc:function(t){return t>=1?t:-1*(Math.sqrt(1-(t/=1)*t)-1)},easeOutCirc:function(t){return 1*Math.sqrt(1-(t=t/1-1)*t)},easeInOutCirc:function(t){return(t/=.5)<1?-0.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},easeInElastic:function(t){var i=1.70158,e=0,s=1;return 0===t?0:1==(t/=1)?1:(e||(e=.3),st?-.5*(s*Math.pow(2,10*(t-=1))*Math.sin((1*t-i)*(2*Math.PI)/e)):s*Math.pow(2,-10*(t-=1))*Math.sin((1*t-i)*(2*Math.PI)/e)*.5+1)},easeInBack:function(t){var i=1.70158;return 1*(t/=1)*t*((i+1)*t-i)},easeOutBack:function(t){var i=1.70158;return 1*((t=t/1-1)*t*((i+1)*t+i)+1)},easeInOutBack:function(t){var i=1.70158;return(t/=.5)<1?.5*(t*t*(((i*=1.525)+1)*t-i)):.5*((t-=2)*t*(((i*=1.525)+1)*t+i)+2)},easeInBounce:function(t){return 1-b.easeOutBounce(1-t)},easeOutBounce:function(t){return(t/=1)<1/2.75?1*(7.5625*t*t):2/2.75>t?1*(7.5625*(t-=1.5/2.75)*t+.75):2.5/2.75>t?1*(7.5625*(t-=2.25/2.75)*t+.9375):1*(7.5625*(t-=2.625/2.75)*t+.984375)},easeInOutBounce:function(t){return.5>t?.5*b.easeInBounce(2*t):.5*b.easeOutBounce(2*t-1)+.5}}),w=s.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)}}(),P=(s.cancelAnimFrame=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(t){return window.clearTimeout(t,1e3/60)}}(),s.animationLoop=function(t,i,e,s,n,o){var a=0,h=b[e]||b.linear,l=function(){a++;var e=a/i,r=h(e);t.call(o,r,e,a),s.call(o,r,e),i>a?o.animationFrame=w(l):n.apply(o)};w(l)},s.getRelativePosition=function(t){var i,e,s=t.originalEvent||t,n=t.currentTarget||t.srcElement,o=n.getBoundingClientRect();return s.touches?(i=s.touches[0].clientX-o.left,e=s.touches[0].clientY-o.top):(i=s.clientX-o.left,e=s.clientY-o.top),{x:i,y:e}},s.addEvent=function(t,i,e){t.addEventListener?t.addEventListener(i,e):t.attachEvent?t.attachEvent("on"+i,e):t["on"+i]=e}),L=s.removeEvent=function(t,i,e){t.removeEventListener?t.removeEventListener(i,e,!1):t.detachEvent?t.detachEvent("on"+i,e):t["on"+i]=c},k=(s.bindEvents=function(t,i,e){t.events||(t.events={}),n(i,function(i){t.events[i]=function(){e.apply(t,arguments)},P(t.chart.canvas,i,t.events[i])})},s.unbindEvents=function(t,i){n(i,function(i,e){L(t.chart.canvas,e,i)})}),F=s.getMaximumWidth=function(t){var i=t.parentNode,e=parseInt(R(i,"padding-left"))+parseInt(R(i,"padding-right"));return i?i.clientWidth-e:0},A=s.getMaximumHeight=function(t){var i=t.parentNode,e=parseInt(R(i,"padding-bottom"))+parseInt(R(i,"padding-top"));return i?i.clientHeight-e:0},R=s.getStyle=function(t,i){return t.currentStyle?t.currentStyle[i]:document.defaultView.getComputedStyle(t,null).getPropertyValue(i)},T=(s.getMaximumSize=s.getMaximumWidth,s.retinaScale=function(t){var i=t.ctx,e=t.canvas.width,s=t.canvas.height;window.devicePixelRatio&&(i.canvas.style.width=e+"px",i.canvas.style.height=s+"px",i.canvas.height=s*window.devicePixelRatio,i.canvas.width=e*window.devicePixelRatio,i.scale(window.devicePixelRatio,window.devicePixelRatio))}),M=s.clear=function(t){t.ctx.clearRect(0,0,t.width,t.height)},W=s.fontString=function(t,i,e){return i+" "+t+"px "+e},z=s.longestText=function(t,i,e){t.font=i;var s=0;return n(e,function(i){var e=t.measureText(i).width;s=e>s?e:s}),s},B=s.drawRoundedRectangle=function(t,i,e,s,n,o){t.beginPath(),t.moveTo(i+o,e),t.lineTo(i+s-o,e),t.quadraticCurveTo(i+s,e,i+s,e+o),t.lineTo(i+s,e+n-o),t.quadraticCurveTo(i+s,e+n,i+s-o,e+n),t.lineTo(i+o,e+n),t.quadraticCurveTo(i,e+n,i,e+n-o),t.lineTo(i,e+o),t.quadraticCurveTo(i,e,i+o,e),t.closePath()};e.instances={},e.Type=function(t,i,s){this.options=i,this.chart=s,this.id=u(),e.instances[this.id]=this,i.responsive&&this.resize(),this.initialize.call(this,t)},a(e.Type.prototype,{initialize:function(){return this},clear:function(){return M(this.chart),this},stop:function(){return e.animationService.cancelAnimation(this),this},resize:function(t){this.stop();var i=this.chart.canvas,e=F(this.chart.canvas),s=this.options.maintainAspectRatio?e/this.chart.aspectRatio:A(this.chart.canvas);return i.width=this.chart.width=e,i.height=this.chart.height=s,T(this.chart),"function"==typeof t&&t.apply(this,Array.prototype.slice.call(arguments,1)),this},reflow:c,render:function(t){if(t&&this.reflow(),this.options.animation&&!t){var i=new e.Animation;i.numSteps=this.options.animationSteps,i.easing=this.options.animationEasing,i.render=function(t,i){var e=s.easingEffects[i.easing],n=i.currentStep/i.numSteps,o=e(n);t.draw(o,n,i.currentStep)},i.onAnimationProgress=this.options.onAnimationProgress,i.onAnimationComplete=this.options.onAnimationComplete,e.animationService.addAnimation(this,i)}else this.draw(),this.options.onAnimationComplete.call(this);return this},generateLegend:function(){return s.template(this.options.legendTemplate,this)},destroy:function(){this.stop(),this.clear(),k(this,this.events);var t=this.chart.canvas;t.width=this.chart.width,t.height=this.chart.height,t.style.removeProperty?(t.style.removeProperty("width"),t.style.removeProperty("height")):(t.style.removeAttribute("width"),t.style.removeAttribute("height")),delete e.instances[this.id]},showTooltip:function(t,i){"undefined"==typeof this.activeElements&&(this.activeElements=[]);var o=function(t){var i=!1;return t.length!==this.activeElements.length?i=!0:(n(t,function(t,e){t!==this.activeElements[e]&&(i=!0)},this),i)}.call(this,t);if(o||i){if(this.activeElements=t,this.draw(),this.options.customTooltips&&this.options.customTooltips(!1),t.length>0)if(this.datasets&&this.datasets.length>1){for(var a,h,r=this.datasets.length-1;r>=0&&(a=this.datasets[r].points||this.datasets[r].bars||this.datasets[r].segments,h=l(a,t[0]),-1===h);r--);var c=[],u=[],d=function(t){var i,e,n,o,a,l=[],r=[],d=[];return s.each(this.datasets,function(t){i=t.points||t.bars||t.segments,i[h]&&i[h].hasValue()&&l.push(i[h])}),s.each(l,function(t){r.push(t.x),d.push(t.y),c.push(s.template(this.options.multiTooltipTemplate,t)),u.push({fill:t._saved.fillColor||t.fillColor,stroke:t._saved.strokeColor||t.strokeColor})},this),a=m(d),n=g(d),o=m(r),e=g(r),{x:o>this.chart.width/2?o:e,y:(a+n)/2}}.call(this,h);new e.MultiTooltip({x:d.x,y:d.y,xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,xOffset:this.options.tooltipXOffset,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,titleTextColor:this.options.tooltipTitleFontColor,titleFontFamily:this.options.tooltipTitleFontFamily,titleFontStyle:this.options.tooltipTitleFontStyle,titleFontSize:this.options.tooltipTitleFontSize,cornerRadius:this.options.tooltipCornerRadius,labels:c,legendColors:u,legendColorBackground:this.options.multiTooltipKeyBackground,title:y(this.options.tooltipTitleTemplate,t[0]),chart:this.chart,ctx:this.chart.ctx,custom:this.options.customTooltips}).draw()}else n(t,function(t){var i=t.tooltipPosition();new e.Tooltip({x:Math.round(i.x),y:Math.round(i.y),xPadding:this.options.tooltipXPadding,yPadding:this.options.tooltipYPadding,fillColor:this.options.tooltipFillColor,textColor:this.options.tooltipFontColor,fontFamily:this.options.tooltipFontFamily,fontStyle:this.options.tooltipFontStyle,fontSize:this.options.tooltipFontSize,caretHeight:this.options.tooltipCaretSize,cornerRadius:this.options.tooltipCornerRadius,text:y(this.options.tooltipTemplate,t),chart:this.chart,custom:this.options.customTooltips}).draw()},this);return this}},toBase64Image:function(){return this.chart.canvas.toDataURL.apply(this.chart.canvas,arguments)}}),e.Type.extend=function(t){var i=this,s=function(){return i.apply(this,arguments)};if(s.prototype=o(i.prototype),a(s.prototype,t),s.extend=e.Type.extend,t.name||i.prototype.name){var n=t.name||i.prototype.name,l=e.defaults[i.prototype.name]?o(e.defaults[i.prototype.name]):{};e.defaults[n]=a(l,t.defaults),e.types[n]=s,e.prototype[n]=function(t,i){var o=h(e.defaults.global,e.defaults[n],i||{});return new s(t,o,this)}}else d("Name not provided for this chart, so it hasn't been registered");return i},e.Element=function(t){a(this,t),this.initialize.apply(this,arguments),this.save()},a(e.Element.prototype,{initialize:function(){},restore:function(t){return t?n(t,function(t){this[t]=this._saved[t]},this):a(this,this._saved),this},save:function(){return this._saved=o(this),delete this._saved._saved,this},update:function(t){return n(t,function(t,i){this._saved[i]=this[i],this[i]=t},this),this},transition:function(t,i){return n(t,function(t,e){this[e]=(t-this._saved[e])*i+this._saved[e]},this),this},tooltipPosition:function(){return{x:this.x,y:this.y}},hasValue:function(){return f(this.value)}}),e.Element.extend=r,e.Point=e.Element.extend({display:!0,inRange:function(t,i){var e=this.hitDetectionRadius+this.radius;return Math.pow(t-this.x,2)+Math.pow(i-this.y,2)a?a>=n||n>=o:n>=o&&a>=n,l=e.distance>=this.innerRadius&&e.distance<=this.outerRadius;return h&&l},tooltipPosition:function(){var t=this.startAngle+(this.endAngle-this.startAngle)/2,i=(this.outerRadius-this.innerRadius)/2+this.innerRadius;return{x:this.x+Math.cos(t)*i,y:this.y+Math.sin(t)*i}},draw:function(t){var i=this.ctx;i.beginPath(),i.arc(this.x,this.y,this.outerRadius<0?0:this.outerRadius,this.startAngle,this.endAngle),i.arc(this.x,this.y,this.innerRadius<0?0:this.innerRadius,this.endAngle,this.startAngle,!0),i.closePath(),i.strokeStyle=this.strokeColor,i.lineWidth=this.strokeWidth,i.fillStyle=this.fillColor,i.fill(),i.lineJoin="bevel",this.showStroke&&i.stroke()}}),e.Rectangle=e.Element.extend({draw:function(){var t=this.ctx,i=this.width/2,e=this.x-i,s=this.x+i,n=this.base-(this.base-this.y),o=this.strokeWidth/2;this.showStroke&&(e+=o,s-=o,n+=o),t.beginPath(),t.fillStyle=this.fillColor,t.strokeStyle=this.strokeColor,t.lineWidth=this.strokeWidth,t.moveTo(e,this.base),t.lineTo(e,n),t.lineTo(s,n),t.lineTo(s,this.base),t.fill(),this.showStroke&&t.stroke()},height:function(){return this.base-this.y},inRange:function(t,i){return t>=this.x-this.width/2&&t<=this.x+this.width/2&&i>=this.y&&i<=this.base}}),e.Animation=e.Element.extend({currentStep:null,numSteps:60,easing:"",render:null,onAnimationProgress:null,onAnimationComplete:null}),e.Tooltip=e.Element.extend({draw:function(){var t=this.chart.ctx;t.font=W(this.fontSize,this.fontStyle,this.fontFamily),this.xAlign="center",this.yAlign="above";var i=this.caretPadding=2,e=t.measureText(this.text).width+2*this.xPadding,s=this.fontSize+2*this.yPadding,n=s+this.caretHeight+i;this.x+e/2>this.chart.width?this.xAlign="left":this.x-e/2<0&&(this.xAlign="right"),this.y-n<0&&(this.yAlign="below");var o=this.x-e/2,a=this.y-n;if(t.fillStyle=this.fillColor,this.custom)this.custom(this);else{switch(this.yAlign){case"above":t.beginPath(),t.moveTo(this.x,this.y-i),t.lineTo(this.x+this.caretHeight,this.y-(i+this.caretHeight)),t.lineTo(this.x-this.caretHeight,this.y-(i+this.caretHeight)),t.closePath(),t.fill();break;case"below":a=this.y+i+this.caretHeight,t.beginPath(),t.moveTo(this.x,this.y+i),t.lineTo(this.x+this.caretHeight,this.y+i+this.caretHeight),t.lineTo(this.x-this.caretHeight,this.y+i+this.caretHeight),t.closePath(),t.fill()}switch(this.xAlign){case"left":o=this.x-e+(this.cornerRadius+this.caretHeight);break;case"right":o=this.x-(this.cornerRadius+this.caretHeight)}B(t,o,a,e,s,this.cornerRadius),t.fill(),t.fillStyle=this.textColor,t.textAlign="center",t.textBaseline="middle",t.fillText(this.text,o+e/2,a+s/2)}}}),e.MultiTooltip=e.Element.extend({initialize:function(){this.font=W(this.fontSize,this.fontStyle,this.fontFamily),this.titleFont=W(this.titleFontSize,this.titleFontStyle,this.titleFontFamily),this.titleHeight=this.title?1.5*this.titleFontSize:0,this.height=this.labels.length*this.fontSize+(this.labels.length-1)*(this.fontSize/2)+2*this.yPadding+this.titleHeight,this.ctx.font=this.titleFont;var t=this.ctx.measureText(this.title).width,i=z(this.ctx,this.font,this.labels)+this.fontSize+3,e=g([i,t]);this.width=e+2*this.xPadding;var s=this.height/2;this.y-s<0?this.y=s:this.y+s>this.chart.height&&(this.y=this.chart.height-s),this.x>this.chart.width/2?this.x-=this.xOffset+this.width:this.x+=this.xOffset},getLineHeight:function(t){var i=this.y-this.height/2+this.yPadding,e=t-1;return 0===t?i+this.titleHeight/3:i+(1.5*this.fontSize*e+this.fontSize/2)+this.titleHeight},draw:function(){if(this.custom)this.custom(this);else{B(this.ctx,this.x,this.y-this.height/2,this.width,this.height,this.cornerRadius);var t=this.ctx;t.fillStyle=this.fillColor,t.fill(),t.closePath(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=this.titleTextColor,t.font=this.titleFont,t.fillText(this.title,this.x+this.xPadding,this.getLineHeight(0)),t.font=this.font,s.each(this.labels,function(i,e){t.fillStyle=this.textColor,t.fillText(i,this.x+this.xPadding+this.fontSize+3,this.getLineHeight(e+1)),t.fillStyle=this.legendColorBackground,t.fillRect(this.x+this.xPadding,this.getLineHeight(e+1)-this.fontSize/2,this.fontSize,this.fontSize),t.fillStyle=this.legendColors[e].fill,t.fillRect(this.x+this.xPadding,this.getLineHeight(e+1)-this.fontSize/2,this.fontSize,this.fontSize)},this)}}}),e.Scale=e.Element.extend({initialize:function(){this.fit()},buildYLabels:function(){this.yLabels=[];for(var t=v(this.stepValue),i=0;i<=this.steps;i++)this.yLabels.push(y(this.templateString,{value:(this.min+i*this.stepValue).toFixed(t)}));this.yLabelWidth=this.display&&this.showLabels?z(this.ctx,this.font,this.yLabels)+10:0},addXLabel:function(t){this.xLabels.push(t),this.valuesCount++,this.fit()},removeXLabel:function(){this.xLabels.shift(),this.valuesCount--,this.fit()},fit:function(){this.startPoint=this.display?this.fontSize:0,this.endPoint=this.display?this.height-1.5*this.fontSize-5:this.height,this.startPoint+=this.padding,this.endPoint-=this.padding;var t,i=this.endPoint,e=this.endPoint-this.startPoint;for(this.calculateYRange(e),this.buildYLabels(),this.calculateXLabelRotation();e>this.endPoint-this.startPoint;)e=this.endPoint-this.startPoint,t=this.yLabelWidth,this.calculateYRange(e),this.buildYLabels(),tthis.yLabelWidth?e/2:this.yLabelWidth,this.xLabelRotation=0,this.display){var n,o=z(this.ctx,this.font,this.xLabels);this.xLabelWidth=o;for(var a=Math.floor(this.calculateX(1)-this.calculateX(0))-6;this.xLabelWidth>a&&0===this.xLabelRotation||this.xLabelWidth>a&&this.xLabelRotation<=90&&this.xLabelRotation>0;)n=Math.cos(S(this.xLabelRotation)),t=n*e,i=n*s,t+this.fontSize/2>this.yLabelWidth&&(this.xScalePaddingLeft=t+this.fontSize/2),this.xScalePaddingRight=this.fontSize/2,this.xLabelRotation++,this.xLabelWidth=n*o;this.xLabelRotation>0&&(this.endPoint-=Math.sin(S(this.xLabelRotation))*o+3)}else this.xLabelWidth=0,this.xScalePaddingRight=this.padding,this.xScalePaddingLeft=this.padding},calculateYRange:c,drawingArea:function(){return this.startPoint-this.endPoint},calculateY:function(t){var i=this.drawingArea()/(this.min-this.max);return this.endPoint-i*(t-this.min)},calculateX:function(t){var i=(this.xLabelRotation>0,this.width-(this.xScalePaddingLeft+this.xScalePaddingRight)),e=i/Math.max(this.valuesCount-(this.offsetGridLines?0:1),1),s=e*t+this.xScalePaddingLeft;return this.offsetGridLines&&(s+=e/2),Math.round(s)},update:function(t){s.extend(this,t),this.fit()},draw:function(){var t=this.ctx,i=(this.endPoint-this.startPoint)/this.steps,e=Math.round(this.xScalePaddingLeft);this.display&&(t.fillStyle=this.textColor,t.font=this.font,n(this.yLabels,function(n,o){var a=this.endPoint-i*o,h=Math.round(a),l=this.showHorizontalLines;t.textAlign="right",t.textBaseline="middle",this.showLabels&&t.fillText(n,e-10,a),0!==o||l||(l=!0),l&&t.beginPath(),o>0?(t.lineWidth=this.gridLineWidth,t.strokeStyle=this.gridLineColor):(t.lineWidth=this.lineWidth,t.strokeStyle=this.lineColor),h+=s.aliasPixel(t.lineWidth),l&&(t.moveTo(e,h),t.lineTo(this.width,h),t.stroke(),t.closePath()),t.lineWidth=this.lineWidth,t.strokeStyle=this.lineColor,t.beginPath(),t.moveTo(e-5,h),t.lineTo(e,h),t.stroke(),t.closePath()},this),n(this.xLabels,function(i,e){var s=this.calculateX(e)+C(this.lineWidth),n=this.calculateX(e-(this.offsetGridLines?.5:0))+C(this.lineWidth),o=this.xLabelRotation>0,a=this.showVerticalLines;0!==e||a||(a=!0),a&&t.beginPath(),e>0?(t.lineWidth=this.gridLineWidth,t.strokeStyle=this.gridLineColor):(t.lineWidth=this.lineWidth,t.strokeStyle=this.lineColor),a&&(t.moveTo(n,this.endPoint),t.lineTo(n,this.startPoint-3),t.stroke(),t.closePath()),t.lineWidth=this.lineWidth,t.strokeStyle=this.lineColor,t.beginPath(),t.moveTo(n,this.endPoint),t.lineTo(n,this.endPoint+5),t.stroke(),t.closePath(),t.save(),t.translate(s,o?this.endPoint+12:this.endPoint+8),t.rotate(-1*S(this.xLabelRotation)),t.font=this.font,t.textAlign=o?"right":"center",t.textBaseline=o?"middle":"top",t.fillText(i,0,0),t.restore()},this))}}),e.RadialScale=e.Element.extend({initialize:function(){this.size=m([this.height,this.width]),this.drawingArea=this.display?this.size/2-(this.fontSize/2+this.backdropPaddingY):this.size/2},calculateCenterOffset:function(t){var i=this.drawingArea/(this.max-this.min);return(t-this.min)*i},update:function(){this.lineArc?this.drawingArea=this.display?this.size/2-(this.fontSize/2+this.backdropPaddingY):this.size/2:this.setScaleSize(),this.buildYLabels()},buildYLabels:function(){this.yLabels=[];for(var t=v(this.stepValue),i=0;i<=this.steps;i++)this.yLabels.push(y(this.templateString,{value:(this.min+i*this.stepValue).toFixed(t)}))},getCircumference:function(){return 2*Math.PI/this.valuesCount},setScaleSize:function(){var t,i,e,s,n,o,a,h,l,r,c,u,d=m([this.height/2-this.pointLabelFontSize-5,this.width/2]),p=this.width,g=0;for(this.ctx.font=W(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily),i=0;ip&&(p=t.x+s,n=i),t.x-sp&&(p=t.x+e,n=i):i>this.valuesCount/2&&t.x-e0){var s,n=e*(this.drawingArea/this.steps),o=this.yCenter-n;if(this.lineWidth>0)if(t.strokeStyle=this.lineColor,t.lineWidth=this.lineWidth,this.lineArc)t.beginPath(),t.arc(this.xCenter,this.yCenter,n,0,2*Math.PI),t.closePath(),t.stroke();else{t.beginPath();for(var a=0;a=0;i--){var e=null,s=null;if(this.angleLineWidth>0&&i%this.angleLineInterval===0&&(e=this.calculateCenterOffset(this.max),s=this.getPointPosition(i,e),t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(s.x,s.y),t.stroke(),t.closePath()),this.backgroundColors&&this.backgroundColors.length==this.valuesCount){null==e&&(e=this.calculateCenterOffset(this.max)),null==s&&(s=this.getPointPosition(i,e));var o=this.getPointPosition(0===i?this.valuesCount-1:i-1,e),a=this.getPointPosition(i===this.valuesCount-1?0:i+1,e),h={x:(o.x+s.x)/2,y:(o.y+s.y)/2},l={x:(s.x+a.x)/2,y:(s.y+a.y)/2};t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(h.x,h.y),t.lineTo(s.x,s.y),t.lineTo(l.x,l.y),t.fillStyle=this.backgroundColors[i],t.fill(),t.closePath()}var r=this.getPointPosition(i,this.calculateCenterOffset(this.max)+5);t.font=W(this.pointLabelFontSize,this.pointLabelFontStyle,this.pointLabelFontFamily),t.fillStyle=this.pointLabelFontColor;var c=this.labels.length,u=this.labels.length/2,d=u/2,p=d>i||i>c-d,f=i===d||i===c-d;0===i?t.textAlign="center":i===u?t.textAlign="center":u>i?t.textAlign="left":t.textAlign="right",f?t.textBaseline="middle":p?t.textBaseline="bottom":t.textBaseline="top",t.fillText(this.labels[i],r.x,r.y)}}}}}),e.animationService={frameDuration:17,animations:[],dropFrames:0,addAnimation:function(t,i){for(var e=0;e1&&(i=Math.floor(this.dropFrames),this.dropFrames-=i);for(var e=0;ethis.animations[e].animationObject.numSteps&&(this.animations[e].animationObject.currentStep=this.animations[e].animationObject.numSteps),this.animations[e].animationObject.render(this.animations[e].chartInstance,this.animations[e].animationObject),this.animations[e].animationObject.currentStep==this.animations[e].animationObject.numSteps&&(this.animations[e].animationObject.onAnimationComplete.call(this.animations[e].chartInstance),this.animations.splice(e,1),e--);var n=Date.now(),o=n-t-this.frameDuration,a=o/this.frameDuration;a>1&&(this.dropFrames+=a),this.animations.length>0&&s.requestAnimFrame.call(window,this.digestWrapper)}},s.addEvent(window,"resize",function(){var t;return function(){clearTimeout(t),t=setTimeout(function(){n(e.instances,function(t){t.options.responsive&&t.resize(t.render,!0)})},50)}}()),p?define("Chart",[],function(){return e}):"object"==typeof module&&module.exports&&(module.exports=e),t.Chart=e,e.noConflict=function(){return t.Chart=i,e}}).call(this),function(){"use strict";var t=this,i=t.Chart,e=i.helpers,s={scaleBeginAtZero:!0,scaleShowGridLines:!0,scaleGridLineColor:"rgba(0,0,0,.05)",scaleGridLineWidth:1,scaleShowHorizontalLines:!0,scaleShowVerticalLines:!0,barShowStroke:!0,barStrokeWidth:2,barValueSpacing:5,barDatasetSpacing:1,legendTemplate:'
      <% for (var i=0; i
    • <%if(datasets[i].label){%><%=datasets[i].label%><%}%>
    • <%}%>
    '};i.Type.extend({name:"Bar",defaults:s,initialize:function(t){var s=this.options;this.ScaleClass=i.Scale.extend({offsetGridLines:!0,calculateBarX:function(t,i,e){var n=this.calculateBaseWidth(),o=this.calculateX(e)-n/2,a=this.calculateBarWidth(t);return o+a*i+i*s.barDatasetSpacing+a/2},calculateBaseWidth:function(){return this.calculateX(1)-this.calculateX(0)-2*s.barValueSpacing; +},calculateBarWidth:function(t){var i=this.calculateBaseWidth()-(t-1)*s.barDatasetSpacing;return i/t}}),this.datasets=[],this.options.showTooltips&&e.bindEvents(this,this.options.tooltipEvents,function(t){var i="mouseout"!==t.type?this.getBarsAtEvent(t):[];this.eachBars(function(t){t.restore(["fillColor","strokeColor"])}),e.each(i,function(t){t&&(t.fillColor=t.highlightFill,t.strokeColor=t.highlightStroke)}),this.showTooltip(i)}),this.BarClass=i.Rectangle.extend({strokeWidth:this.options.barStrokeWidth,showStroke:this.options.barShowStroke,ctx:this.chart.ctx}),e.each(t.datasets,function(i,s){var n={label:i.label||null,fillColor:i.fillColor,strokeColor:i.strokeColor,bars:[]};this.datasets.push(n),e.each(i.data,function(e,s){n.bars.push(new this.BarClass({value:e,label:t.labels[s],datasetLabel:i.label,strokeColor:"object"==typeof i.strokeColor?i.strokeColor[s]:i.strokeColor,fillColor:"object"==typeof i.fillColor?i.fillColor[s]:i.fillColor,highlightFill:i.highlightFill?"object"==typeof i.highlightFill?i.highlightFill[s]:i.highlightFill:"object"==typeof i.fillColor?i.fillColor[s]:i.fillColor,highlightStroke:i.highlightStroke?"object"==typeof i.highlightStroke?i.highlightStroke[s]:i.highlightStroke:"object"==typeof i.strokeColor?i.strokeColor[s]:i.strokeColor}))},this)},this),this.buildScale(t.labels),this.BarClass.prototype.base=this.scale.endPoint,this.eachBars(function(t,i,s){e.extend(t,{width:this.scale.calculateBarWidth(this.datasets.length),x:this.scale.calculateBarX(this.datasets.length,s,i),y:this.scale.endPoint}),t.save()},this),this.render()},update:function(){this.scale.update(),e.each(this.activeElements,function(t){t.restore(["fillColor","strokeColor"])}),this.eachBars(function(t){t.save()}),this.render()},eachBars:function(t){e.each(this.datasets,function(i,s){e.each(i.bars,t,this,s)},this)},getBarsAtEvent:function(t){for(var i,s=[],n=e.getRelativePosition(t),o=function(t){s.push(t.bars[i])},a=0;a<% for (var i=0; i
  • <%if(segments[i].label){%><%=segments[i].label%><%}%>
  • <%}%>'};i.Type.extend({name:"Doughnut",defaults:s,initialize:function(t){this.segments=[],this.outerRadius=(e.min([this.chart.width,this.chart.height])-this.options.segmentStrokeWidth/2)/2,this.SegmentArc=i.Arc.extend({ctx:this.chart.ctx,x:this.chart.width/2,y:this.chart.height/2}),this.options.showTooltips&&e.bindEvents(this,this.options.tooltipEvents,function(t){var i="mouseout"!==t.type?this.getSegmentsAtEvent(t):[];e.each(this.segments,function(t){t.restore(["fillColor"])}),e.each(i,function(t){t.fillColor=t.highlightColor}),this.showTooltip(i)}),this.calculateTotal(t),e.each(t,function(i,e){i.color||(i.color="hsl("+360*e/t.length+", 100%, 50%)"),this.addData(i,e,!0)},this),this.render()},getSegmentsAtEvent:function(t){var i=[],s=e.getRelativePosition(t);return e.each(this.segments,function(t){t.inRange(s.x,s.y)&&i.push(t)},this),i},addData:function(t,e,s){var n=void 0!==e?e:this.segments.length;"undefined"==typeof t.color&&(t.color=i.defaults.global.segmentColorDefault[n%i.defaults.global.segmentColorDefault.length],t.highlight=i.defaults.global.segmentHighlightColorDefaults[n%i.defaults.global.segmentHighlightColorDefaults.length]),this.segments.splice(n,0,new this.SegmentArc({value:t.value,outerRadius:this.options.animateScale?0:this.outerRadius,innerRadius:this.options.animateScale?0:this.outerRadius/100*this.options.percentageInnerCutout,fillColor:t.color,highlightColor:t.highlight||t.color,showStroke:this.options.segmentShowStroke,strokeWidth:this.options.segmentStrokeWidth,strokeColor:this.options.segmentStrokeColor,startAngle:1.5*Math.PI,circumference:this.options.animateRotate?0:this.calculateCircumference(t.value),label:t.label})),s||(this.reflow(),this.update())},calculateCircumference:function(t){return this.total>0?2*Math.PI*(t/this.total):0},calculateTotal:function(t){this.total=0,e.each(t,function(t){this.total+=Math.abs(t.value)},this)},update:function(){this.calculateTotal(this.segments),e.each(this.activeElements,function(t){t.restore(["fillColor"])}),e.each(this.segments,function(t){t.save()}),this.render()},removeData:function(t){var i=e.isNumber(t)?t:this.segments.length-1;this.segments.splice(i,1),this.reflow(),this.update()},reflow:function(){e.extend(this.SegmentArc.prototype,{x:this.chart.width/2,y:this.chart.height/2}),this.outerRadius=(e.min([this.chart.width,this.chart.height])-this.options.segmentStrokeWidth/2)/2,e.each(this.segments,function(t){t.update({outerRadius:this.outerRadius,innerRadius:this.outerRadius/100*this.options.percentageInnerCutout})},this)},draw:function(t){var i=t?t:1;this.clear(),e.each(this.segments,function(t,e){t.transition({circumference:this.calculateCircumference(t.value),outerRadius:this.outerRadius,innerRadius:this.outerRadius/100*this.options.percentageInnerCutout},i),t.endAngle=t.startAngle+t.circumference,t.draw(),0===e&&(t.startAngle=1.5*Math.PI),e<% for (var i=0; i
  • <%if(datasets[i].label){%><%=datasets[i].label%><%}%>
  • <%}%>',offsetGridLines:!1};i.Type.extend({name:"Line",defaults:s,initialize:function(t){this.PointClass=i.Point.extend({offsetGridLines:this.options.offsetGridLines,strokeWidth:this.options.pointDotStrokeWidth,radius:this.options.pointDotRadius,display:this.options.pointDot,hitDetectionRadius:this.options.pointHitDetectionRadius,ctx:this.chart.ctx,inRange:function(t){return Math.pow(t-this.x,2)0&&ithis.scale.endPoint?t.controlPoints.outer.y=this.scale.endPoint:t.controlPoints.outer.ythis.scale.endPoint?t.controlPoints.inner.y=this.scale.endPoint:t.controlPoints.inner.y0&&(s.lineTo(h[h.length-1].x,this.scale.endPoint),s.lineTo(h[0].x,this.scale.endPoint),s.fillStyle=t.fillColor,s.closePath(),s.fill()),e.each(h,function(t){t.draw()})},this))}})}.call(this),function(){"use strict";var t=this,i=t.Chart,e=i.helpers,s={scaleShowLabelBackdrop:!0,scaleBackdropColor:"rgba(255,255,255,0.75)",scaleBeginAtZero:!0,scaleBackdropPaddingY:2,scaleBackdropPaddingX:2,scaleShowLine:!0,segmentShowStroke:!0,segmentStrokeColor:"#fff",segmentStrokeWidth:2,animationSteps:100,animationEasing:"easeOutBounce",animateRotate:!0,animateScale:!1,legendTemplate:'
      <% for (var i=0; i
    • <%if(segments[i].label){%><%=segments[i].label%><%}%>
    • <%}%>
    '};i.Type.extend({name:"PolarArea",defaults:s,initialize:function(t){this.segments=[],this.SegmentArc=i.Arc.extend({showStroke:this.options.segmentShowStroke,strokeWidth:this.options.segmentStrokeWidth,strokeColor:this.options.segmentStrokeColor,ctx:this.chart.ctx,innerRadius:0,x:this.chart.width/2,y:this.chart.height/2}),this.scale=new i.RadialScale({display:this.options.showScale,fontStyle:this.options.scaleFontStyle,fontSize:this.options.scaleFontSize,fontFamily:this.options.scaleFontFamily,fontColor:this.options.scaleFontColor,showLabels:this.options.scaleShowLabels,showLabelBackdrop:this.options.scaleShowLabelBackdrop,backdropColor:this.options.scaleBackdropColor,backdropPaddingY:this.options.scaleBackdropPaddingY,backdropPaddingX:this.options.scaleBackdropPaddingX,lineWidth:this.options.scaleShowLine?this.options.scaleLineWidth:0,lineColor:this.options.scaleLineColor,lineArc:!0,width:this.chart.width,height:this.chart.height,xCenter:this.chart.width/2,yCenter:this.chart.height/2,ctx:this.chart.ctx,templateString:this.options.scaleLabel,valuesCount:t.length}),this.updateScaleRange(t),this.scale.update(),e.each(t,function(t,i){this.addData(t,i,!0)},this),this.options.showTooltips&&e.bindEvents(this,this.options.tooltipEvents,function(t){var i="mouseout"!==t.type?this.getSegmentsAtEvent(t):[];e.each(this.segments,function(t){t.restore(["fillColor"])}),e.each(i,function(t){t.fillColor=t.highlightColor}),this.showTooltip(i)}),this.render()},getSegmentsAtEvent:function(t){var i=[],s=e.getRelativePosition(t);return e.each(this.segments,function(t){t.inRange(s.x,s.y)&&i.push(t)},this),i},addData:function(t,i,e){var s=i||this.segments.length;this.segments.splice(s,0,new this.SegmentArc({fillColor:t.color,highlightColor:t.highlight||t.color,label:t.label,value:t.value,outerRadius:this.options.animateScale?0:this.scale.calculateCenterOffset(t.value),circumference:this.options.animateRotate?0:this.scale.getCircumference(),startAngle:1.5*Math.PI})),e||(this.reflow(),this.update())},removeData:function(t){var i=e.isNumber(t)?t:this.segments.length-1;this.segments.splice(i,1),this.reflow(),this.update()},calculateTotal:function(t){this.total=0,e.each(t,function(t){this.total+=t.value},this),this.scale.valuesCount=this.segments.length},updateScaleRange:function(t){var i=[];e.each(t,function(t){i.push(t.value)});var s=this.options.scaleOverride?{steps:this.options.scaleSteps,stepValue:this.options.scaleStepWidth,min:this.options.scaleStartValue,max:this.options.scaleStartValue+this.options.scaleSteps*this.options.scaleStepWidth}:e.calculateScaleRange(i,e.min([this.chart.width,this.chart.height])/2,this.options.scaleFontSize,this.options.scaleBeginAtZero,this.options.scaleIntegersOnly);e.extend(this.scale,s,{size:e.min([this.chart.width,this.chart.height]),xCenter:this.chart.width/2,yCenter:this.chart.height/2})},update:function(){this.calculateTotal(this.segments),e.each(this.segments,function(t){t.save()}),this.reflow(),this.render()},reflow:function(){e.extend(this.SegmentArc.prototype,{x:this.chart.width/2,y:this.chart.height/2}),this.updateScaleRange(this.segments),this.scale.update(),e.extend(this.scale,{xCenter:this.chart.width/2,yCenter:this.chart.height/2}),e.each(this.segments,function(t){t.update({outerRadius:this.scale.calculateCenterOffset(t.value)})},this)},draw:function(t){var i=t||1;this.clear(),e.each(this.segments,function(t,e){t.transition({circumference:this.scale.getCircumference(),outerRadius:this.scale.calculateCenterOffset(t.value)},i),t.endAngle=t.startAngle+t.circumference,0===e&&(t.startAngle=1.5*Math.PI),e<% for (var i=0; i
  • <%if(datasets[i].label){%><%=datasets[i].label%><%}%>
  • <%}%>'},initialize:function(t){this.PointClass=i.Point.extend({strokeWidth:this.options.pointDotStrokeWidth,radius:this.options.pointDotRadius,display:this.options.pointDot,hitDetectionRadius:this.options.pointHitDetectionRadius,ctx:this.chart.ctx}),this.datasets=[],this.buildScale(t),this.options.showTooltips&&e.bindEvents(this,this.options.tooltipEvents,function(t){var i="mouseout"!==t.type?this.getPointsAtEvent(t):[];this.eachPoints(function(t){t.restore(["fillColor","strokeColor"])}),e.each(i,function(t){t.fillColor=t.highlightFill,t.strokeColor=t.highlightStroke}),this.showTooltip(i)}),e.each(t.datasets,function(i){var s={label:i.label||null,fillColor:i.fillColor,strokeColor:i.strokeColor,pointColor:i.pointColor,pointStrokeColor:i.pointStrokeColor,points:[]};this.datasets.push(s),e.each(i.data,function(e,n){var o;this.scale.animation||(o=this.scale.getPointPosition(n,this.scale.calculateCenterOffset(e))),s.points.push(new this.PointClass({value:e,label:t.labels[n],datasetLabel:i.label,x:this.options.animation?this.scale.xCenter:o.x,y:this.options.animation?this.scale.yCenter:o.y,strokeColor:i.pointStrokeColor,fillColor:i.pointColor,highlightFill:i.pointHighlightFill||i.pointColor,highlightStroke:i.pointHighlightStroke||i.pointStrokeColor}))},this)},this),this.render()},eachPoints:function(t){e.each(this.datasets,function(i){e.each(i.points,t,this)},this)},getPointsAtEvent:function(t){var i=e.getRelativePosition(t),s=e.getAngleFromPoint({x:this.scale.xCenter,y:this.scale.yCenter},i),n=2*Math.PI/this.scale.valuesCount,o=Math.round((s.angle-1.5*Math.PI)/n),a=[];return(o>=this.scale.valuesCount||0>o)&&(o=0),s.distance<=this.scale.drawingArea&&e.each(this.datasets,function(t){a.push(t.points[o])}),a},buildScale:function(t){this.scale=new i.RadialScale({display:this.options.showScale,fontStyle:this.options.scaleFontStyle,fontSize:this.options.scaleFontSize,fontFamily:this.options.scaleFontFamily,fontColor:this.options.scaleFontColor,showLabels:this.options.scaleShowLabels,showLabelBackdrop:this.options.scaleShowLabelBackdrop,backdropColor:this.options.scaleBackdropColor,backgroundColors:this.options.scaleBackgroundColors,backdropPaddingY:this.options.scaleBackdropPaddingY,backdropPaddingX:this.options.scaleBackdropPaddingX,lineWidth:this.options.scaleShowLine?this.options.scaleLineWidth:0,lineColor:this.options.scaleLineColor,angleLineColor:this.options.angleLineColor,angleLineWidth:this.options.angleShowLineOut?this.options.angleLineWidth:0,angleLineInterval:this.options.angleLineInterval?this.options.angleLineInterval:1,pointLabelFontColor:this.options.pointLabelFontColor,pointLabelFontSize:this.options.pointLabelFontSize,pointLabelFontFamily:this.options.pointLabelFontFamily,pointLabelFontStyle:this.options.pointLabelFontStyle,height:this.chart.height,width:this.chart.width,xCenter:this.chart.width/2,yCenter:this.chart.height/2,ctx:this.chart.ctx,templateString:this.options.scaleLabel,labels:t.labels,valuesCount:t.datasets[0].data.length}),this.scale.setScaleSize(),this.updateScaleRange(t.datasets),this.scale.buildYLabels()},updateScaleRange:function(t){var i=function(){var i=[];return e.each(t,function(t){t.data?i=i.concat(t.data):e.each(t.points,function(t){i.push(t.value)})}),i}(),s=this.options.scaleOverride?{steps:this.options.scaleSteps,stepValue:this.options.scaleStepWidth,min:this.options.scaleStartValue,max:this.options.scaleStartValue+this.options.scaleSteps*this.options.scaleStepWidth}:e.calculateScaleRange(i,e.min([this.chart.width,this.chart.height])/2,this.options.scaleFontSize,this.options.scaleBeginAtZero,this.options.scaleIntegersOnly);e.extend(this.scale,s)},addData:function(t,i){this.scale.valuesCount++,e.each(t,function(t,e){var s=this.scale.getPointPosition(this.scale.valuesCount,this.scale.calculateCenterOffset(t));this.datasets[e].points.push(new this.PointClass({value:t,label:i,datasetLabel:this.datasets[e].label,x:s.x,y:s.y,strokeColor:this.datasets[e].pointStrokeColor,fillColor:this.datasets[e].pointColor}))},this),this.scale.labels.push(i),this.reflow(),this.update()},removeData:function(){this.scale.valuesCount--,this.scale.labels.shift(),e.each(this.datasets,function(t){t.points.shift()},this),this.reflow(),this.update()},update:function(){this.eachPoints(function(t){t.save()}),this.reflow(),this.render()},reflow:function(){e.extend(this.scale,{width:this.chart.width,height:this.chart.height,size:e.min([this.chart.width,this.chart.height]),xCenter:this.chart.width/2,yCenter:this.chart.height/2}),this.updateScaleRange(this.datasets),this.scale.setScaleSize(),this.scale.buildYLabels()},draw:function(t){var i=t||1,s=this.chart.ctx;this.clear(),this.scale.draw(),e.each(this.datasets,function(t){e.each(t.points,function(t,e){t.hasValue()&&t.transition(this.scale.getPointPosition(e,this.scale.calculateCenterOffset(t.value)),i)},this),s.lineWidth=this.options.datasetStrokeWidth,s.strokeStyle=t.strokeColor,s.beginPath(),e.each(t.points,function(t,i){0===i?s.moveTo(t.x,t.y):s.lineTo(t.x,t.y)},this),s.closePath(),s.stroke(),s.fillStyle=t.fillColor,this.options.datasetFill&&s.fill(),e.each(t.points,function(t){t.hasValue()&&t.draw()})},this)}})}.call(this); \ No newline at end of file diff --git a/web/js/kimai.js b/web/js/kimai.js index 18f2878a..25baedd2 100644 --- a/web/js/kimai.js +++ b/web/js/kimai.js @@ -10,7 +10,6 @@ $(document).ready(function() { }, hook: function(name) { alert('Hook: ' + name); - console.log($.fn.kimai.settings); }, subscribe: function() { pubSub.on.apply(pubSub, arguments); @@ -31,9 +30,6 @@ $(document).ready(function() { }; $.fn.kimai = function(options) { - console.log('#'); - console.log(options); - console.log('#'); if (methods[options]) { return methods[options].apply( this, Array.prototype.slice.call(arguments, 1)); } else if (typeof options === 'object') {