diff --git a/scipost_django/finances/templates/finances/_logs.html b/scipost_django/finances/templates/finances/_logs.html index 9dd7c7b15375d1c3f9cba3c5d35ea95434bc7c4c..057d87f8802bff604c3596eb552e3a5c2b9183ab 100644 --- a/scipost_django/finances/templates/finances/_logs.html +++ b/scipost_django/finances/templates/finances/_logs.html @@ -1,29 +1,27 @@ {% load scipost_extras %} -<ul class="list-unstyled"> - {% for log in logs %} - <li id="log_{{ log.slug }}" class="pb-2"> - <div class="d-flex justify-content-between"> - <div> - <strong>{{ log.user.first_name }} {{ log.user.last_name }}</strong> - <br> - <span class="text-muted">{{ log.log_type }}</span> - <br> - {{ log.comments|linebreaksbr }} - </div> - <div class="text-muted text-end d-flex justify-content-end"> - <div> - {{ log.work_date }} - <br> - <strong>Duration: {{ log.duration|duration }}</strong> - </div> - <div class="ps-2"> - <a class="text-danger" href="{% url 'finances:log_delete' log.slug %}"><span aria-hidden="true">{% include 'bi/trash-fill.html' %}</a> - </div> - </div> +{% for log in logs %} + <div id="log_{{ log.slug }}" class="row"> + <div class="col"> + <strong>{{ log.user.first_name }} {{ log.user.last_name }}</strong> + <br> + <span class="text-muted">{{ log.log_type }}</span> + <br> + {{ log.comments|linebreaksbr }} + </div> + <div class="text-muted text-end col-auto d-flex"> + <div class=""> + {{ log.work_date }} + <br> + <strong>Duration: {{ log.duration|duration }}</strong> </div> - </li> - {% empty %} - <li>No logs were found.</li> - {% endfor %} -</ul> + <div class="ps-2"> + <a class="text-danger" href="{% url 'finances:log_delete' log.slug %}"><span aria-hidden="true"> + {% include 'bi/trash-fill.html' %} + </a> + </div> + </div> + </div> +{% empty %} + No logs were found. +{% endfor %} diff --git a/scipost_django/production/templates/production/_hx_productionstream_actions_work_log.html b/scipost_django/production/templates/production/_hx_productionstream_actions_work_log.html new file mode 100644 index 0000000000000000000000000000000000000000..46916a2b6fae5e9416353c02c0c366ee78d22d5f --- /dev/null +++ b/scipost_django/production/templates/production/_hx_productionstream_actions_work_log.html @@ -0,0 +1,31 @@ +{% load guardian_tags %} +{% load scipost_extras %} +{% load bootstrap %} + +<div class="row"> + <h3 class="col">Work Logs</h3> + {% include 'finances/_logs.html' with logs=productionstream.work_logs.all|dictsort:"created" %} + + {% if productionstream.total_duration %} + <div class="col-auto ms-auto me-5 border-primary border-top pt-2"> + Total: <strong>{{ productionstream.total_duration|duration }}</strong> + </div> + + {% endif %} +</div> + +{% if work_log_form %} + <div class="row mb-0"> + + <h4>Add hours to the Stream</h4> + <form id="productionstream-{{ productionstream.id }}-work_log_form" + hx-post="{% url 'production:_hx_productionstream_actions_work_log' productionstream_id=productionstream.id %}" + hx-target="#productionstream-{{ productionstream.id }}-work-log-body" + class="mb-2"> + {% csrf_token %} + {{ work_log_form|bootstrap }} + <input type="submit" class="btn btn-primary" name="submit" value="Log"> + </form> + + </div> +{% endif %} diff --git a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html index 48f440f4364c39796ddc598e864b5a48b1b4f018..c96ef07d7ff689535ef170b5a0d4ee80d9eab491 100644 --- a/scipost_django/production/templates/production/_hx_productionstream_details_contents.html +++ b/scipost_django/production/templates/production/_hx_productionstream_details_contents.html @@ -1,5 +1,6 @@ {% load guardian_tags %} {% load bootstrap %} +{% load scipost_extras %} {% get_obj_perms request.user for productionstream as "sub_perms" %} @@ -74,14 +75,17 @@ data-bs-toggle="collapse" data-bs-target="#productionstream-{{ productionstream.id }}-work-log" aria-expanded="false" - aria-controls="productionstream-{{ productionstream.id }}-work-log">Work Log</button> + aria-controls="productionstream-{{ productionstream.id }}-work-log" + hx-get="{% url 'production:_hx_productionstream_actions_work_log' productionstream_id=productionstream.id %}" + hx-trigger="click once" + hx-target="#productionstream-{{ productionstream.id }}-work-log-body">Work Log</button> </h2> <div id="productionstream-{{ productionstream.id }}-work-log" class="accordion-collapse collapse" aria-labelledby="productionstream-{{ productionstream.id }}-work-log-header" data-bs-parent="#productionstream-{{ productionstream.id }}-actions-accordion"> <div id="productionstream-{{ productionstream.id }}-work-log-body" - class="accordion-body">Work log here</div> + class="accordion-body"></div> </div> </div> diff --git a/scipost_django/production/urls.py b/scipost_django/production/urls.py index f2458a89353cadea783a8de1761ff785832cdf0b..6e2b9859433a730b6e50ab446bb7331dab5b2acf 100644 --- a/scipost_django/production/urls.py +++ b/scipost_django/production/urls.py @@ -34,6 +34,11 @@ urlpatterns = [ production_views._hx_productionstream_actions_change_properties, name="_hx_productionstream_actions_change_properties", ), + path( + "actions_work_log", + production_views._hx_productionstream_actions_work_log, + name="_hx_productionstream_actions_work_log", + ), path( "events/", include( diff --git a/scipost_django/production/views.py b/scipost_django/production/views.py index 02d8d929ff70d20128ff09b5e3de15843fcb4b66..ae47ae0931819bca1c12c4a9ecfa3639d05175f7 100644 --- a/scipost_django/production/views.py +++ b/scipost_django/production/views.py @@ -386,6 +386,42 @@ def add_work_log(request, stream_id): return redirect(stream.get_absolute_url()) +@is_production_user() +@permission_required("scipost.can_view_production", raise_exception=True) +def _hx_productionstream_actions_work_log(request, productionstream_id): + productionstream = get_object_or_404(ProductionStream, pk=productionstream_id) + checker = ObjectPermissionChecker(request.user) + if not checker.has_perm("can_work_for_stream", productionstream): + return redirect(productionstream.get_absolute_url()) + + if request.user.has_perm("scipost.can_view_all_production_streams"): + types = constants.PRODUCTION_ALL_WORK_LOG_TYPES + else: + types = constants.PRODUCTION_OFFICERS_WORK_LOG_TYPES + work_log_form = WorkLogForm(request.POST or None, log_types=types) + + if work_log_form.is_valid(): + log = work_log_form.save(commit=False) + log.content = productionstream + log.user = request.user + log.save() + messages.success(request, "Work Log added to Stream.") + else: + # messages.warning(request, "The form was invalidly filled.") + pass + + context = { + "productionstream": productionstream, + "work_log_form": work_log_form, + } + + return render( + request, + "production/_hx_productionstream_actions_work_log.html", + context, + ) + + @is_production_user() @permission_required( "scipost.can_take_decisions_related_to_proofs", raise_exception=True