diff --git a/resources/views/widgets/itemHistory.blade.php b/resources/views/widgets/itemHistory.blade.php new file mode 100644 index 0000000..4b67591 --- /dev/null +++ b/resources/views/widgets/itemHistory.blade.php @@ -0,0 +1,14 @@ +
+
Item History
+ +
diff --git a/src/Providers/KontourServiceProvider.php b/src/Providers/KontourServiceProvider.php index 5fa75b2..6ecda92 100644 --- a/src/Providers/KontourServiceProvider.php +++ b/src/Providers/KontourServiceProvider.php @@ -9,6 +9,7 @@ use Kontenta\KontourSupport\AdminWidgetManager; use Kontenta\KontourSupport\Widgets\MenuWidget; use Kontenta\KontourSupport\RecentVisitsRepository; +use Kontenta\KontourSupport\Widgets\ItemHistoryWidget; use Kontenta\KontourSupport\Widgets\PersonalRecentVisitsWidget; use Kontenta\KontourSupport\Widgets\TeamRecentVisitsWidget; use Kontenta\KontourSupport\Http\Middleware\AuthenticateAdmin; @@ -93,6 +94,12 @@ function ($app) { TeamRecentVisitsWidget::class, true ); + + $this->app->bindIf( + \Kontenta\Kontour\Contracts\ItemHistoryWidget::class, + ItemHistoryWidget::class, + true + ); } /** diff --git a/src/Widgets/ItemHistoryWidget.php b/src/Widgets/ItemHistoryWidget.php new file mode 100644 index 0000000..4a2e652 --- /dev/null +++ b/src/Widgets/ItemHistoryWidget.php @@ -0,0 +1,50 @@ +entries = new Collection(); + } + + public function toHtml() + { + return View::make('kontour::widgets.itemHistory', ['entries' => $this->entries])->render(); + } + + public function addEntry(string $action, \DateTime $datetime, AdminUser $user = null): ItemHistoryWidgetContract + { + $datetime = Carbon::instance($datetime); + $this->entries->push(compact('action', 'datetime', 'user')); + return $this; + } + + public function addCreatedEntry(\DateTime $datetime, AdminUser $user = null): ItemHistoryWidgetContract + { + return $this->addEntry('created', $datetime, $user); + } + + public function addUpdatedEntry(\DateTime $datetime, AdminUser $user = null): ItemHistoryWidgetContract + { + return $this->addEntry('updated', $datetime, $user); + } + + public function isAuthorized(Authorizable $user = null): bool + { + return true; + } +} diff --git a/tests/Feature/Fakes/UserlandController.php b/tests/Feature/Fakes/UserlandController.php index ff804a7..bf12b4a 100644 --- a/tests/Feature/Fakes/UserlandController.php +++ b/tests/Feature/Fakes/UserlandController.php @@ -7,9 +7,13 @@ use Kontenta\Kontour\Events\AdminToolVisited; use Kontenta\KontourSupport\AdminLink; use Kontenta\Kontour\ShowAdminVisit; +use Kontenta\Kontour\Concerns\RegistersAdminWidgets; +use Kontenta\Kontour\Contracts\ItemHistoryWidget; class UserlandController extends BaseController { + use RegistersAdminWidgets; + public function index() { $link = new AdminLink(url()->full(), 'Recent Userland Tool'); @@ -36,7 +40,12 @@ public function show($id) public function edit($id) { - // + $widget = app(ItemHistoryWidget::class); + $this->registerAdminWidget($widget); + $widget->addCreatedEntry(new \DateTime(), Auth::guard(config('kontour.guard'))->user()); + $widget->addUpdatedEntry(new \DateTime(), Auth::guard(config('kontour.guard'))->user()); + + return view('userland::index'); } public function update($id) diff --git a/tests/Feature/Fakes/UserlandServiceProvider.php b/tests/Feature/Fakes/UserlandServiceProvider.php index 9cd2244..1396de6 100644 --- a/tests/Feature/Fakes/UserlandServiceProvider.php +++ b/tests/Feature/Fakes/UserlandServiceProvider.php @@ -41,7 +41,7 @@ protected function registerRoutes() 'namespace' => 'Kontenta\KontourSupport\Tests\Feature\Fakes', ], function ($router) { $router->get('/', 'UserlandController@index')->name('userland.index'); - $router->get('edit', 'UserlandController@edit')->name('userland.edit'); + $router->get('edit/{id}', 'UserlandController@edit')->name('userland.edit'); }); }); } diff --git a/tests/Feature/UserlandControllerTest.php b/tests/Feature/UserlandControllerTest.php index c88dfcf..f8d7af7 100644 --- a/tests/Feature/UserlandControllerTest.php +++ b/tests/Feature/UserlandControllerTest.php @@ -46,14 +46,14 @@ public function test_index_route() public function test_recent_visits_widgets() { $otherUser = factory(User::class)->create(); - $link = new AdminLink(route('userland.edit'), 'Recent Userland Tool'); + $link = new AdminLink(route('userland.edit', 1), 'Recent Userland Tool'); $visit = new EditAdminVisit($link, $this->user); event(new AdminToolVisited($visit)); event(new AdminToolVisited($visit)); $link = new AdminLink(route('userland.index'), 'Other Recent Userland Tool'); $visit = new ShowAdminVisit($link, $otherUser); event(new AdminToolVisited($visit)); - $link = new AdminLink(route('userland.edit'), 'Other Recent Userland Tool'); + $link = new AdminLink(route('userland.edit', 1), 'Other Recent Userland Tool'); $visit = new EditAdminVisit($link, $otherUser); event(new AdminToolVisited($visit)); event(new AdminToolVisited($visit)); @@ -69,16 +69,24 @@ public function test_recent_visits_widgets() $numberOfMatches = substr_count($response->content(), '
  • Recent Userland Tool'); $this->assertEquals(1, $numberOfMatches); - $numberOfMatches = substr_count($response->content(), '
  • Recent Userland Tool'); + $numberOfMatches = substr_count($response->content(), '
  • Recent Userland Tool'); $this->assertEquals(1, $numberOfMatches); // Check team links $response->assertSee('