Skip to content

Commit

Permalink
asset manager & login template
Browse files Browse the repository at this point in the history
  • Loading branch information
avanzu committed May 1, 2014
1 parent 00b1275 commit 0f8ff6c
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ExceptionController extends \Symfony\Bundle\TwigBundle\Controller\Exceptio
protected function findTemplate(Request $request, $format, $code, $debug)
{

if(strpos($request->getPathInfo(), '/admin') !== 0) {
return parent::findTemplate($request, $format, $code, $debug);
}

$name = $debug ? 'exception' : 'error';
if ($debug && 'html' == $format) {
$name = 'exception_full';
Expand Down
8 changes: 7 additions & 1 deletion DependencyInjection/AvanzuAdminThemeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function prepend(ContainerBuilder $container)
'resources' => array(
'AvanzuAdminThemeBundle:layout:form-theme.html.twig'
)
),
'globals' => array(
'admin_theme' => '@avanzu_admin_theme.theme_manager'
)
));
}
Expand All @@ -70,7 +73,10 @@ public function prepend(ContainerBuilder $container)
$jsAssets . 'public/vendor/underscore/underscore.js',
$jsAssets . 'public/vendor/backbone/backbone.js',
$jsAssets . 'public/vendor/marionette/lib/backbone.marionette.js',
$jsAssets . 'public/vendor/AdminLTE/js/bootstrap.js'
$jsAssets . 'public/vendor/AdminLTE/js/bootstrap.js',
$jsAssets . 'public/vendor/bootbox/bootbox.js',
$jsAssets . 'public/js/dialogs.js',
$jsAssets . 'public/js/namespace.js',
),
),
'tools_js' => array(
Expand Down
51 changes: 51 additions & 0 deletions EventListener/SetupThemeListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* SetupThemeListener.php
* publisher
* Date: 01.05.14
*/

namespace Avanzu\AdminThemeBundle\EventListener;


use Avanzu\AdminThemeBundle\Theme\ThemeManager;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;

class SetupThemeListener {

/**
* @var ThemeManager
*/
protected $manager;

protected $cssBase;

protected $lteAdmin;

function __construct($manager, $cssBase = null, $lteAdmin = null)
{
$this->cssBase = $cssBase?:'bundles/avanzuadmintheme/';
$this->lteAdmin = $lteAdmin?:'vendor/AdminLTE/css/';
$this->manager = $manager;
}


public function onKernelController(FilterControllerEvent $event) {

$css = rtrim($this->cssBase, '/').'/'.trim($this->lteAdmin, '/');
$mng = $this->manager;

$mng->registerStyle('jquery-ui', $css.'/jQueryUI/jquery-ui-1.10.3.custom.css');
$mng->registerStyle('bootstrap', $css.'/bootstrap.css', array('jquery-ui'));
$mng->registerStyle('bootstrap-slider', $css.'/bootstrap-slider/bootstrap-slider.css', array('bootstrap'));
$mng->registerStyle('datatables', $css.'/datatables/dataTables.bootstrap.css', array('bootstrap'));
$mng->registerStyle('fontawesome', $css.'/font-awesome.css');
$mng->registerStyle('ionicons', $css.'/ionicons.css');
$mng->registerStyle('admin-lte', $css.'/AdminLTE.css', array('bootstrap-slider', 'fontawesome', 'ionicons','datatables'));
$mng->registerStyle('bs-colorpicker', $css.'/colorpicker/bootstrap-colorpicker.css', array('admin-lte'));
$mng->registerStyle('daterangepicker', $css.'/daterangepicker/daterangepicker-bs3.css', array('admin-lte'));
$mng->registerStyle('timepicker', $css.'/timepicker/bootstrap-timepicker.css', array('admin-lte'));
$mng->registerStyle('wysiwyg', $css.'/bootstrap-wysihtml5/bootstrap3-wysihtml5.css', array('admin-lte'));

}
}
3 changes: 2 additions & 1 deletion Resources/bower/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"marionette" : "*",
"pickadate" : "*",
"holderjs" : "*",
"bootflat" : "*"
"bootflat" : "*",
"bootbox" : "*"
}
}
21 changes: 20 additions & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
<parameter key="avanzu_admin_theme.exception_controller.class">Avanzu\AdminThemeBundle\Controller\ExceptionController</parameter>
<parameter key="twig.controller.exception.class">Avanzu\AdminThemeBundle\Controller\ExceptionController</parameter>
<parameter key="avanzu_admin_theme.widget_extension.class">Avanzu\AdminThemeBundle\Twig\WidgetExtension</parameter>
<parameter key="avanzu_admin_theme.theme_manager.class">Avanzu\AdminThemeBundle\Theme\ThemeManager</parameter>
<parameter key="avanzu_admin_theme.setup_theme_listener.class">Avanzu\AdminThemeBundle\EventListener\SetupThemeListener</parameter>
<parameter key="avanzu_admin_theme.dependency_resolver.class" />
<parameter key="avanzu_admin_theme.css_base" />
<parameter key="avanzu_admin_theme.lte_admin" />

</parameters>

<services>
Expand All @@ -26,6 +32,19 @@
<tag name="twig.extension" />
</service>

<service id="avanzu_admin_theme.theme_manager" class="%avanzu_admin_theme.theme_manager.class%">
<argument type="service" id="service_container" />
<argument>%avanzu_admin_theme.dependency_resolver.class%</argument>
</service>

<service id="avanzu_admin_theme.setup_theme_listener" class="%avanzu_admin_theme.setup_theme_listener.class%">
<argument type="service" id="avanzu_admin_theme.theme_manager"/>
<argument>%avanzu_admin_theme.css_base%</argument>
<argument>%avanzu_admin_theme.lte_admin%</argument>
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" />
</service>

<!--
<service id="avanzu_admin_theme.navbar_user_listener" class="%avanzu_admin_theme.navbar_user_listener.class%">
<tag name="kernel.event_listener" event="theme.navbar_user" method="onShowUser"/>
<tag name="kernel.event_listener" event="theme.sidebar_user" method="onShowUser"/>
Expand All @@ -44,7 +63,7 @@
<tag name="kernel.event_listener" event="theme.sidebar_setup_menu" method="onSetupMenu"/>
<tag name="kernel.event_listener" event="theme.breadcrumb" method="onSetupMenu"/>
</service>

-->
</services>

</container>
Expand Down
10 changes: 8 additions & 2 deletions Resources/public/js/adminLTE.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,12 @@ function change_layout() {
(function($){
"use strict";
$('[data-timepicker]').timepicker();
$('[data-datepicker]').datepicker({showInputs: false});

var format, picker = $('[data-datepicker]');
for(var n = 0; n < picker.length; ++n) {
format = $(picker[n]).attr('data-format') || 'yy-mm-dd';
$(picker[n]).datepicker({
showInputs: false,
dateFormat: format
});
}
})(window.jQuery || window.Zepto);
16 changes: 16 additions & 0 deletions Resources/public/js/dialogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;(function($){
"use strict";

var doConfirm = function(event) {
var $t = $(event.currentTarget) , msg = $t.attr('data-confirm'), href = $t.attr('href');
event.preventDefault();
bootbox.confirm(msg, function(result){
if(result === true) {
window.location = href;
}
});
};

$('[data-confirm]').on('click', doConfirm);

})(jQuery);
13 changes: 13 additions & 0 deletions Resources/public/js/namespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function namespace(namespaceString) {
var parts = namespaceString.split('.'),
parent = window,
currentPart = '';

for(var i = 0, length = parts.length; i < length; i++) {
currentPart = parts[i];
parent[currentPart] = parent[currentPart] || {};
parent = parent[currentPart];
}

return parent;
}
8 changes: 6 additions & 2 deletions Resources/views/layout/base-layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

{# -------------------------------------------------------------------------------------------------- STYLESHEETS #}
{% block stylesheets %}
{% stylesheets '@admin_lte_all_css' filter="cssrewrite" %}
{% for style in admin_theme.styles %}
<link rel="stylesheet" href="{{ asset(style) }}" />
{% endfor %}

{# % stylesheets '@admin_lte_all_css' filter="cssrewrite" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endstylesheets % #}
{% endblock %}


Expand Down
57 changes: 57 additions & 0 deletions Resources/views/layout/login-layout.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% import "AvanzuAdminThemeBundle:layout:macros.html.twig" as macro %}
<!doctype html>
<!--[if lt IE 7 ]><html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]><html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]><html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]><html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{% block title %}Avanzu Admin!{% endblock %}</title>

{# -------------------------------------------------------------------------------------------------- STYLESHEETS #}
{% block stylesheets %}
{% stylesheets '@admin_lte_all_css' filter="cssrewrite" %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}


<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />

{# --------------------------------------------------------------------------------------------- JAVASCRIPTS_HEAD #}
{% block javascripts_head %}
{% javascripts '@AvanzuAdminThemeBundle/Resources/public/vendor/modernizr/modernizr.js'%}
<script type="text/javascript" src="{{ asset(asset_url) }}"></script>
{% endjavascripts %}
<!--[if lt IE 9]>
<![endif]-->

{% endblock %}

</head>
<body class="bg-black">

<div class="form-box" id="login-box">
{% block page_content %}{% endblock %}
</div>



{# ------------------------------------------------------------------------------------------------------ JAVASCRIPTS #}
{% block javascripts %}

{% javascripts '@admin_lte_all' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}

{# ----------------------------------------------------------------------------------------------- JAVASCRIPTS_INLINE #}
{% block javascripts_inline %}
{% endblock %}
</body>
</html>
106 changes: 106 additions & 0 deletions Theme/ThemeManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* ThemeManager.php
* publisher
* Date: 18.04.14
*/

namespace Avanzu\AdminThemeBundle\Theme;


use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetReference;
use Assetic\Factory\AssetFactory;
use Assetic\Factory\LazyAssetManager;
use Assetic\Factory\Resource\FileResource;
use Avanzu\FoundationBundle\Util\DependencyResolverInterface;
use Symfony\Bundle\AsseticBundle\Config\AsseticResource;
use Symfony\Component\DependencyInjection\Container;
use Avanzu\FoundationBundle\Util\DependencyResolver;
use Symfony\Component\HttpKernel\Config\FileLocator;

class ThemeManager
{

/** @var Container */
protected $container;

protected $stylesheets = array();

protected $javascripts = array();

protected $locations = array();

protected $resolverClass;

function __construct($container, $resolverClass = null)
{
$this->container = $container;
$this->resolverClass = $resolverClass?: 'Avanzu\AdminThemeBundle\Util\DependencyResolver';
}



public function registerScript($id, $src, $deps = array(), $location = "bottom")
{

if (!isset($this->javascripts[$id])) {
$this->javascripts[$id] = array(
'src' => $src,
'deps' => $deps,
'location' => $location
);
}

}

public function registerStyle($id, $src, $deps = array()) {
if(!isset($this->stylesheets[$id])) {
$this->stylesheets[$id] = array(
'src' => $src,
'deps' => $deps,
);
}
}

public function getScripts($location = 'bottom') {

$unsorted = array(); $srcList = array(); $assetList = array();
foreach($this->javascripts as $id => $scriptDefinition) {
if($scriptDefinition['location'] == $location) {
$unsorted[$id] = $scriptDefinition;
}
}

$queue = $this->getResolver()->register($unsorted)->resolveAll();
foreach($queue as $def){
$srcList[] = $def['src'];
}
return $srcList;
}

public function getStyles() {
$srcList = array();
$queue = $this->getResolver()->register($this->stylesheets)->resolveAll();
foreach($queue as $def){
$srcList[] = $def['src'];
}
return $srcList;
}

/**
* @return DependencyResolverInterface
*/
protected function getResolver() {
$class = $this->resolverClass;
return new $class;
}

/**
* @return FileLocator
*/
protected function getLocator() {
return $this->container->get('file_locator');
}

}
Loading

0 comments on commit 0f8ff6c

Please sign in to comment.