Skip to content

Commit

Permalink
Merge pull request #12 from delaynore/fix/fix
Browse files Browse the repository at this point in the history
Fix/fix
  • Loading branch information
delaynore authored May 27, 2024
2 parents 40e936a + 21a87a8 commit 16ed0c9
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 68 deletions.
26 changes: 0 additions & 26 deletions app/Http/Controllers/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Models\Attachment;
use App\Enums\AttachmentType;
use App\Http\Requests\StoreAttachmentRequest;
use App\Http\Requests\UpdateAttachmentRequest;
use App\Models\Concept;
use App\Models\Dictionary;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -70,30 +68,6 @@ public function store(Request $request, Dictionary $dictionary, Concept $concept
);
}

/**
* Display the specified resource.
*/
public function show(Attachment $attachment)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Attachment $attachment)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateAttachmentRequest $request, Attachment $attachment)
{
//
}

/**
* Remove the specified resource from storage.
*/
Expand Down
7 changes: 0 additions & 7 deletions app/Http/Controllers/ConceptAttributeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@

class ConceptAttributeController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
Expand Down
7 changes: 0 additions & 7 deletions app/Http/Controllers/ConceptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@

class ConceptController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
Expand Down
54 changes: 44 additions & 10 deletions app/Http/Controllers/ImportExamplesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\ConceptAttributeValue;
use App\Models\Dictionary;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Validation\Rules\File;

Expand Down Expand Up @@ -49,6 +50,10 @@ public function store(Request $request, Dictionary $dictionary, Concept $concept

$fileContent = $file->get();

if ($fileContent == '') {
return redirect()->back()->with('error', __('import.messsages.empty-file'));
}

$currentExampleNumber = (Concept::where('concepts.id', $concept->id)
->join('concept_attributes', 'concepts.id', '=', 'concept_attributes.fk_concept_id')
->join('concept_attribute_values', 'concept_attributes.id', '=', 'concept_attribute_values.fk_concept_attribute_id')
Expand All @@ -64,14 +69,37 @@ public function store(Request $request, Dictionary $dictionary, Concept $concept
$currentLine = 1;
$allExamples = [];
foreach (preg_split("/\r\n|\n|\r/", $fileContent) as $line) {
if ($line == '') {
$currentLine++;
continue;
}
$words = preg_split("/;/", $line);
if (count($words) != count($conceptAttributes)) {
return redirect()->back()->with("error", "Неверное количество столбцов в строке $currentLine. Ожидалось " . count($conceptAttributes) . " столбцов, получено " . count($words));
return redirect()->back()->with(
"error",
__(
'import.messsages.invalid-amount-columns',
[
'line' => $currentLine,
'expected' => count($conceptAttributes),
'actual' => count($words)
]
)
);
}
$allExamples[$currentLine] = [];
foreach ($words as $k => $word) {
if($word == '') {
return redirect()->back()->with("error", "Столбец $k в строке $currentLine пустой");
if ($word === '') {
return redirect()->back()->with(
"error",
__(
'import.messsages.empty-column',
[
'column' => $k + 1,
'line' => $currentLine
]
)
);
}

$type = DataType::from($conceptAttributes[$k]->type);
Expand All @@ -83,21 +111,27 @@ public function store(Request $request, Dictionary $dictionary, Concept $concept
'example_number' => $currentExampleNumber
]);
} else {
$column = $k + 1;
return redirect()->back()->with("error", "Неверный тип данных в строке $currentLine, столбце $column");
return redirect()->back()->with("error", __('import.messsages.invalid-column', ['column' => $k + 1, 'line' => $currentLine]));
}
}

$currentExampleNumber++;
$currentLine++;
}
foreach ($allExamples as $example) {
foreach ($example as $value) {
$value->save();
}

if (count($allExamples) === 0) {
return redirect()->back()->with('error', __('import.messsages.no-valid-rows'));
}

return redirect()->back()->with("success", "Успешно добавлено " . count($allExamples) . " экземпляров");
DB::transaction(function () use ($allExamples) {
foreach ($allExamples as $example) {
foreach ($example as $value) {
$value->save();
}
}
});

return redirect()->back()->with("success", __('import.messsages.success', ['count' => count($allExamples)]));
}

function isParsableTo(string $s, DataType $type): bool
Expand Down
3 changes: 0 additions & 3 deletions lang/ru/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
'have-account' => 'Уже есть аккаунт?',
'to-login' => 'Войти',
'button-register' => 'Зарегистрироваться',
'accept-terms' => 'Я принимаю',
'accept-terms-link' => 'Пользовательское соглашение',

'name' => [
'label' => 'Имя',
'placeholder' => 'Ваше прекрасное имя',
Expand Down
6 changes: 6 additions & 0 deletions lang/ru/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
'description' => 'Для успешного импорта файла, значения должны быть разделены запятой или точкой с запятой, также порядок значений атрибутов должен быть как в примере ниже:',
'messsages' => [
'no-attributes' => 'У понятия нет атрибутов',
'empty-file' => 'Файл пустой',
'invalid-amount-columns' => 'Неверное количество столбцов в строке :line. Ожидалось :expected столбцов, получено :actual.',
'empty-column' => 'Столбец :column в строке :line пустой',
'invalid-column-type' => '"Неверный тип данных в строке :line, столбце :column',
'no-valid-rows' => 'В файле не найдены экземпляры',
'success' => 'Экземпляры в количестве :count успешно импортированы',
],
'available-file-types' => 'TXT, CSV. Максимум 3 МБ.',
'unforget-attribute-types' => 'Также помните, что атрибуты имеет следующие типы данных:',
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/forgot-password.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<x-layout.main>
<section class="w-full bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<x-shared.logo-title />
<x-shared.logo-title :href="route('home')"/>
<div class="w-full p-6 bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md dark:bg-gray-800 dark:border-gray-700 sm:p-8">
<h1 class="mb-1 text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
{{ __('auth.forgot-password.title')}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<x-slot:title>{{ __('auth.login.title') }}</x-slot:title>
<section class="w-full bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<x-shared.logo-title />
<x-shared.logo-title :href="route('home')"/>
<div class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700">
<div class="p-6 space-y-4 md:space-y-6 sm:p-8">
<h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
Expand Down
10 changes: 1 addition & 9 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<section class="w-full bg-gray-50 dark:bg-gray-900">
<div class="flex flex-col items-center justify-center px-6 py-8 mx-auto md:h-screen lg:py-0">
<x-shared.logo-title />
<x-shared.logo-title :href="route('home')"/>
<div class="w-full bg-white rounded-lg shadow dark:border md:mt-0 sm:max-w-md xl:p-0 dark:bg-gray-800 dark:border-gray-700">
<div class="p-6 space-y-4 md:space-y-6 sm:p-8">
<h1 class="text-xl font-bold leading-tight tracking-tight text-gray-900 md:text-2xl dark:text-white">
Expand Down Expand Up @@ -31,14 +31,6 @@
<input type="password" name="password_confirmation" id="password_confirmation" placeholder="{{ __('auth.register.confirm-password.placeholder') }}" class="bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-primary-600 focus:border-primary-600 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required>
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
</div>
<div class="flex items-start">
<div class="flex items-center h-5">
<input id="terms" aria-describedby="terms" type="checkbox" class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800" required="">
</div>
<div class="ml-3 text-sm">
<label for="terms" class="font-light text-gray-500 dark:text-gray-300">{{ __('auth.register.accept-terms')}} <a class="font-medium text-primary-600 hover:underline dark:text-primary-500" href="#">{{ __('auth.register.accept-terms-link')}}</a></label>
</div>
</div>
<button type="submit" class="w-full text-white bg-primary-600 hover:bg-primary-700 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800">{{ __('auth.register.button-register') }}</button>
<p class="text-sm font-light text-gray-500 dark:text-gray-400">
{{ __('auth.register.have-account')}} <a href="{{ route('login') }}" class="font-medium text-primary-600 hover:underline dark:text-primary-500">{{ __('auth.register.to-login') }}</a>
Expand Down
6 changes: 5 additions & 1 deletion resources/views/components/shared/logo-title.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<a href="#" class="flex items-center mb-6 text-2xl font-semibold text-gray-900 dark:text-white">
@props([
'href' => '#',
])

<a href="{{ $href }}" class="flex items-center mb-6 text-2xl font-semibold text-gray-900 dark:text-white">
<x-application-logo class="w-8 h-8 mr-3 fill-current" />
{{ env('APP_NAME') }}
</a>
3 changes: 0 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::view('contact', 'components.pages.contact')->name('contact');
Route::view('about', 'components.pages.about')->name('about');

Route::redirect('/home', '/');

Route::get('/', function (Request $request) {
Expand Down

0 comments on commit 16ed0c9

Please sign in to comment.