Skip to content

Commit 00385ac

Browse files
committed
CRUD Parent added
Users log added
1 parent 726d901 commit 00385ac

File tree

15 files changed

+283
-15
lines changed

15 files changed

+283
-15
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"email": "[email protected]"
1212
}
1313
],
14-
"version": "0.3.0",
14+
"version": "0.2.11",
1515
"require": {
1616
"illuminate/html": "5.0.*@dev",
17-
"intervention/image": "^2.3"
17+
"intervention/image": "^2.3",
18+
"yajra/laravel-datatables-oracle": "~5.0"
1819
},
1920
"classmap": [
2021
"src/Controllers",

src/Commands/QuickAdminInstall.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function copyInitial()
6060
database_path('migrations'. DIRECTORY_SEPARATOR .'2015_10_10_000000_update_users_table.php'));
6161
copy(__DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Migrations'. DIRECTORY_SEPARATOR .'2015_10_10_000000_create_cruds_table',
6262
database_path('migrations'. DIRECTORY_SEPARATOR .'2015_10_10_000000_create_cruds_table.php'));
63+
copy(__DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Migrations'. DIRECTORY_SEPARATOR .'2015_12_11_000000_create_users_logs_table',
64+
database_path('migrations'. DIRECTORY_SEPARATOR .'2015_12_11_000000_create_users_logs_table.php'));
6365
copy(__DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Models'. DIRECTORY_SEPARATOR .'publish'. DIRECTORY_SEPARATOR .'User', app_path('User.php'));
6466
$this->info('Migrations were transferred successfully');
6567
}

src/Controllers/QuickadminCrudController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function create()
2828
$fieldValidation = FieldsDescriber::validation();
2929
$defaultValuesCbox = FieldsDescriber::default_cbox();
3030
$crudsSelect = Crud::lists('title', 'id');
31+
$parentsSelect = Crud::where('parent_id', null)->lists('title', 'id')->prepend('-- no parent --', 'null');
3132
// Get columns for relationship
3233
$models = [];
3334
foreach (Crud::all() as $crud) {
@@ -41,7 +42,7 @@ public function create()
4142
}
4243

4344
return view("qa::cruds.create",
44-
compact('fieldTypes', 'fieldValidation', 'defaultValuesCbox', 'crudsSelect', 'models'));
45+
compact('fieldTypes', 'fieldValidation', 'defaultValuesCbox', 'crudsSelect', 'models', 'parentsSelect'));
4546
}
4647

4748
/**
@@ -119,7 +120,7 @@ public function insert(Request $request)
119120
'icon' => $request->icon != '' ? $request->icon : 'fa-database',
120121
'name' => $request->name,
121122
'title' => $request->title,
122-
'parent_id' => null,
123+
'parent_id' => $request->parent_id != 0 ? $request->parent_id : null,
123124
'roles' => '1'
124125
]);
125126
// Create migrations

src/Events/UserLoginEvents.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Laraveldaily\Quickadmin\Events;
4+
5+
use Illuminate\Queue\SerializesModels;
6+
use Illuminate\Support\Facades\Auth;
7+
use Illuminate\Support\Facades\Event;
8+
use Laraveldaily\Quickadmin\Models\UsersLogs;
9+
10+
class UserLoginEvents extends Event
11+
{
12+
use SerializesModels;
13+
14+
/**
15+
* Create a new event instance.
16+
*
17+
* @return void
18+
*/
19+
public function __construct()
20+
{
21+
Event::listen('auth.login', function ($event) {
22+
UsersLogs::create([
23+
'user_id' => Auth::user()->id,
24+
'action' => 'login',
25+
]);
26+
});
27+
Event::listen('auth.logout', function ($event) {
28+
UsersLogs::create([
29+
'user_id' => Auth::user()->id,
30+
'action' => 'logout',
31+
]);
32+
});
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class CreateUsersLogsTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('users_logs', function (Blueprint $table) {
16+
$table->increments('id');
17+
$table->integer('user_id');
18+
$table->string('action');
19+
$table->string('action_model')->nullable();
20+
$table->integer('action_id')->nullable();
21+
$table->timestamps();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::drop('users_logs');
33+
}
34+
}

src/Models/Crud.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,13 @@ public function setNameAttribute($input)
2525
{
2626
$this->attributes['name'] = ucfirst(Str::camel($input));
2727
}
28+
29+
/**
30+
* Get children links
31+
* @return mixed
32+
*/
33+
public function children()
34+
{
35+
return $this->hasMany('Laraveldaily\Quickadmin\Models\Crud', 'parent_id', 'id')->orderBy('position');
36+
}
2837
}

src/Models/UsersLogs.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace Laraveldaily\Quickadmin\Models;
3+
4+
use Illuminate\Database\Eloquent\Model;
5+
6+
class UsersLogs extends Model
7+
{
8+
protected $fillable = [
9+
'user_id',
10+
'action',
11+
'action_model',
12+
'action_id',
13+
];
14+
15+
public function users()
16+
{
17+
return $this->hasOne('App\User', 'id', 'user_id');
18+
}
19+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Laraveldaily\Quickadmin\Observers;
4+
5+
use Auth;
6+
use Laraveldaily\Quickadmin\Models\UsersLogs;
7+
8+
class UserActionsObserver
9+
{
10+
11+
public function saved($model)
12+
{
13+
if ($model->wasRecentlyCreated == true) {
14+
// Data was just created
15+
$action = 'created';
16+
} else {
17+
// Data was updated
18+
$action = 'updated';
19+
}
20+
UsersLogs::create([
21+
'user_id' => Auth::user()->id,
22+
'action' => $action,
23+
'action_model' => $model->getTable(),
24+
'action_id' => $model->id
25+
]);
26+
}
27+
28+
public function deleting($model)
29+
{
30+
UsersLogs::create([
31+
'user_id' => Auth::user()->id,
32+
'action' => 'deleted',
33+
'action_model' => $model->getTable(),
34+
'action_id' => $model->id
35+
]);
36+
}
37+
}

src/Public/quickadmin/js/main.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
$(document).ready(function () {
2+
3+
var activeSub = $(document).find('.active-sub');
4+
if (activeSub.length > 0) {
5+
activeSub.parent().show();
6+
activeSub.parent().parent().find('.arrow').addClass('open');
7+
activeSub.parent().parent().addClass('open');
8+
}
9+
210
$('.datatable').dataTable({
11+
retrieve: true,
312
"iDisplayLength": 100,
413
"aaSorting": [],
514
"aoColumnDefs": [
615
{'bSortable': false, 'aTargets': [0]}
7-
],
16+
]
817
});
18+
919
$('.ckeditor').each(function () {
1020
CKEDITOR.replace($(this));
1121
})
22+
1223
$('.mass').click(function () {
1324
if ($(this).is(":checked")) {
1425
$('.single').each(function () {
@@ -24,4 +35,64 @@ $(document).ready(function () {
2435
});
2536
}
2637
});
38+
39+
$('.page-sidebar').on('click', 'li > a', function (e) {
40+
41+
if ($('body').hasClass('page-sidebar-closed') && $(this).parent('li').parent('.page-sidebar-menu').size() === 1) {
42+
return;
43+
}
44+
45+
var hasSubMenu = $(this).next().hasClass('sub-menu');
46+
47+
if ($(this).next().hasClass('sub-menu always-open')) {
48+
return;
49+
}
50+
51+
var parent = $(this).parent().parent();
52+
var the = $(this);
53+
var menu = $('.page-sidebar-menu');
54+
var sub = $(this).next();
55+
56+
var autoScroll = menu.data("auto-scroll");
57+
var slideSpeed = parseInt(menu.data("slide-speed"));
58+
var keepExpand = menu.data("keep-expanded");
59+
60+
if (keepExpand !== true) {
61+
parent.children('li.open').children('a').children('.arrow').removeClass('open');
62+
parent.children('li.open').children('.sub-menu:not(.always-open)').slideUp(slideSpeed);
63+
parent.children('li.open').removeClass('open');
64+
}
65+
66+
var slideOffeset = -200;
67+
68+
if (sub.is(":visible")) {
69+
$('.arrow', $(this)).removeClass("open");
70+
$(this).parent().removeClass("open");
71+
sub.slideUp(slideSpeed, function () {
72+
if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) {
73+
if ($('body').hasClass('page-sidebar-fixed')) {
74+
menu.slimScroll({
75+
'scrollTo': (the.position()).top
76+
});
77+
}
78+
}
79+
});
80+
} else if (hasSubMenu) {
81+
$('.arrow', $(this)).addClass("open");
82+
$(this).parent().addClass("open");
83+
sub.slideDown(slideSpeed, function () {
84+
if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) {
85+
if ($('body').hasClass('page-sidebar-fixed')) {
86+
menu.slimScroll({
87+
'scrollTo': (the.position()).top
88+
});
89+
}
90+
}
91+
});
92+
}
93+
if (hasSubMenu == true) {
94+
e.preventDefault();
95+
}
96+
});
97+
2798
});

src/QuickadminServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,25 @@ public function register()
5454
{
5555
// Register main classes
5656
$this->app->make('Laraveldaily\Quickadmin\Controllers\QuickadminController');
57+
$this->app->make('Laraveldaily\Quickadmin\Controllers\UserActionsController');
5758
$this->app->make('Laraveldaily\Quickadmin\Controllers\QuickadminCrudController');
5859
$this->app->make('Laraveldaily\Quickadmin\Cache\QuickCache');
5960
$this->app->make('Laraveldaily\Quickadmin\Builders\MigrationBuilder');
6061
$this->app->make('Laraveldaily\Quickadmin\Builders\ModelBuilder');
6162
$this->app->make('Laraveldaily\Quickadmin\Builders\RequestBuilder');
6263
$this->app->make('Laraveldaily\Quickadmin\Builders\ControllerBuilder');
6364
$this->app->make('Laraveldaily\Quickadmin\Builders\ViewsBuilder');
65+
$this->app->make('Laraveldaily\Quickadmin\Events\UserLoginEvents');
6466
// Register dependency packages
6567
$this->app->register('Illuminate\Html\HtmlServiceProvider');
6668
$this->app->register('Intervention\Image\ImageServiceProvider');
69+
$this->app->register('yajra\Datatables\DatatablesServiceProvider');
6770
// Register dependancy aliases
6871
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
6972
$loader->alias('HTML', 'Illuminate\Html\HtmlFacade');
7073
$loader->alias('Form', 'Illuminate\Html\FormFacade');
7174
$loader->alias('Image', 'Intervention\Image\Facades\Image');
75+
$loader->alias('Datatables', 'yajra\Datatables\Datatables');
7276
}
7377

7478
}

0 commit comments

Comments
 (0)