Skip to content

Commit 843b40c

Browse files
Merge pull request #838 from GhostManager/hotfix/fixed-pfp-distortion
Improved display of profile pictures
2 parents 5ff5167 + e0c14b0 commit 843b40c

File tree

8 files changed

+89
-11
lines changed

8 files changed

+89
-11
lines changed

ghostwriter/home/forms.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def __init__(self, *args, **kwargs):
3535
"""
3636
<h4 class="icon avatar-upload-icon">Avatar Upload</h4>
3737
<hr>
38-
<p>Your new avatar should be a square (equal height and width) for the best looking results.</p>
39-
Previews for images will appear below.</p>
38+
<p>Your avatar will be displayed as a circle and automatically cropped to fit. For best results,
39+
upload a square image (equal height and width) or ensure your face is centered in the image.</p>
40+
<p>Previews for images will appear below.</p>
4041
<div id="avatarPreview" class="pb-3"></div>
4142
"""
4243
),

ghostwriter/reporting/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __init__(self, *args, **kwargs):
218218
self.helper.layout = Layout(
219219
HTML(
220220
"""
221-
<h4 class="icon signature-icon">Report Information</h4>
221+
<h4 class="icon edit-icon">Evidence Information</h4>
222222
<hr>
223223
<p>The friendly name is used to reference this evidence in the report and the caption appears below
224224
the figures in the generated reports.</p>

ghostwriter/reporting/templates/reporting/evidence_detail.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ <h4 class="icon file-icon">File Contents</h4>
106106
<script src="{% static 'js/evidence-lightbox.js' %}"></script>
107107
<script>
108108
$(document).ready(function() {
109-
console.log('Evidence detail page loaded');
109+
// console.log('Evidence detail page loaded');
110110

111111
// Initialize evidence lightbox
112112
if (typeof initEvidenceLightbox === 'function') {
113-
console.log('initEvidenceLightbox function found');
113+
// console.log('initEvidenceLightbox function found');
114114
initEvidenceLightbox();
115115
} else {
116116
console.error('initEvidenceLightbox function not found');
117117
}
118118

119119
// Check if elements exist
120-
console.log('Clickable elements found:', $('.js-open-lightbox').length);
120+
// console.log('Clickable elements found:', $('.js-open-lightbox').length);
121121
});
122122
</script>
123123
{% endblock %}

ghostwriter/reporting/templates/reporting/evidence_form.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
{% block pagetitle %}Evidence Form{% endblock %}
44

5+
{% block breadcrumbs %}
6+
<nav aria-label="breadcrumb">
7+
<ul class="breadcrumb">
8+
<li class="breadcrumb-item"><a href="{% url 'home:dashboard' %}">Dashboard</a></li>
9+
<li class="breadcrumb-item"><a href="{% url 'rolodex:client_detail' report.project.client.id %}">{{ report.project.client.name }}</a></li>
10+
<li class="breadcrumb-item"><a href="{% url 'rolodex:project_detail' report.project.id %}">{{ report.project }}</a></li>
11+
<li class="breadcrumb-item"><a href="{% url 'reporting:report_detail' report.id %}">{{ report }}</a></li>
12+
<li class="breadcrumb-item active" aria-current="page">Evidence Form</li>
13+
</ul>
14+
</nav>
15+
{% endblock %}
16+
517
{% block content %}
618
{% include "reporting/evidence_form_template.html" with form=form %}
719
{% endblock %}

ghostwriter/reporting/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ def get_context_data(self, **kwargs):
731731
report = self.finding_instance.report
732732
else:
733733
report = self.report_instance
734+
ctx["report"] = report
734735
ctx["cancel_link"] = reverse("reporting:report_detail", kwargs={"pk": report.pk}) + "#evidence"
735736
if "modal" in self.kwargs:
736737
friendly_names = self.evidence_queryset.values_list("friendly_name", flat=True)
@@ -818,6 +819,7 @@ def get_form_kwargs(self):
818819

819820
def get_context_data(self, **kwargs):
820821
ctx = super().get_context_data(**kwargs)
822+
ctx["report"] = self.object.associated_report
821823
ctx["cancel_link"] = reverse(
822824
"reporting:evidence_detail",
823825
kwargs={"pk": self.object.pk},

ghostwriter/static/css/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ label {
251251
top: 15px;
252252
right: 25px;
253253
border-color: rgba(255, 255, 255, 0.3);
254+
object-fit: cover;
254255
}
255256

256257
/* ---------------------------------------------------
@@ -538,6 +539,7 @@ input[type='file'] {
538539
position: relative;
539540
display: inline-block;
540541
border-color: rgba(255, 255, 255, 0.3);
542+
object-fit: cover;
541543
}
542544

543545
.avatar_note {
@@ -546,6 +548,7 @@ input[type='file'] {
546548
border-radius: 50%;
547549
border-style: solid;
548550
border-width: 1px;
551+
object-fit: cover;
549552
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
550553
}
551554

ghostwriter/static/js/project.js

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,70 @@ function showHideRow(btn, row) {
178178
// Insert a preview for pasted or selected image files
179179
function renderPreview(fileInput, previewDiv) {
180180
if (fileInput.files[0].type.indexOf('image') == 0) {
181-
previewDiv.innerHTML = '<img id="loadedImage" alt="image"/ >'
182-
let loadedImage = document.getElementById('loadedImage')
183-
loadedImage.src = URL.createObjectURL(fileInput.files[0])
181+
// Clear previous content
182+
while (previewDiv.firstChild) {
183+
previewDiv.removeChild(previewDiv.firstChild);
184+
}
185+
186+
const loadedImage = document.createElement('img');
187+
loadedImage.alt = 'image';
188+
loadedImage.src = URL.createObjectURL(fileInput.files[0]);
184189
loadedImage.style.border = 'thin solid #555555';
190+
previewDiv.appendChild(loadedImage);
191+
}
192+
}
193+
194+
// Insert avatar-specific previews showing how the image will appear in navbar and profile
195+
function renderAvatarPreview(fileInput, previewDiv) {
196+
if (fileInput.files[0].type.indexOf('image') == 0) {
197+
// Clear previous content
198+
while (previewDiv.firstChild) {
199+
previewDiv.removeChild(previewDiv.firstChild);
200+
}
201+
202+
// Create container
203+
const container = document.createElement('div');
204+
container.style.display = 'flex';
205+
container.style.alignItems = 'center';
206+
container.style.justifyContent = 'center';
207+
container.style.gap = '20px';
208+
container.style.flexWrap = 'wrap';
209+
210+
// Create navbar preview section
211+
const navbarSection = document.createElement('div');
212+
const navbarLabel = document.createElement('p');
213+
const navbarStrong = document.createElement('strong');
214+
navbarStrong.textContent = 'Navbar Preview (40x40)';
215+
navbarLabel.appendChild(navbarStrong);
216+
const navbarImg = document.createElement('img');
217+
navbarImg.alt = 'Navbar preview';
218+
navbarImg.className = 'navbar-avatar';
219+
navbarImg.style.position = 'static';
220+
navbarSection.appendChild(navbarLabel);
221+
navbarSection.appendChild(navbarImg);
222+
223+
// Create profile preview section
224+
const profileSection = document.createElement('div');
225+
const profileLabel = document.createElement('p');
226+
const profileStrong = document.createElement('strong');
227+
profileStrong.textContent = 'Profile Preview (250x250)';
228+
profileLabel.appendChild(profileStrong);
229+
const profileImg = document.createElement('img');
230+
profileImg.alt = 'Profile preview';
231+
profileImg.className = 'avatar';
232+
profileImg.style.position = 'static';
233+
profileSection.appendChild(profileLabel);
234+
profileSection.appendChild(profileImg);
235+
236+
// Assemble and append
237+
container.appendChild(navbarSection);
238+
container.appendChild(profileSection);
239+
previewDiv.appendChild(container);
240+
241+
// Set image sources
242+
const imageUrl = URL.createObjectURL(fileInput.files[0]);
243+
navbarImg.src = imageUrl;
244+
profileImg.src = imageUrl;
185245
}
186246
}
187247

ghostwriter/users/templates/users/profile_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
if (pastedFileObj.files.length) {
6464
fileInput.files = pastedFileObj.files
6565
filename.textContent = fileInput.files[0].name
66-
renderPreview(fileInput, previewDiv)
66+
renderAvatarPreview(fileInput, previewDiv)
6767
}
6868
});
6969
// Detect when a file is dragged into the page and update the input and preview
7070
$('input[type=file]').on('change', function () {
7171
let filename = $(this).val().split('\\').pop();
7272
$('#filename').text(filename);
73-
renderPreview(fileInput, previewDiv)
73+
renderAvatarPreview(fileInput, previewDiv)
7474
});
7575
</script>
7676
{% endblock %}

0 commit comments

Comments
 (0)