save course from disk begin

This commit is contained in:
Александр Бабкин
2022-07-12 16:48:24 +03:00
parent 1f59cda01d
commit d093a31512
7 changed files with 175 additions and 15 deletions

View File

@@ -126,4 +126,72 @@ class AUKController extends Controller
AUK::findOrFail($id)->delete();
return redirect()->route('auks.index');
}
/**
* Show form to to load AUKs from file system
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function scan(Request $request)
{
$project_id = $request->session()->get('project_id');
$project = Project::find($project_id);
$auks = array();
$MMC_PATH = $project->mmc_path;
$mmc_dir = scandir($MMC_PATH);
foreach ($mmc_dir as $entry) {
$course_path = $MMC_PATH . '/' . $entry;
if (is_dir($course_path)) {
if (intval($entry) > 0 && intval($entry) < 99) {
$tmp_array = array();
$tmp_array['auk_name'] = "АУК " . $entry;
$tmp_array['auk_path'] = $entry;
$tmp_array['image_dir'] = "";
$mmc_course_dir = scandir($course_path);
foreach ($mmc_course_dir as $course_entry) {
if (strcasecmp($course_entry, 'images') == 0) {
$course_image_path = $course_path . '/' . $course_entry;
if (is_dir($course_image_path)) {
$tmp_array['image_dir'] = $course_entry;
}
}
}
array_push($auks,$tmp_array);
}
}
}
return view('auks.scan', ['project' => $project, 'auks' => $auks]);
}
/**
* Load AUKs from file system
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function load(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'));
}
}

View File

@@ -16,8 +16,9 @@ class CreateAUKsTable extends Migration
Schema::create('auks', function (Blueprint $table) {
$table->id();
$table->integer('project_id')->unsigned();
$table->string('name');
$table->integer('number');
$table->string('auk_name');
$table->string('auk_path');
$table->string('image_dir');
$table->integer('parent_id')->unsigned()->nullable();
$table->timestamps();
$table->softDeletes();

View File

@@ -1084,6 +1084,9 @@ select {
.pr-4 {
padding-right: 1rem;
}
.pb-4 {
padding-bottom: 1rem;
}
.text-center {
text-align: center;
}

View File

@@ -9,11 +9,24 @@
<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="flex flex-row">
<div class="basis-1/2">
<a href="{{ route('auks.create') }}">
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<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>
<div class="basis-1/2 text-right">
<a href="{{ route('auks.scan') }}">
<button
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
<i class="fa fa-search pr-2"></i>{{ __('Scan AUK') }}
</button>
</a>
</div>
</div>
<div align="center" class="pt-4">
<table class="table table-sm border-b border-gray-200">
@@ -22,7 +35,7 @@
{{ __('Title') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('Number') }}
{{ __('Path') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('Actions') }}
@@ -30,8 +43,8 @@
</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">{{ $top_auk->auk_name }}</td>
<td class="p-2 border border-gray-200">{{ $top_auk->auk_path }}</td>
<td class="p-2 border border-gray-200">
<div class="text-center">
@include('auks.actions', ['auk' => $top_auk])

View File

@@ -0,0 +1,74 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ $project->name }}: {{ __('Scan 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">
<h3 class="font-bold text-l text-gray-800 leading-tight pb-4">AUK List in
{{ $project->mmc_path }}</h3>
<table class="table table-sm border-b border-gray-200">
<tr class="border border-gray-200">
<th class="p-2 border border-gray-200">
{{ __('AUK Name') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('AUK path') }}
</th>
<th class="p-2 border border-gray-200">
{{ __('Image dir') }}
</th>
{{-- <th class="p-2 border border-gray-200">
{{ __('Actions') }}
</th> --}}
</tr>
@forelse ($auks as $auk)
<tr class="border border-gray-200">
<td class="p-2 border border-gray-200">{{ $auk['auk_name'] }}</td>
<td class="p-2 border border-gray-200">{{ $auk['auk_path'] }}</td>
<td class="p-2 border border-gray-200">{{ $auk['image_dir'] }}</td>
{{-- <td class="p-2 border border-gray-200">&nbsp;</td> --}}
</tr>
@empty
<tr>
<td colspan="3" class="p-2 border border-gray-200 text-center">No Documents!
</td>
</tr>
@endforelse
</table>
@if (count($auks))
<form method="POST" action="{{ route('auks.store') }}">
@csrf
@for($i = 0; $i < count($auks); $i++)
<input type="hidden" name="auk_name_{{$i}}" value="{{ $auks[$i]['auk_name'] }}">
<input type="hidden" name="auk_path_{{$i}}" value="{{ $auks[$i]['auk_path'] }}">
<input type="hidden" name="image_dir_{{$i}}" value="{{ $auks[$i]['image_dir'] }}">
@endfor
<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>{{ __('Insert AUKs') }}
</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>
@endif
</div>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -41,5 +41,6 @@ Route::resource('/mmc', MMCController::class)->middleware(['auth'])->only(['inde
Route::get('/mmc/scan', [MMCController::class, 'scan'])->middleware(['auth'])->name('mmc.scan');
Route::resource('/documents', DocumentController::class)->except('show')->middleware(['auth']);
Route::resource('/auks', AUKController::class)->except('show')->middleware(['auth']);
Route::get('/auks/scan', [AUKController::class, 'scan'])->middleware(['auth'])->name('auks.scan');
require __DIR__ . '/auth.php';