Skip to content

Commit

Permalink
Implement dashboard driver and status order feature (#5) (#6)
Browse files Browse the repository at this point in the history
* Finish feature add available time

* Remove unused import statement

* Change url and icon of sidebar

* Add forbidden page

* Implement dashboard driver and status order feature
  • Loading branch information
sabynn authored Dec 10, 2022
1 parent fbf9b10 commit 3397cb6
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 51 deletions.
96 changes: 96 additions & 0 deletions dashboard_driver/static/js/change_status_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
function accept_order(id_order){
console.log(id_order)
$.ajax({
url: "/respons-order/accept-order",
type: "POST",
data:{
id_order: id_order,
},
success: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Success accept the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#4fbe87",
}).showToast()
},
failed: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Failed accept the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#ff0000",
}).showToast()
},
})
}

function reject_order(id_order){
$.ajax({
url: "/respons-order/reject-order",
type: "POST",
data:{
id_order: id_order,
},
success: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Success reject the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#4fbe87",
}).showToast()
},
failed: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Failed reject the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#ff0000",
}).showToast()
},
})
}

function finish_order(id_order){
$.ajax({
url: "/respons-order/finish-order",
type: "POST",
data:{
id_order: id_order,
},
success: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Success finish the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#4fbe87",
}).showToast()
},
failed: function(response) {
document.getElementById(id_order).remove()
Toastify({
text: "Failed finish the order",
duration: 3000,
close: true,
gravity: "top",
position: "center",
backgroundColor: "#ff0000",
}).showToast()
},
})
}
126 changes: 112 additions & 14 deletions dashboard_driver/templates/dashboard_driver/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,116 @@
{% extends 'base.html' %}
{% load static %}
{% block meta %}
<link
href="{% static 'assets/extensions/datatables.net-bs5/css/dataTables.bootstrap5.min.css'%}"
rel="stylesheet"
type="text/css"
/>
<link href="{% static 'assets/css/pages/datatables.css' %}" rel="stylesheet" type="text/css"/>
<link href="{% static 'assets/css/pages/fontawesome.css' %}" rel="stylesheet" type="text/css"/>
<link
href="{% static 'assets/extensions/toastify-js/src/toastify.css' %}"
rel="stylesheet"
/>
{% endblock meta %}
{% block content %}

<h1>Dashboard Driver!</h1>
<div class="page-heading">
<div class="page-title">
<div class="row">
<div class="col-12 col-md-6 order-md-1 order-last">
<h3>{{ title }}</h3>
<p class="text-subtitle text-muted">
Your current {{ title|lower }}(s)
</p>
</div>
</div>
</div>

<table>
<thead>
<th>pending_order</th>
</thead>
<tbody>
{% for entry in pending_order %}
<tr>
<td>{{entry.order_date}}</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- Basic Tables start -->
<section class="section">
<div class="card">
<div class="card-body">
<table class="table" id="table1">
<thead>
<tr>
<th>Pickup Location</th>
<th>Destination Location</th>
<th>Order Date</th>
<th>Pickup Date</th>
<th>Distance</th>
<th>Fee</th>
<th>Customer</th>
{% if title == 'Accepted Order' or title == 'Rejected Order' or title == 'Finished Order'%}
<th>Status</th>
{% endif %}
{% if title == 'Pending Order' or title == 'Accepted Order' %}
<th>Action</th>
{% endif %}

{% endblock content %}
</tr>
</thead>
<tbody>
{% for entry in order %}
<tr id="{{entry.id}}">
<td>{{entry.pickup_location}}</td>
<td>{{entry.destination_location}}</td>
<td>{{entry.order_date}}</td>
<td>{{entry.pickup_date}}</td>
<td>{{entry.distance}}</td>
<td>{{entry.fee}}</td>
<td>{{entry.customer.user}}</td>
{% if title == 'Accepted Order'%}
<td class="justify-content-center">
<span class="badge bg-success">Accepted</span>
</td>
{% endif %}
{% if title == 'Rejected Order'%}
<td class="justify-content-center">
<span class="badge bg-danger">Rejected</span>
</td>
{% endif %}
{% if title == 'Finished Order' %}
<td class="justify-content-center">
<span class="badge bg-primary">Finished</span>
</td>
{% endif %}
{% if title == 'Pending Order' %}
<td class="justify-content-center">
<button type="button" class="btn btn-success rounded-pill m-1" onclick="accept_order({{entry.id}})"
>Accept</button
>
<a onclick="reject_order({{entry.id}})" class="btn btn-danger rounded-pill m-1" href="#"
>Reject</a
>
</td>
{% endif %}
{% if title == 'Accepted Order' %}
<td class="justify-content-center">
<button type="button" class="btn btn-primary rounded-pill m-1" onclick="finish_order({{entry.id}})"
>Finish</button
>
</td>
{% endif %}

</tr>

{% endfor %}
</tbody>
</table>
</div>
</div>
</section>
<!-- Basic Tables end -->
</div>

{% endblock content %}
{% block script %}
<script src="{% static 'assets/extensions/jquery/jquery.min.js' %}"></script>
<script rel="javascript" type="text/javascript" src="{% static 'js/change_status_order.js' %}"></script>

<script src="https://cdn.datatables.net/v/bs5/dt-1.12.1/datatables.min.js" type="text/javascript"></script>
<script src="{% static 'assets/js/pages/datatables.js' %}"></script>
<script src="{% static 'assets/extensions/toastify-js/src/toastify.js' %}"></script>
<script src="{% static 'js/add_available_time.js' %}"></script>
{% endblock script %}
37 changes: 26 additions & 11 deletions dashboard_driver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
def addAvailableTime(request):
user = request.user
form = AddAvailableTimeForm(request.POST)
is_driver = check_user_role(request.user)
is_driver = check_user_role(user)

if not is_driver:
return render(request, "forbidden_page.html")

context = {
'is_driver': is_driver,
'form': form
Expand Down Expand Up @@ -50,9 +54,6 @@ def addAvailableTime(request):
"models": driver.available_time.all()}
return render(request, 'dashboard_driver/add_available_time.html', context, status=200)

if request.is_ajax():

return JsonResponse()
return JsonResponse({"failed": "Not using right method"}, status=405)


Expand All @@ -61,13 +62,27 @@ def addAvailableTime(request):
def getDriverOrder(request):
user = request.user
if request.method == 'GET':
is_driver = check_user_role(user)
if not is_driver:
return render(request, "forbidden_page.html")
driver = Driver.objects.get(user=user)
dashboard_driver = DashboardDriver.objects.get(driver=driver)
value = {
"accepted_order": list(dashboard_driver.order.filter(status=OrderStatus.ACCEPTED)),
"rejected_order": list(dashboard_driver.order.filter(status=OrderStatus.REJECTED)),
"pending_order": list(dashboard_driver.order.filter(status=OrderStatus.PENDING)),
"history_order": list(dashboard_driver.order.filter(status=OrderStatus.FINISHED)),
}
return render(request, "dashboard_driver/index.html", value)
status = request.GET.get('status')

context = {"is_driver": is_driver}
if status == 'accepted':
context["order"] = list(dashboard_driver.order.filter(status=OrderStatus.ACCEPTED))
context["title"] = "Accepted Order"
elif status == 'rejected':
context["order"] = list(dashboard_driver.order.filter(status=OrderStatus.REJECTED))
context["title"] = "Rejected Order"
elif status == 'pending':
context["order"] = list(dashboard_driver.order.filter(status=OrderStatus.PENDING))
context["title"] = "Pending Order"
print(dashboard_driver.order.all())
elif status == 'finished':
context["order"] = list(dashboard_driver.order.filter(status=OrderStatus.FINISHED))
context["title"] = "Finished Order"

return render(request, "dashboard_driver/index.html", context)
return JsonResponse({"failed": "Not using GET method"}, status=405)
25 changes: 25 additions & 0 deletions main/templates/forbidden_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% load static %}

{% block content %}
<div id="error">
<div class="error-page container">
<div class="col-md-8 col-12 offset-md-2">
<div class="text-center">
<img
class="img-error"
src="{% static 'assets/images/samples/error-403.svg'%}"
alt="Not Found"
/>
<h1 class="error-title">Forbidden</h1>
<p class="fs-5 text-gray-600">
You are unauthorized to see this page.
</p>
<a href="{% url 'main:home'%}" class="btn btn-lg btn-outline-primary mt-3"
>Go Home</a
>
</div>
</div>
</div>
</div>
{% endblock content %}
5 changes: 3 additions & 2 deletions respons_order/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
app_name = 'respons_order'
from django.urls import path
from .views import accept_order, reject_order
from .views import accept_order, reject_order, finish_order

urlpatterns = [
path('accept-order', accept_order, name="accept_order"),
path('reject-order', reject_order, name="reject_order")
path('reject-order', reject_order, name="reject_order"),
path('finish-order', finish_order, name="finish_order")
]
Loading

0 comments on commit 3397cb6

Please sign in to comment.