Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to delete sizzle time entries from the front end #2856

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions website/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,10 @@ def search(self, request, *args, **kwargs):
query = request.query_params.get("q", "")
projects = Project.objects.filter(
Q(name__icontains=query)
| Q(description__icontains=query)
| Q(tags__name__icontains=query)
| Q(stars__icontains=query)
| Q(forks__icontains=query)
| Q(description__icontains(query)
| Q(tags__name__icontains(query)
| Q(stars__icontains(query)
| Q(forks__icontains(query)
DonnieBLT marked this conversation as resolved.
Show resolved Hide resolved
).distinct()

project_data = []
Expand Down Expand Up @@ -793,11 +793,11 @@ def filter(self, request, *args, **kwargs):
projects = Project.objects.all()

if freshness:
projects = projects.filter(freshness__icontains=freshness)
projects = projects.filter(freshness__icontains(freshness)
DonnieBLT marked this conversation as resolved.
Show resolved Hide resolved
if stars:
projects = projects.filter(stars__gte=stars)
projects = projects.filter(stars__gte(stars)
DonnieBLT marked this conversation as resolved.
Show resolved Hide resolved
if forks:
projects = projects.filter(forks__gte=forks)
projects = projects.filter(forks__gte(forks)
DonnieBLT marked this conversation as resolved.
Show resolved Hide resolved
if tags:
projects = projects.filter(tags__name__in=tags.split(",")).distinct()

Expand Down Expand Up @@ -857,7 +857,7 @@ def perform_create(self, serializer):
def start(self, request):
"""Starts a new time log"""
data = request.data
data["start_time"] = timezone.now() # Set start time to current tim
data["start_time"] = timezone.now() # Set start time to current time

serializer = self.get_serializer(data=data)
try:
Expand Down Expand Up @@ -895,6 +895,16 @@ def stop(self, request, pk=None):
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

def destroy(self, request, pk=None):
"""Deletes a time log"""
try:
timelog = self.get_object()
except ObjectDoesNotExist:
raise NotFound(detail="Time log not found.")

timelog.delete()
return Response({"detail": "Time log deleted successfully."}, status=status.HTTP_204_NO_CONTENT)


class ActivityLogViewSet(viewsets.ModelViewSet):
queryset = ActivityLog.objects.all()
Expand Down
41 changes: 39 additions & 2 deletions website/templates/sizzle/time_logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ <h2>Existing Time Logs</h2>
<th scope="col">End Time</th>
<th scope="col">Duration</th>
<th scope="col">GitHub Issue URL</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody id="time-logs-table-body">
{% for log in time_logs %}
{% if log.end_time %}
<tr>
<tr id="time-log-{{ log.id }}">
<td>{{ log.start_time|date:"DATETIME_FORMAT" }}</td>
<td>{{ log.end_time|date:"DATETIME_FORMAT" }}</td>
<td>{{ log.duration }}</td>
Expand All @@ -81,11 +82,14 @@ <h2>Existing Time Logs</h2>
target="_blank"
rel="noopener noreferrer">{{ log.github_issue_url }}</a>
</td>
<td>
<button class="btn btn-danger delete-button" data-log-id="{{ log.id }}">Delete</button>
</td>
</tr>
{% endif %}
{% empty %}
<tr>
<td colspan="4" class="text-center">No time logs available.</td>
<td colspan="5" class="text-center">No time logs available.</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -238,6 +242,39 @@ <h2>Existing Time Logs</h2>
}
});
});

// Handle Delete Time Log Button Click
$('.delete-button').on('click', function(){
const logId = $(this).data('log-id');

if (!confirm('Are you sure you want to delete this time log?')) {
return;
}

$.ajax({
url: `${apiBaseUrl}${logId}/`,
type: 'DELETE',
headers: {
'Authorization': `Token ${token}`,
'Content-Type': 'application/json'
},
success: function(data){
// Remove the deleted log from the table
$(`#time-log-${logId}`).remove();
},
error: function(xhr){
let error = 'An unexpected error occurred.';
if (xhr.responseJSON && xhr.responseJSON.detail) {
error = xhr.responseJSON.detail;
} else if (xhr.status === 0) {
error = 'Network error. Please check your connection.';
}
$('#message-container').html(`<div class="alert_box" role="alert">
Error: ${error}
</div>`);
}
});
});
});
})();
</script>
Expand Down
Loading