Permalink
Browse files

Page Builder - add documents component

  • Loading branch information...
bpocallaghan committed Oct 21, 2017
1 parent 2164ebe commit 7dd6bb9d987236a502bcbedcde705b4d50b24eef
@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers\Admin\Pages;
use Redirect;
use App\Models\Page;
use App\Http\Requests;
use App\Models\PageDocument;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\AdminController;
class PageDocumentsController extends AdminController
{
/**
* Show the form for creating a new content.
*
* @param Page $page
* @return Response
*/
public function create(Page $page)
{
$item = PageDocument::create([
'heading' => 'Documents Heading',
'heading_element' => 'h2',
]);
return $this->view('pages.components.documents')
->with('page', $page)
->with('item', $item);
}
/**
* Show the form for editing the specified content.
*
* @param Page $page
* @param PageDocument $document
* @return Response
*/
public function edit(Page $page, PageDocument $document)
{
return $this->view('pages.components.documents')->with('page', $page)->with('item', $document);
}
/**
* Update the specified content in storage.
*
* @param Page $page
* @param PageDocument $document
* @return Response
*/
public function update(Page $page, PageDocument $document)
{
$attributes = request()->validate(PageDocument::$rules, PageDocument::$messages);
unset($attributes['page_id']);
$item = $this->updateEntry($document, $attributes);
$page->attachComponent($item);
return redirect_to_resource();
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use App\Models\Traits\Documentable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Titan\Models\TitanCMSModel;
/**
* Class PageDocument
* @mixin \Eloquent
*/
class PageDocument extends TitanCMSModel
{
use SoftDeletes, Documentable;
protected $table = 'page_documents';
protected $guarded = ['id'];
/**
* Validation rules for this model
*/
static public $rules = [
'heading' => 'required|min:3:max:255',
'heading_element' => 'required|max:2',
'content' => 'nullable|max:3000',
'page_id' => 'required|exists:pages,id',
];
/**
* Get the heading name
* @return mixed
*/
public function getNameAttribute()
{
return $this->heading;
}
}
@@ -21,6 +21,8 @@ class PageSection extends Model
static public $TYPE_GALLERY = 'gallery';
static public $TYPE_DOCUMENT = 'document';
/**
* Get the page
*/
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePageDocumentsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('page_documents', function (Blueprint $table) {
$table->increments('id')->unique()->index();
$table->string('heading');
$table->string('heading_element')->default('h1');
$table->string('heading_class')->nullable();
$table->text('content')->nullable();
$table->timestamps();
$table->softDeletes();
$table->integer('created_by')->unsigned();
$table->integer('updated_by')->unsigned()->nullable();
$table->integer('deleted_by')->unsigned()->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('page_documents');
}
}
@@ -47,6 +47,11 @@
<span class="btn-label"><i class="fa fa-fw fa-image"></i></span>
Create Gallery Component
</a>
<a class="btn btn-labeled btn-primary" href="{{ Request::url().'/document/create' }}">
<span class="btn-label"><i class="fa fa-fw fa-files-o"></i></span>
Create Documents Component
</a>
</div>
<div class="row">
@@ -78,7 +83,8 @@
<span class="text-bold" style="font-size: larger;">
{{ $item->component->heading }}
<span class="text-muted">
({{ $item->component->heading_element }})
({{ $item->component->heading_element }}
)
<em><small>{{ $item->type }}</small></em>
</span>
</span>
@@ -101,6 +107,10 @@
@foreach($item->component->photos as $photo)
<img class=img-responsive" src="{{ $photo->thumb_url }}" style="height: 30px;">
@endforeach
@elseif($item->type == 'document')
@foreach($item->component->documents as $document)
<a href="{{ $document->url }}">{{ $document->name }}</a>{{ $loop->last?'':' | ' }}
@endforeach
@endif
</div>
</div>
@@ -12,7 +12,6 @@
</div>
<div class="box-body no-padding">
<div class="callout callout-info callout-help">
<h4 class="title">How it works?</h4>
<p>
@@ -40,4 +39,3 @@
</div>
</div>
@endsection
@@ -0,0 +1,45 @@
@extends('layouts.admin')
@section('content')
<div class="row">
<div class="col-xs-12">
<div class="box box-primary box-solid">
<div class="box-header with-border">
<h3 class="box-title">
<span><i class="fa fa-edit"></i></span>
<span>{{ isset($item)? 'Edit the ' . $item->heading . ' entry': 'Create a new Page Documents Section' }}</span>
</h3>
</div>
<div class="box-body no-padding">
<div class="callout callout-info callout-help">
<h4 class="title">How it works?</h4>
<p>
Create a Documents Page Component<br/>
Enter the heading<br/>
Upload your documents<br/>
Click on 'submit' to save the page documents<br/>
</p>
</div>
<form method="POST" action="/admin/pages/{{ $page->id . '/sections/document' . (isset($item)? "/{$item->id}" : '')}}" accept-charset="UTF-8">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
<input name="page_id" type="hidden" value="{{ $page->id }}">
<input name="_method" type="hidden" value="{{isset($item)? 'PUT':'POST'}}">
<fieldset>
@include('admin.pages.components.form_heading')
@include('admin.pages.components.form_content', ['height' => 120])
</fieldset>
@include('admin.partials.form_footer')
</form>
</div>
</div>
</div>
</div>
@include('admin.documents.documentable', ['documentable' => $item, 'documents' => $item->documents])
@endsection
@@ -8,11 +8,13 @@
</div>
</div>
@include('admin.partials.summernote.document', ['summernote' => '#content-content'])
@section('scripts')
@parent
<script type="text/javascript" charset="utf-8">
$(function () {
pageSummerNote('.summernote', {{ $height or '300' }});
pageSummerNote('#content-content', {{ $height or '300' }});
function pageSummerNote(selector, height)
{
@@ -24,9 +26,12 @@ function pageSummerNote(selector, height)
['style', ['bold', 'italic', 'underline', 'strikethrough', 'clear']],
['color', ['color']],
['layout', ['ul', 'ol', 'paragraph']],
['insert', ['table', /*'link', 'picture', 'video',*/ 'hr']],
['insert', ['table', 'link', 'document', /*, 'picture', 'video',*/ 'hr']],
['misc', ['fullscreen', 'codeview', 'undo']]
]
],
buttons: {
document: DocumentButton
}
});
}
})
@@ -17,6 +17,8 @@
@include('website.pages.page_media')
@elseif($content->type == 'gallery')
@include('website.pages.page_gallery')
@elseif($content->type == 'document')
@include('website.pages.page_documents')
@endif
@endforeach
</div>
@@ -0,0 +1,13 @@
{!! $content->component->content !!}
<div class="gallery">
<div class="row">
@foreach($content->component->documents as $item)
<div class="col-xs-6 col-sm-4 col-lg-3">
<a href="{{ $item->url }}" rel="group" title="{{ $item->name }}" target="_blank">
{{ $item->name }}
</a>
</div>
@endforeach
</div>
</div>
@@ -160,6 +160,7 @@ function () {
Route::resource('/{page}/sections/content', 'PageContentController');
Route::resource('/{page}/sections/media', 'PageMediaController');
Route::resource('/{page}/sections/gallery', 'PageGalleryController');
Route::resource('/{page}/sections/document', 'PageDocumentsController');
});
Route::resource('pages', 'Pages\PagesController');

0 comments on commit 7dd6bb9

Please sign in to comment.