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

END:BUILD: Assign responsibles to contract requests since control boa… #71

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 0 additions & 15 deletions hiring_module/.example-env

This file was deleted.

3 changes: 2 additions & 1 deletion hiring_module/hiring_app/templates/control_board/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<main id="main" class="expanded">
{% include 'control_board/center_container.html' %}

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


<div>
{% block control_board %}

Expand Down
10 changes: 6 additions & 4 deletions hiring_module/hiring_app/templates/control_board/table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


<table style="width: 100%; border-collapse: collapse; margin-top: 14px;">
<thead>
<tr style="background-color: #2A8FD0; color: white;">
Expand All @@ -14,16 +15,17 @@
<tbody>

{% for request in requests %}
<tr onclick="redirectToInfoPage('{{ request.id }}')" style="cursor: pointer;">
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.id }}</td>
<tr style="cursor: pointer;">
<td onclick="redirectToInfoPage('{{ request.id }}')" style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.id }}</td>
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.created_by.first_name }} {{ request.created_by.last_name }}</td>
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.leader_assigned_to.first_name }} {{ request.leader_assigned_to.last_name }}</td>
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.manager_assigned_to.first_name }} {{ request.manager_assigned_to.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 id="statusButton" style="border: 2px solid white; padding: 10px; text-align: center; position: relative; background-color: #f2f2f2;">{{ request.state }}</td>
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.contrato }}</td>
<td style="border: 2px solid white; padding: 10px; text-align: center; background-color: #f2f2f2;">{{ request.start_date|date:"d-m-Y" }}</td>
</tr>
{% endfor %}

</tbody>
</table>

Expand Down
1 change: 1 addition & 0 deletions hiring_module/hiring_app/templates/request_hiring.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<main id="main" class="expanded" style="display: flex; flex-direction: column; min-height: auto; background-color: #E5E5E5; padding: 1rem;">
<div style="text-align: center; margin-top: 1rem;">

{% include 'request_hiring/center_container.html' %}
</div>
<h2 style="color: #434343; font-size: 1.5rem; line-height: 2rem; font-weight: 600; padding-bottom: 0.5rem; padding-top: 1rem;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<p>{{ contract_request.id }}</p>
</div>
<div style="flex: 1; padding-left: 24px; padding-right: 24px; border-right: 1px solid #cbd5e0;">
<p style="font-weight: 600; color: #2d3748;">Líder:</p>
{% include 'request_hiring/components/assign_leader.html' %}
<p style="font-weight: 600; color: #2d3748;">Leader:</p>
{% include 'request_hiring/components/assign_leader.html' with leaders=leaders contract_request=contract_request %}
</div>
<div style="flex: 1; padding-left: 24px; padding-right: 24px; border-right: 1px solid #cbd5e0;">
<p style="font-weight: 600; color: #2d3748;">Gestor:</p>
{% include 'request_hiring/components/assign_manager.html' %}
{% include 'request_hiring/components/assign_manager.html' with managers=managers contract_request=contract_request %}
</div>
<div style="flex: 1; padding-left: 24px;">
<p style="font-weight: 600; color: #2d3748;">Cambiar estado:</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<form id="ChangeLeaderForm" method="post" action="{% url 'hiring_app:assign_leader' contract_request.id %}" style="margin-bottom: 1rem;">
<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" style="width: 100%; margin-top: 0.5rem; padding: 0.5rem; background-color: #ffffff; border: 1px solid #cbd5e0; border-radius: 0.375rem; outline: none; transition: border-color 0.15s ease-in-out;"

{% if not is_admin %}
disabled
{% endif %}

>
<option value="" disabled selected>Seleccionar</option>
<select name="leader" class="leaderSelect" style="width: 100%; margin-top: 0.5rem; padding: 0.5rem; background-color: #ffffff; border: 1px solid #cbd5e0; border-radius: 0.375rem; outline: none; transition: border-color 0.15s ease-in-out;" {% if actualgroup != 'admin' %} disabled {% endif %}>
<option value="" selected>Seleccionar</option>
{% for leader in leaders %}
<option 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 }}" {% 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,24 +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" style="width: 100%; margin-top: 0.5rem; padding: 0.5rem; background-color: #ffffff; border: 1px solid #cbd5e0; border-radius: 0.375rem; outline: none; transition: border-color 0.15s ease-in-out;"
<select name="manager" class="managerSelect" style="width: 100%; margin-top: 0.5rem; padding: 0.5rem; background-color: #ffffff; border: 1px solid #cbd5e0; border-radius: 0.375rem; outline: none; transition: border-color 0.15s ease-in-out;"

{% if not is_admin and not is_leader %}
{% if actualgroup != "admin" and actualgroup != 'leader' %}
disabled
{% endif %}

>
<option value="" disabled selected style="color: #a0aec0;">Seleccionar</option>
{% for manager in managers %}

<option value="{{ manager.id }}" {% 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