-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nicoaudy/generator-panel
Generator panel
- Loading branch information
Showing
4 changed files
with
301 additions
and
3 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,250 @@ | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css"> | ||
| ||
<div id="manthra"> | ||
<form action="#" @submit.prevent="handleSubmit"> | ||
<div class="container"> | ||
<div class="card"> | ||
<header class="card-header"> | ||
<p class="card-header-title"> | ||
@{{ welcome }} | ||
</p> | ||
<a href="#" class="card-header-icon" aria-label="more options"> | ||
<span class="icon"> | ||
<i class="fas fa-angle-down" aria-hidden="true"></i> | ||
</span> | ||
</a> | ||
</header> | ||
|
||
<div class="card-content"> | ||
<div class="content"> | ||
<div class="columns"> | ||
<div class="column"></div> | ||
<div class="column is-four-fifths"> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">Model Name<sup | ||
style="color:red">*</sup></label> | ||
<div class="control"> | ||
<input class="input" type="text" v-model="model" | ||
placeholder="eg: Post" required> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">Model Namespace</label> | ||
<div class="control"> | ||
<input class="input" type="text" v-model="model_namespace" | ||
placeholder="eg: Models"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns"> | ||
<div class="column"> | ||
<label class="label">Fields<sup style="color:red">*</sup></label> | ||
</div> | ||
<div class="column"> | ||
<div class="field is-right" style="float: right"> | ||
<a class="button is-link" @click="addMoreFields">Add Field</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns" v-for="(field, i) in fields"> | ||
<div class="column"> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="control"> | ||
<input class="input" type="text" v-model="field.name" | ||
placeholder="Field Name" required> | ||
</div> | ||
</div> | ||
<div class="column"> | ||
<div class="control"> | ||
<div class="select is-primary"> | ||
<select v-model="field.type"> | ||
<option :value="type" v-for="type in types"> | ||
@{{ type }} | ||
</option> | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="column"> | ||
<div class="control"> | ||
<a class="button is-danger" | ||
@click="removeFields(i)">X</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">Controller Namespace</label> | ||
<div class="control"> | ||
<input class="input" type="text" | ||
v-model="controller_namespace" placeholder="eg: Admin"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">View Path</label> | ||
<div class="control"> | ||
<input class="input" type="text" v-model="view_path" | ||
placeholder="eg: admin"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<label class="label">Route Group</label> | ||
<div class="control"> | ||
<input class="input" type="text" v-model="route_group" | ||
placeholder="eg: admin"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="columns"> | ||
<div class="column"> | ||
<div class="field"> | ||
<button class="button is-primary" type="submit" | ||
:class="loading ? 'is-loading' : null">Generate</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="column"></div> | ||
</div> | ||
</div> | ||
</div> | ||
<footer class="card-footer"> | ||
<div class="card-footer-item"> | ||
<h3> | ||
Made with ❤️ | ||
<a href="https://github.com/nicoaudy" target="_blank">🔥 NicoAudy</a> | ||
</h3> | ||
</div> | ||
</footer> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script> | ||
<script src="https://unpkg.com/vue-toasted"></script> | ||
<script> | ||
Vue.config.devtools = true | ||
Vue.use(Toasted) | ||
new Vue({ | ||
el: '#manthra', | ||
mounted() { | ||
this.$toasted.show("🧛Just write what you want, and let manthra do the rest 🔥🤙", { | ||
theme: "outline", | ||
position: "top-right", | ||
duration : 3000 | ||
}); | ||
}, | ||
data: { | ||
welcome: 'Laravel Manthra', | ||
loading: false, | ||
types: [ | ||
'string', | ||
'char', | ||
'varchar', | ||
'date', | ||
'datetime', | ||
'time', | ||
'timestamp', | ||
'text', | ||
'mediumtext', | ||
'longtext', | ||
'json', | ||
'jsonb', | ||
'binary', | ||
'integer', | ||
'bigint', | ||
'tinyint', | ||
'smallint', | ||
'boolean', | ||
'decimal', | ||
'double', | ||
'float' | ||
], | ||
model: '', | ||
fields: [{name: '', type: 'string'}], | ||
controller_namespace: '', | ||
model_namespace: '', | ||
view_path: '', | ||
route_group: '', | ||
}, | ||
methods: { | ||
addMoreFields() { | ||
this.fields.push({ | ||
name: '', | ||
type: 'string' | ||
}) | ||
}, | ||
removeFields(i) { | ||
this.fields.splice(i, 1) | ||
}, | ||
resetForm() { | ||
this.model = '' | ||
this.fields = [{name: '', type: 'string'}] | ||
this.controller_namespace = '' | ||
this.model_namespace = '' | ||
this.view_path = '' | ||
this.route_group = '' | ||
}, | ||
async handleSubmit(){ | ||
this.loading = true | ||
this.$toasted.show("Manthra is working... 🧛🧛", { | ||
theme: "bubble", | ||
position: "top-right", | ||
duration : 3000 | ||
}); | ||
try { | ||
let data = {} | ||
data['model'] = this.model | ||
data['fields'] = this.fields | ||
data['controller_namespace'] = this.controller_namespace | ||
data['model_namespace'] = this.model_namespace | ||
data['view_path'] = this.view_path | ||
data['route_group'] = this.route_group | ||
const response = await axios.post('/manthra', data) | ||
const result = await response | ||
setTimeout(() => { | ||
this.resetForm() | ||
this.loading = false | ||
this.$toasted.show("Manthra success generated 🤙☕", { | ||
theme: "outline", | ||
position: "top-right", | ||
duration : 3000 | ||
}); | ||
}, 1000) | ||
} catch (error) { | ||
this.loading = false | ||
this.$toasted.show("whoops looks like something went wrong, please check your input. 🔥🔥🔥", { | ||
theme: "outline", | ||
position: "top-right", | ||
duration : 5000 | ||
}); | ||
} | ||
} | ||
} | ||
}) | ||
</script> |
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,39 @@ | ||
<?php | ||
|
||
namespace NicoAudy\LaravelManthra\Http\Controllers; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class ManthraController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
return view('manthra::manthra-index'); | ||
} | ||
|
||
public function store() | ||
{ | ||
$fields = $this->merge_fields(request('fields')); | ||
|
||
Artisan::call("manthra:all", [ | ||
'name' => request('model'), | ||
'--fields' => $fields, | ||
'--validations' => '', | ||
'--controller-namespace' => request('controller_namespace'), | ||
'--model-namespace' => request('model_namespace'), | ||
'--view-path' => request('view_path'), | ||
'--route-group' => request('group_group') | ||
]); | ||
} | ||
|
||
private function merge_fields(array $fields): string | ||
{ | ||
$merge = ''; | ||
foreach ($fields as $field) { | ||
$merge .= $field['name'] . '#' . $field['type'] . ';'; | ||
} | ||
|
||
return $merge; | ||
} | ||
} |
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
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,8 @@ | ||
<?php | ||
|
||
$namespace = 'NicoAudy\LaravelManthra\Http\Controllers'; | ||
|
||
Route::namespace($namespace)->prefix('manthra')->group(function () { | ||
Route::get('/', 'ManthraController@index'); | ||
Route::post('/', 'ManthraController@store')->name('generate-manthra'); | ||
}); |