]> BookStack Code Mirror - bookstack/commitdiff
Added created_by and updated_by to entities. Fixes #3
authorDan Brown <redacted>
Sat, 8 Aug 2015 20:28:50 +0000 (21:28 +0100)
committerDan Brown <redacted>
Sat, 8 Aug 2015 20:28:50 +0000 (21:28 +0100)
13 files changed:
app/Book.php
app/Chapter.php
app/Http/Controllers/BookController.php
app/Http/Controllers/ChapterController.php
app/Http/Controllers/ImageController.php
app/Http/Controllers/PageController.php
app/Image.php
app/Page.php
database/migrations/2015_08_08_200447_add_users_to_entities.php [new file with mode: 0644]
resources/assets/sass/_text.scss
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/pages/show.blade.php

index 35df08338d09046bf68ff52221ad560b934e1d50..abd23d64e1aa02707261cb3e0421ba3ba6cdd3ed 100644 (file)
@@ -29,6 +29,16 @@ class Book extends Model
         return $this->hasMany('Oxbow\Chapter');
     }
 
+    public function createdBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'created_by');
+    }
+
+    public function updatedBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'updated_by');
+    }
+
     public function children()
     {
         $pages = $this->pages()->where('chapter_id', '=', 0)->get();
index 77c16138580c20d9b1d719fae49a2598c7663d43..b7623798a5c67d9883238e941254601875bcc67e 100644 (file)
@@ -17,6 +17,16 @@ class Chapter extends Model
         return $this->hasMany('Oxbow\Page')->orderBy('priority', 'ASC');
     }
 
+    public function createdBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'created_by');
+    }
+
+    public function updatedBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'updated_by');
+    }
+
     public function getUrl()
     {
         return '/books/' . $this->book->slug . '/chapter/' . $this->slug;
index 269e240a4bb1084abda91ec36fd301bfb7d16ef5..7aed33d194d7df6c580e08da9ad59b18588b1f11 100644 (file)
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
 
 use Illuminate\Http\Request;
 
+use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Str;
 use Oxbow\Http\Requests;
 use Oxbow\Repos\BookRepo;
@@ -65,6 +66,8 @@ class BookController extends Controller
             $slug .= '1';
         }
         $book->slug = $slug;
+        $book->created_by = Auth::user()->id;
+        $book->updated_by = Auth::user()->id;
         $book->save();
         return redirect('/books');
     }
@@ -113,6 +116,7 @@ class BookController extends Controller
             $slug += '1';
         }
         $book->slug = $slug;
+        $book->updated_by = Auth::user()->id;
         $book->save();
         return redirect($book->getUrl());
     }
index 42c511d95d9a97458d0ae5c3266ce7d9d1ddb17e..d5ccae024250b6e4c77d4c92390f0d70d25094e0 100644 (file)
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
 
 use Illuminate\Http\Request;
 
+use Illuminate\Support\Facades\Auth;
 use Oxbow\Http\Requests;
 use Oxbow\Http\Controllers\Controller;
 use Oxbow\Repos\BookRepo;
@@ -56,6 +57,8 @@ class ChapterController extends Controller
         $chapter = $this->chapterRepo->newFromInput($request->all());
         $chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id);
         $chapter->priority = $this->bookRepo->getNewPriority($book);
+        $chapter->created_by = Auth::user()->id;
+        $chapter->updated_by = Auth::user()->id;
         $book->chapters()->save($chapter);
         return redirect($book->getUrl());
     }
@@ -102,6 +105,7 @@ class ChapterController extends Controller
         $chapter = $this->chapterRepo->getBySlug($chapterSlug, $book->id);
         $chapter->fill($request->all());
         $chapter->slug = $this->chapterRepo->findSuitableSlug($chapter->name, $book->id, $chapter->id);
+        $chapter->updated_by = Auth::user()->id;
         $chapter->save();
         return redirect($chapter->getUrl());
     }
index 2014b360487ae12e1ed2e7efc98e38b71f979839..a2271a547cd00b0a7ca6f13fe73fc1c538f2bb75 100644 (file)
@@ -5,6 +5,7 @@ namespace Oxbow\Http\Controllers;
 use Illuminate\Filesystem\Filesystem as File;
 use Illuminate\Http\Request;
 
+use Illuminate\Support\Facades\Auth;
 use Intervention\Image\Facades\Image as ImageTool;
 use Illuminate\Support\Facades\DB;
 use Oxbow\Http\Requests;
@@ -126,6 +127,8 @@ class ImageController extends Controller
         // Create and save image object
         $this->image->name = $name;
         $this->image->url = $imagePath . $name;
+        $this->image->created_by = Auth::user()->id;
+        $this->image->updated_by = Auth::user()->id;
         $this->image->save();
         return response()->json($this->image);
     }
index c84bc803f53a50e1bdbfd12cab37af2e15b7ea68..b660819282a10eada9bc6a0198ada92dd656ff15 100644 (file)
@@ -4,6 +4,7 @@ namespace Oxbow\Http\Controllers;
 
 use Illuminate\Http\Request;
 
+use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Str;
 use Oxbow\Http\Requests;
 use Oxbow\Repos\BookRepo;
@@ -82,6 +83,8 @@ class PageController extends Controller
 
         $page->book_id = $book->id;
         $page->text = strip_tags($page->html);
+        $page->created_by = Auth::user()->id;
+        $page->updated_by = Auth::user()->id;
         $page->save();
         return redirect($page->getUrl());
     }
@@ -130,6 +133,7 @@ class PageController extends Controller
         $page->fill($request->all());
         $page->slug = $this->pageRepo->findSuitableSlug($page->name, $book->id, $page->id);
         $page->text = strip_tags($page->html);
+        $page->updated_by = Auth::user()->id;
         $page->save();
         return redirect($page->getUrl());
     }
index a51c18f75a5e101ea2cb3498d69288d321f06154..9d2835dc3e3763375aec36d5d7d32017e84909d4 100644 (file)
@@ -10,4 +10,14 @@ class Image extends Model
     {
         return storage_path() . $this->url;
     }
+
+    public function createdBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'created_by');
+    }
+
+    public function updatedBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'updated_by');
+    }
 }
index cb54de4423c96265c673ecce3d5ce9d0cdd60e66..fd90b6d48f8131bca30b3adbf87ca7cd5c9f9b68 100644 (file)
@@ -32,9 +32,14 @@ class Page extends Model
         return $this->chapter()->count() > 0;
     }
 
-    public function parent()
+    public function createdBy()
     {
-        return $this->belongsTo('Oxbow\Page', 'page_id');
+        return $this->belongsTo('Oxbow\User', 'created_by');
+    }
+
+    public function updatedBy()
+    {
+        return $this->belongsTo('Oxbow\User', 'updated_by');
     }
 
     public function getUrl()
diff --git a/database/migrations/2015_08_08_200447_add_users_to_entities.php b/database/migrations/2015_08_08_200447_add_users_to_entities.php
new file mode 100644 (file)
index 0000000..7e402bd
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddUsersToEntities extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('pages', function (Blueprint $table) {
+            $table->integer('created_by');
+            $table->integer('updated_by');
+        });
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->integer('created_by');
+            $table->integer('updated_by');
+        });
+        Schema::table('images', function (Blueprint $table) {
+            $table->integer('created_by');
+            $table->integer('updated_by');
+        });
+        Schema::table('books', function (Blueprint $table) {
+            $table->integer('created_by');
+            $table->integer('updated_by');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('pages', function (Blueprint $table) {
+            $table->dropColumn('created_by');
+            $table->dropColumn('updated_by');
+        });
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->dropColumn('created_by');
+            $table->dropColumn('updated_by');
+        });
+        Schema::table('images', function (Blueprint $table) {
+            $table->dropColumn('created_by');
+            $table->dropColumn('updated_by');
+        });
+        Schema::table('books', function (Blueprint $table) {
+            $table->dropColumn('created_by');
+            $table->dropColumn('updated_by');
+        });
+    }
+}
index 3751621545e02c16e9d204321ccfb82e2bda4484..f09c571219a46627d14d4c183ec4d2fa5d273105 100644 (file)
@@ -169,6 +169,9 @@ p.neg, p .neg, span.neg, .text-neg {
 
 p.muted, p .muted, span.muted, .text-muted {
        color: lighten($text-dark, 26%);
+    &.small, .small {
+      color: lighten($text-dark, 42%);
+    }
 }
 
 p.primary, p .primary, span.primary, .text-primary {
index b4ae5cdb394dd0134f49209ebd09027eff9e978f..8c03d74ce853bfe40ad1b40b355cdb59bee762b3 100644 (file)
@@ -37,7 +37,7 @@
                         {{$childElement->getExcerpt()}}
                     </p>
 
-                    @if(is_a($childElement, 'Oxbow\Chapter'))
+                    @if(is_a($childElement, 'Oxbow\Chapter') && count($childElement->pages) > 0)
                         <div class="inset-list">
                             @foreach($childElement->pages as $page)
                                 <h4><a href="{{$page->getUrl()}}"><i class="zmdi zmdi-file-text"></i> {{$page->name}}</a></h4>
             @endforeach
         </div>
 
+        <p class="text-muted small">
+            Created {{$book->created_at->diffForHumans()}} @if($book->createdBy) by {{$book->createdBy->name}} @endif
+            <br>
+            Last Updated {{$book->updated_at->diffForHumans()}} @if($book->createdBy) by {{$book->updatedBy->name}} @endif
+        </p>
+
     </div>
 
 
index 3420c142009770bd50e402f0bb9f2d1ccb9cac1c..a72bbaf6a4f7e925d10da0ecf519bf7e55b796d9 100644 (file)
         @else
             <p class="text-muted">No pages are in this chapter</p>
         @endif
+
+        <p class="text-muted small">
+            Created {{$chapter->created_at->diffForHumans()}} @if($chapter->createdBy) by {{$chapter->createdBy->name}} @endif
+            <br>
+            Last Updated {{$chapter->updated_at->diffForHumans()}} @if($chapter->createdBy) by {{$chapter->updatedBy->name}} @endif
+        </p>
     </div>
 
 
index a57828b3bf3bee6a5f371ba1b50774a79c529cd5..2fae349526e6322396eb504558d329f31a39aed4 100644 (file)
             </div>
         @endif
         {!! $page->html !!}
+
+        <hr>
+        <p class="text-muted small">
+            Created {{$page->created_at->diffForHumans()}} @if($page->createdBy) by {{$page->createdBy->name}} @endif
+            <br>
+            Last Updated {{$page->updated_at->diffForHumans()}} @if($page->createdBy) by {{$page->updatedBy->name}} @endif
+        </p>
     </div>
 
 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.