diff --git a/apps/home/urls.py b/apps/home/urls.py index 3c7f478..3c52a97 100644 --- a/apps/home/urls.py +++ b/apps/home/urls.py @@ -1,25 +1,20 @@ # -*- encoding: utf-8 -*- -from django.urls import path, re_path, include +from django.urls import path, include +from django.shortcuts import redirect from apps.home import views from .views import TicketView +def reverse_to_index(reqeust): + return redirect("dashboard") + urlpatterns = [ - - # The home page - path('', views.index, name='home'), - - # Custom Dashboard + path("", reverse_to_index, name="index"), path('dashboard/', views.dashboard, name="dashboard"), path('tickets/', include([ path('', TicketView.as_view(), name="tickets"), path('new/', views.new_ticket, name="ticket-new"), - path('get/', include([ - path('one/', views.get_ticket, name="ticket-getone"), - path('many/', views.get_tickets, name="ticket-getmany"), - path("filtercounts/", views.get_filter_counts, name="ticket-getfiltercounts"), - ])), ])), # # Matches any html file diff --git a/apps/home/views.py b/apps/home/views.py index 4a459ab..71cff0f 100644 --- a/apps/home/views.py +++ b/apps/home/views.py @@ -29,13 +29,11 @@ class TicketView(TemplateView): @method_decorator(login_required) def get(self, request): - tickets = Ticket.objects.all().order_by("-create_timestamp") priorities = TicketPriority.objects.all() tags = TicketTag.objects.all() departments = Department.objects.all() context = { - "tickets": tickets, "priorities": priorities, "tags": tags, "departments": departments, @@ -44,108 +42,6 @@ class TicketView(TemplateView): return render(request, "home/tickets.html", context) - # @method_decorator(login_required) - # @require_POST - # def fetch_ticket(self, request) -> JsonResponse: - # ticket = Ticket.objects.get(id=request.POST.get("ticket_id")) - # context = {"ticket": ticket.serialize()} - # return JsonResponse(context) - - # @method_decorator(login_required) - # @require_POST - # def fetch_tickets(self, request) -> JsonResponse: - # filters = json.loads(request.POST.get("filters", "{}")) - # queryset = Ticket.objects.all() - - # for key, values in filters.items(): - # print(key, values) - - # for value in values: - # if value == "all": continue # don't apply a filter if we want all - # queryset = queryset.filter(**{key: [value]}) - - # tickets = queryset.order_by("-create_timestamp") - - # context = {"tickets": [ticket.serialize() for ticket in tickets]} - - # return JsonResponse(context) - - # @method_decorator(login_required) - # @require_POST - # def fetch_filter_counts(self, request) -> JsonResponse: - # priorities = TicketPriority.objects.all() - # tags = TicketTag.objects.all() - # departments = Department.objects.all() - - # tickets = Ticket.objects.all() - - # context = { - # "priority_counts": {}, - # "tag_counts": {}, - # "department_counts": {}, - # "ticket_count": tickets.count() - # } - - # for priority in priorities: - # priority_count = tickets.filter(priority=priority).count() - # context["priority_counts"][str(priority.id)] = priority_count - - # for tag in tags: - # tag_count = tickets.filter(tags__in=[tag]).count() - # context["tag_counts"][str(tag.id)] = tag_count - - # for department in departments: - # department_count = tickets.filter(author__department=department).count() - # context["department_counts"][str(department.id)] = department_count - - # return JsonResponse(context) - - # @method_decorator(login_required) - # @require_POST - # def new_ticket(self, request) -> JsonResponse: - - # getall = lambda *keys: [request.POST.get(key) for key in keys] - # getlist = lambda key: request.POST.getlist(key) - - # title, description, author_id, priority_id = getall( - # "title", "description", "author_id", "priority_id" - # ) - # tag_ids = getlist("tag_ids[]") - - # author = get_user_model().objects.get(id=author_id) - # priority = TicketPriority.objects.get(id=priority_id) - # tags = [ - # tag for tag in TicketTag.objects.filter(id__in=tag_ids) - # ] - - # ticket = Ticket.objects.create( - # title=title, - # description=description, - # author=author, - # priority=priority, - # ) - # ticket.tags.set(tags) - - # return JsonResponse({"success": "ticket created successfully"}) - - -@login_required() -def tickets(request): - tickets = Ticket.objects.all().order_by("-create_timestamp") - priorities = TicketPriority.objects.all() - tags = TicketTag.objects.all() - departments = Department.objects.all() - - context = { - "tickets": tickets, - "priorities": priorities, - "tags": tags, - "departments": departments, - "dayago": datetime.now() - timedelta(hours=24) - } - - return render(request, "home/tickets.html", context) - @login_required @require_POST @@ -239,14 +135,6 @@ def new_ticket(request): return JsonResponse({"success": "ticket created successfully"}) -@login_required() -def index(request): - context = {'segment': 'index'} - - html_template = loader.get_template('home/index.html') - return HttpResponse(html_template.render(context, request)) - - @login_required() def pages(request): context = {} diff --git a/apps/templates/home/tickets.html b/apps/templates/home/tickets.html index d9a04bb..49165c7 100644 --- a/apps/templates/home/tickets.html +++ b/apps/templates/home/tickets.html @@ -123,59 +123,35 @@
-
-
- - - +
- + + -
-
-
-
- - +
+ Showing Results +
-
- +
@@ -187,50 +163,25 @@
- - - -
- + + - -
- - + +
@@ -247,7 +198,7 @@
-
+
@@ -494,12 +445,8 @@ function loadFilterCounts() { $.ajax({ - url: "{% url 'ticket-getfiltercounts' %}", - type: "POST", - dataType: "json", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}" - }, + url: "{% url 'api:filter-counts' %}", + type: "GET", success: function(data) { console.log(JSON.stringify(data, null, 4)); @@ -507,6 +454,7 @@ updateFilterCounts('tag', data); updateFilterCounts('department', data); $("#filterPriorityAll .badge").text(data.ticket_count); + $("#ticketCount").text(data.ticket_count) }, error: function(data) { @@ -517,19 +465,17 @@ function loadAllTickets() { $("#ticketsContainer").empty(); + // alert(JSON.stringify(filters, null, 4)); $.ajax({ - url: "{% url 'ticket-getmany' %}", - type: "POST", + url: "{% url 'api:ticket' %}", + type: "GET", dataType: "json", - data: { - csrfmiddlewaretoken: "{{ csrf_token }}", - filters: JSON.stringify(filters) - }, + data: filters, success: function(data) { console.log(JSON.stringify(data, null, 4)) - data.tickets.forEach(function(ticket) { + data.forEach(function(ticket) { var timestamp = new Date(ticket.timestamp); var formattedTime; @@ -583,10 +529,10 @@ }); }, error: function(data) { - alert(JSON.stringify(data, null, 4)) + alert(JSON.stringify(data, null, 4)); + console.error(`${data.responseJSON.error}\n${data.responseJSON.detail}`); } }); - } function displayTicket(ticketElement) { @@ -621,17 +567,16 @@ displayedTicketID = ticketID; $.ajax({ - url: `{% url 'ticket-getone' %}`, - type: 'POST', + url: `{% url 'api:ticket' %}`, + type: 'get', dataType: 'json', data: { - csrfmiddlewaretoken: '{{ csrf_token }}', - ticket_uuid: ticketID + uuid__in: [ticketID] }, success: function (data) { console.log(JSON.stringify(data, null, 4)); - var ticket = data.ticket; + var ticket = data[0]; var author = ticket.author; var department = author.department; var priority = ticket.priority;