Skip to content

Commit

Permalink
Merge pull request #71 from ICESI-PI1-2024A-G1/assignResponsiblesCont…
Browse files Browse the repository at this point in the history
…rolBoard

END:BUILD: Assign responsibles to contract requests since control boa…
  • Loading branch information
Alejolonber25 authored Apr 24, 2024
2 parents 78a8b86 + 2385fd1 commit 5832238
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 76 deletions.
15 changes: 0 additions & 15 deletions hiring_module/.example-env

This file was deleted.

27 changes: 27 additions & 0 deletions hiring_module/hiring_app/templates/control_board/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}
Panel de control
{% endblock %}
{% block aditionalMetadata %}
{% endblock %}

{% block content %}

<main id="main" class="expanded">
{% include 'control_board/center_container.html' %}

{% include 'control_board/table.html' with managers=managers leaders=leaders group=actualgroup%}


<div>
{% block control_board %}

{% endblock %}
</div>

{% include 'control_board/state_change.html' %}
</main>


{% endblock %}
17 changes: 8 additions & 9 deletions hiring_module/hiring_app/templates/control_board/table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<script>
function redirectToInfoPage(id) {
// Construir la URL con el ID proporcionado
Expand Down Expand Up @@ -34,14 +33,14 @@ <h6 class="m-0 font-weight-bold text-primary">Listado de solicitudes de contrata
</thead>
<tbody>
{% for request in requests %}
<tr href="#" onclick="redirectToInfoPage('{{ request.id }}')">
<td>{{ request.id }}</td>
<td>{{ request.created_by.first_name }} {{ request.created_by.last_name }}</td>
<td>{{ request.leader_assigned_to.first_name }} {{ request.leader_assigned_to.last_name }}</td>
<td>{{ request.manager_assigned_to.first_name }} {{ request.manager_assigned_to.last_name }}</td>
<td>{{ request.state }}</td>
<td>{{ request.contrato }}</td>
<td>{{ request.start_date|date:"d-m-Y" }}</td>
<tr>
<td href="#" onclick="redirectToInfoPage('{{ request.id }}')">{{ request.id }}</td>
<td href="#" onclick="redirectToInfoPage('{{ request.id }}')">{{ request.created_by.first_name }} {{ request.created_by.last_name }}</td>
<td>{% include 'request_hiring/components/assign_leader.html' with leaders=leaders contract_request=request form_id_prefix='change_leader_form_' %}</td>
<td>{% include 'request_hiring/components/assign_manager.html' with managers=managers contract_request=request form_id_prefix='change_manager_form_' %}</td>
<td href="#" onclick="redirectToInfoPage('{{ request.id }}')">{{ request.state }}</td>
<td href="#" onclick="redirectToInfoPage('{{ request.id }}')">{{ request.contrato }}</td>
<td href="#" onclick="redirectToInfoPage('{{ request.id }}')">{{ request.start_date|date:"d-m-Y" }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
1 change: 0 additions & 1 deletion hiring_module/hiring_app/templates/request_hiring.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Solicitud de contratación de {{contract_request.created_by.first_name}}</h1>

</div>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Lider asignado:
<br>
</div>
<div class="pt-3 h5 mb-0 font-weight-bold text-gray-800">{% include 'request_hiring/components/assign_leader.html' %}</div>
<div class="pt-3 h5 mb-0 font-weight-bold text-gray-800">{% include 'request_hiring/components/assign_leader.html' with leaders=leaders contract_request=contract_request %}</div>
</div>

</div>
Expand All @@ -28,7 +28,7 @@
Gestor asignado:
<br>
</div>
<div class="pt-3 h5 mb-0 font-weight-bold text-gray-800">{% include 'request_hiring/components/assign_manager.html' %}</div>
<div class="pt-3 h5 mb-0 font-weight-bold text-gray-800">{% include 'request_hiring/components/assign_manager.html' with managers=managers contract_request=contract_request %}</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
<form id="ChangeLeaderForm" method="post" action="{% url 'hiring_app:assign_leader' contract_request.id %}">
<form class="change-leader-form_{{ form_id_prefix }}{{ contract_request.id }}" method="post" action="{% url 'hiring_app:assign_leader' contract_request.id %}" style="margin-bottom: 1rem;">
{% csrf_token %}

<select name="leader" id="leaderSelect" class="btn btn-white border border-2 border-dark text-dark dropdown-toggle col"
{% if not is_admin %}
disabled
{% endif %}

>
<option class="col" disabled selected>Seleccionar</option>
<select name="leader" class="leaderSelect btn btn-white border border-2 border-dark text-dark dropdown-toggle col" {% if actualgroup != 'admin' %} disabled {% endif %}>
<option value="" class="col" selected>Seleccionar</option>
{% for leader in leaders %}
<option class="col" value="{{ leader.id }}"
{% if leader.id == contract_request.leader_assigned_to.id %}
selected
{% endif %}>
{{ leader.first_name }} {{ leader.last_name }}
</option>
<option value="{{ leader.id }}" class="col" {% if leader.id == contract_request.leader_assigned_to.id %} selected {% endif %}> {{ leader.first_name }} {{ leader.last_name }}</option>
{% endfor %}
</select>

</form>

<script>
document.addEventListener('DOMContentLoaded', function () {
var selectElement = document.getElementById('leaderSelect');
document.addEventListener('DOMContentLoaded', function () {
var selectElements = document.querySelectorAll('.leaderSelect');
selectElements.forEach(function(selectElement) {
selectElement.addEventListener('change', function () {
document.getElementById('ChangeLeaderForm').submit();
var form = selectElement.closest('form');
form.submit();
});
});
</script>
});
</script>
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<form id="ChangeManagerForm" method="post" action="{% url 'hiring_app:assign_manager' contract_request.id %}" style="margin-bottom: 1rem;">
<form class="change-manager-form_{{ form_id_prefix }}{{ contract_request.id }}" method="post" action="{% url 'hiring_app:assign_manager' contract_request.id %}" style="margin-bottom: 1rem;">
{% csrf_token %}
<select name="manager" id="managerSelect"
class="btn btn-white border border-2 border-dark text-dark dropdown-toggle col"
{% if not is_admin and not is_leader %}
<select name="manager" class="managerSelect btn btn-white border border-2 border-dark text-dark dropdown-toggle col" {% if actualgroup != "admin" and actualgroup != 'leader' %}
disabled
{% endif %}

>
<option class="col" value="" disabled selected >Seleccionar</option>

{% for manager in managers %}

<option class="col" value="{{ manager.id }}"
{% if manager.id == contract_request.manager_assigned_to.id %}
selected
{% endif %}
>
{{ manager.first_name }} {{ manager.last_name }}
</option>


<option value="{{ manager.id }}" class="col" {% if manager.id == contract_request.manager_assigned_to.id %}selected{% endif %} style="color: #4a5568;">{{ manager.first_name }} {{ manager.last_name }}</option>
{% endfor %}

</select>
</form>

<script>
document.addEventListener('DOMContentLoaded', function () {
var selectElement = document.getElementById('managerSelect');
document.addEventListener('DOMContentLoaded', function () {
var selectElements = document.querySelectorAll('.managerSelect');
selectElements.forEach(function(selectElement) {
selectElement.addEventListener('change', function () {
document.getElementById('ChangeManagerForm').submit();
var form = selectElement.closest('form');
form.submit();
});
});
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class AdministratorDashboardView(View):
# Redirect to correct dashboard based on user role
@method_decorator(role_redirect)
def dispatch(self, request, *args, **kwargs):
context = {}
context = {
'actualgroup': 'admin'
}
context.update(get_requests(self.request.user))
return render(request, self.template_name, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class LeaderDashboardView(View):
# Redirect to correct dashboard based on user role
@method_decorator(role_redirect)
def dispatch(self, request, *args, **kwargs):
context = {}
context = {
'actualgroup': 'leader'
}
context.update(get_requests(self.request.user))
return render(request, self.template_name, context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ManagerDashboardView(View):
# Redirect to correct dashboard based on user role
@method_decorator(role_redirect)
def dispatch(self, request, *args, **kwargs):
context = {}
context = {
'actualgroup': 'manager'
}
context.update(get_requests(self.request.user))
return render(request, self.template_name, context)

Expand Down
16 changes: 12 additions & 4 deletions hiring_module/hiring_app/views/control_board/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,31 @@ def wrapper(request, *args, **kwargs):
return wrapper

def get_requests(user):
print(user)
groups = [group.name for group in user.groups.all()]
requests_CEX = CEXContractRequest.objects.none()
requests_monitoring = MonitoringContractRequest.objects.none()

if 'admin' in groups or 'leader' in groups:
if 'admin' in groups:
requests_CEX = CEXContractRequest.objects.all()
requests_monitoring = MonitoringContractRequest.objects.all()
elif 'leader' in groups:
requests_CEX = CEXContractRequest.objects.filter(leader_assigned_to=user.id)
requests_monitoring = MonitoringContractRequest.objects.filter(leader_assigned_to=user.id)
elif 'manager' in groups:
requests_CEX = CEXContractRequest.objects.filter(manager_assigned_to=user.id)
requests_monitoring = MonitoringContractRequest.objects.filter(manager_assigned_to=user.id)


groupManager = Group.objects.get(name='manager')
groupLeader = Group.objects.get(name='leader')
managers = list(CustomUser.objects.filter(groups=groupManager))
leaders = list(CustomUser.objects.filter(groups=groupLeader))
return {
'requests': list(requests_CEX) + list(requests_monitoring),
'filled_requests': list(requests_CEX.filter(state='filed')) + list(requests_monitoring.filter(state='filed')),
'reviewed_requests': list(requests_CEX.filter(state='review')) + list(requests_monitoring.filter(state='review')),
'for_validate_requests': list(requests_CEX.filter(state__in=['pending', 'incomplete'])) + list(requests_monitoring.filter(state__in=['pending', 'incomplete']))
'for_validate_requests': list(requests_CEX.filter(state__in=['pending', 'incomplete'])) + list(requests_monitoring.filter(state__in=['pending', 'incomplete'])),
'leaders': leaders,
'managers': managers,
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def post(self, request, idContract):
request.session['error_message'] = 'Selected user is not leader.'
else:
request.session['error_message'] = 'You do not have permission for this action.'
return redirect('hiring_app:info', idContract=idContract)
return redirect(request.META.get('HTTP_REFERER'))

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def post(self, request, idContract):
request.session['error_message'] = 'Selected user is not manager.'
else:
request.session['error_message'] = 'You do not have permission for this action.'
return redirect('hiring_app:info', idContract=idContract)
return redirect(request.META.get('HTTP_REFERER'))

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

class RequestHiringView(View):
def references(self, request, idContract):
is_admin = any(group.name == 'admin' for group in self.request.user.groups.all())
is_leader = any(group.name == 'leader' for group in self.request.user.groups.all())
is_manager = any(group.name == 'manager' for group in self.request.user.groups.all())
groupManager = Group.objects.get(name='manager')
groupLeader = Group.objects.get(name='leader')
managers = list(CustomUser.objects.filter(groups=groupManager))
Expand All @@ -35,9 +32,7 @@ def references(self, request, idContract):
'leaders': leaders,
'error_message': request.session.pop('error_message', None),
'user': self.request.user,
'is_admin': is_admin,
'is_leader': is_leader,
'is_manager': is_manager,
'actualgroup': str(self.request.user.groups.first()),
'snapshot_comment': snapshot_comment
}

Expand Down

0 comments on commit 5832238

Please sign in to comment.