Skip to content

Commit

Permalink
add TrixField
Browse files Browse the repository at this point in the history
add Filters
and some small improvments
  • Loading branch information
Max-Hutschenreiter committed Oct 4, 2021
1 parent 6ea5c50 commit 9563a12
Show file tree
Hide file tree
Showing 21 changed files with 46,170 additions and 136 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@
You can install the package via composer:

```bash
composer require max-hutschenreiter/the-laravel-admin-panel
composer require the42coders/the-laravel-admin-panel
```

You need to register the routes to your web.php routes File as well. Since the-laravel-admin-panel Package is very powerful make sure to secure the routes with whatever authentication you use in the rest of your app.

```php
Route::group(['middleware' => ['auth']], function () {
\the42coders\Workflows\Workflows::routes();
\the42coders\TLAP\TLAP::routes();
});
```

You need to publish the assets of the Package

```bash
php artisan vendor:publish --provider="the42coders\the-laravel-admin-panel\TLAPServiceProvider" --tag=assets
php artisan vendor:publish --provider="the42coders\TLAP\TLAPServiceProvider" --tag=assets
```

Other publishable Contents are

config

```bash
php artisan vendor:publish --provider="the42coders\the-laravel-admin-panel\TLAPServiceProvider" --tag=config
php artisan vendor:publish --provider="the42coders\TLAP\TLAPServiceProvider" --tag=config
```

language

```bash
php artisan vendor:publish --provider="the42coders\the-laravel-admin-panel\TLAPServiceProvider" --tag=lang
php artisan vendor:publish --provider="the42coders\TLAP\TLAPServiceProvider" --tag=lang
```

views

```bash
php artisan vendor:publish --provider="the42coders\the-laravel-admin-panel\TLAPServiceProvider" --tag=views
php artisan vendor:publish --provider="the42coders\TLAP\TLAPServiceProvider" --tag=views
```


Expand Down Expand Up @@ -72,7 +72,7 @@ Now you can just visit the url of https://your-website.de/admin.
You can change the url under which the admin panel will be accessible
in the tlap.php config file with the path variable.

This package autoloads your relations if you use return types on them.
This package autoload your relations if you use return types on them.

``` php
public function posts(): HasMany
Expand Down
51 changes: 51 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/*
* You can place your custom package configuration in here.
*/

return [

/*
Expand Down Expand Up @@ -30,4 +31,54 @@
//'companies' => 'App\Models\Company',
],

/*
|--------------------------------------------------------------------------
| Relations
|--------------------------------------------------------------------------
|
| Define an array of Relation return types which will be automatically resolved in the show and edit view.
|
*/

'relations' => [
'HasOne',
'HasMany',
'BelongsTo',
'BelongsToMany',
'MorphToMany',
'MorphTo'
],

/*
|--------------------------------------------------------------------------
| Auto Field discovery
|--------------------------------------------------------------------------
|
| Define an array of Fields which should be used if no fields are defined
|
*/

'autofields' => [
'type' => [
'tinyint(1)' => 'the42coders\TLAP\Fields\CheckboxField',
'text' => 'the42coders\TLAP\Fields\TrixField',
'timestamp' => 'the42coders\TLAP\Fields\TimeStampField',
'datetime' => 'the42coders\TLAP\Fields\TimeStampField',
'bigint' => 'the42coders\TLAP\Fields\NumberField',
'bigint unsigned' => 'the42coders\TLAP\Fields\NumberField',
],
'name' => [
'pw' => 'the42coders\TLAP\Fields\PasswordField',
'password' => 'the42coders\TLAP\Fields\PasswordField',
],
],

'datatableFilter' => [
'type' => [
'text' => 'the42coders\TLAP\Filters\ShortenTextFilter',
'timestamp' => 'the42coders\TLAP\Filters\FormatTimestamps',
'datetime' => 'the42coders\TLAP\Filters\FormatTimestamps',
],
],

];
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"datatables.net-responsive-bs5": "^2.2.9",
"jquery": "^3.5.1",
"jquery-datatables-checkboxes": "^1.2.12",
"sweetalert2": "^11.0.11"
"sweetalert2": "^11.0.11",
"trix": "^1.3.1"
}
}
8,565 changes: 8,562 additions & 3 deletions public/css/tlap.css

Large diffs are not rendered by default.

37,357 changes: 37,355 additions & 2 deletions public/js/tlap.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions resources/js/tlap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ try {

import 'bootstrap';
import 'datatables.net-bs5';
import 'trix';
//import 'datatables.net-responsive-bs';
//import 'datatables.net-responsive-bs5';
//import 'jquery-datatables-checkboxes';
Expand Down
1 change: 1 addition & 0 deletions resources/sass/tlap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import "~datatables.net-bs5/css/dataTables.bootstrap5.css";
@import "~datatables.net-responsive-bs";
@import "~datatables.net-responsive-bs5";
@import "~trix/dist/trix.css";

body{
background-color: #edf2f9;
Expand Down
40 changes: 40 additions & 0 deletions resources/views/datatable/datatable.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script>
$( document ).ready(function() {
$('#{{$tableName}}').DataTable({
"scrollX": true,
"processing": true,
"serverSide": true,
"ajax": {
"url": "{{ route('tlap.datatable', ['models' => $TLAPModel::getModelPluralName()]) }}",
@if(!empty($model))
"data": {
"ids": {{ $model->$relation()->pluck('id') }}
}
@endif
},
'columnDefs': [
{
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
}
],
"columns": [
@foreach($TLAPModel::getDatatableFields() as $fieldName)
{ "data": "{{ $fieldName }}", "title": "{{ $fieldName }}" },
@endforeach
{"data": "",
render : function(data, type, row) {
console.log(row);
return '' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/show" class="show"><i class="bi bi-eye"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/edit" class="show"><i class="bi bi-pencil-square"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/delete" class="show"><i class="bi bi-trash"></i></a>' +
''
} },
],
'order': [[1, 'asc']]
});
});
</script>
14 changes: 14 additions & 0 deletions resources/views/forms/textarea_field.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="mb-3 col-md-{{ $field->col ?? '12' }}">
<label for="{{ $field->name }}" class="form-label">{{ $field->label ?? $field->name }}</label>
<textarea class="form-control @error($field->name) is-invalid @enderror" id="{{ $field->name }}" rows="10" name="{{ $field->name }}" placeholder="{{ $field->label ?? $field->name }}" aria-describedby="{{ $field->name }}-error">
@if(old($field->name)) {{ old($field->name) }} @else {{ $value }} @endif
</textarea>
@if(isset($field->description))
<p class="mt-2 text-sm text-gray-500">
{{ $field->description }}
</p>
@endif
@error($field->name)
<p class="invalid-feedback" id="{{ $field->name }}-error">{{ $message }}</p>
@enderror
</div>
15 changes: 15 additions & 0 deletions resources/views/forms/trix_field.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="mb-3 col-md-{{ $field->col ?? '12' }}">
<label for="{{ $field->name }}" class="form-label">{{ $field->label ?? $field->name }}</label>
<input id="{{ $field->name }}" type="hidden" name="{{ $field->name }}">
<trix-editor class="form-control @error($field->name) is-invalid @enderror" input="{{ $field->name }}" rows="10" placeholder="{{ $field->label ?? $field->name }}" aria-describedby="{{ $field->name }}-error">
@if(old($field->name)) {!! old($field->name) !!} @else {!! $value !!} @endif
</trix-editor>
@if(isset($field->description))
<p class="mt-2 text-sm text-gray-500">
{{ $field->description }}
</p>
@endif
@error($field->name)
<p class="invalid-feedback" id="{{ $field->name }}-error">{{ $message }}</p>
@enderror
</div>
15 changes: 15 additions & 0 deletions resources/views/pages/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@
<a class="btn btn-light" href="/{{ config('tlap.path') }}/{{ $model::getModelPluralName() }}/">Zurück</a>
<button class="btn btn-success" type="submit">Speichern</button>
</form>
<div class="col-md-12">
@foreach($model::withRelations() as $relation)
<h3>{{ $relation }}</h3>
@if(empty($model->$relation) || $model->$relation->count() <= 0)
<p>No relatated Models found</p>
@else
<table id="datatable-{{$relation}}" class="table display responsive nowrap" width="100%">
</table>

@include('tlap::datatable.datatable', ['tableName' => 'datatable-'.$relation, 'TLAPModel' => $model->$relation()->first(), 'relation'=> $relation])


@endif
@endforeach
</div>
@endsection
49 changes: 1 addition & 48 deletions resources/views/pages/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,5 @@
@endsection

@section('scripts')
<script>
$( document ).ready(function() {
$('#datatest').DataTable({
"scrollX": true,
"processing": true,
"serverSide": true,
"ajax": "{{ route('tlap.datatable', ['models' => $TLAPModel::getModelPluralName()]) }}",
'columnDefs': [
{{--{
'targets': 0,
'render': function(data, type, row, meta){
if(type === 'display'){
data = '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>';
}
return data;
},
'checkboxes': {
'selectRow': true,
'selectAllRender': '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>'
}
},--}}
{
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
}
],
"columns": [
@foreach($TLAPModel::getDatatableFields() as $fieldName)
{ "data": "{{ $fieldName }}", "title": "{{ $fieldName }}" },
@endforeach
{"data": "",
render : function(data, type, row) {
console.log(row);
return '' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/show" class="show"><i class="bi bi-eye"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/edit" class="show"><i class="bi bi-pencil-square"></i></a> ' +
'<a href="/admin/{{ $TLAPModel::getModelPluralName() }}/'+row.id+'/delete" class="show"><i class="bi bi-trash"></i></a>' +
''
} },
],
'order': [[1, 'asc']]
});
});
</script>
@include('tlap::datatable.datatable', ['tableName' => 'datatest', 'TLAPModel' => $TLAPModel])
@endsection
Loading

0 comments on commit 9563a12

Please sign in to comment.