Skip to content

Commit dc64c1f

Browse files
authored
Merge pull request #2456 from JisanAR03/company_dashboard_domain
update the whole domain system in company dashboard
2 parents 2e60585 + b974a44 commit dc64c1f

File tree

6 files changed

+764
-209
lines changed

6 files changed

+764
-209
lines changed

company/templates/company/add_domain.html

Lines changed: 84 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,18 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Domain Information</
136136
<label for="webshot"
137137
class="relative cursor-pointer rounded-md bg-white font-semibold text-red-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-red-600 focus-within:ring-offset-2 hover:text-red-500">
138138
<span class="text-red-600">Upload a webshot</span>
139-
<input id="webshot" name="webshot" type="file" class="sr-only" />
139+
<input id="webshot"
140+
name="webshot"
141+
type="file"
142+
class="sr-only"
143+
onchange="displayWebshotPreview()" />
140144
</label>
141145
<p class="pl-1">or drag and drop</p>
142146
</div>
143147
<p class="text-xs leading-5 text-gray-600">PNG, JPG, GIF up to 10MB</p>
144148
</div>
145149
</div>
150+
<div id="webshotPreview" class="mt-4"></div>
146151
</div>
147152
</div>
148153
</div>
@@ -152,13 +157,13 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Domain Managers</h2>
152157
Add Emails which will be allowed to start hunts and manage reported bugs.
153158
Email should be domain mail and should be registerd user on BLT.
154159
</p>
155-
<button onclick="add_email_container()"
160+
<button onclick="add_user_selection()"
156161
type="button"
157162
class="w-[120px] h-[40px] bg-red-500 text-white font-bold rounded-md mt-2 hover:bg-red-600 transition-all">
158-
Add Email
163+
Add User
159164
</button>
160-
<div class="sm:col-span-4 mt-5" id="email-container">
161-
<label for="email" class="block text-sm font-medium leading-6 text-gray-900">Email address</label>
165+
<div class="sm:col-span-4 mt-5" id="user-selection-container">
166+
<label for="user" class="block text-sm font-medium leading-6 text-gray-900">Select Domain Manager</label>
162167
</div>
163168
</div>
164169
<div class="border-b border-gray-900/10 pb-12 mt-5">
@@ -199,9 +204,6 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
199204
</div>
200205
</div>
201206
<div class="mt-6 flex items-center justify-end gap-x-6">
202-
<button type="button"
203-
onclick="cancelForm()"
204-
class="text-md font-semibold leading-6 text-gray-900">Cancel</button>
205207
<button type="submit"
206208
class="rounded-md bg-red-600 px-11 py-3 text-md font-semibold text-white shadow-sm hover:bg-red-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-red-600">
207209
Save
@@ -212,38 +214,53 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
212214
{% endblock body %}
213215
{% block js %}
214216
<script>
215-
function remove_email_container(){
216-
let email_container = document.getElementById("email-container");
217-
let lst_child = email_container.lastElementChild;
218-
email_container.removeChild(lst_child);
217+
function remove_user_selection(event) {
218+
let user_container = document.getElementById("user-selection-container");
219+
let parentDiv = event.target.closest('.user-selection');
220+
user_container.removeChild(parentDiv);
221+
updateUserSelections();
219222
}
220223

221-
function add_email_container(){
222-
const email_container_child_html = document.createElement('div');
223-
email_container_child_html.innerHTML = `
224-
<div class="mt-2 flex flex-row items-center w-[50%]">
225-
<input name="email" type="email" autocomplete="email" required class="w-[90%] block rounded-md border-0 py-1.5 pl-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-red-600 sm:text-sm sm:leading-6" />
226-
<button type="button" onclick="remove_email_container()">
227-
<i class="fa-sharp fa-solid fa-trash fa-lg text-[#596780] ml-4 hover:text-black"></i>
228-
</button>
229-
</div>
224+
function add_user_selection() {
225+
const user_selection_child_html = document.createElement('div');
226+
user_selection_child_html.classList.add('mt-2', 'flex', 'flex-row', 'items-center', 'w-[50%]', 'user-selection');
227+
user_selection_child_html.innerHTML = `
228+
<select name="user" class="w-[90%] block rounded-md border-0 py-1.5 pl-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-red-600 sm:text-sm sm:leading-6" onchange="updateUserSelections()">
229+
${getUserOptions([])}
230+
</select>
231+
<button type="button" onclick="remove_user_selection(event)">
232+
<i class="fa-sharp fa-solid fa-trash fa-lg text-[#596780] ml-4 hover:text-black"></i>
233+
</button>
230234
`;
231235

232-
let email_container = document.getElementById("email-container");
233-
email_container.appendChild(email_container_child_html)
236+
let user_container = document.getElementById("user-selection-container");
237+
user_container.appendChild(user_selection_child_html);
238+
updateUserSelections();
234239
}
235240

236-
</script>
237-
<script>
238-
function cancelForm(){
239-
let deleteForm = document.getElementById("deleteForm");
240-
let confirmDelete = confirm("Are you sure you want to cancel, your progress would be lost.");
241-
if (confirmDelete === true){
242-
deleteForm.submit();
243-
}
241+
function getUserOptions(excludeList) {
242+
let optionsHtml = '<option value="" disabled selected>Select a user</option>';
243+
{% for user in users %}
244+
if (!excludeList.includes('{{ user.email }}')) {
245+
optionsHtml += `<option value="{{ user.email }}">{{ user.username }} ({{ user.email }})</option>`;
246+
}
247+
{% endfor %}
248+
return optionsHtml;
249+
}
250+
251+
function updateUserSelections() {
252+
const selects = document.querySelectorAll('#user-selection-container select');
253+
const selectedUsers = Array.from(selects).map(select => select.value);
254+
255+
selects.forEach(select => {
256+
const currentValue = select.value;
257+
select.innerHTML = getUserOptions(selectedUsers.filter(user => user !== currentValue));
258+
select.value = currentValue; // Preserve the current value after options are updated
259+
});
244260
}
245261

246262

263+
247264
function displayLogoPreview() {
248265
var fileInput = document.getElementById("logo");
249266
var previewDiv = document.getElementById("previewLogoDiv");
@@ -265,5 +282,41 @@ <h2 class="text-base font-semibold leading-7 text-gray-900">Notifications</h2>
265282
}
266283
}
267284

285+
function displayWebshotPreview() {
286+
var fileInput = document.getElementById("webshot");
287+
var previewDiv = document.getElementById("webshotPreview");
288+
289+
if (fileInput.files.length > 0) {
290+
var file = fileInput.files[0];
291+
var reader = new FileReader();
292+
293+
reader.onload = function(event) {
294+
var img = new Image();
295+
img.src = event.target.result;
296+
297+
img.onload = function() {
298+
var canvas = document.createElement("canvas");
299+
var ctx = canvas.getContext("2d");
300+
301+
var maxDim = 300;
302+
var scale = Math.min(maxDim / img.width, maxDim / img.height);
303+
304+
canvas.width = img.width * scale;
305+
canvas.height = img.height * scale;
306+
307+
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
308+
309+
previewDiv.innerHTML = "";
310+
previewDiv.style.display = "flex";
311+
previewDiv.style.justifyContent = "center";
312+
previewDiv.appendChild(canvas);
313+
};
314+
};
315+
316+
reader.readAsDataURL(file);
317+
} else {
318+
previewDiv.innerHTML = "";
319+
}
320+
}
268321
</script>
269322
{% endblock js %}

company/templates/company/company_manage_domains.html

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h5 class="text-xl font-bold leading-none text-gray-900">All Domains</h5>
4141
<div class="flex items-center space-x-4">
4242
<div class="flex-shrink-0">
4343
<img class="w-8 h-8 rounded-full"
44-
src="{{ MEDIA_URL }}{{ domain.logo }}"
44+
src="{% if domain.logo %}{{ MEDIA_URL }}{{ domain.logo }}{% else %}https://via.placeholder.com/50?text=No+Logo{% endif %}"
4545
alt="Domain Logo"
4646
width="32px"
4747
height="32px">
@@ -51,15 +51,21 @@ <h5 class="text-xl font-bold leading-none text-gray-900">All Domains</h5>
5151
<p class="text-sm text-gray-500 truncate dark:text-gray-400">{{ domain.url }}</p>
5252
</div>
5353
<div class="inline-flex items-center text-base font-semibold text-gray-900 ">
54-
<a href="{% url 'view_domain' domain.id %}">View</a>
54+
<a href="{% url 'edit_domain' company domain.id %}">Edit</a>
55+
<a class="ml-4" href="{% url 'view_domain' domain.id %}">View</a>
5556
<form id="deleteForm"
56-
action="{% url 'add_domain' company %}?domain={{ domain.id }}"
57+
action="{% url 'add_domain' company %}"
5758
method="post"
5859
class="inline">
5960
{% csrf_token %}
6061
<input type="hidden" name="_method" value="delete">
62+
<input type="hidden" name="domain_id" value="{{ domain.id }}">
63+
<button type="submit"
64+
class="ml-4"
65+
onclick="return confirm('Are you sure you want to delete this domain?')">
66+
Delete
67+
</button>
6168
</form>
62-
<button type="button" onclick="deleteDomain()" class="ml-2">Delete</button>
6369
</div>
6470
</div>
6571
</li>
@@ -69,14 +75,3 @@ <h5 class="text-xl font-bold leading-none text-gray-900">All Domains</h5>
6975
</div>
7076
</div>
7177
{% endblock body %}
72-
{% block js %}
73-
<script>
74-
function deleteDomain(){
75-
let deleteForm = document.getElementById("deleteForm");
76-
let confirmDelete = confirm("this will delete the domain and hunts associated with it.");
77-
if (confirmDelete === true){
78-
deleteForm.submit();
79-
}
80-
}
81-
</script>
82-
{% endblock js %}

0 commit comments

Comments
 (0)