mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
IMPR: Dataobjects changelog and Dashboard panel
This commit is contained in:
parent
383029df24
commit
fb0f1951c3
44
src/Dashboard/Changelog.php
Normal file
44
src/Dashboard/Changelog.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace A2nt\CMSNiceties\Dashboard;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\View\ViewableData;
|
||||
|
||||
class Changelog extends ViewableData
|
||||
{
|
||||
private $object;
|
||||
public function __construct(DataObject $object)
|
||||
{
|
||||
$this->object = $object;
|
||||
}
|
||||
|
||||
public function CMSEditLink($version = null)
|
||||
{
|
||||
if(!$version) {
|
||||
return $this->object->CMSEditLink();
|
||||
}
|
||||
|
||||
return Controller::join_links(
|
||||
$this->object->CMSEditLink(),
|
||||
'/ItemEditForm/field/History/item/28/view?VersionID='.$version
|
||||
);
|
||||
}
|
||||
|
||||
public function Created()
|
||||
{
|
||||
return $this->object->dbObject('Created');
|
||||
}
|
||||
|
||||
public function Versions()
|
||||
{
|
||||
$versions = $this->object->allVersions();
|
||||
return $this->object->allVersions();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return $this->renderWith(__CLASS__);
|
||||
}
|
||||
}
|
57
src/Dashboard/Dashboard.php
Normal file
57
src/Dashboard/Dashboard.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace A2nt\CMSNiceties\Dashboard;
|
||||
|
||||
use App\Models\VacancyCandidate;
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
|
||||
class Dashboard extends LeftAndMain
|
||||
{
|
||||
private static $menu_title = "Dashboard";
|
||||
private static $url_segment = "dashboard";
|
||||
private static $menu_priority = 100;
|
||||
private static $url_priority = 30;
|
||||
|
||||
private static $menu_icon_class = 'font-icon-dashboard';
|
||||
private static $managed_models = [
|
||||
VacancyCandidate::class,
|
||||
];
|
||||
|
||||
protected static function getRecentObjects($class, $limit = 10)
|
||||
{
|
||||
return $class::get()
|
||||
->sort('LastEdited DESC')
|
||||
->limit($limit);
|
||||
}
|
||||
|
||||
public function RecentPages()
|
||||
{
|
||||
return self::getRecentObjects(SiteTree::class);
|
||||
}
|
||||
|
||||
public function RecentFiles()
|
||||
{
|
||||
return self::getRecentObjects(File::class);
|
||||
}
|
||||
|
||||
public function RecentObjects()
|
||||
{
|
||||
$models = self::config()->get('managed_models');
|
||||
if(!count($models)){
|
||||
return null;
|
||||
}
|
||||
|
||||
$objects = [];
|
||||
foreach ($models as $model) {
|
||||
$objects[] = [
|
||||
'Title' => singleton($model)->plural_name(),
|
||||
'Objects' => self::getRecentObjects($model),
|
||||
];
|
||||
}
|
||||
|
||||
return ArrayList::create($objects);
|
||||
}
|
||||
}
|
31
templates/A2nt/CMSNiceties/Dashboard/Changelog.ss
Normal file
31
templates/A2nt/CMSNiceties/Dashboard/Changelog.ss
Normal file
@ -0,0 +1,31 @@
|
||||
<h2>Changelog</h2>
|
||||
<ol>
|
||||
|
||||
<% if $Versions %>
|
||||
<% loop $Versions %>
|
||||
<li>
|
||||
<% if $First %>
|
||||
Current Version #{$Version} {$relField('LastEdited')}
|
||||
<% if $Author %>
|
||||
(Author $Author.Title)
|
||||
<% end_if %>
|
||||
<% else %>
|
||||
<a href="{$Top.CMSEditLink($Version)}">
|
||||
Version #{$Version}
|
||||
{$relField('LastEdited')}
|
||||
<% if $Author %>
|
||||
(Author $Author.Title)
|
||||
<% end_if %>
|
||||
</a>
|
||||
<% end_if %>
|
||||
</li>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
|
||||
<li>
|
||||
Created {$Created.Ago}
|
||||
<% if $Author %>
|
||||
(Author $Author.Title)
|
||||
<% end_if %>
|
||||
</li>
|
||||
</ol>
|
@ -0,0 +1,48 @@
|
||||
<div
|
||||
class="cms-content fill-height flexbox-area-grow cms-tabset center $BaseCSSClasses"
|
||||
data-layout-type="border" data-pjax-fragment="Content"
|
||||
id="DashboardAdmin"
|
||||
>
|
||||
|
||||
<div class="cms-content-header north">
|
||||
<div class="cms-content-header-info vertical-align-items flexbox-area-grow">
|
||||
<div class="breadcrumbs-wrapper">
|
||||
<span class="cms-panel-link crumb last">
|
||||
<% if $SectionTitle %>
|
||||
$SectionTitle
|
||||
<% else %>
|
||||
<%t A2nt\CMSNiceties\Dashboard\Dashboard.Title 'Dashboard' %>
|
||||
<% end_if %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%-- div class="cms-content-header-tabs cms-tabset-nav-primary ss-ui-tabs-nav">
|
||||
<ul class="cms-tabset-nav-primary">
|
||||
<% loop $ManagedModelTabs %>
|
||||
<li class="tab-$Tab $LinkOrCurrent<% if $LinkOrCurrent == 'current' %> ui-tabs-active<% end_if %>">
|
||||
<a href="$Link" class="cms-panel-link" title="$Title.ATT">$Title</a>
|
||||
</li>
|
||||
<% end_loop %>
|
||||
</ul>
|
||||
</div --%>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="cms-content-fields center ui-widget-content cms-panel-padded fill-height flexbox-area-grow"
|
||||
data-layout-type="border"
|
||||
>
|
||||
<div class="cms-content-view">
|
||||
<div class="dashboard-blocks" style="display:flex;flex-direction:row;grid-gap:4rem">
|
||||
<% include A2nt\CMSNiceties\Dashboard\Includes\RecentPages %>
|
||||
<% include A2nt\CMSNiceties\Dashboard\Includes\RecentFiles %>
|
||||
<% if $RecentObjects %>
|
||||
<% loop $RecentObjects %>
|
||||
<% include A2nt\CMSNiceties\Dashboard\Includes\RecentObjects %>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
16
templates/A2nt/CMSNiceties/Dashboard/Includes/RecentFiles.ss
Normal file
16
templates/A2nt/CMSNiceties/Dashboard/Includes/RecentFiles.ss
Normal file
@ -0,0 +1,16 @@
|
||||
<% if $RecentFiles %>
|
||||
<div class="dashboard__block dashboard__block--files">
|
||||
<h2 class="dashboard__block__title">
|
||||
<%t A2nt\CMSNiceties\Dashboard\Dashboard.RecentFiles 'Recent Files' %>
|
||||
</h2>
|
||||
|
||||
<% loop $RecentFiles %>
|
||||
<div class="recent recent--file">
|
||||
<a href="{$CMSEditLink}">
|
||||
$Name
|
||||
($LastEdited.Ago)
|
||||
</a>
|
||||
</div>
|
||||
<% end_loop %>
|
||||
</div>
|
||||
<% end_if %>
|
@ -0,0 +1,19 @@
|
||||
<div class="dashboard__block dashboard__block--objects">
|
||||
<h2 class="dashboard__block__title">
|
||||
$Title
|
||||
</h2>
|
||||
|
||||
<% loop $Objects %>
|
||||
<div class="recent recent--object">
|
||||
<% if $CMSEditLink %>
|
||||
<a href="{$CMSEditLink}">
|
||||
$Title
|
||||
($LastEdited.Ago)
|
||||
</a>
|
||||
<% else %>
|
||||
$Title
|
||||
($LastEdited.Ago)
|
||||
<% end_if %>
|
||||
</div>
|
||||
<% end_loop %>
|
||||
</div>
|
16
templates/A2nt/CMSNiceties/Dashboard/Includes/RecentPages.ss
Normal file
16
templates/A2nt/CMSNiceties/Dashboard/Includes/RecentPages.ss
Normal file
@ -0,0 +1,16 @@
|
||||
<% if $RecentPages %>
|
||||
<div class="dashboard__block dashboard__block--pages">
|
||||
<h2 class="dashboard__block__title">
|
||||
<%t A2nt\CMSNiceties\Dashboard\Dashboard.RecentPages 'Recent Pages' %>
|
||||
</h2>
|
||||
|
||||
<% loop $RecentPages %>
|
||||
<div class="recent recent--page">
|
||||
<a href="{$CMSEditLink}">
|
||||
$MenuTitle
|
||||
($LastEdited.Ago)
|
||||
</a>
|
||||
</div>
|
||||
<% end_loop %>
|
||||
</div>
|
||||
<% end_if %>
|
Loading…
Reference in New Issue
Block a user