From dac2ca68e1dfb9db21db4c1ed8051ffff61e44d4 Mon Sep 17 00:00:00 2001 From: reza Date: Thu, 5 Dec 2019 10:59:28 +0330 Subject: [PATCH] Initial Commit --- .gitignore | 1 + .styleci.yml | 18 +++++++++ LICENSE | 21 ++++++++++ README.md | 24 +++++++++++ composer.json | 40 +++++++++++++++++++ src/AppServiceProvider.php | 32 +++++++++++++++ .../Administration/DepartmentForm.php | 28 +++++++++++++ .../Templates/Administration/department.json | 23 +++++++++++ .../Administration/Departments/Create.php | 14 +++++++ .../Administration/Departments/Destroy.php | 19 +++++++++ .../Administration/Departments/Edit.php | 15 +++++++ .../Administration/Departments/InitTable.php | 14 +++++++ .../Administration/Departments/Options.php | 14 +++++++ .../Administration/Departments/Store.php | 21 ++++++++++ .../Administration/Departments/TableData.php | 14 +++++++ .../Administration/Departments/Update.php | 17 ++++++++ .../Departments/ValidateDepartmentRequest.php | 21 ++++++++++ .../Imports/Importers/DepartmentImporter.php | 21 ++++++++++ src/app/Imports/Templates/departments.json | 14 +++++++ src/app/Models/Department.php | 13 ++++++ .../Administration/DepartmentTable.php | 24 +++++++++++ .../Templates/Administration/departments.json | 17 ++++++++ src/database/factories/DepartmentFactory.php | 11 +++++ ..._11_30_213527_create_departments_table.php | 25 ++++++++++++ ...13527_create_structure_for_departments.php | 28 +++++++++++++ src/routes/api.php | 28 +++++++++++++ 26 files changed, 517 insertions(+) create mode 100644 .gitignore create mode 100644 .styleci.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/AppServiceProvider.php create mode 100644 src/app/Forms/Builders/Administration/DepartmentForm.php create mode 100644 src/app/Forms/Templates/Administration/department.json create mode 100644 src/app/Http/Controllers/Administration/Departments/Create.php create mode 100644 src/app/Http/Controllers/Administration/Departments/Destroy.php create mode 100644 src/app/Http/Controllers/Administration/Departments/Edit.php create mode 100644 src/app/Http/Controllers/Administration/Departments/InitTable.php create mode 100644 src/app/Http/Controllers/Administration/Departments/Options.php create mode 100644 src/app/Http/Controllers/Administration/Departments/Store.php create mode 100644 src/app/Http/Controllers/Administration/Departments/TableData.php create mode 100644 src/app/Http/Controllers/Administration/Departments/Update.php create mode 100644 src/app/Http/Requests/Administration/Departments/ValidateDepartmentRequest.php create mode 100644 src/app/Imports/Importers/DepartmentImporter.php create mode 100644 src/app/Imports/Templates/departments.json create mode 100644 src/app/Models/Department.php create mode 100644 src/app/Tables/Builders/Administration/DepartmentTable.php create mode 100644 src/app/Tables/Templates/Administration/departments.json create mode 100644 src/database/factories/DepartmentFactory.php create mode 100644 src/database/migrations/2017_11_30_213527_create_departments_table.php create mode 100644 src/database/migrations/2017_11_30_213527_create_structure_for_departments.php create mode 100644 src/routes/api.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..fb4eeb1 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,18 @@ +preset: laravel + +enabled: + - strict + - unalign_double_arrow + - phpdoc_order + - phpdoc_separation + +disabled: + - short_array_syntax + +finder: + exclude: + - "public" + - "resources" + - "tests" + name: + - "*.php" \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a8fe188 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 laravel-enso + +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: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a6feef --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Departments + +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dc3819bf2c654b3d8dcaaed8898b214f)](https://www.codacy.com/app/laravel-enso/departments?utm_source=github.com&utm_medium=referral&utm_content=laravel-enso/departments&utm_campaign=Badge_Grade) +[![StyleCI](https://github.styleci.io/repos/85554059/shield?branch=master)](https://github.styleci.io/repos/85554059) +[![License](https://poser.pugx.org/laravel-enso/departments/license)](https://packagist.org/packages/laravel-enso/departments) +[![Total Downloads](https://poser.pugx.org/laravel-enso/departments/downloads)](https://packagist.org/packages/laravel-enso/departments) +[![Latest Stable Version](https://poser.pugx.org/laravel-enso/departments/version)](https://packagist.org/packages/laravel-enso/departments) + +Departments is a package for the Laravel Enso environment, designed for the management of departments. + +**Note:** *This package cannot be used outside of the Enso environment and is not included by default +in the [Laravel Enso Core](https://github.com/laravel-enso/Core) package.* + +### Installation, Configuration & Usage + +Be sure to check out the full documentation for this package available at [docs.laravel-enso.com](https://docs.laravel-enso.com/backend/departments.html) + +### Contributions + +are welcome. Pull requests are great, but issues are good too. + +### License + +This package is released under the MIT license. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..386cddf --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name": "laravel-enso/departments", + "description": "Projects for Laravel Enso", + "keywords": [ + "laravel-enso", + "departments" + ], + "homepage": "https://github.com/laravel-enso/departments", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Reza Fouladi", + "email": "raftx24@gmail.com", + "homepage": "https://laravel-enso.com", + "role": "Developer" + }, + { + "name": "Adrian Ocneanu", + "email": "aocneanu@gmail.com", + "homepage": "https://laravel-enso.com", + "role": "Developer" + } + ], + "require": { + "php": ">=7.3.0" + }, + "autoload": { + "psr-4": { + "LaravelEnso\\Departments\\": "src/" + } + }, + "extra": { + "laravel": { + "providers": [ + "LaravelEnso\\Departments\\AppServiceProvider" + ] + } + } +} diff --git a/src/AppServiceProvider.php b/src/AppServiceProvider.php new file mode 100644 index 0000000..92d600f --- /dev/null +++ b/src/AppServiceProvider.php @@ -0,0 +1,32 @@ +load() + ->publish(); + } + + private function load() + { + $this->loadRoutesFrom(__DIR__.'/routes/api.php'); + + $this->loadMigrationsFrom(__DIR__.'/database/migrations'); + + return $this; + } + + private function publish() + { + $this->publishes([ + __DIR__.'/database/factories' => database_path('factories'), + ], 'department-factories'); + + return $this; + } +} diff --git a/src/app/Forms/Builders/Administration/DepartmentForm.php b/src/app/Forms/Builders/Administration/DepartmentForm.php new file mode 100644 index 0000000..6ee0c72 --- /dev/null +++ b/src/app/Forms/Builders/Administration/DepartmentForm.php @@ -0,0 +1,28 @@ +form = new Form(static::TemplatePath); + } + + public function create() + { + return $this->form->create(); + } + + public function edit(Department $department) + { + return $this->form->edit($department); + } +} diff --git a/src/app/Forms/Templates/Administration/department.json b/src/app/Forms/Templates/Administration/department.json new file mode 100644 index 0000000..597fed0 --- /dev/null +++ b/src/app/Forms/Templates/Administration/department.json @@ -0,0 +1,23 @@ +{ + "routePrefix": "administration.departments", + "sections": [{ + "columns": 2, + "fields": [{ + "label": "Name", + "name": "name", + "value": "", + "meta": { + "type": "input", + "content": "text" + } + }, { + "label": "Description", + "name": "description", + "value": "", + "meta": { + "type": "input", + "content": "text" + } + }] + }] +} diff --git a/src/app/Http/Controllers/Administration/Departments/Create.php b/src/app/Http/Controllers/Administration/Departments/Create.php new file mode 100644 index 0000000..9a6b4b8 --- /dev/null +++ b/src/app/Http/Controllers/Administration/Departments/Create.php @@ -0,0 +1,14 @@ + $form->create()]; + } +} diff --git a/src/app/Http/Controllers/Administration/Departments/Destroy.php b/src/app/Http/Controllers/Administration/Departments/Destroy.php new file mode 100644 index 0000000..f672100 --- /dev/null +++ b/src/app/Http/Controllers/Administration/Departments/Destroy.php @@ -0,0 +1,19 @@ +delete(); + + return [ + 'message' => __('The department was successfully deleted'), + 'redirect' => 'administration.departments.index', + ]; + } +} diff --git a/src/app/Http/Controllers/Administration/Departments/Edit.php b/src/app/Http/Controllers/Administration/Departments/Edit.php new file mode 100644 index 0000000..73efcc9 --- /dev/null +++ b/src/app/Http/Controllers/Administration/Departments/Edit.php @@ -0,0 +1,15 @@ + $form->edit($department)]; + } +} diff --git a/src/app/Http/Controllers/Administration/Departments/InitTable.php b/src/app/Http/Controllers/Administration/Departments/InitTable.php new file mode 100644 index 0000000..7788d80 --- /dev/null +++ b/src/app/Http/Controllers/Administration/Departments/InitTable.php @@ -0,0 +1,14 @@ +fill($request->validated())->save(); + + return [ + 'message' => __('The department was successfully created'), + 'redirect' => 'administration.departments.edit', + 'param' => ['department' => $department->id], + ]; + } +} diff --git a/src/app/Http/Controllers/Administration/Departments/TableData.php b/src/app/Http/Controllers/Administration/Departments/TableData.php new file mode 100644 index 0000000..a90faf0 --- /dev/null +++ b/src/app/Http/Controllers/Administration/Departments/TableData.php @@ -0,0 +1,14 @@ +update($request->validated()); + + return ['message' => __('The department was successfully updated')]; + } +} diff --git a/src/app/Http/Requests/Administration/Departments/ValidateDepartmentRequest.php b/src/app/Http/Requests/Administration/Departments/ValidateDepartmentRequest.php new file mode 100644 index 0000000..a5126f9 --- /dev/null +++ b/src/app/Http/Requests/Administration/Departments/ValidateDepartmentRequest.php @@ -0,0 +1,21 @@ + 'required|string', + 'description' => 'required|string' + ]; + } +} diff --git a/src/app/Imports/Importers/DepartmentImporter.php b/src/app/Imports/Importers/DepartmentImporter.php new file mode 100644 index 0000000..1d879e9 --- /dev/null +++ b/src/app/Imports/Importers/DepartmentImporter.php @@ -0,0 +1,21 @@ +import($row); + } + + private function import($row) + { + Department::create($row->toArray()); + } +} diff --git a/src/app/Imports/Templates/departments.json b/src/app/Imports/Templates/departments.json new file mode 100644 index 0000000..2b41568 --- /dev/null +++ b/src/app/Imports/Templates/departments.json @@ -0,0 +1,14 @@ +{ + "timeout": 500, + "sheets": [{ + "name": "departments", + "importerClass": "LaravelEnso\\Departments\\app\\Imports\\Importers\\DepartmentImporter", + "columns": [{ + "name": "name", + "validations": "string|required|unique:user_groups,name" + }, { + "name": "description", + "validations": "string|nullable" + }] + }] +} diff --git a/src/app/Models/Department.php b/src/app/Models/Department.php new file mode 100644 index 0000000..31a9c95 --- /dev/null +++ b/src/app/Models/Department.php @@ -0,0 +1,13 @@ +define(Department::class, function (Faker $faker) { + return [ + 'name' => $faker->name, + 'description' => $faker->sentence, + ]; +}); diff --git a/src/database/migrations/2017_11_30_213527_create_departments_table.php b/src/database/migrations/2017_11_30_213527_create_departments_table.php new file mode 100644 index 0000000..d31f219 --- /dev/null +++ b/src/database/migrations/2017_11_30_213527_create_departments_table.php @@ -0,0 +1,25 @@ +increments('id'); + + $table->string('name')->unique(); + $table->string('description')->nullable(); + + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('departments'); + } +} diff --git a/src/database/migrations/2017_11_30_213527_create_structure_for_departments.php b/src/database/migrations/2017_11_30_213527_create_structure_for_departments.php new file mode 100644 index 0000000..6044d57 --- /dev/null +++ b/src/database/migrations/2017_11_30_213527_create_structure_for_departments.php @@ -0,0 +1,28 @@ + 'administration.departments.create', 'description' => 'Create department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.store', 'description' => 'Store a new department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.show', 'description' => 'Show department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.edit', 'description' => 'Edit department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.update', 'description' => 'Update department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.destroy', 'description' => 'Delete department', 'type' => 1, 'is_default' => false], + ['name' => 'administration.departments.initTable', 'description' => 'Init table for departments', 'type' => 0, 'is_default' => false], + + ['name' => 'administration.departments.tableData', 'description' => 'Get table data for departments', 'type' => 0, 'is_default' => false], + + ['name' => 'administration.departments.exportExcel', 'description' => 'Export excel for departments', 'type' => 0, 'is_default' => false], + + ['name' => 'administration.departments.options', 'description' => 'Get department options for select', 'type' => 0, 'is_default' => false], + ]; + + protected $menu = [ + 'name' => 'Departments', 'icon' => 'building', 'route' => 'administration.departments.index', 'order_index' => 0, 'has_children' => false + ]; + + protected $parentMenu = 'Administration'; +} diff --git a/src/routes/api.php b/src/routes/api.php new file mode 100644 index 0000000..f406464 --- /dev/null +++ b/src/routes/api.php @@ -0,0 +1,28 @@ +namespace('LaravelEnso\Departments\app\Http\Controllers') + ->prefix('api') + ->group(function () { + //Route::namespace('Administration') + // ->prefix('administration')->as('administration.') + // ->group(function () { + + Route::namespace('Administration\Departments') + ->prefix('administration/departments')->as('administration.departments.') + ->group(function () { + Route::get('create', 'Create')->name('create'); + Route::post('', 'Store')->name('store'); + Route::get('{department}/edit', 'Edit')->name('edit'); + + Route::patch('{department}', 'Update')->name('update'); + + Route::delete('{department}', 'Destroy')->name('destroy'); + + Route::get('initTable', 'InitTable')->name('initTable'); + Route::get('tableData', 'TableData')->name('tableData'); + + Route::get('options', 'Options')->name('options'); + }); + //}); + });