Skip to content

Commit

Permalink
添加模板渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
junjun committed Jun 2, 2016
1 parent da50e1a commit 9ce8269
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 23 deletions.
32 changes: 31 additions & 1 deletion src/Collections/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ abstract class AbstractCollection implements CollectionInterface
* @var Application
*/
protected $app;


/**
* 模板名称
* @var string
*/
protected $template;

/**
Expand All @@ -52,6 +56,13 @@ abstract class AbstractCollection implements CollectionInterface
*/
protected $global = [];

/**
* icon名称
* @var string
*/
protected $icon;

protected $url;
/**
* 注册收集器
* @param Application $app
Expand Down Expand Up @@ -125,6 +136,11 @@ public function getTemplate()
return $this->template;
}

public function getIcon()
{
return $this->icon;
}

/**
* 获取收集器收集到的信息数量
* @return int
Expand All @@ -134,6 +150,20 @@ public function calcBadge()
$this->badge = count($this->data[$this->template]);
}

public function getMenu()
{
/**
* @var $current \Illuminate\Routing\Route
*/
$current = $this->app['router']->current();
return [
'name' => $this->getName(),
'icon' => $this->getIcon(),
'badge' => $this->getBadge(),
'url' => route('purple.index', ['id' => $current->getParameter('id'), 'key' => $this->getName()])
];
}

public function formatData()
{
return [
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Database extends AbstractCollection
protected $name = 'db';

protected $icon = 'database';

protected $template = 'query';

public function before(Application $application)
Expand Down
3 changes: 1 addition & 2 deletions src/Collections/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class Event extends AbstractCollection

public function before(Application $application)
{
parent::before($application);

/**
* @var $event \Illuminate\Events\Dispatcher
*/
parent::before($application);
$event = $application['events'];
$event->listen('*', [$this, 'eventFired']);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Collections/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Route extends AbstractCollection
protected $icon = 'road';

protected $template = 'routes';

public function after(Application $app, Response $response)
{
/**
Expand Down
4 changes: 3 additions & 1 deletion src/Controller/PurpleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function buildViewData($result, CollectionInterface $collection)
protected function getGlobalData()
{
$global = [];
$menu = [];
/**
* @var $hook \Purple\PurpleHook
*/
Expand All @@ -67,9 +68,10 @@ protected function getGlobalData()

foreach ($collections as $collection) {
$global = array_merge($collection->getGlobal(), $global);
array_push($menu, $collection->getMenu());
}

$global['menu'] = [];
$global['menus'] = $menu;
return $global;
}

Expand Down
1 change: 0 additions & 1 deletion src/PurpleHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function __construct(Application $app)
$this->app = $app;

foreach ($this->defaultCollections as $collection) {
// array_push($this->collections, $app->make($collection));
$collection = $app->make($collection);
$this->collections[$collection->getName()] = $collection;
}
Expand Down
32 changes: 16 additions & 16 deletions src/Resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class="fa fa-reply"></i></a></span>
</header>
<nav>
<ul>
@foreach($menu as $item)
<li>
<a href="{{ array_get($item, 'url') }}" @if(array_get($item, 'title') == $name)class="active"@endif>
@if(array_get($item, 'title') != $name)
<span class="label">
{{ array_get($item, 'title') }} <i class="arrow"></i>
</span>
@endif
<i class="fa fa-{{ array_get($item, 'icon') }}"></i>
@if (array_get($item, 'badge') > 0)
<span class="badge">
<i class="badge-inner">{{ array_get($item, 'badge') > 9 ? '+' : array_get($item, 'badge') }}</i>
</span>
@endif
</a>
</li>
@foreach($menus as $item)
<li>
<a href="{{ $item['url'] }}" @if(array_get($item, 'name') == $name)class="active"@endif>
@if(array_get($item, 'name') != $name)
<span class="label">
{{ array_get($item, 'name') }} <i class="arrow"></i>
</span>
@endif
<i class="fa fa-{{ array_get($item, 'icon') }}"></i>
@if (array_get($item, 'badge') > 0)
<span class="badge">
<i class="badge-inner">{{ array_get($item, 'badge') > 9 ? '+' : array_get($item, 'badge') }}</i>
</span>
@endif
</a>
</li>
@endforeach
</ul>
</nav>
Expand Down
File renamed without changes.

0 comments on commit 9ce8269

Please sign in to comment.