diff --git a/app/Http/Controllers/PostController.php b/app/Http/Controllers/PostController.php
index 40c381d..a4f0f93 100755
--- a/app/Http/Controllers/PostController.php
+++ b/app/Http/Controllers/PostController.php
@@ -62,7 +62,17 @@ public function __construct(Request $request, PostRepository $repo, ActivityLogR
$this->activity = $activity;
$this->user = $user;
$this->category = $category;
- $this->middleware('permission:access-post');
+ $this->middleware('permission:access-post')->except(['index']);
+ }
+
+ /**
+ * Display all posts
+ *
+ * @return Post[]|Collection
+ */
+ public function index()
+ {
+ return $this->repo->getPosts($this->request->all());
}
/**
@@ -200,9 +210,7 @@ public function uploadCover($id)
$filename = uniqid();
request()->file('image')->move($image_path, $filename . "." . $extension);
$img = \Image::make($image_path . $filename . "." . $extension);
- $img->resize(500, null, function ($constraint) {
- $constraint->aspectRatio();
- });
+ $img->resize(600, 300);
$img->save($image_path . $filename . "." . $extension);
$post->cover = $image_path . $filename . "." . $extension;
$post->save();
diff --git a/app/Post.php b/app/Post.php
index 2357d01..b9295e8 100755
--- a/app/Post.php
+++ b/app/Post.php
@@ -17,6 +17,7 @@
* @property string|null $cover
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
+ * @property-read string|null $stripped_body
* @property-read \App\User $user
* @property-read \App\Category $category
*/
@@ -34,6 +35,13 @@ class Post extends Model
'body'
];
+ /**
+ * The accessors to append to the model's array form.
+ *
+ * @var array
+ */
+ protected $appends = ['stripped_body'];
+
/**
* Get the user that owns the post.
*
@@ -74,6 +82,26 @@ public function getUpdatedAtAttribute()
return Carbon::parse($this->attributes['updated_at'])->diffForHumans();
}
+ /**
+ * Get body with the stripped HTML tags.
+ *
+ * @return string
+ */
+ public function getStrippedBodyAttribute()
+ {
+ return strip_tags($this->attributes['body']);
+ }
+
+ /**
+ * Get cover image.
+ *
+ * @return string
+ */
+ public function getCoverAttribute()
+ {
+ return $this->attributes['cover'] ?: 'uploads/images/cover-default.png';
+ }
+
/**
* Sets the title and the readable slug.
*
diff --git a/app/Repositories/PostRepository.php b/app/Repositories/PostRepository.php
index 88c0e6e..d472396 100755
--- a/app/Repositories/PostRepository.php
+++ b/app/Repositories/PostRepository.php
@@ -24,6 +24,25 @@ public function __construct(Post $post)
$this->post = $post;
}
+ /**
+ * Get published posts.
+ *
+ * @param array $params
+ *
+ * @return Post[]|Collection
+ */
+ public function getPosts($params = [])
+ {
+ $page_length = isset($params['page_length']) ? $params['page_length'] : config('config.page_length');
+ $published = $this->post->with('user', 'user.profile', 'category')->filterByIsDraft(0);
+
+ if (!isset($params['page_length'])) {
+ return $published->get();
+ }
+
+ return $published->orderBy('created_at', 'desc')->paginate($page_length);
+ }
+
/**
* Get post query.
*
diff --git a/public/uploads/images/cover-default.jpg b/public/uploads/images/cover-default.jpg
deleted file mode 100644
index 927874c..0000000
Binary files a/public/uploads/images/cover-default.jpg and /dev/null differ
diff --git a/public/uploads/images/cover-default.png b/public/uploads/images/cover-default.png
new file mode 100644
index 0000000..09a1f27
Binary files /dev/null and b/public/uploads/images/cover-default.png differ
diff --git a/resources/assets/js/components/PaginationRecord.vue b/resources/assets/js/components/PaginationRecord.vue
index c24080a..0c233cf 100755
--- a/resources/assets/js/components/PaginationRecord.vue
+++ b/resources/assets/js/components/PaginationRecord.vue
@@ -3,7 +3,7 @@
+
+
@@ -52,6 +84,14 @@
export default {
data() {
return {
+ posts: {
+ total: 0,
+ data: []
+ },
+ splitted: [],
+ filterPostForm: {
+ page_length: 9
+ },
loginForm: new Form({
email: '',
password: ''
@@ -70,6 +110,9 @@
return '/uploads/config/background/background.jpg'
}
},
+ mounted() {
+ this.getPosts();
+ },
methods: {
submit() {
this.loginForm.post('/api/auth/login')
@@ -93,6 +136,47 @@
},
getConfig(config) {
return helper.getConfig(config);
+ },
+ getPosts(page) {
+ if (typeof page !== 'number') {
+ page = 1;
+ }
+ let url = helper.getFilterURL(this.filterPostForm);
+ axios.get('/api/posts?page=' + page + url)
+ .then(response => response.data)
+ .then(response => {
+ this.posts = response;
+ this.splitted = this.chunk(response.data, 3);
+ })
+ .catch(error => {
+ helper.showDataErrorMsg(error);
+ });
+ },
+ chunk(arr, len) {
+ let chunks = [];
+ let i = 0;
+ let n = arr.length;
+ while (i < n) {
+ chunks.push(arr.slice(i, i += len));
+ }
+ return chunks;
+ },
+ limitWords(textToLimit, wordLimit) {
+ let finalText = "";
+ let text2 = textToLimit.replace(/\s+/g, ' ');
+ let text3 = text2.split(' ');
+ let numberOfWords = text3.length;
+ let i = 0;
+
+ if (numberOfWords > wordLimit) {
+ for (i = 0; i < wordLimit; i++) {
+ finalText = finalText + " " + text3[i] + " ";
+ }
+
+ return finalText + "...";
+ }
+
+ return textToLimit;
}
}
}
diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss
index eaee648..72f8f27 100755
--- a/resources/assets/sass/app.scss
+++ b/resources/assets/sass/app.scss
@@ -30,6 +30,7 @@ html {
a:hover, a:focus {
text-decoration: none;
+ color: $bodytext;
}
a.link {
@@ -2545,4 +2546,17 @@ samp {
.input-group > .form-control:not(:last-child),
.input-group > .custom-select:not(:last-child) {
border-radius: 0.25rem !important;
+}
+
+.card:focus .card-img img, .card:hover .card-img img {
+ opacity: .8
+}
+
+.card-img img {
+ opacity: 1;
+ transition: opacity .3s ease-in-out;
+}
+
+.cover-img {
+ background-color: #fff !important;
}
\ No newline at end of file
diff --git a/resources/assets/sass/colors/blue-dark.scss b/resources/assets/sass/colors/blue-dark.scss
index fbaa4bd..f8e2546 100755
--- a/resources/assets/sass/colors/blue-dark.scss
+++ b/resources/assets/sass/colors/blue-dark.scss
@@ -66,6 +66,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -76,6 +80,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/blue.scss b/resources/assets/sass/colors/blue.scss
index 6f80020..dc5817a 100755
--- a/resources/assets/sass/colors/blue.scss
+++ b/resources/assets/sass/colors/blue.scss
@@ -54,6 +54,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -64,6 +68,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/default-dark.scss b/resources/assets/sass/colors/default-dark.scss
index 804bd77..6bf3fb1 100755
--- a/resources/assets/sass/colors/default-dark.scss
+++ b/resources/assets/sass/colors/default-dark.scss
@@ -52,6 +52,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -62,6 +66,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/default.scss b/resources/assets/sass/colors/default.scss
index 0716383..9152c06 100755
--- a/resources/assets/sass/colors/default.scss
+++ b/resources/assets/sass/colors/default.scss
@@ -42,6 +42,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -52,6 +56,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/green-dark.scss b/resources/assets/sass/colors/green-dark.scss
index 1ac2463..26dd9d0 100755
--- a/resources/assets/sass/colors/green-dark.scss
+++ b/resources/assets/sass/colors/green-dark.scss
@@ -66,6 +66,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -76,6 +80,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/green.scss b/resources/assets/sass/colors/green.scss
index 5bb949f..36a89e2 100755
--- a/resources/assets/sass/colors/green.scss
+++ b/resources/assets/sass/colors/green.scss
@@ -56,6 +56,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -66,6 +70,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/megna-dark.scss b/resources/assets/sass/colors/megna-dark.scss
index e49837d..2b2539f 100755
--- a/resources/assets/sass/colors/megna-dark.scss
+++ b/resources/assets/sass/colors/megna-dark.scss
@@ -66,6 +66,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -76,6 +80,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/megna.scss b/resources/assets/sass/colors/megna.scss
index d2ffa99..4f291b1 100755
--- a/resources/assets/sass/colors/megna.scss
+++ b/resources/assets/sass/colors/megna.scss
@@ -56,6 +56,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -66,6 +70,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/purple-dark.scss b/resources/assets/sass/colors/purple-dark.scss
index 5b0f1f0..ee4b3d8 100755
--- a/resources/assets/sass/colors/purple-dark.scss
+++ b/resources/assets/sass/colors/purple-dark.scss
@@ -71,6 +71,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -81,6 +85,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/purple.scss b/resources/assets/sass/colors/purple.scss
index 171def3..e0142bf 100755
--- a/resources/assets/sass/colors/purple.scss
+++ b/resources/assets/sass/colors/purple.scss
@@ -56,6 +56,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -66,6 +70,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/red-dark.scss b/resources/assets/sass/colors/red-dark.scss
index 415259b..281c1cd 100755
--- a/resources/assets/sass/colors/red-dark.scss
+++ b/resources/assets/sass/colors/red-dark.scss
@@ -66,6 +66,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -76,6 +80,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/resources/assets/sass/colors/red.scss b/resources/assets/sass/colors/red.scss
index ec1aa74..60fac27 100755
--- a/resources/assets/sass/colors/red.scss
+++ b/resources/assets/sass/colors/red.scss
@@ -56,6 +56,10 @@ a.link {
background-color: $themecolor !important;
}
+.card-img {
+ background-color: $themecolor;
+}
+
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
@@ -66,6 +70,10 @@ a.link {
border-color: $themecolor;
}
+.post-title {
+ color: $themecolor;
+}
+
.right-sidebar {
.rpanel-title {
background: $themecolor;
diff --git a/routes/api.php b/routes/api.php
index 9b606c6..e52063c 100755
--- a/routes/api.php
+++ b/routes/api.php
@@ -12,6 +12,7 @@
*/
Route::get('/configuration/variable', 'ConfigurationController@getConfigurationVariable');
+Route::get('/posts','PostController@index');
Route::group(['prefix' => 'auth'], function () {
Route::post('/login', 'AuthController@authenticate');