Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #13 from kontenta/widgetviews
Browse files Browse the repository at this point in the history
Widgetviews
  • Loading branch information
erik-epineer authored Sep 24, 2018
2 parents 1513873 + 20c56e7 commit 47851f2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 20 deletions.
12 changes: 12 additions & 0 deletions resources/views/widgets/menu.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul data-kontour-widget="menu">
@foreach($links as $heading => $headingLinks)
<li>
<span>{{ $heading }}</span>
<ul>
@foreach($headingLinks as $link)
<li>{{ $link }}</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
8 changes: 8 additions & 0 deletions resources/views/widgets/personalRecentVisits.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<aside data-kontour-widget="personalRecentVisits">
<header>Recent</header>
<ul>
@foreach($visits as $visit)
<li data-kontour-visit-type="{{ $visit->getType() }}">{{ $visit->getLink() }}</li>
@endforeach
</ul>
</aside>
8 changes: 8 additions & 0 deletions resources/views/widgets/teamRecentVisits.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<aside data-kontour-widget="teamRecentVisits">
<header>Team Recent</header>
<ul>
@foreach($visits as $visit)
<li data-kontour-visit-type="{{ $visit->getType() }}" data-kontour-username="{{ $visit->getUser()->getDisplayName() }}">{{ $visit->getLink() }}</li>
@endforeach
</ul>
</aside>
8 changes: 4 additions & 4 deletions src/Providers/KontourServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Kontenta\KontourSupport\AdminRouteManager;
use Kontenta\KontourSupport\AdminViewManager;
use Kontenta\KontourSupport\AdminWidgetManager;
use Kontenta\KontourSupport\MenuWidget;
use Kontenta\KontourSupport\Widgets\MenuWidget;
use Kontenta\KontourSupport\RecentVisitsRepository;
use Kontenta\KontourSupport\PersonalRecentVisitsWidget;
use Kontenta\KontourSupport\TeamRecentVisitsWidget;
use Kontenta\KontourSupport\Widgets\PersonalRecentVisitsWidget;
use Kontenta\KontourSupport\Widgets\TeamRecentVisitsWidget;
use Kontenta\KontourSupport\Http\Middleware\AuthenticateAdmin;
use Kontenta\KontourSupport\Http\Middleware\RedirectIfAuthenticated;
use Kontenta\Kontour\Concerns\RegistersAdminRoutes;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function boot()
{
$this->registerResources();
$this->registerRoutes();
$this->registerEventListeners();
$this->registerEventListeners();
$this->registerWidgets();

if ($this->app->runningInConsole()) {
Expand Down
9 changes: 3 additions & 6 deletions src/MenuWidget.php → src/Widgets/MenuWidget.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

namespace Kontenta\KontourSupport;
namespace Kontenta\KontourSupport\Widgets;

use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Support\Collection;
use Kontenta\Kontour\Contracts\MenuWidget as MenuWidgetContract;
use Kontenta\Kontour\Contracts\AdminLink;
use Illuminate\Support\Facades\View;

class MenuWidget implements MenuWidgetContract
{
Expand All @@ -21,11 +22,7 @@ public function __construct()

public function toHtml()
{
return '<ul>'.$this->links->map(function ($links, $heading) {
return '<li><span>'.$heading.'</span><ul>'.$links->map(function ($link) {
return '<li>'.$link->toHtml().'</li>';
})->implode("\n").'</ul></li>';
})->implode("\n").'</ul>';
return View::make('kontour::widgets.menu', ['links' => $this->links])->render();
}

public function addLink(AdminLink $link, string $desiredHeading = null): MenuWidgetContract
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Kontenta\KontourSupport;
namespace Kontenta\KontourSupport\Widgets;

use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Kontenta\KontourSupport\RecentVisitsRepository;
use Kontenta\Kontour\Contracts\PersonalRecentVisitsWidget as PersonalRecentVisitsWidgetContract;

class PersonalRecentVisitsWidget implements PersonalRecentVisitsWidgetContract
Expand All @@ -17,9 +19,7 @@ public function __construct(RecentVisitsRepository $repository)

public function toHtml()
{
return '<aside data-kontour-widget="PersonalRecentVisitsWidget"><header>Recent</header><ul>' . $this->getVisits()->map(function ($visit) {
return '<li data-kontour-visit-type="' . $visit->getType() . '">' . $visit->getLink()->toHtml() . '</li>';
})->implode("\n") . '</ul></aside>';
return View::make('kontour::widgets.personalRecentVisits', ['visits' => $this->getVisits()])->render();
}

public function isAuthorized(Authorizable $user = null): bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Kontenta\KontourSupport;
namespace Kontenta\KontourSupport\Widgets;

use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Kontenta\KontourSupport\RecentVisitsRepository;
use Kontenta\Kontour\Contracts\TeamRecentVisitsWidget as TeamRecentVisitsWidgetContract;

class TeamRecentVisitsWidget implements TeamRecentVisitsWidgetContract
Expand All @@ -17,9 +19,7 @@ public function __construct(RecentVisitsRepository $repository)

public function toHtml()
{
return '<aside data-kontour-widget="TeamRecentVisitsWidget"><header>Team Recent</header><ul>' . $this->getVisits()->map(function ($visit) {
return '<li data-kontour-visit-type="' . $visit->getType() . '" data-kontour-username="' . $visit->getUser()->getDisplayName() . '">' . $visit->getLink()->toHtml() . '</li>';
})->implode("\n") . '</ul></aside>';
return View::make('kontour::widgets.teamRecentVisits', ['visits' => $this->getVisits()])->render();
}

public function isAuthorized(Authorizable $user = null): bool
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/UserlandControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function test_recent_visits_widgets()
$response->assertOk();

// Check personal links
$response->assertSee('<aside data-kontour-widget="PersonalRecentVisitsWidget">');
$response->assertSee('<aside data-kontour-widget="personalRecentVisits">');
$response->assertSee('<header>Recent</header>');

$numberOfMatches = substr_count($response->content(), '<li data-kontour-visit-type="show"><a href="' . route('userland.index') . '">Recent Userland Tool</a>');
Expand All @@ -73,7 +73,7 @@ public function test_recent_visits_widgets()
$this->assertEquals(1, $numberOfMatches);

// Check team links
$response->assertSee('<aside data-kontour-widget="TeamRecentVisitsWidget">');
$response->assertSee('<aside data-kontour-widget="teamRecentVisits">');
$response->assertSee('<header>Team Recent</header>');

$numberOfMatches = substr_count($response->content(), '<li data-kontour-visit-type="edit" data-kontour-username="' . $otherUser->getDisplayName() . '"><a href="' . route('userland.edit') . '">Other Recent Userland Tool</a>');
Expand Down

0 comments on commit 47851f2

Please sign in to comment.