Skip to content

Commit

Permalink
Merge branch 'release/4.1.8'
Browse files Browse the repository at this point in the history
* release/4.1.8:
  Optimized the view gathering on top referers
  cleanup
  Apply fixes from StyleCI (#441)
  Optimized statistic queries and refactored view trends
  Limit view select to created_at
  • Loading branch information
austintoddj committed Mar 6, 2019
2 parents 047ab1f + 4ad894f commit ced5273
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 117 deletions.
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/app.js": "/js/app.js?id=85577627b51c6fe6aace",
"/css/app.css": "/css/app.css?id=f13a10a1564f49e2b5f0",
"/css/app.css": "/css/app.css?id=4ee7db11d1a503a78968",
"/js/app.js.map": "/js/app.js.map?id=28b80c57c98ffab2c36d",
"/favicon.png": "/favicon.png?id=39d853e8c2bdbc38fde3"
}
4 changes: 4 additions & 0 deletions resources/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// Bootstrap
@import "~bootstrap/scss/bootstrap";

[v-cloak] {
display: none;
}

body:not(.user-is-tabbing) a:focus,
body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) input:focus,
Expand Down
50 changes: 26 additions & 24 deletions resources/views/posts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@section('content')
<post-list :models="{{ $data['posts'] }}" inline-template>
<div class="container" v-cloak>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="d-flex justify-content-between">
Expand All @@ -35,34 +35,36 @@ class="form-control border-0 pl-0"
</div>

@if(count($data['posts']))
<div class="d-flex border-top py-3 align-items-center" v-for="post in filteredList">
<div class="mr-auto py-1">
<p class="mb-1">
<a :href="'/canvas/posts/' + post.id + '/edit'" class="font-weight-bold lead">@{{ post.title }}</a>
</p>
<p class="mb-1" v-if="post.summary">@{{ post.summary }}</p>
<p class="text-muted mb-0">
<span v-if="post.published_at <= new Date().toJSON().slice(0, 19).replace('T', ' ')">Published @{{ moment(post.published_at).fromNow() }}</span>
<span v-else class="text-danger">Draft</span>
Updated @{{ moment(post.updated_at).fromNow() }}
</p>
</div>
<div class="ml-auto d-none d-lg-block">
<a :href="'/canvas/posts/' + post.id + '/edit'">
<div v-if="post.featured_image"
class="mr-2"
:style="{ backgroundImage: 'url(' + post.featured_image + ')' }"
style="background-size: cover;width: 57px; height: 57px; -webkit-border-radius: 50%;-moz-border-radius: 50%;border-radius: 50%;"></div>
<span v-else class="fa-stack fa-2x align-middle">
<div v-cloak>
<div class="d-flex border-top py-3 align-items-center" v-for="post in filteredList">
<div class="mr-auto py-1">
<p class="mb-1">
<a :href="'/canvas/posts/' + post.id + '/edit'" class="font-weight-bold lead">@{{ post.title }}</a>
</p>
<p class="mb-1" v-if="post.summary">@{{ post.summary }}</p>
<p class="text-muted mb-0">
<span v-if="post.published_at <= new Date().toJSON().slice(0, 19).replace('T', ' ')">Published @{{ moment(post.published_at).fromNow() }}</span>
<span v-else class="text-danger">Draft</span>
Updated @{{ moment(post.updated_at).fromNow() }}
</p>
</div>
<div class="ml-auto d-none d-lg-block">
<a :href="'/canvas/posts/' + post.id + '/edit'">
<div v-if="post.featured_image"
class="mr-2"
:style="{ backgroundImage: 'url(' + post.featured_image + ')' }"
style="background-size: cover;width: 57px; height: 57px; -webkit-border-radius: 50%;-moz-border-radius: 50%;border-radius: 50%;"></div>
<span v-else class="fa-stack fa-2x align-middle">
<i class="fas fa-circle fa-stack-2x text-black-50"></i>
<i class="fas fa-fw fa-stack-1x fa-camera fa-inverse"></i>
</span>
</a>
</a>
</div>
</div>
</div>

<p class="mt-4" v-if="!filteredList.length">No posts matched the given search criteria.</p>
<p class="mt-4" v-if="!filteredList.length">No posts matched the given search criteria.</p>
</div>
@else
<p class="mt-4">No posts were found, start by <a href="{{ route('canvas.post.create') }}">adding a new post</a>.</p>
@endif
Expand Down
4 changes: 2 additions & 2 deletions resources/views/stats/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="card-deck mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title text-muted small text-uppercase font-weight-bold">Total Views</h5>
<h5 class="card-title text-muted small text-uppercase font-weight-bold">Views (30 days)</h5>
<p class="card-text display-4">{{ \Canvas\SuffixedNumber::format($data['views']['count']) }}</p>
</div>
</div>
Expand Down Expand Up @@ -57,7 +57,7 @@ class="font-weight-bold lead">{{ $post->title }}</a>
</p>
</div>
<div class="ml-auto d-none d-lg-block">
<span class="text-muted mr-3">{{ \Canvas\SuffixedNumber::format($post->views->count()) }} View(s)</span>
<span class="text-muted mr-3">{{ \Canvas\SuffixedNumber::format($post->views_count) }} View(s)</span>
Created {{ \Carbon\Carbon::parse($post->created_at)->diffForHumans() }}
</div>
</div>
Expand Down
28 changes: 15 additions & 13 deletions resources/views/tags/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@section('content')
<tag-list :models="{{ $data['tags'] }}" inline-template>
<div class="container" v-cloak>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="d-flex justify-content-between">
Expand All @@ -35,20 +35,22 @@ class="form-control border-0 px-0 py-0"
</div>

@if(count($data['tags']))
<div class="d-flex border-top py-3 align-items-center" v-for="tag in filteredList">
<div class="mr-auto">
<p class="mb-0 py-1">
<a :href="'/canvas/tags/' + tag.id + '/edit'"
class="font-weight-bold lead">@{{ tag.name }}</a>
</p>
<div v-cloak>
<div class="d-flex border-top py-3 align-items-center" v-for="tag in filteredList">
<div class="mr-auto">
<p class="mb-0 py-1">
<a :href="'/canvas/tags/' + tag.id + '/edit'"
class="font-weight-bold lead">@{{ tag.name }}</a>
</p>
</div>
<div class="ml-auto">
<span class="text-muted mr-3">@{{ tag.posts_count }} Post(s)</span>
Created @{{ moment(tag.created_at).fromNow() }}
</div>
</div>
<div class="ml-auto">
<span class="text-muted mr-3">@{{ tag.posts_count }} Post(s)</span>
Created @{{ moment(tag.created_at).fromNow() }}
</div>
</div>

<p class="mt-4" v-if="!filteredList.length">No tags matched the given search criteria.</p>
<p class="mt-4" v-if="!filteredList.length">No tags matched the given search criteria.</p>
</div>
@else
<p class="mt-4">No tags were found, start by <a href="{{ route('canvas.tag.create') }}">adding a new tag</a>.</p>
@endif
Expand Down
28 changes: 15 additions & 13 deletions resources/views/topics/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@section('content')
<topic-list :models="{{ $data['topics'] }}" inline-template>
<div class="container" v-cloak>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="d-flex justify-content-between">
Expand All @@ -35,20 +35,22 @@ class="form-control border-0 px-0 py-0"
</div>

@if(count($data['topics']))
<div class="d-flex border-top py-3 align-items-center" v-for="topic in filteredList">
<div class="mr-auto">
<p class="mb-0 py-1">
<a :href="'/canvas/topics/' + topic.id + '/edit'"
class="font-weight-bold lead">@{{ topic.name }}</a>
</p>
<div v-cloak>
<div class="d-flex border-top py-3 align-items-center" v-for="topic in filteredList">
<div class="mr-auto">
<p class="mb-0 py-1">
<a :href="'/canvas/topics/' + topic.id + '/edit'"
class="font-weight-bold lead">@{{ topic.name }}</a>
</p>
</div>
<div class="ml-auto">
<span class="text-muted mr-3">@{{ topic.posts_count }} Post(s)</span>
Created @{{ moment(topic.created_at).fromNow() }}
</div>
</div>
<div class="ml-auto">
<span class="text-muted mr-3">@{{ topic.posts_count }} Post(s)</span>
Created @{{ moment(topic.created_at).fromNow() }}
</div>
</div>

<p class="mt-4" v-if="!filteredList.length">No topics matched the given search criteria.</p>
<p class="mt-4" v-if="!filteredList.length">No topics matched the given search criteria.</p>
</div>
@else
<p class="mt-4">No topics were found, start by <a href="{{ route('canvas.topic.create') }}">adding a new topic</a>.</p>
@endif
Expand Down
26 changes: 12 additions & 14 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
use Canvas\Post;
use Canvas\Topic;
use Carbon\Carbon;
use Illuminate\View\View;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Illuminate\Routing\Controller;
use Illuminate\Http\RedirectResponse;

class PostController extends Controller
{
/**
* Show a paginated list of posts.
*
* @return View
* @return \Illuminate\View\View
*/
public function index(): View
public function index()
{
$data = [
'posts' => Post::orderByDesc('created_at')->with('tags')->get(),
Expand All @@ -31,9 +29,9 @@ public function index(): View
/**
* Show the form for creating a new post.
*
* @return View
* @return \Illuminate\View\View
*/
public function create(): View
public function create()
{
$data = [
'id' => Str::uuid(),
Expand All @@ -48,9 +46,9 @@ public function create(): View
* Show the form for editing an existing post.
*
* @param string $id
* @return View
* @return \Illuminate\View\View
*/
public function edit(string $id): View
public function edit(string $id)
{
$post = Post::findOrFail($id);

Expand All @@ -67,9 +65,9 @@ public function edit(string $id): View
/**
* Store a newly created post in storage.
*
* @return RedirectResponse
* @return \Illuminate\Http\RedirectResponse
*/
public function store(): RedirectResponse
public function store()
{
$data = [
'id' => request('id'),
Expand Down Expand Up @@ -121,9 +119,9 @@ public function store(): RedirectResponse
* Update a post in storage.
*
* @param string $id
* @return RedirectResponse
* @return \Illuminate\Http\RedirectResponse
*/
public function update(string $id): RedirectResponse
public function update(string $id)
{
$post = Post::findOrFail($id);

Expand Down Expand Up @@ -176,9 +174,9 @@ public function update(string $id): RedirectResponse
* Soft delete a post in storage.
*
* @param string $id
* @return RedirectResponse
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(string $id): RedirectResponse
public function destroy(string $id)
{
$post = Post::findOrFail($id);
$post->delete();
Expand Down
28 changes: 19 additions & 9 deletions src/Http/Controllers/StatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
namespace Canvas\Http\Controllers;

use Canvas\Post;
use Illuminate\View\View;
use Canvas\View;
use Illuminate\Routing\Controller;

class StatsController extends Controller
{
/**
* The number of days to generate statistics for.
*
* @const int
*/
const DAYS_PRIOR = 30;

/**
* Show the overall statistics for all posts.
*
* @return View
* @return \Illuminate\View\View
*/
public function index(): View
public function index()
{
$posts = Post::with('views')->orderByDesc('created_at')->paginate(10);
$views = \Canvas\View::all();
$posts = Post::withCount('views')->orderByDesc('created_at')->paginate();
$views = View::whereBetween('created_at', [
now()->subDays(self::DAYS_PRIOR)->toDateTimeString(),
now()->toDateTimeString(),
])->select('created_at')->get();

$data = [
'posts' => [
Expand All @@ -26,7 +36,7 @@ public function index(): View
],
'views' => [
'count' => $views->count(),
'trend' => json_encode(\Canvas\View::viewTrend($views)),
'trend' => json_encode(View::viewTrend($views, self::DAYS_PRIOR)),
],
];

Expand All @@ -37,11 +47,11 @@ public function index(): View
* Show data analytics for a single post.
*
* @param string $id
* @return View
* @return \Illuminate\View\View
*/
public function show(string $id): View
public function show(string $id)
{
$post = Post::with('views')->findOrFail($id);
$post = Post::findOrFail($id);

if ($post->published) {
$data = [
Expand Down
Loading

0 comments on commit ced5273

Please sign in to comment.