Skip to content

Commit 143f078

Browse files
committed
New version of QuickAdmin
1 parent 8d7408c commit 143f078

37 files changed

+5956
-1856
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"email": "[email protected]"
1212
}
1313
],
14-
"version": "0.2.11",
14+
"version": "0.4.0",
1515
"require": {
1616
"illuminate/html": "5.0.*@dev",
1717
"intervention/image": "^2.3",

license.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2015 LaravelDaily
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## License
2+
This package license information is stored in license.txt file.
3+
4+
## Requirements
5+
* Laravel `^5.1.11` - Because of ACL authorization engine: http://laravel.com/docs/5.1/authorization#introduction
6+
17
## Quick Admin installation
28
1. Install the package via `composer require laraveldaily/quickadmin`.
39
2. Add `Laraveldaily\Quickadmin\QuickadminServiceProvider::class,` to your `\config\app.php` providers.

src/Builders/ControllerBuilder.php

Lines changed: 84 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use Illuminate\Support\Str;
55
use Laraveldaily\Quickadmin\Cache\QuickCache;
6-
use Laraveldaily\Quickadmin\Models\Crud;
6+
use Laraveldaily\Quickadmin\Models\Menu;
77

88
class ControllerBuilder
99
{
@@ -21,6 +21,7 @@ class ControllerBuilder
2121
private $fields;
2222
private $relationships;
2323
private $files;
24+
private $enum;
2425

2526
/**
2627
* Build our controller file
@@ -29,11 +30,22 @@ public function build()
2930
{
3031
$cache = new QuickCache();
3132
$cached = $cache->get('fieldsinfo');
32-
$this->template = __DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Templates'. DIRECTORY_SEPARATOR .'controller';
33+
$this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'controller';
3334
$this->name = $cached['name'];
3435
$this->fields = $cached['fields'];
3536
$this->relationships = $cached['relationships'];
3637
$this->files = $cached['files'];
38+
$this->enum = $cached['enum'];
39+
$this->names();
40+
$template = (string) $this->loadTemplate();
41+
$template = $this->buildParts($template);
42+
$this->publish($template);
43+
}
44+
45+
public function buildCustom($name)
46+
{
47+
$this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'customController';
48+
$this->name = $name;
3749
$this->names();
3850
$template = (string) $this->loadTemplate();
3951
$template = $this->buildParts($template);
@@ -71,7 +83,8 @@ private function buildParts($template)
7183
'$RELATIONSHIP_COMPACT_EDIT$',
7284
'$RELATIONSHIP_NAMESPACES$',
7385
'$FILETRAIT$',
74-
'$FILESAVING$'
86+
'$FILESAVING$',
87+
'$ENUM$',
7588
], [
7689
$this->namespace,
7790
$this->modelName,
@@ -86,7 +99,8 @@ private function buildParts($template)
8699
$this->compactEditBuilder(),
87100
$this->relationshipsNamespaces(),
88101
$this->files > 0 ? 'use App\Http\Controllers\Traits\FileUploadTrait;' : '',
89-
$this->files > 0 ? '$this->saveFiles($request);' : ''
102+
$this->files > 0 ? '$this->saveFiles($request);' : '',
103+
$this->enum > 0 ? $this->enum() : '',
90104
], $template);
91105

92106
return $template;
@@ -122,13 +136,13 @@ public function relationshipsNamespaces()
122136
if ($this->relationships == 0) {
123137
return '';
124138
} else {
125-
$cruds = Crud::all()->keyBy('id');
139+
$menus = Menu::all()->keyBy('id');
126140
$relationships = '';
127141
$first = true;
128142
foreach ($this->fields as $field) {
129143
if ($field->type == 'relationship') {
130-
$crud = $cruds[$field->relationship_id];
131-
$relationships .= 'use App\\' . ucfirst(Str::camel($crud->name)) . ";\r\n";
144+
$menu = $menus[$field->relationship_id];
145+
$relationships .= 'use App\\' . ucfirst(Str::camel($menu->name)) . ";\r\n";
132146
}
133147
}
134148

@@ -145,7 +159,7 @@ public function relationshipsBuilder()
145159
if ($this->relationships == 0) {
146160
return '';
147161
} else {
148-
$cruds = Crud::all()->keyBy('id');
162+
$menus = Menu::all()->keyBy('id');
149163
$relationships = '';
150164
$first = true;
151165
foreach ($this->fields as $field) {
@@ -154,11 +168,11 @@ public function relationshipsBuilder()
154168
if (!$first) {
155169
$relationships .= ' ';
156170
}
157-
$crud = $cruds[$field->relationship_id];
171+
$menu = $menus[$field->relationship_id];
158172
$relationships .= '$'
159173
. $field->relationship_name
160174
. ' = '
161-
. ucfirst(Str::camel($crud->name))
175+
. ucfirst(Str::camel($menu->name))
162176
. '::lists("'
163177
. $field->relationship_field
164178
. '", "id");'
@@ -176,21 +190,40 @@ public function relationshipsBuilder()
176190
*/
177191
public function compactBuilder()
178192
{
179-
if ($this->relationships == 0) {
193+
if ($this->relationships == 0 && $this->enum == 0) {
180194
return '';
181195
} else {
182196
$compact = ', compact($RELATIONS$)';
183-
$first = true;
184-
foreach ($this->fields as $field) {
185-
if ($field->type == 'relationship') {
186-
$toReplace = '';
187-
if ($first != true) {
188-
$toReplace .= ', ';
189-
} else {
190-
$first = false;
197+
if ($this->relationships > 0) {
198+
$first = true;
199+
foreach ($this->fields as $field) {
200+
if ($field->type == 'relationship') {
201+
$toReplace = '';
202+
if ($first != true) {
203+
$toReplace .= ', ';
204+
} else {
205+
$first = false;
206+
}
207+
$toReplace .= '"' . $field->relationship_name . '"$RELATIONS$';
208+
$compact = str_replace('$RELATIONS$', $toReplace, $compact);
209+
}
210+
}
211+
}
212+
if ($this->enum > 0) {
213+
if (!isset($first)) {
214+
$first = true;
215+
}
216+
foreach ($this->fields as $field) {
217+
if ($field->type == 'enum') {
218+
$toReplace = '';
219+
if ($first != true) {
220+
$toReplace .= ', ';
221+
} else {
222+
$first = false;
223+
}
224+
$toReplace .= '"' . $field->title . '"$RELATIONS$';
225+
$compact = str_replace('$RELATIONS$', $toReplace, $compact);
191226
}
192-
$toReplace .= '"' . $field->relationship_name . '"$RELATIONS$';
193-
$compact = str_replace('$RELATIONS$', $toReplace, $compact);
194227
}
195228
}
196229
$compact = str_replace('$RELATIONS$', '', $compact);
@@ -205,13 +238,22 @@ public function compactBuilder()
205238
*/
206239
public function compactEditBuilder()
207240
{
208-
if ($this->relationships == 0) {
241+
if ($this->relationships == 0 && $this->enum == 0) {
209242
return '';
210243
} else {
211244
$compact = '';
212-
foreach ($this->fields as $field) {
213-
if ($field->type == 'relationship') {
214-
$compact .= ', "' . $field->relationship_name . '"';
245+
if ($this->relationships > 0) {
246+
foreach ($this->fields as $field) {
247+
if ($field->type == 'relationship') {
248+
$compact .= ', "' . $field->relationship_name . '"';
249+
}
250+
}
251+
}
252+
if ($this->enum > 0) {
253+
foreach ($this->fields as $field) {
254+
if ($field->type == 'enum') {
255+
$compact .= ', "' . $field->title . '"';
256+
}
215257
}
216258
}
217259

@@ -239,11 +281,24 @@ private function names()
239281
*/
240282
private function publish($template)
241283
{
242-
if (!file_exists(app_path('Http'. DIRECTORY_SEPARATOR .'Controllers'. DIRECTORY_SEPARATOR .'Admin'))) {
243-
mkdir(app_path('Http'. DIRECTORY_SEPARATOR .'Controllers'. DIRECTORY_SEPARATOR .'Admin'));
244-
chmod(app_path('Http'. DIRECTORY_SEPARATOR .'Controllers'. DIRECTORY_SEPARATOR .'Admin'), 0777);
284+
if (!file_exists(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'))) {
285+
mkdir(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'));
286+
chmod(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin'), 0777);
245287
}
246-
file_put_contents(app_path('Http'. DIRECTORY_SEPARATOR .'Controllers'. DIRECTORY_SEPARATOR .'Admin'. DIRECTORY_SEPARATOR . $this->fileName), $template);
288+
file_put_contents(app_path('Http' . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . 'Admin' . DIRECTORY_SEPARATOR . $this->fileName),
289+
$template);
290+
}
291+
292+
public function enum()
293+
{
294+
$return = "\r\n";
295+
foreach ($this->fields as $field) {
296+
if ($field->type == 'enum') {
297+
$return .= ' $' . $field->title . ' = ' . $this->modelName . '::$' . $field->title . ";\r\n";
298+
}
299+
}
300+
301+
return $return;
247302
}
248303

249304
}

src/Builders/MigrationBuilder.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function build()
2525
{
2626
$cache = new QuickCache();
2727
$cached = $cache->get('fieldsinfo');
28-
$this->template = __DIR__ . DIRECTORY_SEPARATOR .'..'. DIRECTORY_SEPARATOR .'Templates'. DIRECTORY_SEPARATOR .'migration';
28+
$this->template = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'migration';
2929
$this->name = $cached['name'];
3030
$this->fields = $cached['fields'];
3131
$this->soft = $cached['soft_delete'];
@@ -90,6 +90,22 @@ private function buildFields()
9090
$field->relationship_name
9191
], $migrationTypes[$field->type]);
9292
$fields .= ' '; // Add formatting space to the migration
93+
if ($field->type == 'enum') {
94+
$values = '';
95+
$field->enum = explode(',', $field->enum);
96+
foreach ($field->enum as $val) {
97+
// Remove first whitespace
98+
if (strpos(substr($val, 0, 1), ' ') !== false) {
99+
$len = strlen($val);
100+
$val = substr($val, 1, $len);
101+
}
102+
$values .= '"' . $val . '"';
103+
if ($val != last($field->enum)) {
104+
$values .= ', ';
105+
}
106+
}
107+
$migrationLine = str_replace('$VALUES$', $values, $migrationLine);
108+
}
93109
$fields .= '$table->' . $migrationLine . ";\r\n";
94110
if ($field->type == 'relationship') {
95111
$used[$field->relationship_name] = $field->relationship_name;

src/Builders/ModelBuilder.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use Illuminate\Support\Str;
55
use Laraveldaily\Quickadmin\Cache\QuickCache;
6-
use Laraveldaily\Quickadmin\Models\Crud;
6+
use Laraveldaily\Quickadmin\Models\Menu;
77

88
class ModelBuilder
99
{
@@ -25,6 +25,8 @@ class ModelBuilder
2525
private $date;
2626
// Have datetimepickers?
2727
private $datetime;
28+
// Have enum?
29+
private $enum;
2830

2931
/**
3032
* Build our model file
@@ -40,6 +42,7 @@ public function build()
4042
$this->password = $cached['password'];
4143
$this->date = $cached['date'];
4244
$this->datetime = $cached['datetime'];
45+
$this->enum = $cached['enum'];
4346
$this->names();
4447
$template = (string) $this->loadTemplate();
4548
$template = $this->buildParts($template);
@@ -94,6 +97,7 @@ private function buildParts($template)
9497
'$DATEPICKERS_CALL$',
9598
'$DATEPICKERS$',
9699
'$DATETIMEPICKERS$',
100+
'$ENUMS$',
97101
], [
98102
$this->namespace,
99103
$soft_call,
@@ -108,6 +112,7 @@ private function buildParts($template)
108112
$this->date > 0 || $this->datetime > 0 ? "use Carbon\Carbon; \n\r" : '',
109113
$this->date > 0 ? $this->datepickers() : '',
110114
$this->datetime > 0 ? $this->datetimepickers() : '',
115+
$this->enum > 0 ? $this->enum() : '',
111116
], $template);
112117

113118
return $template;
@@ -161,12 +166,12 @@ private function buildFillables()
161166
*/
162167
private function buildRelationships()
163168
{
164-
$cruds = Crud::all()->keyBy('id');
169+
$menus = Menu::all()->keyBy('id');
165170
$used = [];
166171
$relationships = '';
167172
foreach ($this->fields as $key => $field) {
168173
if (!in_array($field->title, $used) && $field->type == 'relationship') {
169-
$crud = $cruds[$field->relationship_id];
174+
$menu = $menus[$field->relationship_id];
170175
$relLine = '
171176
public function $RELATIONSHIP$()
172177
{
@@ -176,8 +181,8 @@ public function $RELATIONSHIP$()
176181
'$RELATIONSHIP$',
177182
'$RELATIONSHIP_MODEL$'
178183
], [
179-
strtolower($crud->name),
180-
ucfirst(Str::camel($crud->name))
184+
strtolower($menu->name),
185+
ucfirst(Str::camel($menu->name))
181186
], $relLine);
182187
$relationships .= $relLine;
183188
}
@@ -286,4 +291,33 @@ public function get' . $camel . 'Attribute($input)
286291

287292
return $dates;
288293
}
294+
295+
/**
296+
* Generate enum model
297+
* @return string
298+
*/
299+
public function enum()
300+
{
301+
$return = "\r\n";
302+
foreach ($this->fields as $field) {
303+
if ($field->type == 'enum') {
304+
$values = '';
305+
$field->enum = explode(',', $field->enum);
306+
foreach ($field->enum as $val) {
307+
// Remove first whitespace
308+
if (strpos(substr($val, 0, 1), ' ') !== false) {
309+
$len = strlen($val);
310+
$val = substr($val, 1, $len);
311+
}
312+
$values .= '"' . $val . '" => "' . $val . '"';
313+
if ($val != last($field->enum)) {
314+
$values .= ', ';
315+
}
316+
}
317+
$return .= ' public static $' . $field->title . ' = [' . $values . '];' . "\r\n";
318+
}
319+
}
320+
321+
return $return;
322+
}
289323
}

0 commit comments

Comments
 (0)