Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
raftx24 committed Dec 5, 2019
0 parents commit dac2ca6
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
18 changes: 18 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
40 changes: 40 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
32 changes: 32 additions & 0 deletions src/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace LaravelEnso\Departments;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->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;
}
}
28 changes: 28 additions & 0 deletions src/app/Forms/Builders/Administration/DepartmentForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace LaravelEnso\Departments\app\Forms\Builders\Administration;

use LaravelEnso\Departments\app\Models\Department;
use LaravelEnso\Forms\app\Services\Form;

class DepartmentForm
{
protected const TemplatePath = __DIR__.'/../../Templates/Administration/department.json';

protected $form;

public function __construct()
{
$this->form = new Form(static::TemplatePath);
}

public function create()
{
return $this->form->create();
}

public function edit(Department $department)
{
return $this->form->edit($department);
}
}
23 changes: 23 additions & 0 deletions src/app/Forms/Templates/Administration/department.json
Original file line number Diff line number Diff line change
@@ -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"
}
}]
}]
}
14 changes: 14 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Forms\Builders\Administration\DepartmentForm;

class Create extends Controller
{
public function __invoke(DepartmentForm $form)
{
return ['form' => $form->create()];
}
}
19 changes: 19 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Destroy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Models\Department;

class Destroy extends Controller
{
public function __invoke(Department $department)
{
$department->delete();

return [
'message' => __('The department was successfully deleted'),
'redirect' => 'administration.departments.index',
];
}
}
15 changes: 15 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Forms\Builders\Administration\DepartmentForm;
use LaravelEnso\Departments\app\Models\Department;

class Edit extends Controller
{
public function __invoke(Department $department, DepartmentForm $form)
{
return ['form' => $form->edit($department)];
}
}
14 changes: 14 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/InitTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Tables\Builders\Administration\DepartmentTable;
use LaravelEnso\Tables\app\Traits\Init;

class InitTable extends Controller
{
use Init;

protected $tableClass = DepartmentTable::class;
}
14 changes: 14 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Models\Department;
use LaravelEnso\Select\app\Traits\OptionsBuilder;

class Options extends Controller
{
use OptionsBuilder;

protected $model = Department::class;
}
21 changes: 21 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Store.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Http\Requests\Administration\Departments\ValidateDepartmentRequest;
use LaravelEnso\Departments\app\Models\Department;

class Store extends Controller
{
public function __invoke(ValidateDepartmentRequest $request, Department $department)
{
$department->fill($request->validated())->save();

return [
'message' => __('The department was successfully created'),
'redirect' => 'administration.departments.edit',
'param' => ['department' => $department->id],
];
}
}
14 changes: 14 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/TableData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Tables\Builders\Administration\DepartmentTable;
use LaravelEnso\Tables\app\Traits\Data;

class TableData extends Controller
{
use Data;

protected $tableClass = DepartmentTable::class;
}
17 changes: 17 additions & 0 deletions src/app/Http/Controllers/Administration/Departments/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace LaravelEnso\Departments\app\Http\Controllers\Administration\Departments;

use Illuminate\Routing\Controller;
use LaravelEnso\Departments\app\Http\Requests\Administration\Departments\ValidateDepartmentRequest;
use LaravelEnso\Departments\app\Models\Department;

class Update extends Controller
{
public function __invoke(ValidateDepartmentRequest $request, Department $department)
{
$department->update($request->validated());

return ['message' => __('The department was successfully updated')];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace LaravelEnso\Departments\app\Http\Requests\Administration\Departments;

use Illuminate\Foundation\Http\FormRequest;

class ValidateDepartmentRequest extends FormRequest
{
public function authorize()
{
return true;
}

public function rules()
{
return [
'name' => 'required|string',
'description' => 'required|string'
];
}
}
21 changes: 21 additions & 0 deletions src/app/Imports/Importers/DepartmentImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace LaravelEnso\Departments\app\Imports\Importers;

use LaravelEnso\Core\app\Models\User;
use LaravelEnso\DataImport\app\Contracts\Importable;
use LaravelEnso\Departments\app\Models\Department;
use LaravelEnso\Helpers\app\Classes\Obj;

class DepartmentImporter implements Importable
{
public function run(Obj $row, User $user, Obj $params)
{
$this->import($row);
}

private function import($row)
{
Department::create($row->toArray());
}
}
14 changes: 14 additions & 0 deletions src/app/Imports/Templates/departments.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}]
}
Loading

0 comments on commit dac2ca6

Please sign in to comment.