diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index f16a305..65cf509 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -138,12 +138,46 @@ class CompanyController extends Controller $list_employers = Employer::query()->active()->orderBy('name_company')->get(); if ($request->ajax()) { - return view('admin.employer_main.index_ajax', compact('employers', 'list_employers')); + return view('admin.employer_main.table', compact('employers', 'list_employers')); } else { return view('admin.employer_main.index', compact('employers', 'list_employers')); } } + public function employers_main_add(Request $request) + { + $page = $request->get('page', 1); + $page = intval($page); + + employers_main::insert([ + 'employer_id' => 0, + 'sort' => 100 + ]); + + $pageSize = 10; + $offset = ($page - 1) * $pageSize; + $employers = employers_main::query()->OrderBy('sort')->offset($offset)->limit($pageSize)->get(); + $list_employers = Employer::query()->active()->orderBy('name_company')->get(); + return view('admin.employer_main.table', compact('employers', 'list_employers')); + } + + public function employers_main_remove(Request $request) + { + $id = $request->get('id', 0); + $page = $request->get('page', 1); + $page = intval($page); + + if ($id !== 0) { + employers_main::where('id', $id)->delete(); + } + + $pageSize = 10; + $offset = ($page - 1) * $pageSize; + $employers = employers_main::query()->OrderBy('sort')->offset($offset)->limit($pageSize)->get(); + $list_employers = Employer::query()->active()->orderBy('name_company')->get(); + return view('admin.employer_main.table', compact('employers', 'list_employers')); + } + //////////// кабинет - редактор seo-сайта ///////////////////////////// public function editor_seo() { $pages = SEO::query()->OrderBy('url')->paginate(15); diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index 77c1c24..be96eb7 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -496,15 +496,13 @@ class EmployerController extends Controller $params = $request->all(); $user1 = $params['user_id']; $user2 = $params['to_user_id']; - $id_vacancy = $params['ad_employer_id']; - $ad_name = $params['ad_name']; $rules = [ - 'text' => 'required|min:1|max:150000', - 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' + 'text' => 'nullable|required_without:file|min:1|max:150000', + 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' ]; $messages = [ - 'required' => 'Укажите обязательное поле', + 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', 'min' => [ 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 'integer' => 'Поле «:attribute» должно быть :min или больше', @@ -526,8 +524,7 @@ class EmployerController extends Controller ->first() ; if ($chat->id){ - return redirect()->route('employer.dialog', ['chat' => $chat->id]) - ->withErrors($validator); + return redirect()->route('employer.dialog', ['chat' => $chat->id])->withErrors($validator); } else { return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); } diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 7431e0e..03d9a89 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -1033,15 +1033,13 @@ class WorkerController extends Controller $params = $request->all(); $user1 = $params['user_id']; $user2 = $params['to_user_id']; - $id_vacancy = $params['ad_employer_id']; - $ad_name = $params['ad_name']; $rules = [ - 'text' => 'required|min:1|max:150000', - 'file' => 'file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' + 'text' => 'nullable|required_without:file|min:1|max:150000', + 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' ]; $messages = [ - 'required' => 'Укажите обязательное поле', + 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', 'min' => [ 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 'integer' => 'Поле «:attribute» должно быть :min или больше', @@ -1057,8 +1055,17 @@ class WorkerController extends Controller $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { - return redirect()->route('worker.dialog', ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]) - ->withErrors($validator); + $chat = Chat::where('user_id', $user1) + ->where('to_user_id', $user2) + ->where('is_removed', 0) + ->first() + ; + + if ($chat->id){ + return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator); + } else { + return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); + } } else { $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); diff --git a/app/Models/Message.php b/app/Models/Message.php index bdbc333..26ff776 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -24,6 +24,7 @@ class Message extends Model 'chat_id_from', 'chat_id_to', 'reply_message_id', + 'original_file_name', ]; @@ -57,7 +58,9 @@ class Message extends Model $message_params['user_id'] = $user_id; $message_params['to_user_id'] = $to_user_id; if ($request && $request->has('file')) { - $message_params['file'] = $request->file('file')->store($file_store_path, 'public'); + $file = $request->file('file'); + $message_params['file'] = $file->store($file_store_path, 'public'); + $message_params['original_file_name'] = $file->getClientOriginalName(); } $chat_form = Chat::firstOrCreate([ diff --git a/database/migrations/2024_08_16_172341_alter_table_messages.php b/database/migrations/2024_08_16_172341_alter_table_messages.php new file mode 100644 index 0000000..2ef1fc1 --- /dev/null +++ b/database/migrations/2024_08_16_172341_alter_table_messages.php @@ -0,0 +1,32 @@ +string('original_file_name', 255)->nullable(true)->after('file'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('messages', function (Blueprint $table) { + $table->dropColumn('original_file_name'); + }); + } +}; diff --git a/public/css/general.css b/public/css/general.css index 0f631a2..12987ec 100644 --- a/public/css/general.css +++ b/public/css/general.css @@ -27,6 +27,7 @@ /* Конец Диалог модал */ .button-loader { + display: inline-block; border: 2px solid #f3f3f3; -webkit-animation: spin 1s linear infinite; animation: spin 1s linear infinite; diff --git a/public/css/style_may2024.css b/public/css/style_may2024.css index 544fe03..8746134 100644 --- a/public/css/style_may2024.css +++ b/public/css/style_may2024.css @@ -7214,6 +7214,29 @@ main + .news { padding: 10px; line-height: 1.6; } +.chatbox__item-body-file-name-wrap{ + display: flex; + align-items: center; +} +.chatbox__item-body-file-name-wrap svg{ + height: 20px; + width: 20px; +} +.chatbox__item-body-file-name-wrap a{ + margin-left: 20px; + border-radius: 8px; + padding: 2px 8px; + -webkit-box-shadow: inset 0px 0px 14px -7px rgba(66, 68, 90, 1); + -moz-box-shadow: inset 0px 0px 14px -7px rgba(66, 68, 90, 1); + box-shadow: inset 0px 0px 14px -7px rgba(66, 68, 90, 1); +} +.chatbox__item_reverse .chatbox__item-body-file-name-wrap a{ + margin-left: 0px; + margin-right: 20px; +} +.chatbox__item-body-file-name-wrap a:hover{ + box-shadow: 0px 0px 5px 1px rgb(139 136 136); +} .chatbox__item-text .admin-chat-answer{ padding: 2px 5px; height: auto; diff --git a/resources/views/admin/employer_main/index.blade.php b/resources/views/admin/employer_main/index.blade.php index 07dbe9b..c5c09d3 100644 --- a/resources/views/admin/employer_main/index.blade.php +++ b/resources/views/admin/employer_main/index.blade.php @@ -5,20 +5,18 @@ $(document).ready(function() { $(document).on('change', '.check_js', function () { var this_ = $(this); - var id = this_.attr('id'); + var wrap = this_.closest('tr'); + var id = wrap.data('id'); var field = this_.attr('data-field'); var value = this_.val(); var ajax_block = $('#ajax_block'); var str ="id=" + id + "&"+ field + "=" + value; - console.log(str); + $.ajax({ type: "GET", url: "{{ url()->full()}}", data: str, success: function (data) { - console.log('Обновление таблицы пользователей '); - //data = JSON.parse(data); - //console.log(data); ajax_block.html(data); }, headers: { @@ -30,39 +28,66 @@ }); }); + $(document).on('click', '.employers-main-remove-button', function(){ + spinStart($(this)); + var this_btn = $(this); + var wrap = this_btn.closest('tr'); + var id = wrap.data('id'); + + @php + $page = request()->get('page'); + @endphp + + $.ajax({ + type: "POST", + url: "{{ route('admin.employers-main-remove')}}", + data: { + id: id, + page: {{ $page }} + }, + success: function (data) { + $('#ajax_block').html(data); + }, + headers: { + 'X-CSRF-TOKEN': $('[name="_token"]').val() + }, + error: function (data) { + console.log('Error: ' + data); + } + }); + }); + + $(document).on('click', '.employers-main-add-button', function(){ + spinStart($(this)); + var this_btn = $(this); + + @php + $page = request()->get('page'); + @endphp + + $.ajax({ + type: "POST", + url: "{{ route('admin.employers-main-add')}}", + data:{ + page: {{ $page }} + }, + success: function (data) { + spinStop(this_btn); + $('#ajax_block').html(data); + }, + headers: { + 'X-CSRF-TOKEN': $('[name="_token"]').val() + }, + error: function (data) { + console.log('Error: ' + data); + } + }); + }); + }); @endsection -@section('search') - -@endsection - @section('content') + @csrf +
+ +
-
- - - - - - - - - - - @foreach($employers as $emp) - - - - - - - @endforeach - -
Название пунктаНазвание компанииСортировка
- {{$emp->id}} - - {{$emp->name}} - - - - -
-
- -
- appends($_GET)->links('admin.pagginate'); ?> -
+ @include('admin.employer_main.table')
+
+ appends($_GET)->links('admin.pagginate'); ?> +
+ @endsection diff --git a/resources/views/admin/employer_main/index_ajax.blade.php b/resources/views/admin/employer_main/index_ajax.blade.php deleted file mode 100644 index 9e9b6b9..0000000 --- a/resources/views/admin/employer_main/index_ajax.blade.php +++ /dev/null @@ -1,63 +0,0 @@ -
- - - - - - - - - - - - - - - - - - - -
Название пунктаНазвание компанииСортировка
- {{$emp->id}} - - {{$emp->name}} - - - - -
-
- -
- appends($_GET)->links('admin.pagginate'); ?> -
diff --git a/resources/views/admin/employer_main/table.blade.php b/resources/views/admin/employer_main/table.blade.php new file mode 100644 index 0000000..f59eee4 --- /dev/null +++ b/resources/views/admin/employer_main/table.blade.php @@ -0,0 +1,53 @@ +
+ + + + + + + + + + @foreach($employers as $emp) + + + + + + @endforeach + +
Название компанииСортировка
+ + + + + +
+
diff --git a/resources/views/employers/dialog.blade.php b/resources/views/employers/dialog.blade.php index 383e4fe..456258b 100644 --- a/resources/views/employers/dialog.blade.php +++ b/resources/views/employers/dialog.blade.php @@ -5,6 +5,11 @@ $(function(){ var chatbox_div = $('.chatbox__list'); chatbox_div.scrollTop(chatbox_div.prop("scrollHeight")); + + $('form.chatbox__bottom [name="file"]').on('change', function() { + var fileName = $(this).val().split('\\').pop(); + $('.chatbox-file-name-wrap').text('Добавлен файл: ' + fileName); + }); }); $(document).on('change', '#send_btn', function() { @@ -173,14 +178,33 @@
-
- {{ $it->text }} - @if($it->reply_message_id) -
- {{ $it->reply_message->text }} + @if($it->text || $it->reply_message_id) +
+ {{ $it->text ?? '' }} + + @if($it->reply_message_id) +
+ {{ $it->reply_message->text }} +
+ @endif +
+ @endif + @if ((isset($it->file)) && (!empty($it->file))) +
+
+ @if($it->original_file_name) + {{ $it->original_file_name }} + @else + + + + @endif
- @endif -
+ + Скачать + +
+ @endif
{{ $it->created_at }}
@@ -209,13 +233,24 @@
-
{{ $it->text }}
+ @if($it->text) +
{{ $it->text }}
+ @endif @if ((isset($it->file)) && (!empty($it->file))) - - - - - +
+ + Скачать + +
+ @if($it->original_file_name) + {{ $it->original_file_name }} + @else + + + + @endif +
+
@endif
{{ $it->created_at }}
@@ -225,26 +260,29 @@ @endforeach @endif -
- @csrf - - - - - - - - -
+
+
+ @csrf + + + + + + + + +
+
+
diff --git a/resources/views/workers/dialog.blade.php b/resources/views/workers/dialog.blade.php index 35919ae..7de2fdd 100644 --- a/resources/views/workers/dialog.blade.php +++ b/resources/views/workers/dialog.blade.php @@ -6,6 +6,11 @@ var chatbox_div = $('.chatbox__list'); chatbox_div.scrollTop(chatbox_div.prop("scrollHeight")); + $('form.chatbox__bottom [name="file"]').on('change', function() { + var fileName = $(this).val().split('\\').pop(); + $('.chatbox-file-name-wrap').text('Добавлен файл: ' + fileName); + }); + $('.admin-chat-answer').click(function(){ var modal = $('#answer_from_admin_chat_modal'); @@ -182,7 +187,25 @@ @endif
-
{{ $it->text }}
+ @if($it->text) +
{{ $it->text }}
+ @endif + @if ((isset($it->file)) && (!empty($it->file))) +
+
+ @if($it->original_file_name) + {{ $it->original_file_name }} + @else + + + + @endif +
+ + Скачать + +
+ @endif
{{ $it->created_at }}
@@ -214,6 +237,7 @@ @endif
+ @if($chat->is_admin_chat || $it->text || $it->reply_message_id)
@if($chat->is_admin_chat)
+ @endif @if ((isset($it->file)) && (!empty($it->file))) - - - - - +
+ + Скачать + +
+ @if($it->original_file_name) + {{ $it->original_file_name }} + @else + + + + @endif +
+
@endif
{{ $it->created_at }}
@@ -247,26 +283,29 @@ @endif @if(!$chat->is_admin_chat) -
- @csrf - - - - - - - - -
+
+
+ @csrf + + + + + + + + +
+
+
@endif diff --git a/routes/web.php b/routes/web.php index 8df3177..827dd5e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -337,6 +337,8 @@ Route::group([ // кабинет - редактор работодатели на главной Route::get('employers-main', [CompanyController::class, 'employers_main'])->name('employers-main'); + Route::post('employers-main-add', [CompanyController::class, 'employers_main_add'])->name('employers-main-add'); + Route::post('employers-main-remove', [CompanyController::class, 'employers_main_remove'])->name('employers-main-remove'); // кабинет - редактор seo-сайта