From 2bd6a0b25862866ecd408897a197194392f5e9c0 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Tue, 24 Nov 2015 03:07:43 -0800 Subject: [PATCH] #2, #20: Added revision tracking to genres, tracks, albums, users, and playlists. Also ordered genres alphabetically in the genre editor. --- app/Album.php | 3 +- app/Genre.php | 3 +- .../Controllers/Api/Web/GenresController.php | 4 +- app/Playlist.php | 3 +- app/Track.php | 3 ++ app/User.php | 3 +- composer.json | 3 +- composer.lock | 52 ++++++++++++++++++- ...15_11_24_025733_create_revisions_table.php | 46 ++++++++++++++++ public/templates/partials/credits-dialog.html | 1 + .../app/controllers/admin-genres.coffee | 4 +- 11 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 database/migrations/2015_11_24_025733_create_revisions_table.php diff --git a/app/Album.php b/app/Album.php index f72ee9ca..027f8188 100644 --- a/app/Album.php +++ b/app/Album.php @@ -30,10 +30,11 @@ use Cache; use Poniverse\Ponyfm\Traits\TrackCollection; use URL; use Poniverse\Ponyfm\Traits\SlugTrait; +use Venturecraft\Revisionable\RevisionableTrait; class Album extends Model { - use SoftDeletes, SlugTrait, DispatchesJobs, TrackCollection; + use SoftDeletes, SlugTrait, DispatchesJobs, TrackCollection, RevisionableTrait; protected $dates = ['deleted_at']; diff --git a/app/Genre.php b/app/Genre.php index dfffb077..2d6f7cbf 100644 --- a/app/Genre.php +++ b/app/Genre.php @@ -24,6 +24,7 @@ use DB; use Illuminate\Database\Eloquent\Relations\Relation; use Poniverse\Ponyfm\Traits\SlugTrait; use Illuminate\Database\Eloquent\Model; +use Venturecraft\Revisionable\RevisionableTrait; class Genre extends Model { @@ -34,7 +35,7 @@ class Genre extends Model public $timestamps = false; - use SlugTrait; + use SlugTrait, RevisionableTrait; public function tracks(){ return $this->hasMany(Track::class, 'genre_id'); diff --git a/app/Http/Controllers/Api/Web/GenresController.php b/app/Http/Controllers/Api/Web/GenresController.php index 23622b1d..6e09d41c 100644 --- a/app/Http/Controllers/Api/Web/GenresController.php +++ b/app/Http/Controllers/Api/Web/GenresController.php @@ -35,7 +35,9 @@ class GenresController extends ApiControllerBase $genres = Genre::with(['trackCountRelation' => function($query) { $query->withTrashed(); - }])->get(); + }]) + ->orderBy('name', 'asc') + ->get(); return Response::json([ 'genres' => $genres->toArray() diff --git a/app/Playlist.php b/app/Playlist.php index b30cc7b2..e223469f 100644 --- a/app/Playlist.php +++ b/app/Playlist.php @@ -29,10 +29,11 @@ use Cache; use Poniverse\Ponyfm\Traits\TrackCollection; use URL; use Poniverse\Ponyfm\Traits\SlugTrait; +use Venturecraft\Revisionable\RevisionableTrait; class Playlist extends Model { - use SoftDeletes, SlugTrait, DispatchesJobs, TrackCollection; + use SoftDeletes, SlugTrait, DispatchesJobs, TrackCollection, RevisionableTrait; protected $table = 'playlists'; diff --git a/app/Track.php b/app/Track.php index 09604f20..34727b8b 100644 --- a/app/Track.php +++ b/app/Track.php @@ -35,6 +35,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Str; use Log; use URL; +use Venturecraft\Revisionable\RevisionableTrait; class Track extends Model { @@ -46,6 +47,8 @@ class Track extends Model SlugTrait::setTitleAttribute as setTitleAttributeSlug; } + use RevisionableTrait; + public static $Formats = [ 'FLAC' => [ 'index' => 0, diff --git a/app/User.php b/app/User.php index b517138c..6062154e 100644 --- a/app/User.php +++ b/app/User.php @@ -31,10 +31,11 @@ use Illuminate\Foundation\Auth\Access\Authorizable; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\URL; use Illuminate\Support\Str; +use Venturecraft\Revisionable\RevisionableTrait; class User extends Model implements AuthenticatableContract, CanResetPasswordContract, \Illuminate\Contracts\Auth\Access\Authorizable { - use Authenticatable, CanResetPassword, Authorizable; + use Authenticatable, CanResetPassword, Authorizable, RevisionableTrait; protected $table = 'users'; protected $hidden1 = ['password_hash', 'password_salt', 'bio']; diff --git a/composer.json b/composer.json index db280b4b..69b2eb09 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "intouch/laravel-newrelic": "*", "barryvdh/laravel-ide-helper": "^2.1", "guzzlehttp/guzzle": "~6.0", - "doctrine/dbal": "^2.5" + "doctrine/dbal": "^2.5", + "venturecraft/revisionable": "^1.23" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index e63169c3..a45118e3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "de5e29b9defac1327482713da4fc062d", - "content-hash": "e9ed56cee43eb3096269b8fc9db1bf9b", + "hash": "5f66a059010df46b5b6e50c3e4056e17", + "content-hash": "07e7a5fff5a8914a7ced3d14959d194f", "packages": [ { "name": "barryvdh/laravel-ide-helper", @@ -2636,6 +2636,54 @@ ], "time": "2015-07-28 15:18:12" }, + { + "name": "venturecraft/revisionable", + "version": "1.23.0", + "source": { + "type": "git", + "url": "https://github.com/VentureCraft/revisionable.git", + "reference": "75af7add8d857ac0dfcb41398f1958c7ac51d72c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/VentureCraft/revisionable/zipball/75af7add8d857ac0dfcb41398f1958c7ac51d72c", + "reference": "75af7add8d857ac0dfcb41398f1958c7ac51d72c", + "shasum": "" + }, + "require": { + "illuminate/support": "~4.0|~5.0|~5.1", + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/migrations" + ], + "psr-0": { + "Venturecraft\\Revisionable": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Duell", + "email": "me@chrisduell.com" + } + ], + "description": "Keep a revision history for your models without thinking, created as a package for use with Laravel", + "homepage": "http://github.com/venturecraft/revisionable", + "keywords": [ + "ardent", + "history", + "laravel", + "model", + "revision" + ], + "time": "2015-11-09 22:01:31" + }, { "name": "vlucas/phpdotenv", "version": "v1.1.1", diff --git a/database/migrations/2015_11_24_025733_create_revisions_table.php b/database/migrations/2015_11_24_025733_create_revisions_table.php new file mode 100644 index 00000000..59711e98 --- /dev/null +++ b/database/migrations/2015_11_24_025733_create_revisions_table.php @@ -0,0 +1,46 @@ +increments('id'); + $table->string('revisionable_type'); + $table->integer('revisionable_id')->unsigned(); + $table->integer('user_id')->unsigned()->nullable(); + $table->string('key'); + $table->text('old_value')->nullable(); + $table->text('new_value')->nullable(); + $table->timestamps(); + + $table->index(array('revisionable_id', 'revisionable_type')); + + $table->foreign('user_id')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('revisions'); + } +} diff --git a/public/templates/partials/credits-dialog.html b/public/templates/partials/credits-dialog.html index 80dc9472..43a52c38 100644 --- a/public/templates/partials/credits-dialog.html +++ b/public/templates/partials/credits-dialog.html @@ -43,6 +43,7 @@
  • Angularytics - for making Google Analytics useful in a single-page app
  • UI-Router - for making non-trivial Angular.js routes possible
  • UI-Bootstrap - for making Bootstrap and Angular.js get along
  • +
  • Revisionable - for making audit logs easy