Merge pull request #328 from JoeForks/feature/presenters

[WIP] Added presenters and timezone locales with diff and popover
This commit is contained in:
James Brooks
2015-01-08 17:20:37 +00:00
10 changed files with 169 additions and 21 deletions

View File

@@ -50,6 +50,15 @@ $(function() {
// App setup
window.CachetHQ = {};
moment.locale(Global.locale);
$('abbr.timeago').each(function () {
var $el = $(this);
$el
.livestamp($el.data('timeago'))
.popover();
});
window.CachetHQ.Notifier = function () {
this.notify = function (message, type, options) {
type = (typeof type === 'undefined' || type === 'error') ? 'error' : type;

View File

@@ -95,6 +95,9 @@ return [
'providers' => [
/*
* Laravel Framework Service Providers...
*/
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
'Illuminate\Cache\CacheServiceProvider',
@@ -120,6 +123,9 @@ return [
'Illuminate\Validation\ValidationServiceProvider',
'Illuminate\View\ViewServiceProvider',
/*
* Packages Service Providers...
*/
'Dingo\Api\Provider\ApiServiceProvider',
'GrahamCampbell\Security\SecurityServiceProvider',
'GrahamCampbell\Binput\BinputServiceProvider',
@@ -128,7 +134,11 @@ return [
'Roumen\Feed\FeedServiceProvider',
'Thujohn\Rss\RssServiceProvider',
'Jenssegers\Date\DateServiceProvider',
'McCool\LaravelAutoPresenter\LaravelAutoPresenterServiceProvider',
/*
* Application Service Providers...
*/
'CachetHQ\Cachet\Providers\AuthServiceProvider',
'CachetHQ\Cachet\Providers\ConsoleServiceProvider',
'CachetHQ\Cachet\Providers\RepositoryServiceProvider',

View File

@@ -46,6 +46,10 @@
</style>
@endif
<script type="text/javascript">
var Global = {};
Global.locale = '{{ Setting::get('app_locale') }}';
</script>
<script src="{{ elixir('js/all.js') }}"></script>
</head>
<body class="status-page">

View File

@@ -14,7 +14,10 @@
<div class="panel-heading">
<strong>{{ $incident->name }}</strong>
<br>
<small class="date">{{ $incident->created_at->diffForHumans() }}</small>
<small class="date">
<abbr class="timeago" tabindex="{{ $incidentID }}" data-container="body" data-toggle="popover" data-placement="right" data-trigger="focus" data-content="{{ $incident->created_at_formated }}" data-timeago="{{ $incident->created_at_iso }}">
</abbr>
</small>
</div>
@if($incident->hasMessage())
<div class="panel-body">

View File

@@ -1,18 +1,20 @@
{
"name": "Cachet",
"dependencies": {
"bootstrap-sass-official": "~3.3.1",
"humane-js": "~3.2.2",
"ionicons": "~2.0.0",
"jquery": "~2.1.1",
"jquery-minicolors": "~2.1.10",
"jquery-serialize-object": "~2.4.3",
"lodash": "~2.4.1",
"messenger": "~1.4.1",
"Sortable": "~1.0.0",
"animate-sass": "~0.6.2"
},
"resolutions": {
"jquery": "~2.1.1"
}
"name": "Cachet",
"dependencies": {
"bootstrap-sass-official": "~3.3.1",
"humane-js": "~3.2.2",
"ionicons": "~2.0.0",
"jquery": "~2.1.1",
"jquery-minicolors": "~2.1.10",
"jquery-serialize-object": "~2.4.3",
"lodash": "~2.4.1",
"messenger": "~1.4.1",
"Sortable": "~1.0.0",
"animate-sass": "~0.6.2",
"moment": "~2.8.4",
"livestampjs": "~1.1.2"
},
"resolutions": {
"jquery": "~2.1.1"
}
}

View File

@@ -22,7 +22,8 @@
"roumen/feed": "~2.8",
"thujohn/rss": "~1.0",
"watson/validating": "0.10.*",
"jenssegers/date": "~2.0"
"jenssegers/date": "~2.0",
"mccool/laravel-auto-presenter": "~2.2@dev"
},
"require-dev": {
"phpunit/phpunit": "~4.3",

60
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "50862b080034db5b187b78c30807c1d5",
"hash": "b561fa017bd12ef775f7765fe28d8839",
"packages": [
{
"name": "classpreloader/classpreloader",
@@ -1458,6 +1458,60 @@
],
"time": "2014-12-10 16:59:07"
},
{
"name": "mccool/laravel-auto-presenter",
"version": "2.2.x-dev",
"source": {
"type": "git",
"url": "https://github.com/ShawnMcCool/laravel-auto-presenter.git",
"reference": "79e1eab2528262e325419e9441967bd390c4b667"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ShawnMcCool/laravel-auto-presenter/zipball/79e1eab2528262e325419e9441967bd390c4b667",
"reference": "79e1eab2528262e325419e9441967bd390c4b667",
"shasum": ""
},
"require": {
"illuminate/events": "4.2.*",
"illuminate/pagination": "4.2.*",
"illuminate/support": "4.2.*",
"illuminate/view": "4.2.*",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "~0.8",
"phpunit/phpunit": "~4.0"
},
"type": "library",
"autoload": {
"psr-0": {
"McCool\\LaravelAutoPresenter": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "graham@mineuk.com"
},
{
"name": "Shawn McCool",
"email": "shawn@heybigname.com"
}
],
"description": "A system for auto-decorating models with presenter objects.",
"keywords": [
"eloquent",
"laravel",
"lpm",
"presenter"
],
"time": "2015-01-07 21:55:43"
},
{
"name": "monolog/monolog",
"version": "1.12.0",
@@ -3792,7 +3846,9 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"mccool/laravel-auto-presenter": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

View File

@@ -27,6 +27,8 @@ gulp.task('default', function() {
'bower_components/lodash/dist/lodash.js',
'bower_components/messenger/build/js/messenger.js',
'bower_components/Sortable/Sortable.js',
'bower_components/moment/min/moment-with-locales.js',
'bower_components/livestampjs/livestamp.js',
'bower_components/jquery-minicolors/jquery.minicolors.js',
'bower_components/jquery-serialize-object/jquery.serialize-object.js',
'js/app.js',

View File

@@ -7,6 +7,7 @@ use Dingo\Api\Transformer\TransformableInterface;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use McCool\LaravelAutoPresenter\PresenterInterface;
use Watson\Validating\ValidatingTrait;
/**
@@ -21,7 +22,7 @@ use Watson\Validating\ValidatingTrait;
* @property \Carbon\Carbon $updated_at
* @property \Carbon\Carbon $deleted_at
*/
class Incident extends Model implements TransformableInterface
class Incident extends Model implements TransformableInterface, PresenterInterface
{
use SoftDeletingTrait, ValidatingTrait;
@@ -52,6 +53,16 @@ class Incident extends Model implements TransformableInterface
*/
protected $appends = ['humanStatus'];
/**
* Get presenter class.
*
* @return string
*/
public function getPresenter()
{
return 'CachetHQ\Cachet\Presenters\IncidentPresenter';
}
/**
* An incident belongs to a component.
*

View File

@@ -0,0 +1,50 @@
<?php
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Models\Incident;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\BasePresenter;
class IncidentPresenter extends BasePresenter
{
/**
* Create a incident presenter instance.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
*/
public function __construct(Incident $incident)
{
$this->resource = $incident;
}
/**
* Present diff for humans date time.
*
* @return string
*/
public function created_at_diff()
{
return (new Date($this->resource->created_at))->diffForHumans();
}
/**
* Present formated date time.
*
* @return string
*/
public function created_at_formated()
{
return ucfirst((new Date($this->resource->created_at))->format('l j F Y H:i:s'));
}
/**
* Present formated date time.
*
* @return string
*/
public function created_at_iso()
{
return $this->resource->created_at->toISO8601String();
}
}