Skip to content

Commit

Permalink
use same view/tables for missions page and consultant missions tab
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalfox committed Sep 15, 2024
1 parent da37a2a commit 93eb53f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 96 deletions.
4 changes: 2 additions & 2 deletions core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"/staffing/production-report/",
"/staffing/production-report/2009/07",
"/staffing/fixed-price-mission-report/",
"/staffing/mission/",
"/staffing/mission/all",
"/staffing/missions/",
"/staffing/missions/all",
"/staffing/mission/1/",
"/staffing/mission/1/#tab-staffing",
"/staffing/mission/1/#tab-timesheet",
Expand Down
7 changes: 3 additions & 4 deletions staffing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
re_path(r'^production-report/(?P<year>\d+)/(?P<month>\d+)/?$', v.prod_report, name='prod_report'),
re_path(r'^fixed-price-mission-report/?$', v.fixed_price_missions_report, name="fixed_price_missions_report"),
re_path(r'^missions/$', v.missions, name='missions'),
re_path(r'^missions/consultant/(?P<consultant_id>\d+)/$', v.missions, name='consultant-missions'),
re_path(r'^missions/all', v.missions, {'only_active': False}, 'all-missions'),
re_path(r'^missions/consultant/(?P<consultant_id>\d+)/all', v.missions, {'only_active': False}, 'consultant-all-missions'),
re_path(r'^missions/all$', v.missions, {'only_active': False}, name='all_missions'),
re_path(r'^missions/consultant/(?P<consultant_id>\d+)/$', v.consultant_missions, name="consultant_missions"),
re_path(r'^missions/all/consultant/(?P<consultant_id>\d+)/$', v.consultant_missions, {'only_active': False}, name="consultant_all_missions"),
re_path(r'^mission/(?P<mission_id>\d+)/$', v.mission_home, name="mission_home"),
re_path(r'^mission/update/$', v.mission_update, name="mission_inline_update"),
re_path(r'^mission/(?P<pk>\d+)/update$', v.MissionUpdate.as_view(), name='mission_update'),
re_path(r'^mission/(?P<mission_id>\d+)/consultants$', v.mission_consultants, name="mission_consultants"),
re_path(r'^mission/newfromdeal/(?P<lead_id>\d+)/$', v.create_new_mission_from_lead, name="create_new_mission_from_lead"),
re_path(r'^missions/consultant/(?P<consultant_id>\d+)/$', v.consultant_missions, name="consultant_missions"),
re_path(r'^forecast/mission/(?P<mission_id>\d+)/$', v.mission_staffing, name="mission_staffing"),
re_path(r'^forecast/shift/(?P<shift>\d+)/mission/(?P<mission_id>\d+)/$', v.mission_staffing_shift, name="mission_staffing_shift"),
re_path(r'^mission/(?P<mission_id>\d+)/deactivate$', v.deactivate_mission, name="deactivate_mission"),
Expand Down
19 changes: 16 additions & 3 deletions staffing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,28 @@ def consultant_staffing(request, consultant_id):
"user": request.user})


@pydici_subcontractor
def consultant_missions(request, consultant_id):
@pydici_non_public
def consultant_missions(request, only_active=True, consultant_id=None):
"""List of current consultant mission"""
consultant = Consultant.objects.get(id=consultant_id)
if not subcontractor_is_user(consultant, request.user):
# subcontractor cannot see other people page
return HttpResponseRedirect(reverse("core:forbidden"))

return render(request, "staffing/consultant_missions.html", {"consultant": consultant})
if only_active:
data_url = reverse('staffing:consultant_active_mission_table_DT', args=(consultant_id,))
else:
data_url = reverse('staffing:consultant_all_mission_table_DT', args=(consultant_id,))

return render(request, "staffing/_mission_table.html",
{"all": not only_active,
"consultant": consultant,
"data_url": data_url,
"datatable_options": ''' "columnDefs": [{ "orderable": false, "targets": [4, 8, 9] },
{ className: "hidden-xs hidden-sm hidden-md", "targets": [6,7,8,9]}],
"order": [[3, "asc"]]
''',
"user": request.user})


@pydici_non_public
Expand Down
6 changes: 4 additions & 2 deletions templates/people/consultant.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>{{ consultant.full_name }} {% if consultant.subcontractor %} - {% trans "sub

<div>
<!-- Nav tabs -->
{% cache 3600 consultant_menu consultant.id request.GET.year request.GET.month %}
{% cache 3600 consultant_menu consultant.id request.GET.year request.GET.month request.GET.all_missions %}
<ul class="nav nav-tabs" id="consultant-tabs">
{% if consultant.subcontractor %}
<li class="active"><button class="nav-link active" data-bs-toggle="tab" type="button" role="tab" data-bs-target="#tab-home" data-tab-url="{% url 'people:subcontractor_detail' consultant.id %}"><i class="bi bi-house"></i> {% trans "Home" %}</button></li>
Expand All @@ -37,7 +37,9 @@ <h1>{{ consultant.full_name }} {% if consultant.subcontractor %} - {% trans "sub
{% if pydici_feature.staffing %}
<li class="nav-item"><button class="nav-link" data-bs-toggle="tab" type="button" role="tab" data-bs-target="#tab-staffing" data-tab-url="{% url 'staffing:consultant_staffing' consultant.id %}"><i class="bi-eye"></i> {% trans "Forecast staffing" %}</button></li>
{% endif %}
<li class="nav-item"><button class="nav-link" data-bs-toggle="tab" type="button" role="tab" data-bs-target="#tab-missions" data-tab-url="{% url 'staffing:consultant_missions' consultant.id %}"><i class="bi-list-ul"></i> {% trans "Missions" %}</button></li>
{% if not consultant.subcontractor %}
<li class="nav-item"><button class="nav-link" data-bs-toggle="tab" type="button" role="tab" data-bs-target="#tab-missions" data-tab-url="{% url 'staffing:consultant_missions' consultant_id=consultant.id %}"><i class="bi-list-ul"></i> {% trans "Missions" %}</button></li>
{% endif %}
</ul>
{% endcache %}
</div>
Expand Down
60 changes: 60 additions & 0 deletions templates/staffing/_mission_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% load i18n %}
<div id="missions-content" class="row mt-2">
{% if consultant %}
<div class="my-3 d-flex flex-row">
{% if all %}
<br/><a class="btn btn-primary" id="active-missions" href="#">{% trans "Display only active missions" %}</a><br/><br/>
{% else %}
<br/><a class="btn btn-primary" id="all-missions" href="#">{% trans "Display all missions" %}</a><br/><br/>
{% endif %}

</div>
{% endif %}
<table id="mission_table" class="table table-striped table-hover table-sm table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>{% trans "name" %}</th>
<th>{% trans "subsidiary" %}</th>
<th>{% trans "responsible" %}</th>
<th>{% trans "nature" %}</th>
<th>{% trans "Mission id" %}</th>
<th>{% trans "amount (k€)" %}</th>
<th>{% trans "billing mode" %}</th>
<th>{% trans "product" %}</th>
<th>{% trans "Forecast in future" %}</th>
<th>{% trans "Up to date forecast" %}</th>
<th>{% trans "Archiving" %}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>

{% with "mission_table" as table_id %}
{% include "core/_datatables.html" %}
{% endwith %}

<script type="text/JavaScript">
<!--

// Function that process ajax callback
function process_mission_archive(data) {
if (data.error==true) {
alert("{% trans 'Archiving failed' %}");
}
else {
$("#mission_" + data.id).closest("tr").hide("fast");
}
};
{% if consultant %}
// Toggle all or only active missions when embeded in consultant mission tab
$('#all-missions').on("click", function () {
$('#missions-content').load('{% url 'staffing:consultant_all_missions' consultant.id %}');
});
$('#active-missions').on("click", function () {
$('#missions-content').load('{% url 'staffing:consultant_missions' consultant.id %}');
});
{% endif %}
-->
</script>
</div>
31 changes: 0 additions & 31 deletions templates/staffing/consultant_missions.html

This file was deleted.

59 changes: 5 additions & 54 deletions templates/staffing/missions.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,13 @@
{% block content %}

{% if all %}
{% if consultant %}
<h1>{% blocktrans %}All missions of {{ consultant }}{% endblocktrans %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:consultant-missions' consultant.id %}">{% trans "Only display active missions" %}</a><br/><br/>
{% else %}
<h1>{% trans "All missions" %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:missions' %}">{% trans "Only display active missions" %}</a><br/><br/>
{% endif %}
<h1>{% trans "All missions" %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:missions' %}">{% trans "Only display active missions" %}</a><br/><br/>
{% else %}
{% if consultant %}
<h1>{% blocktrans %}Actives missions of {{ consultant }}{% endblocktrans %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:consultant-all-missions' consultant.id %}">{% trans "Also display inactive missions" %}</a><br/><br/>
{% else %}
<h1>{% trans "Active missions" %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:all-missions' %}">{% trans "Also display inactive missions" %}</a><br/><br/>
{% endif %}
<h1>{% trans "Active missions" %}</h1>
<br/><a class="btn btn-primary" href="{% url 'staffing:all_missions' %}">{% trans "Also display inactive missions" %}</a><br/><br/>
{% endif %}

<table id="mission_table" class="table table-striped table-hover table-sm table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>{% trans "name" %}</th>
<th>{% trans "subsidiary" %}</th>
<th>{% trans "responsible" %}</th>
<th>{% trans "nature" %}</th>
<th>{% trans "Mission id" %}</th>
<th>{% trans "amount (k€)" %}</th>
<th>{% trans "billing mode" %}</th>
<th>{% trans "product" %}</th>
<th>{% trans "Forecast in future" %}</th>
<th>{% trans "Up to date forecast" %}</th>
<th>{% trans "Archiving" %}</th>
</tr>
</thead>
<tbody>
</tbody>
</table>


{% with "mission_table" as table_id %}
{% include "core/_datatables.html" %}
{% endwith %}

<script type="text/JavaScript">
<!--

// Function that process ajax callback
function process_mission_archive(data) {
if (data.error==true) {
alert("{% trans 'Archiving failed' %}");
}
else {
$("#mission_" + data.id).closest("tr").hide("fast");
}
};
-->
</script>

{% include "staffing/_mission_table.html" %}

{% endblock %}

0 comments on commit 93eb53f

Please sign in to comment.