Mark notifications as read when user views the JO. User is redirected to the JO when clicking the View JO action. #433
This commit is contained in:
parent
00ae620878
commit
3a57c484a2
3 changed files with 76 additions and 0 deletions
|
|
@ -6,3 +6,9 @@ notification_rows:
|
|||
path: /notifications/rows
|
||||
controller: App\Controller\NotificationController::rows
|
||||
methods: [POST]
|
||||
|
||||
# ajax call
|
||||
notification_ajax_read:
|
||||
path: /notifications/read
|
||||
controller: App\Controller\NotificationController::markNotificationRead
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ namespace App\Controller;
|
|||
use App\Entity\Notification;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
|
@ -87,6 +89,11 @@ class NotificationController extends Controller
|
|||
$row['id'] = $orow->getID();
|
||||
$row['message'] = $orow->getMessage();
|
||||
$row['notif_type'] = $orow->getNotificationTypeName();
|
||||
$row['jo_id'] = $orow->getJobOrder()->getID();
|
||||
$row['flag_read'] = $orow->isNotificationRead();
|
||||
|
||||
// add row metadata
|
||||
$row['meta']['view_jo_url'] = $this->generateUrl('jo_walkin_edit_form', ['id' => $row['jo_id']]);
|
||||
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
|
@ -97,4 +104,26 @@ class NotificationController extends Controller
|
|||
'data' => $rows
|
||||
]);
|
||||
}
|
||||
|
||||
public function markNotificationRead(EntityManagerInterface $em, Request $req)
|
||||
{
|
||||
$id = $req->request->get('id');
|
||||
|
||||
$notif = $em->getRepository(Notification::class)->find($id);
|
||||
// make sure this notification exists
|
||||
if (empty($notif)) {
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => 'No notification found.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$notif->setReadNotification();
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $this->json([
|
||||
'success' => 'Changes have been saved!'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,17 @@
|
|||
serverFiltering: true,
|
||||
serverSorting: true
|
||||
},
|
||||
rows: {
|
||||
beforeTemplate: function(row, data, index) {
|
||||
console.log(data.flag_read);
|
||||
if (data.flag_read) {
|
||||
$(row).addClass('m-table__row--primary');
|
||||
}
|
||||
else {
|
||||
$(row).addClass('m-table__row--danger');
|
||||
}
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'id',
|
||||
|
|
@ -68,10 +79,40 @@
|
|||
field: 'notif_type',
|
||||
title: 'Notification Type'
|
||||
},
|
||||
{
|
||||
field: 'Actions',
|
||||
width: 110,
|
||||
title: 'Actions',
|
||||
sortable: false,
|
||||
overflow: 'visible',
|
||||
template: function (row, index, datatable) {
|
||||
var actions = '';
|
||||
|
||||
if (row.meta.view_jo_url != '') {
|
||||
actions += '<a href="' + row.meta.view_jo_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit" data-id="' + row.id + '" title="View JO"><i class="la la-edit"></i></a>';
|
||||
}
|
||||
return actions;
|
||||
},
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var table = $("#data-rows").mDatatable(options);
|
||||
|
||||
$(document).on('click', '.btn-edit', function(e) {
|
||||
var url = $(this).prop('href');
|
||||
var id = $(this).data('id');
|
||||
console.log(id);
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
url: "{{ url('notification_ajax_read') }}",
|
||||
data: { id: id }
|
||||
}).done(function(response) {
|
||||
console.log(response);
|
||||
}).error(function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue