AUK ready

This commit is contained in:
Александр Бабкин
2022-07-04 16:04:58 +03:00
parent 621b1fd677
commit 240351d832
15 changed files with 458 additions and 14 deletions

View File

@@ -3,27 +3,37 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\AUK;
use App\Models\Project;
class AUKController extends Controller
{
/**
* Display a listing of the resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index()
public function index(Request $request)
{
//
$project_id = $request->session()->get('project_id');
$project = Project::find($project_id);
$top_auks = $project->auks()->where('parent_id',0)->get();
return view('auks.list', ['project' => $project, 'top_auks' => $top_auks]);
}
/**
* Show the form for creating a new resource.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function create()
public function create(Request $request)
{
//
$project_id = $request->session()->get('project_id');
$project = Project::find($project_id);
$top_auks = $project->auks()->where('parent_id',0)->get();
return view('auks.create', ['project' => $project, 'top_auks' => $top_auks]);
}
/**
@@ -34,7 +44,22 @@ class AUKController extends Controller
*/
public function store(Request $request)
{
//
$project_id = $request->session()->get('project_id');
$request->validate([
'name' => ['required', 'string', 'max:255'],
'number' => ['required', 'integer'],
'parent_id' => ['required', 'integer'],
]);
// $user =
AUK::create([
'project_id' => $project_id,
'name' => $request->name,
'number' => $request->number,
'parent_id' => $request->parent_id,
]);
return redirect(route('auks.index'));
}
/**
@@ -51,12 +76,17 @@ class AUKController extends Controller
/**
* Show the form for editing the specified resource.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
public function edit(Request $request,$id)
{
//
$project_id = $request->session()->get('project_id');
$project = Project::find($project_id);
$top_auks = $project->auks()->where('parent_id',0)->get();
$auk = AUK::find($id);
return view('auks.edit', ['project' => $project, 'top_auks' => $top_auks, 'auk' => $auk]);
}
/**
@@ -68,7 +98,21 @@ class AUKController extends Controller
*/
public function update(Request $request, $id)
{
//
$project_id = $request->session()->get('project_id');
$request->validate([
'name' => ['required', 'string', 'max:255'],
'number' => ['required', 'integer'],
'parent_id' => 'required|integer|different:id',
]);
$document = AUK::find($id);
$document->project_id = $project_id;
$document->name = $request->name;
$document->number = $request->number;
$document->parent_id = $request->parent_id;
$document->save();
return redirect()->route('auks.index');
}
/**
@@ -79,6 +123,7 @@ class AUKController extends Controller
*/
public function destroy($id)
{
//
AUK::findOrFail($id)->delete();
return redirect()->route('auks.index');
}
}

26
app/Models/AUK.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class AUK extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'auks';
protected $fillable = [
'project_id',
'name',
'number',
'parent_id',
];
public function childs()
{
return $this->hasMany('App\Models\AUK','parent_id','id');
}
}

View File

@@ -4,10 +4,12 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Project extends Model
{
use HasFactory;
use HasFactory, SoftDeletes;
protected $fillable = [
'name',
'description',
@@ -18,4 +20,10 @@ class Project extends Model
{
return $this->hasMany(Document::class);
}
public function auks()
{
return $this->hasMany(AUK::class);
}
}

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAUKsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('auks', function (Blueprint $table) {
$table->id();
$table->integer('project_id')->unsigned();
$table->string('name');
$table->integer('number');
$table->integer('parent_id')->unsigned()->nullable();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('auks');
}
}

View File

@@ -0,0 +1,16 @@
{{-- <a href="{{ route('auks.show',$auk->id) }}">
<i class="fa fa-eye text-green-500 hover:text-green-700 px-2 text-lg"></i>
</a> --}}
<a href="{{ route('auks.edit', $auk->id) }}">
<i class="fa fa-edit text-blue-500 hover:text-blue-700 px-2 text-lg"></i>
</a>
@if (!count($auk->childs))
<form class="inline-block" action="{{ route('auks.destroy', $auk->id) }}" method="POST"
onsubmit="return confirm('{{ __('Are you sure remove AUK ') . $auk->name . '?' }}');">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit">
<i class="fa fa-trash text-red-500 hover:text-red-700 px-2 text-lg"></i>
</button>
</form>
@endif

View File

@@ -0,0 +1,75 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ $project->name }}: {{ __('Create AUK') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<div class="w-96 mx-auto">
@if ($errors->any())
<div class="alert alert-danger text-red-500 p-2">
<ul class="list-unstyled alert alert-danger">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form method="POST" action="{{ route('auks.store') }}">
@csrf
<!-- Document name -->
<div>
<x-label for="name" :value="__('Title')" />
<x-input id="name" class="block mt-1 w-full" type="text" name="name"
:value="old('name')" required autofocus />
</div>
<div>
<x-label for="number" :value="__('Number')" />
<x-input id="number" class="block mt-1 w-full" type="text" name="number"
:value="old('number')" required />
</div>
<div>
<x-label for="parent_id" :value="__('Parent AUK')" />
<x-select id="parent_id" class="block mt-1 w-full" name="parent_id" required>
<option value="0">---</option>
@foreach ($top_auks as $auks)
<option value="{{ $auks->id }}">{{ $auks->name }} ({{ $auks->number }})</option>
@if (count($auks->childs))
@include('auks.optionChild', [
'childs' => $auks->childs,
'level' => 1,
])
@endif
@endforeach
</x-select>
</div>
<div class="flex items-center justify-end mt-4">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-add pr-2"></i>{{ __('Create AUK') }}
</button>
<div class="pl-2">
<a href="{{ route('auks.index') }}"
class="btn bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-cancel pr-2"></i>{{ __('Cancel') }}
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,81 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ $project->name }}: {{ __('Edit AUK') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<div class="w-96 mx-auto">
@if ($errors->any())
<div class="alert alert-danger text-red-500 p-2">
<ul class="list-unstyled alert alert-danger">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form method="POST" action="{{ route('auks.update',$auk->id) }}">
@csrf
@method('PUT')
<input type="hidden" id="id" name="id" value="{{ $auk->id }}">
<div>
<x-label for="name" value="{{ __('Title') }}" />
<x-input id="name" class="block mt-1 w-full" type="text" name="name"
value="{{ $auk->name }}" required autofocus />
</div>
<div>
<x-label for="number" value="{{ __('Number') }}" />
<x-input id="number" class="block mt-1 w-full" type="text" name="number"
value="{{ $auk->number }}" required />
</div>
<div>
<x-label for="parent_id" value="{{ __('Parent AUK') }}" />
<x-select id="parent_id" class="block mt-1 w-full" name="parent_id" required>
<option value="0">---</option>
@foreach ($top_auks as $top_auk)
@if ($auk->parent_id == $top_auk->id)
<option value="{{ $top_auk->id }}" selected>{{ $top_auk->name }} ({{ $top_auk->number }})</option>
@else
<option value="{{ $top_auk->id }}">{{ $top_auk->name }} ({{ $top_auk->number }})</option>
@endif
@if (count($top_auk->childs))
@include('documents.optionChildSelected', [
'childs' => $top_auk->childs,
'parent_id' => $top_auk->parent_id,
'level' => 1,
])
@endif
@endforeach
</x-select>
</div>
<div class="flex items-center justify-end mt-4">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-add pr-2"></i>{{ __('Save AUK') }}
</button>
<div class="pl-2">
<a href="{{ route('auks.index') }}"
class="btn bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-cancel pr-2"></i>{{ __('Cancel') }}
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,64 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ $project->name }}: {{ __('AUK list') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<a href="{{ route('auks.create') }}">
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-add pr-2"></i>{{ __('Create AUK') }}
</button>
</a>
<div align="center" class="pt-4">
<table class="table table-sm border-b border-gray-200">
<tr class="border border-gray-200">
<th class="p-2 border border-gray-200">
{{ __('Title') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('Number') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('Actions') }}
</th>
</tr>
@forelse ($top_auks as $top_auk)
<tr class="border border-gray-200">
<td class="p-2 border border-gray-200">{{ $top_auk->name }}</td>
<td class="p-2 border border-gray-200">{{ $top_auk->number }}</td>
<td class="p-2 border border-gray-200">
<div class="text-center">
@include('auks.actions', ['auk' => $top_auk])
</div>
</td>
</tr>
@if (count($top_auk->childs))
@php
$level = 1;
@endphp
@include('auks.tableChild', [
'childs' => $top_auk->childs,
'level' => $level,
])
@endif
@empty
<tr>
<td colspan="3" class="p-2 border border-gray-200 text-center">No AUKs!</td>
</tr>
@endforelse
</table>
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,9 @@
@foreach ($childs as $child)
<option value="{{ $child->id }}">{{ str_pad('', $level, '-') . ' ' . $child->name }}</option>
@if (count($child->childs))
@include('documents.optionChild', [
'childs' => $child->childs,
'level' => $level + 1,
])
@endif
@endforeach

View File

@@ -0,0 +1,14 @@
@foreach ($childs as $child)
@if ($parent_id == $child->id)
<option value="{{ $child->id }}" selected>{{ str_pad('', $level, '-') . ' ' . $child->name }}</option>
@else
<option value="{{ $child->id }}">{{ str_pad('', $level, '-') . ' ' . $child->name }}</option>
@endif
@if (count($child->childs))
@include('auks.optionChildSelected', [
'childs' => $child->childs,
'parent_id' => $auk->parent_id,
'level' => $level + 1,
])
@endif
@endforeach

View File

@@ -0,0 +1,51 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Show project') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<div class="w-96 mx-auto">
<div>
<x-label for="name" :value="__('Title')" />
<x-input id="name" class="block mt-1 w-full" type="text" name="name" value="{{ $project->name }}" readonly />
</div>
<!-- Description -->
<div class="mt-4">
<x-label for="description" :value="__('Description')" />
<x-input id="description" class="block mt-1 w-full" type="text" name="description" value="{{ $project->description }}" readonly />
</div>
<!-- MMC Path -->
<div class="mt-4">
<x-label for="mmc_path" :value="__('MMC Path')" />
<x-input id="mmc_path" class="block mt-1 w-full" type="text" name="mmc_path" value="{{ $project->mmc_path }}" readonly />
</div>
<div class="flex items-center justify-end mt-4">
<div class="pl-2">
<a href="{{ route('projects.edit',$project->id) }}" class="btn bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-edit pr-2"></i>{{__('Edit project')}}
</a>
</div>
<div class="pl-2">
<a href="{{ route('projects.index') }}" class="btn bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-cancel pr-2"></i>{{__('Cancel')}}
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,19 @@
@foreach ($childs as $child)
<tr>
<td class="p-2 border border-gray-200">
{{ str_pad('', $level, '-') . ' ' . $child->name }}
</td>
<td class="p-2 border border-gray-200">
{{ $child->number }}
</td>
<td class="p-2 border border-gray-200">
@include('auks.actions', ['auk' => $child])
</td>
</tr>
@if (count($child->childs))
@include('auks.tableChild', [
'childs' => $child->childs,
'level' => $level + 1,
])
@endif
@endforeach

View File

@@ -1,7 +1,7 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ $project->name }}: {{ __('Create document') }}
{{ $project->name }}: {{ __('Edit document') }}
</h2>
</x-slot>

View File

@@ -40,7 +40,7 @@
</x-nav-link>
</div>
<div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex">
<x-nav-link :href="route('auk.index')" :active="request()->routeIs('auk.index')|request()->routeIs('auk.create')|request()->routeIs('auk.show')|request()->routeIs('auk.edit')">
<x-nav-link :href="route('auks.index')" :active="request()->routeIs('auks.index')|request()->routeIs('auks.create')|request()->routeIs('auks.show')|request()->routeIs('auks.edit')">
{{ __('AUK') }}
</x-nav-link>
</div>

View File

@@ -38,7 +38,7 @@ Route::resource('/projects', ProjectController::class)->middleware(['auth']);
Route::post('/project/{project}/select',SelectProjectController::class)->middleware(['auth'])->name('project.select');
Route::resource('/mmc', MMCController::class)->middleware(['auth']);
Route::resource('/documents', DocumentController::class)->middleware(['auth']);
Route::resource('/auk', AUKController::class)->middleware(['auth']);
Route::resource('/documents', DocumentController::class)->except('show')->middleware(['auth']);
Route::resource('/auks', AUKController::class)->except('show')->middleware(['auth']);
require __DIR__ . '/auth.php';