Skip to content

Commit

Permalink
Merge branch 'release/5.3.8'
Browse files Browse the repository at this point in the history
* release/5.3.8:
  Apply fixes from StyleCI (#705)
  updates
  compiled assets
  added ext-intl as a dependency
  added the post type
  Removal of the lining of the variable $locale
  Fix Class 'Locale' not found
  compiled assets
  fixes #695
  cleanup and refactor
  Apply fixes from StyleCI (#701)
  refactoring and cleanup
  • Loading branch information
austintoddj committed Apr 13, 2020
2 parents 0d57521 + 9d2b769 commit 6245b63
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterCanvasTablesUserIdColumnType extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('canvas_user_meta', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable(false)->charset(null)->change();
});

Schema::table('canvas_posts', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable(false)->charset(null)->change();
});

Schema::table('canvas_tags', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable(false)->charset(null)->change();
});

Schema::table('canvas_topics', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable(false)->charset(null)->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('canvas_user_meta', function (Blueprint $table) {
$table->string('user_id')->change();
});

Schema::table('canvas_posts', function (Blueprint $table) {
$table->string('user_id')->change();
});

Schema::table('canvas_tags', function (Blueprint $table) {
$table->string('user_id')->change();
});

Schema::table('canvas_topics', function (Blueprint $table) {
$table->string('user_id')->change();
});
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
verbose="true"
>
<testsuites>
<testsuite name="Canvas Test Suite">
<testsuite name="Canvas Unit Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions public/js/app.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*!
* FilePond 4.13.0
* FilePond 4.13.2
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -65,14 +65,14 @@
*/

/*!
* Sizzle CSS Selector Engine v2.3.4
* Sizzle CSS Selector Engine v2.3.5
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2019-04-08
* Date: 2020-03-14
*/

/*!
Expand All @@ -89,7 +89,7 @@
*/

/*!
* jQuery JavaScript Library v3.4.1
* jQuery JavaScript Library v3.5.0
* https://jquery.com/
*
* Includes Sizzle.js
Expand All @@ -99,7 +99,7 @@
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2019-05-01T21:04Z
* Date: 2020-04-10T15:07Z
*/

/*!
Expand Down
2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=3fd793e8b505909a4667",
"/js/app.js": "/js/app.js?id=a3ab02b70dc2d53a9e5a",
"/css/app.css": "/css/app.css?id=48eae9fc081d95312ccd",
"/css/app-dark.css": "/css/app-dark.css?id=96ccf9a9c90446210f79",
"/favicon.ico": "/favicon.ico?id=f7a1a9d5196af323a9eb"
Expand Down
8 changes: 4 additions & 4 deletions resources/js/screens/posts/PostIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="d-flex justify-content-between my-3">
<h1>{{ trans.app.posts_simple }}</h1>

<select name="" id="" v-model="postType" @change="changeType" class="my-auto ml-auto w-auto bg-transparent custom-select border-0">
<select name="" id="" v-model="type" @change="changeType" class="my-auto ml-auto w-auto bg-transparent custom-select border-0">
<option value="published">{{ trans.app.published }} ({{ publishedCount }})</option>
<option value="draft">{{ trans.app.draft }} ({{ draftCount }})</option>
</select>
Expand Down Expand Up @@ -70,7 +70,7 @@
<div slot="no-results" class="text-left">
<div class="my-5">
<p class="lead text-center text-muted mt-5">
<span v-if="postType === 'published'">{{ trans.app.you_have_no_published_posts }}</span>
<span v-if="type === 'published'">{{ trans.app.you_have_no_published_posts }}</span>
<span v-else>{{ trans.app.you_have_no_draft_posts }}</span>
</p>
<p class="lead text-center text-muted mt-1">
Expand Down Expand Up @@ -111,7 +111,7 @@
posts: [],
publishedCount: 0,
draftCount: 0,
postType: 'published',
type: 'published',
infiniteId: +new Date(),
trans: JSON.parse(Canvas.translations),
}
Expand All @@ -123,7 +123,7 @@
.get('/api/posts', {
params: {
page: this.page,
postType: this.postType,
type: this.type,
},
})
.then(response => {
Expand Down
3 changes: 2 additions & 1 deletion resources/js/screens/stats/StatsIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
this.request()
.get('/api/posts', {
params: {
page: this.page
page: this.page,
type: 'published'
},
})
.then(response => {
Expand Down
3 changes: 1 addition & 2 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Locale;
use RuntimeException;

class Canvas
Expand Down Expand Up @@ -60,7 +59,7 @@ private static function getAvailableLanguageCodes()
$translations = collect();

foreach ($locales as $locale) {
$translations->put($locale, Str::ucfirst(Locale::getDisplayName($locale, $locale)));
$translations->put($locale, Str::upper($locale));
}

return $translations->toArray();
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/LocaleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class LocaleController extends Controller
{
/**
* Return the app translations for a given locale.
* Handle the incoming request.
*
* @return string
*/
public function update()
public function __invoke()
{
return collect(['app' => trans('canvas::app', [], request('locale'))])->toJson();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class MediaController extends Controller
{
/**
* Stores a given file and returns the path.
* Store a newly created resource in storage.
*
* @return mixed
*/
Expand All @@ -30,7 +30,7 @@ public function store()
}

/**
* Deletes a given file from storage.
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\JsonResponse
*/
Expand Down
80 changes: 42 additions & 38 deletions src/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,45 @@
class PostController extends Controller
{
/**
* Get all the posts.
* Display a listing of the resource.
*
* @return JsonResponse
*/
public function index(): JsonResponse
{
$publishedCount = Post::forCurrentUser()->published()->count();
$draftCount = Post::forCurrentUser()->draft()->count();

if (request()->query('postType') == 'draft') {
return response()->json([
'posts' => Post::forCurrentUser()->draft()->latest()->withCount('views')->paginate(),
'draftCount' => $draftCount,
'publishedCount' => $publishedCount,
], 200);
} else {
return response()->json([
'posts' => Post::forCurrentUser()->published()->latest()->withCount('views')->paginate(),
'draftCount' => $draftCount,
'publishedCount' => $publishedCount,
], 200);
switch (request()->query('type')) {
case 'draft':
return response()->json([
'posts' => Post::forCurrentUser()->draft()->latest()->withCount('views')->paginate(),
'draftCount' => Post::forCurrentUser()->draft()->count(),
'publishedCount' => Post::forCurrentUser()->published()->count(),
], 200);
break;

case 'published':
return response()->json([
'posts' => Post::forCurrentUser()->published()->latest()->withCount('views')->paginate(),
'draftCount' => Post::forCurrentUser()->draft()->count(),
'publishedCount' => Post::forCurrentUser()->published()->count(),
], 200);
break;

default:
return response()->json([], 404);
break;
}
}

/**
* Get a single post or return a UUID to create one.
* Display the specified resource.
*
* @param null $id
* @param $id
* @return JsonResponse
* @throws Exception
*/
public function show($id = null): JsonResponse
public function show($id): JsonResponse
{
if (Post::forCurrentUser()->pluck('id')->contains($id) || $this->isNewPost($id)) {
$tags = Tag::forCurrentUser()->get(['name', 'slug']);
$topics = Topic::forCurrentUser()->get(['name', 'slug']);

if (Post::forCurrentUser()->pluck('id')->contains($id)) {
if ($this->isNewPost($id)) {
$uuid = Uuid::uuid4();

Expand All @@ -59,23 +61,23 @@ public function show($id = null): JsonResponse
'id' => $uuid->toString(),
'slug' => "post-{$uuid->toString()}",
]),
'tags' => $tags,
'topics' => $topics,
'tags' => Tag::forCurrentUser()->get(['name', 'slug']),
'topics' => Topic::forCurrentUser()->get(['name', 'slug']),
]);
} else {
return response()->json([
'post' => Post::forCurrentUser()->with('tags:name,slug', 'topic:name,slug')->find($id),
'tags' => $tags,
'topics' => $topics,
'tags' => Tag::forCurrentUser()->get(['name', 'slug']),
'topics' => Topic::forCurrentUser()->get(['name', 'slug']),
]);
}
} else {
return response()->json(null, 301);
return response()->json(null, 404);
}
}

/**
* Create or update a post.
* Store a newly created resource in storage.
*
* @param string $id
* @return JsonResponse
Expand Down Expand Up @@ -116,7 +118,7 @@ public function store(string $id): JsonResponse
],
], $messages)->validate();

$post = $id !== 'create' ? Post::forCurrentUser()->find($id) : new Post(['id' => request('id')]);
$post = $this->isNewPost($id) ? new Post(['id' => request('id')]) : Post::forCurrentUser()->find($id);

$post->fill($data);
$post->meta = $data['meta'];
Expand All @@ -130,11 +132,11 @@ public function store(string $id): JsonResponse
$this->syncTags(request('tags'))
);

return response()->json($post->refresh());
return response()->json($post->refresh(), 201);
}

/**
* Delete a post.
* Remove the specified resource from storage.
*
* @param string $id
* @return mixed
Expand All @@ -146,12 +148,14 @@ public function destroy(string $id)
if ($post) {
$post->delete();

return response()->json([], 204);
return response()->json(null, 204);
} else {
return response()->json(null, 404);
}
}

/**
* Return true if we're creating a new post.
* Return true if the given ID is for a new post.
*
* @param string $id
* @return bool
Expand All @@ -162,7 +166,7 @@ private function isNewPost(string $id): bool
}

/**
* Attach or create a given topic.
* Sync the topic assigned to the post.
*
* @param $incomingTopic
* @return array
Expand All @@ -175,7 +179,7 @@ private function syncTopic($incomingTopic): array

if (! $topic) {
$topic = Topic::create([
'id' => $id = Uuid::uuid4(),
'id' => $id = Uuid::uuid4()->toString(),
'name' => $incomingTopic['name'],
'slug' => $incomingTopic['slug'],
'user_id' => request()->user()->id,
Expand All @@ -189,7 +193,7 @@ private function syncTopic($incomingTopic): array
}

/**
* Attach or create tags given an incoming array.
* Sync the tags assigned to the post.
*
* @param array $incomingTags
* @return array
Expand All @@ -204,7 +208,7 @@ private function syncTags(array $incomingTags): array

if (! $tag) {
$tag = Tag::create([
'id' => $id = Uuid::uuid4(),
'id' => $id = Uuid::uuid4()->toString(),
'name' => $incomingTag['name'],
'slug' => $incomingTag['slug'],
'user_id' => request()->user()->id,
Expand Down
Loading

0 comments on commit 6245b63

Please sign in to comment.