Skip to content

Commit

Permalink
button shifted to report-ip-list page
Browse files Browse the repository at this point in the history
  • Loading branch information
krrish-sehgal committed Nov 13, 2024
2 parents 0679af0 + 1acbf2c commit 0a25030
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 110 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ langchain-openai = "^0.1.25"
unstructured = "^0.16.5"
Markdown = "^3.6"
faiss-cpu = "^1.8.0"
openai = "^1.54.3"
openai = "^1.54.4"
psutil = "^5.9.8"
python-bitcoinrpc = "^1.0"
sendgrid = "^6.11.0"
Expand Down
33 changes: 18 additions & 15 deletions website/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ class Meta:
"subscribed_users": forms.CheckboxSelectMultiple(),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance and self.instance.user:
# Populate email from user model
self.fields["email"].initial = self.instance.user.email

def save(self, commit=True):
profile = super().save(commit=False)
if commit:
# Save email to User model
if self.instance and self.instance.user:
self.instance.user.email = self.cleaned_data["email"]
self.instance.user.save()
profile.save()
return profile
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# print("UserProfileForm __init__")
# print(self.instance)
# print(self.instance.user)
# if self.instance and self.instance.user:
# # Populate email from user model
# self.fields["email"].initial = self.instance.user.email

# def save(self, commit=True):
# profile = super().save(commit=False)
# if commit:
# # Save email to User model
# if self.instance and self.instance.user:
# self.instance.user.email = self.cleaned_data["email"]
# self.instance.user.save()
# profile.save()
# return profile


class UserDeleteForm(forms.Form):
Expand Down
9 changes: 0 additions & 9 deletions website/templates/includes/sidenav.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@
<span>Bug Bounties</span>
</a>
</li>
<li class="mb-2 {% if request.path == '/report-ip/' %}bg-gray-200{% endif %}">
<a href="{% url 'report_ip' %}"
class="flex items-center w-full text-black no-underline p-2">
<div class="icon text-purple-500">
<i class="fas fa-network-wired fa-lg mr-2"></i>
</div>
<span>Report an IP</span>
</a>
</li>
<li class="mb-2 {% if request.path == '/reported-ips/' %}bg-gray-200{% endif %}">
<a href="{% url 'reported_ips_list' %}"
class="flex items-center w-full text-black no-underline p-2">
Expand Down
27 changes: 26 additions & 1 deletion website/templates/reported_ips_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,31 @@
font-size: 1.4rem;
color: #333;
}
a.floating-report-ip-button {
position: fixed;
bottom: 50px;
left: 220px;
padding: 10px 15px;
background-color: #c51919; /* Red background */
color: #fff; /* White text */
text-decoration: none;
border-radius: 5px;
font-weight: bold;
display: inline-flex;
align-items: center;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
transition: transform 0.3s ease;
z-index: 1000;
}

a.floating-report-ip-button:hover {
transform: scale(1.1); /* Hover effect */
}

a.floating-report-ip-button i {
margin-right: 6px;
}
</style>
<h1>Reported IPs</h1>
<div class="report-container">
{% for ip in reported_ips %}
<div class="report-card" onclick="toggleExpand(this)">
Expand Down Expand Up @@ -170,6 +192,9 @@ <h1>Reported IPs</h1>
<i class="fab fa-figma"></i>
</a>
</div>
<a href="{% url 'report_ip' %}" class="floating-report-ip-button">
<i class="fas fa-exclamation-triangle"></i> Report an IP
</a>
<script>
function toggleExpand(card) {
const descriptionContent = card.querySelector(".description-content");
Expand Down
164 changes: 85 additions & 79 deletions website/templates/sizzle/sizzle.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h1 class="text-4xl font-semibold text-gray-800 mb-8">Your Sizzle Report</h1>
<td class="py-3 px-4 border-b border-gray-200">
{% if user.is_authenticated %}
<button class="delete-entry bg-red-500 text-white py-1 px-3 rounded"
data-id="{{ entry.id }}">Delete</button>
data-id="{{ sizzle_data.id }}">Delete</button>
{% endif %}
</td>
</tr>
Expand Down Expand Up @@ -147,90 +147,96 @@ <h1 class="text-4xl font-semibold text-gray-800 mb-8">Your Sizzle Report</h1>
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script type="text/javascript">
$(function() {
$('input[name="daterange"]').daterangepicker({
opens: 'left',
locale: {
format: 'YYYY-MM-DD'
}
}, function(start, end, label) {
$('#report-date').text(start.format('D.M.YYYY') + ' - ' + end.format('D.M.YYYY') + ' Report');

// Fetch and update report logs
$.ajax({
url: '{% url "timelogsreport" %}',
data: {
start_date: start.format('YYYY-MM-DDTHH:mm:ssZ'),
end_date: end.format('YYYY-MM-DDTHH:mm:ssZ')
},
success: function(data) {
// if success the report-table div will be fully clean and the new data will be added for each item in the data added like present item
$('#report-table').empty();
data.forEach(function(item) {
$('#report-table').append(`
<div class="bg-white shadow-lg rounded-lg overflow-hidden mb-8">
<div class="bg-red-500 text-white text-center py-4 text-lg font-semibold">
${item.date}
</div>
<table class="min-w-full bg-white">
<thead>
<tr class="bg-red-500 text-white text-sm uppercase tracking-wider">
<th class="text-left py-3 px-4 border-b border-gray-200">Issue Title</th>
<th class="text-left py-3 px-4 border-b border-gray-200">Started</th>
<th class="text-left py-3 px-4 border-b border-gray-200">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td class="py-3 px-4 border-b border-gray-200">${item.issue_title}</td>
<td class="py-3 px-4 border-b border-gray-200">${item.start_time}</td>
<td class="py-3 px-4 border-b border-gray-200">${item.duration}</td>
<td class="py-3 px-4 border-b border-gray-200">
{% if user.is_authenticated %}
<button class="delete-entry bg-red-500 text-white py-1 px-3 rounded" data-id="${item.id}">
Delete
</button>
{% endif %}
</td>
</tr>
</tbody>
</table>
$(function() {
// Initialize daterange picker
$('input[name="daterange"]').daterangepicker({
opens: 'left',
locale: {
format: 'YYYY-MM-DD'
}
}, function(start, end, label) {
$('#report-date').text(start.format('D.M.YYYY') + ' - ' + end.format('D.M.YYYY') + ' Report');

// Fetch and update report logs
$.ajax({
url: '{% url "timelogsreport" %}',
data: {
start_date: start.format('YYYY-MM-DDTHH:mm:ssZ'),
end_date: end.format('YYYY-MM-DDTHH:mm:ssZ')
},
success: function(data) {
// Clear existing content and append the new data
$('#report-table').empty();
data.forEach(function(item) {
$('#report-table').append(`
<div class="bg-white shadow-lg rounded-lg overflow-hidden mb-8">
<div class="bg-red-500 text-white text-center py-4 text-lg font-semibold">
${item.date}
</div>
`);
});
<table class="min-w-full bg-white">
<thead>
<tr class="bg-red-500 text-white text-sm uppercase tracking-wider">
<th class="text-left py-3 px-4 border-b border-gray-200">Issue Title</th>
<th class="text-left py-3 px-4 border-b border-gray-200">Started</th>
<th class="text-left py-3 px-4 border-b border-gray-200">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td class="py-3 px-4 border-b border-gray-200">${item.issue_title}</td>
<td class="py-3 px-4 border-b border-gray-200">${item.start_time}</td>
<td class="py-3 px-4 border-b border-gray-200">${item.duration}</td>
<td class="py-3 px-4 border-b border-gray-200">
<button class="delete-entry bg-red-500 text-white py-1 px-3 rounded" data-id="${item.id}">
Delete
</button>
<span>Item ID: ${item.id}</span>
</td>
</tr>
</tbody>
</table>
</div>
`);
});
},
error: function(xhr, status, error) {
alert('An error occurred while fetching the report logs.');
}
});
});

// Event delegation for dynamically added delete buttons (moved outside the AJAX success callback)
$(document).on('click', '.delete-entry', function() {
var entryId = $(this).data('id');
if (!entryId) {
console.error("Entry ID is missing or empty.");
return;
}
if (confirm("Are you sure you want to delete this time entry?")) {
fetch("{% url 'delete_time_entry' %}", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-CSRFToken": "{{ csrf_token }}",
},
error: function(xhr, status, error) {
alert('An error occurred while fetching the report logs.');
body: new URLSearchParams({ id: entryId }),
})
.then(response => response.json())
.then(data => {
if (data.success) {
console.log("Success");
// Remove the row from the table if the delete was successful
this.closest("tr").remove();
} else {
console.log("Failed");
alert("Failed to delete time entry.");
}
});
});
}
});
});

document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll(".delete-entry").forEach(function(button) {
button.addEventListener("click", function() {
const entryId = this.getAttribute("data-id");
if (confirm("Are you sure you want to delete this time entry?")) {
fetch("{% url 'delete_time_entry' %}", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": "{{ csrf_token }}",
},
body: JSON.stringify({ id: entryId }),
})
.then(response => response.json())
.then(data => {
if (data.success) {
this.closest("tr").remove();
} else {
alert("Failed to delete time entry.");
}
});
}
});
});
});

</script>
{% endif %}
{% endblock content %}
2 changes: 1 addition & 1 deletion website/views/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ def get_context_data(self, **kwargs):

if self.request.user.is_authenticated:
context["wallet"] = Wallet.objects.get(user=self.request.user)
context["issue_count"] = Issue.objects.filter(url__contains=self.object.domain_name.count())
context["issue_count"] = Issue.objects.filter(url__contains=self.object.domain_name).count()
context["all_comment"] = self.object.comments.all
context["all_users"] = User.objects.all()
context["likes"] = UserProfile.objects.filter(issue_upvoted=self.object).count()
Expand Down
2 changes: 2 additions & 0 deletions website/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ def TimeLogListAPIView(request):
formatted_date = first_log.created.strftime("%d %B %Y")

day_data = {
"id": first_log.id,
"issue_title": issue_title,
"duration": formatted_duration,
"start_time": start_time,
Expand Down Expand Up @@ -1059,6 +1060,7 @@ def sizzle(request):
date = last_data.created.strftime("%d %B %Y")

sizzle_data = {
"id": last_data.id,
"issue_title": issue_title,
"duration": formatted_duration,
"start_time": start_time,
Expand Down

0 comments on commit 0a25030

Please sign in to comment.