Permalink
Browse files

Admin Pages - merge page components into one only

  • Loading branch information...
bpocallaghan committed Jan 25, 2018
1 parent 315fc9f commit 1f191f22e1e51cf4d032957ba1e17dde782701f1
Showing with 351 additions and 916 deletions.
  1. +4 −1 TODO.md
  2. +81 −22 app/Http/Controllers/Admin/Pages/PageContentController.php
  3. +0 −62 app/Http/Controllers/Admin/Pages/PageDocumentsController.php
  4. +0 −63 app/Http/Controllers/Admin/Pages/PageGalleryController.php
  5. +0 −145 app/Http/Controllers/Admin/Pages/PageMediaController.php
  6. +18 −1 app/Http/Controllers/Website/PagesController.php
  7. +36 −12 app/Models/PageContent.php
  8. +0 −40 app/Models/PageDocument.php
  9. +0 −30 app/Models/PageGallery.php
  10. +0 −54 app/Models/PageMedia.php
  11. +5 −16 app/Models/Photo.php
  12. +51 −53 composer.lock
  13. +6 −3 database/migrations/2017_10_10_123309_create_page_content_table.php
  14. +0 −41 database/migrations/2017_10_10_145319_create_page_media_table.php
  15. +0 −38 database/migrations/2017_10_11_094455_create_page_gallery_table.php
  16. +0 −38 database/migrations/2017_10_20_142234_create_page_documents_table.php
  17. +2 −6 database/seeds/PageTableSeeder.php
  18. +22 −40 resources/views/admin/pages/components/components.blade.php
  19. +53 −4 resources/views/admin/pages/components/content.blade.php
  20. +0 −45 resources/views/admin/pages/components/documents.blade.php
  21. +0 −46 resources/views/admin/pages/components/gallery.blade.php
  22. +0 −86 resources/views/admin/pages/components/media.blade.php
  23. +2 −2 resources/views/website/home.blade.php
  24. +22 −10 resources/views/website/pages/page.blade.php
  25. +22 −3 resources/views/website/pages/page_content.blade.php
  26. +12 −12 resources/views/website/pages/page_documents.blade.php
  27. +15 −24 resources/views/website/pages/page_gallery.blade.php
  28. +0 −16 resources/views/website/pages/page_media.blade.php
  29. +0 −3 routes/web.php
@@ -1,5 +1,8 @@
##Admin Starter - TODO
- ~~Merge the Page Components into one (no more seperate tables and create pages)~~
- Page Content (media) - add cropper
- Resource with single photo - save image in photos table and not his own table (upload directory and cropper)
- ~~Add cropper for Gallery photos~~
- Add cropper for Images (Banners)
- ~~Update bootstrap 4 to latest beta version~~
@@ -11,7 +14,7 @@
- ~~[FAQ](https://github.com/bpocallaghan/faq)~~
- ~~[Corporate](https://github.com/bpocallaghan/corporate)~~
- ~~[Changelogs](https://github.com/bpocallaghan/changelogs)~~
- Roles and Permissions
- Roles and Permissions (https://github.com/spatie/laravel-permission ?)
- Titan (The core required modules pages, banners, gallery, etc)
- Unit Testing
- Vuejs
@@ -2,13 +2,14 @@
namespace App\Http\Controllers\Admin\Pages;
use Redirect;
use Image;
use App\Models\Page;
use App\Http\Requests;
use App\Models\Content;
use App\Models\PageContent;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use App\Http\Controllers\Admin\AdminController;
use Titan\Models\Traits\ImageThumb;
class PageContentController extends AdminController
{
@@ -20,24 +21,12 @@ class PageContentController extends AdminController
*/
public function create(Page $page)
{
return $this->view('pages.components.content')->with('page', $page);
}
/**
* Store a newly created content in storage.
*
* @param Page $page
* @return Response
*/
public function store(Page $page)
{
$attributes = request()->validate(PageContent::$rules, PageContent::$messages);
unset($attributes['page_id']);
$item = $this->createEntry(PageContent::class, $attributes);
$page->attachComponent($item);
// create new content (used to link media and documents to)
$item = PageContent::create();
return redirect_to_resource();
return $this->view('pages.components.content')
->with('page', $page)
->with('item', $item);
}
/**
@@ -49,7 +38,9 @@ public function store(Page $page)
*/
public function edit(Page $page, PageContent $content)
{
return $this->view('pages.components.content')->with('page', $page)->with('item', $content);
return $this->view('pages.components.content')
->with('page', $page)
->with('item', $content);
}
/**
@@ -61,11 +52,79 @@ public function edit(Page $page, PageContent $content)
*/
public function update(Page $page, PageContent $content)
{
$attributes = request()->validate(PageContent::$rules, PageContent::$messages);
if (is_null(request()->file('media'))) {
$attributes = request()->validate(array_except(PageContent::$rules, 'media'),
PageContent::$messages);
}
else {
$attributes = request()->validate(PageContent::$rules, PageContent::$messages);
$media = $this->moveAndCreatePhoto($attributes['media']);
if ($media) {
$attributes['media'] = $media;
}
}
unset($attributes['page_id']);
$content = $this->updateEntry($content, $attributes);
$item = $this->updateEntry($content, $attributes);
$page->attachComponent($item);
return redirect_to_resource();
}
/**
* Save Image in Storage, crop image and save in public/uploads/images
* @param UploadedFile $file
* @param array $size
* @return \Illuminate\Http\JsonResponse|static
*/
private function moveAndCreatePhoto(
UploadedFile $file,
$size = ['l' => [1000, 1000], 's' => [300, 300]]
) {
$extension = '.' . $file->extension();
$name = token();
$filename = $name . $extension;
$path = upload_path_images();
$imageTmp = Image::make($file->getRealPath());
if (!$imageTmp) {
return false;
}
$largeSize = $size['l'];
$thumbSize = $size['s'];
// save original
$imageTmp->save($path . $name . ImageThumb::$originalAppend . $extension);
// if width is the biggest - resize on max width
if ($imageTmp->width() > $imageTmp->height()) {
// resize the image to the large height and constrain aspect ratio (auto width)
$imageTmp->resize(null, $largeSize[1], function ($constraint) {
$constraint->aspectRatio();
})->save($path . $filename);
// resize the image to the thumb height and constrain aspect ratio (auto width)
$imageTmp->resize(null, $thumbSize[1], function ($constraint) {
$constraint->aspectRatio();
})->save($path . $name . ImageThumb::$thumbAppend . $extension);
}
else {
// resize the image to the large width and constrain aspect ratio (auto height)
$imageTmp->resize($largeSize[0], null, function ($constraint) {
$constraint->aspectRatio();
})->save($path . $filename);
// resize the image to the thumb width and constrain aspect ratio (auto width)
$imageTmp->resize($thumbSize[0], null, function ($constraint) {
$constraint->aspectRatio();
})->save($path . $name . ImageThumb::$thumbAppend . $extension);
}
return $filename;
}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 1f191f2

Please sign in to comment.