-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
PovilasKorop
committed
Oct 27, 2015
0 parents
commit 59c8f6e
Showing
59 changed files
with
20,071 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "laraveldaily/quickadmin", | ||
"description": "Package for creating adminpanel in Laravel 5", | ||
"authors": [ | ||
{ | ||
"name": "ModestasV", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "PovilasKorop", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"version": "0.1.0", | ||
"require": { | ||
"illuminate/html": "5.0.*@dev" | ||
}, | ||
"classmap": [ | ||
"src/Controllers", | ||
"src/Cache", | ||
"src/Models" | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Laraveldaily\\Quickadmin\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Quick Admin installation | ||
1. Install the package via `composer require quickadmin/quickadmin`. | ||
2. Add `Quickadmin\Quickadmin\QuickadminServiceProvider::class,` to your `\config\app.php` providers. | ||
3. Run `php artisan quickadmin:install` and fill the required information. | ||
4. Access QuickAdmin panel by visiting `http://yourdomain/qa`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
namespace Laraveldaily\Quickadmin\Builders; | ||
|
||
use Illuminate\Support\Str; | ||
use Laraveldaily\Quickadmin\Cache\QuickCache; | ||
|
||
class ControllerBuilder | ||
{ | ||
// Controller namespace | ||
private $namespace = 'App\Http\Controllers'; | ||
// Template | ||
private $template; | ||
// Global names | ||
private $name; | ||
private $className; | ||
private $modelName; | ||
private $requestName; | ||
private $fileName; | ||
|
||
/** | ||
* Build our controller file | ||
*/ | ||
public function build() | ||
{ | ||
$cache = new QuickCache(); | ||
$cached = $cache->get('fieldsinfo'); | ||
$this->template = __DIR__ . '/../Templates/controller'; | ||
$this->name = $cached['name']; | ||
$this->fields = $cached['fields']; | ||
$this->soft = $cached['soft_delete']; | ||
$this->names(); | ||
$template = (string) $this->loadTemplate(); | ||
$template = $this->buildParts($template); | ||
$this->publish($template); | ||
} | ||
|
||
/** | ||
* Load controller template | ||
*/ | ||
private function loadTemplate() | ||
{ | ||
return file_get_contents($this->template); | ||
} | ||
|
||
/** | ||
* Build controller template parts | ||
* | ||
* @param $template | ||
* | ||
* @return mixed | ||
*/ | ||
private function buildParts($template) | ||
{ | ||
$template = str_replace([ | ||
'$NAMESPACE$', | ||
'$MODEL$', | ||
'$REQUESTNAME$', | ||
'$CLASS$', | ||
'$COLLECTION$', | ||
'$RESOURCE$', | ||
], [ | ||
$this->namespace, | ||
$this->modelName, | ||
$this->requestName, | ||
$this->className, | ||
strtolower($this->modelName), | ||
strtolower($this->modelName), | ||
], $template); | ||
|
||
return $template; | ||
} | ||
|
||
/** | ||
* Generate names | ||
*/ | ||
private function names() | ||
{ | ||
$camelName = ucfirst(Str::camel($this->name)); | ||
$this->className = $camelName . 'Controller'; | ||
$this->modelName = $camelName; | ||
$this->requestName = $camelName . 'Request'; | ||
|
||
$fileName = $this->className . '.php'; | ||
$this->fileName = $fileName; | ||
} | ||
|
||
/** | ||
* Publish file into it's place | ||
*/ | ||
private function publish($template) | ||
{ | ||
file_put_contents(app_path('Http/Controllers/' . $this->fileName), $template); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
namespace Laraveldaily\Quickadmin\Builders; | ||
|
||
use Illuminate\Support\Str; | ||
use Laraveldaily\Quickadmin\Cache\QuickCache; | ||
|
||
class MigrationBuilder | ||
{ | ||
// Template | ||
private $template; | ||
// Names | ||
private $name; | ||
private $className; | ||
private $fileName; | ||
// Fields | ||
private $fields; | ||
// Soft delete? | ||
private $soft; | ||
|
||
/** | ||
* Build our migration file | ||
*/ | ||
public function build() | ||
{ | ||
$cache = new QuickCache(); | ||
$cached = $cache->get('fieldsinfo'); | ||
$this->template = __DIR__ . '/../Templates/migration'; | ||
$this->name = $cached['name']; | ||
$this->fields = $cached['fields']; | ||
$this->soft = $cached['soft_delete']; | ||
$this->names(); | ||
$template = (string) $this->loadTemplate(); | ||
$template = $this->buildParts($template); | ||
$this->publish($template); | ||
} | ||
|
||
/** | ||
* Load migration template | ||
*/ | ||
private function loadTemplate() | ||
{ | ||
return file_get_contents($this->template); | ||
} | ||
|
||
/** | ||
* Build migration template parts | ||
* | ||
* @param $template | ||
* | ||
* @return mixed | ||
*/ | ||
private function buildParts($template) | ||
{ | ||
$camelName = Str::camel($this->name); | ||
$tableName = strtolower($camelName); | ||
$fields = $this->buildFields(); | ||
$template = str_replace([ | ||
'$TABLENAME$', | ||
'$CLASS$', | ||
'$FIELDS$' | ||
], [ | ||
$tableName, | ||
$this->className, | ||
$fields | ||
], $template); | ||
|
||
return $template; | ||
} | ||
|
||
/** | ||
* Build migration fields | ||
* @return string | ||
*/ | ||
private function buildFields() | ||
{ | ||
$used = []; | ||
$fields = '$table->increments("id");' . "\r\n"; | ||
foreach ($this->fields as $field) { | ||
// Check if there is no duplication for radio and checkbox | ||
if (!in_array($field->title, $used)) { | ||
$fields .= '$table->string("' . $field->title . '");' . "\r\n"; | ||
$used[$field->title] = $field->title; | ||
} | ||
} | ||
if ($this->soft == 1) { | ||
$fields .= '$table->softDeletes();'; | ||
} | ||
$fields .= '$table->timestamps();'; | ||
|
||
return $fields; | ||
} | ||
|
||
/** | ||
* Generate file and class names for the migration | ||
*/ | ||
private function names() | ||
{ | ||
$fileName = date("Y_m_d_His") . '_create_'; | ||
$fileName .= str_replace(' ', '_', $this->name); | ||
$fileName = strtolower($fileName) . '_table.php'; | ||
$this->fileName = $fileName; | ||
|
||
$className = 'Create' . ' ' . $this->name . ' Table'; | ||
$className = Str::camel($className); | ||
$this->className = ucfirst($className); | ||
} | ||
|
||
/** | ||
* Publish file into it's place | ||
*/ | ||
private function publish($template) | ||
{ | ||
file_put_contents(database_path('migrations/' . $this->fileName), $template); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
namespace Laraveldaily\Quickadmin\Builders; | ||
|
||
use Illuminate\Support\Str; | ||
use Laraveldaily\Quickadmin\Cache\QuickCache; | ||
|
||
class ModelBuilder | ||
{ | ||
// Model namespace | ||
private $namespace = 'App'; | ||
// Template | ||
private $template; | ||
// Names | ||
private $name; | ||
private $className; | ||
private $fileName; | ||
// Fields | ||
private $fields; | ||
// Soft delete? | ||
private $soft; | ||
|
||
/** | ||
* Build our model file | ||
*/ | ||
public function build() | ||
{ | ||
$cache = new QuickCache(); | ||
$cached = $cache->get('fieldsinfo'); | ||
$this->template = __DIR__ . '/../Templates/model'; | ||
$this->name = $cached['name']; | ||
$this->fields = $cached['fields']; | ||
$this->soft = $cached['soft_delete']; | ||
$this->names(); | ||
$template = (string) $this->loadTemplate(); | ||
$template = $this->buildParts($template); | ||
$this->publish($template); | ||
} | ||
|
||
/** | ||
* Load model template | ||
*/ | ||
private function loadTemplate() | ||
{ | ||
return file_get_contents($this->template); | ||
} | ||
|
||
/** | ||
* Build model template parts | ||
* | ||
* @param $template | ||
* | ||
* @return mixed | ||
*/ | ||
private function buildParts($template) | ||
{ | ||
$camelName = Str::camel($this->name); | ||
// Insert table names | ||
$tableName = strtolower($camelName); | ||
$fillables = $this->buildFillables(); | ||
if ($this->soft == 1) { | ||
$soft_call = 'use Illuminate\Database\Eloquent\SoftDeletes;'; | ||
$soft_use = 'use SoftDeletes;'; | ||
$soft_date = '/** | ||
* The attributes that should be mutated to dates. | ||
* | ||
* @var array | ||
*/ | ||
protected $dates = [\'deleted_at\'];'; | ||
} else { | ||
$soft_call = ''; | ||
$soft_use = ''; | ||
$soft_date = ''; | ||
} | ||
$template = str_replace([ | ||
'$NAMESPACE$', | ||
'$SOFT_DELETE_CALL$', | ||
'$SOFT_DELETE_USE$', | ||
'$SOFT_DELETE_DATES$', | ||
'$TABLENAME$', | ||
'$CLASS$', | ||
'$FILLABLE$' | ||
], [ | ||
$this->namespace, | ||
$soft_call, | ||
$soft_use, | ||
$soft_date, | ||
$tableName, | ||
$this->className, | ||
$fillables | ||
], $template); | ||
|
||
return $template; | ||
} | ||
|
||
/** | ||
* Build model fillables | ||
* @return string | ||
*/ | ||
private function buildFillables() | ||
{ | ||
$used = []; | ||
$fillables = ''; | ||
foreach ($this->fields as $field) { | ||
// Check if there is no duplication for radio and checkbox | ||
if (!in_array($field->title, $used)) { | ||
$fillables .= "'" . $field->title . "',\r\n"; | ||
$used[$field->title] = $field->title; | ||
} | ||
} | ||
|
||
return $fillables; | ||
} | ||
|
||
/** | ||
* Generate file and class names for the model | ||
*/ | ||
private function names() | ||
{ | ||
$this->className = ucfirst(Str::camel($this->name)); | ||
|
||
$fileName = $this->className . '.php'; | ||
$this->fileName = $fileName; | ||
} | ||
|
||
/** | ||
* Publish file into it's place | ||
*/ | ||
private function publish($template) | ||
{ | ||
file_put_contents(app_path($this->fileName), $template); | ||
} | ||
|
||
} |
Oops, something went wrong.