This repository has been archived by the owner on Oct 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from kontenta/item-history
Item history
- Loading branch information
Showing
6 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<section data-kontour-widget="itemHistory"> | ||
<header>Item History</header> | ||
<ul> | ||
@foreach($entries as $entry) | ||
<li lang="en" data-kontour-entry-action="{{ $entry['action'] }}"@if($entry['user']) data-kontour-username="{{ $entry['user']->getDisplayName() }}"@endif> | ||
<span>{{ ucfirst($entry['action']) }}</span> | ||
<time datetime="{{ $entry['datetime']->toDateTimeString() }}">{{ $entry['datetime']->diffForHumans() }}</time> | ||
@if($entry['user']) | ||
<span>by</span> <span>{{ $entry['user']->getDisplayName() }}</span> | ||
@endif | ||
</li> | ||
@endforeach | ||
</ul> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Kontenta\KontourSupport\Widgets; | ||
|
||
use Illuminate\Contracts\Auth\Access\Authorizable; | ||
use Illuminate\Support\Collection; | ||
use Kontenta\Kontour\Contracts\ItemHistoryWidget as ItemHistoryWidgetContract; | ||
use Kontenta\Kontour\Contracts\AdminUser; | ||
use Illuminate\Support\Facades\View; | ||
use Carbon\Carbon; | ||
|
||
class ItemHistoryWidget implements ItemHistoryWidgetContract | ||
{ | ||
/** | ||
* @var Collection | ||
*/ | ||
protected $entries; | ||
|
||
public function __construct() | ||
{ | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters