Commit 2f592b01f80b545ae7a6b7e2cbc4f42efd6ed128

Authored by Сергей П
1 parent a939109322
Exists in master

сообщения

Showing 13 changed files with 263 additions and 347 deletions Side-by-side Diff

app/Http/Controllers/EmployerController.php
... ... @@ -338,43 +338,10 @@ class EmployerController extends Controller
338 338 public function messages($type_message) {
339 339 $user_id = Auth()->user()->id;
340 340  
341   - $chats = Chat::query()
342   - ->with('user')
343   - ->with('worker')
344   - ->with('employer')
345   - ->with('last_message')
346   - ->withCount(['unread_messages' => function ($query) use($user_id) {
347   - $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
348   - }])
349   - ->where('user_id', '=', $user_id)
350   - ->orderByDesc('is_fixed')
351   - ->orderByDesc('last_message_date')
352   - ->paginate(5)
353   - ;
354   - //dd($chats);
355   -
356   - /*$messages_input = Message::query()->with('vacancies')->with('user_from')->
357   - Where('to_user_id', $user_id)->OrderByDesc('created_at');
358   -
359   - $messages_output = Message::query()->with('vacancies')->
360   - with('user_to')->where('user_id', $user_id)->
361   - OrderByDesc('created_at');
362   -
363   - $count_input = $messages_input->count();
364   - $count_output = $messages_output->count();
365   -
366   - if ($type_message == 'input') {
367   - $messages = $messages_input->paginate(5);
368   - }
369   -
370   - if ($type_message == 'output') {
371   - $messages = $messages_output->paginate(5);
372   - }*/
373   -
374   - //dd($user_id, $messages[2]->vacancies);
375   - //jobs);
  341 + $chats = Chat::get_user_chats($user_id);
  342 + $user_type = 'employer';
376 343  
377   - return view('employers.messages', compact('chats','user_id'));
  344 + return view('employers.messages', compact('chats','user_id', 'user_type'));
378 345 }
379 346  
380 347 // Диалог между пользователями
... ... @@ -392,18 +359,17 @@ class EmployerController extends Controller
392 359 where('id', $user2->id)->first();
393 360 }
394 361  
395   - $Messages = Message::query()->
396   - where('ad_employer_id', '=', $ad_employer)->
397   - where(function($query) use ($user1, $user2) {
398   - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
399   - })->orWhere(function($query) use ($user1, $user2) {
400   - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
401   - })->where('ad_employer_id', '=', $ad_employer)->OrderBy('created_at')->get();
402   -
403   - $id_vac = $Messages[$Messages->count() - 1]->ad_employer_id;
  362 + $Messages = Message::query()
  363 + ->where(function($query) use ($user1, $user2) {
  364 + $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
  365 + })
  366 + ->orWhere(function($query) use ($user1, $user2) {
  367 + $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
  368 + })
  369 + ->orderBy('created_at')
  370 + ->get()
  371 + ;
404 372  
405   - //$ad_employer = null;
406   - //if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first();
407 373 $sender = $user1;
408 374  
409 375 Message::where('user_id', '=', $user2->id)
... ... @@ -414,6 +380,18 @@ class EmployerController extends Controller
414 380 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages'));
415 381 }
416 382  
  383 + public function pin_chat(Request $request){
  384 + $chat_id = $request->get('id');
  385 + $is_fixed = $request->get('is_fixed');
  386 +
  387 + Chat::pin_chat($chat_id, $is_fixed);
  388 + }
  389 +
  390 + public function remove_chat(Request $request){
  391 + $chat_id = $request->get('id');
  392 + Chat::remove_chat($chat_id);
  393 + }
  394 +
417 395 // Регистрация работодателя
418 396 public function register_employer(Request $request) {
419 397 $params = $request->all();
app/Http/Controllers/WorkerController.php
... ... @@ -8,6 +8,7 @@ use App\Http\Requests\PrevCompanyRequest;
8 8 use App\Http\Requests\SertificationRequest;
9 9 use App\Models\Ad_employer;
10 10 use App\Models\ad_response;
  11 +use App\Models\Chat;
11 12 use App\Models\Dop_info;
12 13 use App\Models\infobloks;
13 14 use App\Models\Job_title;
... ... @@ -494,27 +495,10 @@ class WorkerController extends Controller
494 495 {
495 496 $user_id = Auth()->user()->id;
496 497  
497   - $messages_input = Message::query()->with('vacancies')->with('user_from')->
498   - Where('to_user_id', $user_id)->OrderByDesc('created_at');
  498 + $chats = Chat::get_user_chats($user_id);
  499 + $user_type = 'worker';
499 500  
500   - $messages_output = Message::query()->with('vacancies')->
501   - with('user_to')->where('user_id', $user_id)->
502   - OrderByDesc('created_at');
503   -
504   - $count_input = $messages_input->count();
505   - $count_output = $messages_output->count();
506   -
507   - if ($type_message == 'input') {
508   - $messages = $messages_input->paginate(5);
509   - }
510   -
511   - if ($type_message == 'output') {
512   - $messages = $messages_output->paginate(5);
513   - }
514   -
515   - //dd($messages);
516   - // Вернуть все 100%
517   - return view('workers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id'));
  501 + return view('workers.messages', compact('chats','user_id', 'user_type'));
518 502 }
519 503  
520 504 // Избранный
... ... @@ -840,28 +824,13 @@ class WorkerController extends Controller
840 824 }
841 825  
842 826 $Messages = Message::query()->
843   - //with('response')->
844   - where(function($query) use ($user1, $user2) {
845   - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
846   - })->orWhere(function($query) use ($user1, $user2) {
847   - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
848   - })->OrderBy('created_at')->get();
849   -
850   - $id_vac = null;
851   - /*foreach ($Messages as $it) {
852   - if (isset($it->response)) {
853   - foreach ($it->response as $r) {
854   - if (isset($r->ad_employer_id)) {
855   - $id_vac = $r->ad_employer_id;
856   - break;
857   - }
858   - }
859   - }
860   - if (!is_null($id_vac)) break;
861   - }*/
862   -
863   - //$ad_employer = null;
864   - //if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first();
  827 + where(function($query) use ($user1, $user2) {
  828 + $query->where('user_id', $user1->id)->where('to_user_id', $user2->id);
  829 + })->orWhere(function($query) use ($user1, $user2) {
  830 + $query->where('user_id', $user2->id)->where('to_user_id', $user1->id);
  831 + })->OrderBy('created_at')
  832 + ->get()
  833 + ;
865 834  
866 835 return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer'));
867 836 }
... ... @@ -4,6 +4,7 @@ namespace App\Models;
4 4  
5 5 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 6 use Illuminate\Database\Eloquent\Model;
  7 +use Carbon\Carbon;
7 8  
8 9 class Chat extends Model
9 10 {
... ... @@ -40,4 +41,37 @@ class Chat extends Model
40 41 return $this->hasMany(Message::class, 'user_id', 'to_user_id');
41 42 }
42 43  
  44 + public static function pin_chat(int $chat_id, $fixed)
  45 + {
  46 + return self::where('id', '=', $chat_id)
  47 + ->update([
  48 + 'is_fixed' => !empty($fixed) ? 1 : 0,
  49 + 'fixation_date' => !empty($fixed) ? Carbon::now() : null
  50 + ]);
  51 + }
  52 +
  53 + public static function remove_chat(int $chat_id)
  54 + {
  55 + return self::where('id', '=', $chat_id)
  56 + ->update(['is_removed' => 1]);
  57 + }
  58 +
  59 + public static function get_user_chats(int $user_id){
  60 + return Chat::query()
  61 + ->with('user')
  62 + ->with('worker')
  63 + ->with('employer')
  64 + ->with('last_message')
  65 + ->withCount(['unread_messages' => function ($query) use($user_id) {
  66 + $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
  67 + }])
  68 + ->where('user_id', '=', $user_id)
  69 + ->where('is_removed', '=', 0)
  70 + ->orderByDesc('is_fixed')
  71 + ->orderByDesc('fixation_date')
  72 + ->orderByDesc('last_message_date')
  73 + ->paginate(5)
  74 + ;
  75 + }
  76 +
43 77 }
database/migrations/2024_07_19_063615_create_chat_table.php
... ... @@ -19,6 +19,7 @@ return new class extends Migration
19 19 $table->integer('to_user_id');
20 20 $table->boolean('is_removed')->default(false);
21 21 $table->boolean('is_fixed')->default(false);
  22 + $table->dateTime('fixation_date')->nullable(true);
22 23 $table->dateTime('last_message_date')->nullable(false);
23 24 $table->integer('last_message_id')->nullable(false);
24 25 $table->dateTime('fixed_time')->nullable(true);
public/css/style_may2024.css
... ... @@ -6748,23 +6748,12 @@ main + .news {
6748 6748 gap: 20px;
6749 6749 }
6750 6750 .messages__body {
6751   - display: -webkit-box;
6752   - display: -ms-flexbox;
6753   - display: flex;
6754   - -webkit-box-orient: vertical;
6755   - -webkit-box-direction: normal;
6756   - -ms-flex-direction: column;
6757   - flex-direction: column;
6758   - gap: 10px;
6759   - width: 100%;
6760   -}
6761   -@media (min-width: 768px) {
6762   - .messages__body {
6763   - gap: 20px;
6764   - }
  6751 + width: 100%;
  6752 + max-height: 800px;
  6753 + overflow: auto;
  6754 + padding: 5px;
6765 6755 }
6766 6756 .messages__item {
6767   - display: none;
6768 6757 -webkit-box-align: center;
6769 6758 -ms-flex-align: center;
6770 6759 align-items: center;
... ... @@ -6773,6 +6762,9 @@ main + .news {
6773 6762 background: linear-gradient(95deg, #f2f5fc 59.82%, #ebf2fc 99.99%);
6774 6763 padding: 10px;
6775 6764 font-size: 12px;
  6765 + display: flex;
  6766 + justify-content: space-between;
  6767 + margin-bottom: 20px;
6776 6768 }
6777 6769 @media (min-width: 768px) {
6778 6770 .messages__item {
... ... @@ -6780,12 +6772,6 @@ main + .news {
6780 6772 font-size: 18px;
6781 6773 }
6782 6774 }
6783   -.messages__item:nth-of-type(1), .messages__item:nth-of-type(2), .messages__item:nth-of-type(3), .messages__item:nth-of-type(4), .messages__item:nth-of-type(5), .messages__item:nth-of-type(6) {
6784   - display: -webkit-box;
6785   - display: -ms-flexbox;
6786   - display: flex;
6787   - justify-content: space-between;
6788   -}
6789 6775 .messages__item-info {
6790 6776 display: -webkit-box;
6791 6777 display: -ms-flexbox;
... ... @@ -6888,9 +6874,12 @@ main + .news {
6888 6874 .messages__item-buttons button:hover svg path{
6889 6875 stroke: black;
6890 6876 }
6891   -.messages__item-buttons button:hover svg#pin_on path{
  6877 +.messages__item-buttons button.pin-on:hover svg#pin_off path{
6892 6878 fill: black;
6893 6879 }
  6880 +.messages__item-buttons button.pin-on svg{
  6881 + fill: gray;
  6882 +}
6894 6883 .messages__item-date {
6895 6884 color: #00000070;
6896 6885 width: 90px;
... ... @@ -9305,3 +9294,26 @@ body .cke_notifications_area{
9305 9294 padding: 5px 10px;
9306 9295 border-radius: 45px;
9307 9296 }
  9297 +
  9298 +/* Диалог модал */
  9299 +.modal-dialog{
  9300 + border-radius: 10px;
  9301 +}
  9302 +.modal-dialog .modal-dialog-footer{
  9303 + display: flex;
  9304 + justify-content: space-between;
  9305 +}
  9306 +
  9307 +.button-loader {
  9308 + border: 2px solid #f3f3f3;
  9309 + -webkit-animation: spin 1s linear infinite;
  9310 + animation: spin 1s linear infinite;
  9311 + border-top: 2px solid #555;
  9312 + border-radius: 50%;
  9313 + width: 20px;
  9314 + height: 20px;
  9315 +}
  9316 +@keyframes spin {
  9317 + 0% { transform: rotate(0deg); }
  9318 + 100% { transform: rotate(360deg); }
  9319 +}
... ... @@ -0,0 +1,12 @@
  1 +
  2 +var spinStart = function(button) {
  3 + button.prop('disabled', true);
  4 + if (!button.find('.button-loader').length){
  5 + button.html('<div class="button-loader"></div>' + button.html());
  6 + }
  7 +};
  8 +
  9 +var spinStop= function(button) {
  10 + button.prop('disabled', false);
  11 + button.find('.button-loader').remove();
  12 +};
resources/views/chats/chats_list.blade.php
... ... @@ -0,0 +1,100 @@
  1 +@if ($chats->count())
  2 + @csrf
  3 + @foreach($chats as $chat)
  4 + <div class="messages__item hover-shadow {{ intval($chat->is_fixed) == 1 ? 'chat-fixed' : '' }}">
  5 + <div class="messages__item-info">
  6 + <div class="messages__item-photo">
  7 + <a class="" href="{{ route($user_type . '.dialog', ['user1' => $chat->user_id, 'user2' => $chat->to_user_id, 'ad_employer' => 0]) }}">
  8 + @if (isset($chat->employer->logo))
  9 + <img src="{{ asset(Storage::url($chat->employer->logo)) }}" alt="">
  10 + @elseif(isset($chat->worker->photo))
  11 + <img src="{{ asset(Storage::url($chat->worker->photo)) }}" alt="">
  12 + @else
  13 + <img src="{{ asset('images/default_man.jpg') }}" alt="">
  14 + @endif
  15 + </a>
  16 + </div>
  17 + <div class="messages__item-text">
  18 + <div>
  19 + <a class="messages__item-target" href="{{ route($user_type . '.dialog', ['user1' => $chat->user_id, 'user2' => $chat->to_user_id, 'ad_employer' => 0]) }}">
  20 + <b>
  21 + @if ($chat->employer && $chat->employer->name_company)
  22 + {{ $chat->employer->name_company }}
  23 + @else
  24 + {{ $chat->user->surname . ' ' . $chat->user->name_man . ' ' . $chat->user->surname2 }}
  25 + @endif
  26 + </b>
  27 + </a>
  28 + </div>
  29 + <div>
  30 + {{ $chat->last_message->text }}
  31 + </div>
  32 + </div>
  33 + </div>
  34 +
  35 + <div class="messages__item-actions" data-chat-id="{{ $chat->id }}">
  36 + <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}</div>
  37 + <div class="messages__item-buttons">
  38 + @if($chat->unread_messages_count > 0)
  39 + <div class="unread-messages-count mr-15">{{ $chat->unread_messages_count }}</div>
  40 + @endif
  41 +
  42 + <button class="pin-chat {{ intval($chat->is_fixed) == 1 ? 'pin-on' : 'pin-off' }} mr-15">
  43 + @include('svg.pin_off')
  44 + </button>
  45 + <button class="remove-chat" data-fancybox data-src="#remove_chat">
  46 + <svg>
  47 + <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use>
  48 + </svg>
  49 + </button>
  50 + </div>
  51 + <div class="clear"></div>
  52 + </div>
  53 + </div>
  54 + @endforeach
  55 + <div style="margin-top: 20px">
  56 + {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }}
  57 + </div><!-- конец -->
  58 +@else
  59 + <div class="notify">
  60 + <svg>
  61 + <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use>
  62 + </svg>
  63 + <span>Сообщений не найдено</span>
  64 + </div>
  65 +@endif
  66 +
  67 +<script>
  68 + $(function (){
  69 + $('.pin-chat').click(function(){
  70 + var this_btn = $(this);
  71 + var chat_id = this_btn.closest('.messages__item-actions').data('chat-id');
  72 + var $is_fixed = this_btn.hasClass('pin-on') ? 0 : 1;
  73 +
  74 + $.ajax({
  75 + type: "POST",
  76 + url: "{{ route('employer.pin_chat') }}",
  77 + data: {
  78 + id: chat_id,
  79 + is_fixed: $is_fixed
  80 + },
  81 + headers: {
  82 + 'X-CSRF-TOKEN': $('[name="_token"]').val()
  83 + },
  84 + success: function(){
  85 + location.reload();
  86 + }
  87 + });
  88 + });
  89 +
  90 + $('.remove-chat').click(function(){
  91 + var this_btn = $(this);
  92 + var chat_id = this_btn.closest('.messages__item-actions').data('chat-id');
  93 + var wrap = this_btn.closest('.messages__item');
  94 + var target = wrap.find('.messages__item-target').text();
  95 +
  96 + $('#remove_chat').data('chat-id', chat_id);
  97 + $('#remove_chat').find('.target-chat').text(target.trim());
  98 + });
  99 + });
  100 +</script>
resources/views/employers/dialog.blade.php
... ... @@ -92,15 +92,6 @@
92 92 </div>
93 93 <div class="messages__item-text">
94 94 <div>{{ $companion->surname." ".$companion->name_man." ".$companion->surname2." (".$companion->id.")" }} </div>
95   - <div><span>Вакансия:</span>
96   - @if ($ad_employer == 0)
97   - @if (isset($_GET['ad_name'])){{ $_GET['ad_name'] }}@else Не указано @endif
98   - @else
99   - <a href="{{ route('vacancie', ['vacancy' => $ad_employer]) }}">
100   - @if (isset($_GET['ad_name'])){{ $_GET['ad_name'] }} ({{ $ad_employer }}) @else Не указано @endif
101   - </a>
102   - @endif
103   - </div>
104 95 </div>
105 96 </div>
106 97 @if (isset($companion->workers[0]->id))
resources/views/employers/messages.blade.php
1 1 @extends('layout.frontend', ['title' => 'Сообщения от пользователей - РекаМоре'])
2 2 @section('scripts')
3   - <script>
4   - console.log('Test system');
5   - $(document).on('change', '#sort_ajax', function() {
6   - var this_ = $(this);
7   - var val_ = this_.val();
8   - console.log('sort items '+val_);
9 3  
10   - $.ajax({
11   - type: "GET",
12   - url: "{{ route('shipping_companies') }}",
13   - data: "sort="+val_+"&block=1",
14   - success: function (data) {
15   - console.log('Выбор сортировки');
16   - console.log(data);
17   - $('#block_1').html(data);
18   - },
19   - headers: {
20   - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
21   - },
22   - error: function (data) {
23   - data = JSON.stringify(data);
24   - console.log('Error: ' + data);
25   - }
26   - });
27   -
28   - $.ajax({
29   - type: "GET",
30   - url: "{{ route('shipping_companies') }}",
31   - data: "sort="+val_+"&block=2",
32   - success: function (data) {
33   - console.log('Выбор сортировки2');
34   - console.log(data);
35   - history.pushState({}, '', "{{ route('shipping_companies') }}?sort="+val_+"@if (isset($_GET['page']))&page={{ $_GET['page'] }}@endif");
36   - $('#block_2').html(data);
37   - },
38   - headers: {
39   - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
40   - },
41   - error: function (data) {
42   - data = JSON.stringify(data);
43   - console.log('Error: ' + data);
44   - }
45   - });
46   - });
47   - </script>
48 4 @endsection
49 5  
50 6 @section('content')
... ... @@ -71,70 +27,7 @@
71 27 <div class="cabinet__body-item">
72 28 <div class="messages">
73 29 <div class="messages__body">
74   - @if ($chats->count())
75   - @foreach($chats as $chat)
76   - <div class="">
77   - <a class="messages__item hover-shadow" href="{{ route('employer.dialog', ['user1' => $chat->user_id, 'user2' => $chat->to_user_id, 'ad_employer' => 0]) }}">
78   - <div class="messages__item-info">
79   - <div class="messages__item-photo">
80   - @if (isset($chat->worker->photo))
81   - <img src="{{ asset(Storage::url($chat->worker->photo)) }}" alt="">
82   - @else
83   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
84   - @endif
85   - </div>
86   - <div class="messages__item-text">
87   - <div>
88   - <b>
89   - @if ($chat->employer && $chat->employer->name_company)
90   - {{ $chat->employer->name_company }}
91   - @else
92   - {{ $chat->user->surname . ' ' . $chat->user->name_man . ' ' . $chat->user->surname2 }}
93   - @endif
94   - </b>
95   - </div>
96   - <div>
97   - {{ $chat->last_message->text }}
98   - </div>
99   - </div>
100   - </div>
101   -
102   - <div class="messages__item-actions">
103   - <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}</div>
104   - <div class="messages__item-buttons">
105   - @if($chat->unread_messages_count > 0)
106   - <div class="unread-messages-count mr-15">{{ $chat->unread_messages_count }}</div>
107   - @endif
108   -
109   - <button class="mr-15">
110   - @if(intval($chat->is_fixed) == 1)
111   - @include('svg.pin_on')
112   - @else
113   - @include('svg.pin_off')
114   - @endif
115   - </button>
116   - <button class="">
117   - <svg>
118   - <use xlink:href="{{ asset('images/sprite.svg#del') }}"></use>
119   - </svg>
120   - </button>
121   - </div>
122   - <div class="clear"></div>
123   - </div>
124   - </a>
125   - </div>
126   - @endforeach
127   - <div style="margin-top: 20px">
128   - {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }}
129   - </div><!-- конец -->
130   - @else
131   - <div class="notify">
132   - <svg>
133   - <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use>
134   - </svg>
135   - <span>Сообщений не найдено</span>
136   - </div>
137   - @endif
  30 + @include('chats.chats_list')
138 31 </div>
139 32 </div>
140 33 </div>
... ... @@ -142,5 +35,5 @@
142 35 </div>
143 36 </div>
144 37 </section>
145   - </div>
  38 + @include('modals.chats.remove_chat')
146 39 @endsection
resources/views/layout/frontend.blade.php
... ... @@ -8,6 +8,7 @@
8 8 <meta name="theme-color" content="#377D87">
9 9 <script src="{{ asset('js/jquery.js') }}"></script>
10 10 <script src="{{ asset('js/jquery-ui.js') }}"></script>
  11 + <script src="{{ asset('js/func.js') }}"></script>
11 12 <link rel="stylesheet" href="{{ asset('js/chosen/chosen.min.css') }}">
12 13 <script src="{{ asset('js/chosen/chosen.jquery.min.js') }}"></script>
13 14 <!--<script type="text/javascript" src=" asset('js/jquery.cookie.js') }}"></script>-->
resources/views/modals/chats/remove_chat.blade.php
... ... @@ -0,0 +1,36 @@
  1 +<div id="remove_chat" class="modal-dialog">
  2 + <div class="modal-dialog-title">
  3 + <h2>Удалить чат</h2>
  4 + </div>
  5 + <div class="modal-dialog-body">
  6 + <p>Вы действительно хотите удалить час с "<b><span class="target-chat"></span></b>"?</p>
  7 + </div>
  8 + <div class="modal-dialog-footer">
  9 + <button type="button" class="button remove-chat-button">Удалить</button>
  10 + <button type="button" class="button button_light" onclick="$.fancybox.close();">Закрыть</button>
  11 + </div>
  12 +</div>
  13 +
  14 +<script>
  15 + $(function(){
  16 + $('.remove-chat-button').click(function(){
  17 + spinStart($(this));
  18 + var wrap = $(this).closest('#remove_chat');
  19 + var chat_id = wrap.data('chat-id');
  20 +
  21 + $.ajax({
  22 + type: "POST",
  23 + url: "{{ route('employer.remove_chat') }}",
  24 + data: {
  25 + id: chat_id
  26 + },
  27 + headers: {
  28 + 'X-CSRF-TOKEN': $('[name="_token"]').val()
  29 + },
  30 + success: function(){
  31 + location.reload();
  32 + }
  33 + });
  34 + });
  35 + });
  36 +</script>
resources/views/workers/messages.blade.php
... ... @@ -25,129 +25,15 @@
25 25 <h2 class="title cabinet__title">Сообщения</h2>
26 26 </div>
27 27 <div class="cabinet__body-item">
28   - <div class="cabinet__filters">
29   - <div class="cabinet__filters-item">
30   - <div class="cabinet__filters-buttons">
31   - <a href="{{ route('worker.messages', ['type_message' => 'input']) }}" class="button button_light @if ($type_message == 'input') active @endif">Входящие ({{ $count_input }})</a>
32   - <a href="{{ route('worker.messages', ['type_message' => 'output']) }}" class="button button_light @if ($type_message == 'output') active @endif">Исходящие ({{ $count_output }})</a>
33   - </div>
  28 + <div class="messages">
  29 + <div class="messages__body">
  30 + @include('chats.chats_list')
34 31 </div>
35   - <!--<div class="cabinet__filters-item">
36   - <div class="select">
37   - <select class="js-select2" id="sort_ajax" name="sort_ajax">
38   - <option value="default">Сортировка (по умолчанию)</option>
39   - <option value="name (asc)">По имени (возрастание)</option>
40   - <option value="name (desc)">По имени (убывание)</option>
41   - <option value="created_at (asc)">По дате (возрастание)</option>
42   - <option value="created_at (desc)">По дате (убывание)</option>
43   - </select>
44   - </div>
45   - </div>-->
46 32 </div>
47   - @if ($messages->count())
48   - @foreach($messages as $it)
49   - <div class="messages__item">
50   - <div class="messages__item-info">
51   - <!--<pre> print_r(asset(Storage::url($it->user_from->employers[0]->logo))) }}</pre>-->
52   - <div class="messages__item-photo">
53   - <svg>
54   - <use xlink:href="{{ asset('images/sprite.svg#pic') }}"></use>
55   - </svg>
56   - <!-- Комментарий: обновление структуры вывода картинок, все корректное -->
57   - @if ($type_message == 'input')
58   - @if (isset($it->user_from->is_worker))
59   - @if ($it->user_from->is_worker)
60   - @if (isset($it->user_from->workers[0]->photo))
61   - <img src="{{ asset(Storage::url($it->user_to->workers[0]->photo)) }}" alt="">
62   - @else
63   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
64   - @endif
65   - @else
66   - @if (isset($it->user_from->employers[0]->logo))
67   - <img src="{{ asset(Storage::url($it->user_from->employers[0]->logo)) }}" alt="">
68   - @else
69   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
70   - @endif
71   - @endif
72   - @else
73   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
74   - @endif
75   - @endif
76   -
77   - <!-- Обновление исходящих сообщений - фотографии компании и работника -->
78   - <!-- коммит 2 -->
79   - @if ($type_message == 'output')
80   - @if (isset($it->user_from->is_worker))
81   - @if ($it->user_from->is_worker)
82   - @if (isset($it->user_from->workers[0]->photo))
83   - <img src="{{ asset(Storage::url($it->user_from->workers[0]->photo)) }}" alt="">
84   - @else
85   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
86   - @endif
87   - @else
88   - @if (isset($it->user_from->employers->logo))
89   - <img src="{{ asset(Storage::url($it->user_from->employers->logo)) }}" alt="">
90   - @else
91   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
92   - @endif
93   - @endif
94   - @else
95   - <img src="{{ asset('images/default_man.jpg') }}" alt="">
96   - @endif
97   - @endif
98   - </div>
99   - <div class="messages__item-text">
100   - <div>@if (isset($it->vacancies)) @php $ad_name = $it->vacancies->name; @endphp @else @php $ad_name = 'Вакансия удалена'; @endphp @endif
101   - От: @if (isset($it->user_from))
102   - @if ($it->user_from->id !== $user_id)
103   - <a href="{{ route('worker.dialog', ['user1' => $user_id, 'user2' => $it->user_from->id, 'ad_employer' => $it->ad_employer_id, 'ad_name' => $ad_name]) }}" style="text-decoration: underline">
104   - {{ $it->user_from->surname." ".$it->user_from->name_man." ".$it->user_from->surname2." (".$it->user_from->id.")" }}
105   - </a>
106   - @else
107   - {{ $it->user_from->surname." ".$it->user_from->name_man." ".$it->user_from->surname2." (".$it->user_from->id.")" }}
108   - @endif
109   - @else
110   - Удаленный пользователь
111   - @endif
112   - <br>
113   - К: @if (isset($it->user_to))
114   - @if ($it->user_to->id !== $user_id)
115   -
116   - <a href="{{ route('worker.dialog', ['user1' => $user_id, 'user2' => $it->user_to->id, 'ad_employer' => $it->ad_employer_id, 'ad_name' => $ad_name]) }}" style="text-decoration: underline">
117   - {{ $it->user_to->surname." ".$it->user_to->name_man." ".$it->user_to->surname2." (".$it->user_to->id.")" }}
118   - </a>
119   - @else
120   - {{ $it->user_to->surname." ".$it->user_to->name_man." ".$it->user_to->surname2." (".$it->user_to->id.")" }}
121   - @endif
122   - @else
123   - Удаленный пользователь
124   - @endif
125   - </div>
126   - <div><span>Вакансия:</span>@if (isset($it->vacancies)) {{ $it->vacancies->name." (".($it->vacancies->id).")" }} @else Удалена @endif</div>
127   - <div><span>Текст:</span>{{ $it->text }}</div>
128   - </div>
129   - </div>
130   - <div class="messages__item-date">{{ $it->created_at }}</div>
131   - </div>
132   - @endforeach
133   -
134   - <div style="margin-top: 20px">
135   - {{ $messages->onEachSide(0)->appends($_GET)->links('paginate') }}
136   - </div><!-- конец -->
137   -
138   - @else
139   - <div class="notify">
140   - <svg>
141   - <use xlink:href="{{ asset('images/sprite.svg#i') }}"></use>
142   - </svg>
143   - <span>Сообщений не найдено</span>
144   - </div>
145   - @endif
146 33 </div>
147 34 </div>
148 35 </div>
149 36 </div>
150 37 </section>
151   - </div>
152   - <div>
  38 + @include('modals.chats.remove_chat')
153 39 @endsection
... ... @@ -649,6 +649,9 @@ Route::group([
649 649  
650 650 // Отправил сообщение
651 651 Route::post('сообщение/', [EmployerController::class, 'new_message'])->name('new_message');
  652 +
  653 + Route::post('pin_chat/', [EmployerController::class, 'pin_chat'])->name('pin_chat');
  654 + Route::post('remove_chat/', [EmployerController::class, 'remove_chat'])->name('remove_chat');
652 655 });
653 656  
654 657 Route::get('TestWorker', [WorkerController::class, 'TestWorker'])->name('TestWorker');