Skip to content

Commit

Permalink
Working on document editing and saving
Browse files Browse the repository at this point in the history
  • Loading branch information
coogle committed May 8, 2014
1 parent 5828354 commit 540361c
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 4 deletions.
64 changes: 64 additions & 0 deletions app/controllers/DocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,70 @@ public function listDocuments()
return View::make('documents.list', compact('docs'));
}

public function saveDocumentEdits($documentId)
{
if(!Auth::check()) {
return Redirect::to('documents')->with('error', 'You must be logged in');
}

$content = Input::get('content');
$contentId = Input::get('content_id');

if(!empty($content)) {
return Redirect::to('documents')->with('error', "You must provide content to save");
}

if(!empty($contentId)) {
$docContent = DocContent::find($contentId);
} else {
$docContent = new DocContent();
}

if(!$docContent instanceof DocContent) {
return Redirect::to('documents')->with('error', 'Could not locate document to save');
}

$document = Doc::find($documentId);

if(!$document instanceof Doc) {
return Redirect::to('documents')->with('error', "Could not locate the document");
}

$docContent->doc_id = $documentId;
$docContent->content = $content;

try {
DB::transaction(function() use ($docContent, $content, $documentId) {
$docContent->save();
$document->indexContent($docContent);
});
} catch(\Exception $e) {
return Redirect::to('documents')->with('error', "There was an error saving the document: {$e->getMessage()}");
}

return Redirect::to('documents')->with('success_message', 'Document Saved Successfully');
}

public function editDocument($documentId)
{
if(!Auth::check()) {
return Redirect::to('/')->with('error', 'You must be logged in');
}

$doc = Doc::find($documentId);

if(is_null($doc)) {
return Response::error('404');
}

return View::make('documents.edit', array(
'page_id' => 'edit_doc',
'page_title' => "Editing {$doc->title}",
'doc' => $doc,
'contentItem' => $doc->content()->where('parent_id')->first()
));
}

public function createDocument()
{
if(!Auth::check()) {
Expand Down
3 changes: 2 additions & 1 deletion app/models/Doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public function get_file_path($format = 'markdown'){
return $path;
}

public function store_content($doc, $doc_content){
public function indexContent($doc_content)
{
$es = self::esConnect();

File::put($this->get_file_path('markdown'), $doc_content->content);
Expand Down
5 changes: 3 additions & 2 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
//Document Routes
Route::get('documents/search', 'DocumentsController@getSearch');
Route::get('documents', 'DocumentsController@listDocuments');
Route::get('documents/view/{slug}', 'DocumentsController@viewDocument');
Route::get('documents/edit/{slug}', 'DocumentsController@editDocument');
Route::get('documents/view/{documentId}', 'DocumentsController@viewDocument');
Route::get('documents/edit/{documentId}', 'DocumentsController@editDocument');
Route::put('documents/edit/{documentId}', 'DocumentsController@saveDocumentEdits');
Route::post('documents/create', 'DocumentsController@createDocument');
Route::post('documents/save', 'DocumentsController@saveDocument');
Route::delete('/documents/delete/{slug}', 'DocumentsController@deleteDocument');
Expand Down
114 changes: 114 additions & 0 deletions app/views/documents/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@extends('layouts/main')
@section('content')
<div class="row">
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/documents">Documents</a></li>
<li class="active">{{ $doc->title }}</li>
</ol>
</div>
<div class="row content" ng-controller="DashboardEditorController" ng-init="init()">
<a href="/documents/view/{{ $doc->id }}" style="float:right" class="public-link"><span class="glyphicon glyphicon-eye-open"></span> Public View</a>
<div class="col-md-12">
{{ Form::open(array('url' => '/documents/edit/' . $doc->id, 'method' => 'put', 'id'=>'doc_content_form',
'class' => 'form-horizontal', 'style' => 'style="padding: 0 50px; border: 1px dotted lightgray;"')) }}
<tabset>
<tab heading="Document Content">
<div class="row">
<input type="hidden" name="content_id" value="{{{ $contentItem->id }}}"/>
<div class="row">
<input type="hidden" name="content_id" value="{{{ $contentItem->id }}}" ng-model="doc.content.id"/>

<div class="doc_item_content">
<div id="wmd-button-bar"></div>
<textarea class="wmd-input" id="wmd-input" name="content" ng-model="doc.content.content"
>{{{ $contentItem->content }}}</textarea>
<div id="wmd-preview" class="wmd-panel wmd-preview"></div>
</div>
{{ Form::hidden('doc_id', $doc->id) }}
<div class="form_actions">
{{ Form::submit('Save Doc', array('name' => 'submit', 'id' => 'submit', 'class'=>'btn')) }}
</div>
<div id="save_message" class="alert hidden"></div>
</div>
{{ Form::token() . Form::close() }}
</div>
</tab>
<tab heading="Document Information">
<div class="row">
<h2>Document Information</h2>
<div class="col-md-7">
<form class="form-horizontal">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title: </label>
<div class="col-sm-10">
<input type="text" name="title" id="title" value="{{{ $doc->title }}}" ng-model="doc.title" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="slug" class="col-sm-2 control-label">Slug: </label>
<div class="col-sm-10">
<input type="text" name="slug" id="slug" value="{{{ $doc->slug }}}" ng-model="doc.slug" class="form-control"/>
<p class="help-block">a-z (lowercase), 0-9, and "-" only.</p>
</div>
</div>
<div class="form-group">
<label for="status" class="col-sm-2 control-label">Status: </label>
<div class="col-sm-10 select2-full-width">
<input name="status" type="hidden" ui-select2="statusOptions" ng-model="status" ng-change="statusChange(status)" data-placeholder="">
</div>
</div>
<div class="form-group">
<label for="sponsor" class="col-sm-2 control-label">Sponsor: </label>
<div class="col-sm-10 select2-full-width">
<input type="hidden" ui-select2="sponsorOptions" ng-model="sponsor" ng-change="sponsorChange(sponsor)" id="sponsor">
</div>
</div>
<div class="form-group">
<label for="categories" class="col-sm-2 control-label">Categories: </label>
<div class="col-sm-10 select2-full-width">
<input type="hidden" ui-select2="categoryOptions" ng-model="categories" ng-change="categoriesChange(categories)" />
</div>
</div>
</form>
</div>
<div class="col-md-4 col-md-offset-1">
<div class="row" ng-if="dates.length > 0">
<strong>Existing Dates:</strong>
</div>
<div class="existing-date row" ng-repeat="date in dates">
<form class="form-horizontal">
<div class="form-group no-bottom-margin">
<div class="col-sm-10">
<input class="date-label form-control" ng-model="date.label" />
</div>
<label class="control-label col-sm-1"><a class="close" ng-click="deleteDate(date)">&times;</a></label>
</div>
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" data-target="#">
<% date.date | date:'short' %>
</a>
<ul class="dropdown-menu">
<datetimepicker ng-model="date.date" datetimepicker-config="{dropdownSelector: '.dropdown-toggle' }"></datetimepicker>
</ul>
</div>
<div class="btn btn-info" ng-show="date.$changed" ng-click="saveDate(date)">Update</div>
</form>
</div>
<div class="dates row">
<form>
<div class="form-group">
<div class="new-date col-sm-10">
<input name="newdate-label" class="form-control" ng-model="newdate.label" type="text" placeholder="Date Label" />
<datetimepicker ng-model="newdate.date" on-set-time="createDate"></datetimepicker>
</div>
</div>
</form>
</div>
</div>
</div>
</tab>
</tabset>
</div>
</div>
@endsection
2 changes: 1 addition & 1 deletion app/views/documents/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@section('content')
<div class="row">
<ol class="breadcrumb">
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/">Home</a></li>
<li class="active">Documents</li>
</ol>
</div>
Expand Down

0 comments on commit 540361c

Please sign in to comment.