Skip to content
Snippets Groups Projects
Commit e924c524 authored by Valentin Groues's avatar Valentin Groues :eyes:
Browse files

fix issue with appointment length computation - #78

parent 34b7bd24
No related branches found
No related tags found
1 merge request!25fix issue with appointment length computation - #78
Pipeline #
function appointment_type_begaviour(selectObj, outObject,api_call) { function appointment_type_behaviour(checkboxes, outObject, api_call) {
var appointment_types_data = null; var appointment_types_data = null;
function get_appointment_type_by_id(id) { var global_sequential_time = 0;
for (var i=0 ;i <appointment_types_data.length;i++) { var global_time = 0;
if (id == appointment_types_data[i].id) { var global_parallel_time = 0;
return appointment_types_data[i];
} function recompute_parallel_time(object) {
var result = 0;
var object_id = -1;
if (object) {
object_id = object.attr('id');
}
$.each(checkboxes, function (index, value) {
var checkbox = $(value);
var val = parseInt(checkbox.attr('value'));
if (checkbox.is(":checked") || checkbox.attr('id') == object_id) {
var appointment_type = appointment_types_data[val];
if (appointment_type.can_be_parallelized) {
result = Math.max(result, appointment_type.default_duration)
}
}
});
return result;
} }
return null;
} function recompute_sequential_time(object) {
function compute_time(object) { var result = 0;
var vals = object.val(); var object_id = -1;
var time = 0; if (object) {
var max_paralel_time = 0; object_id = object.attr('id');
for (var i=0;i<vals.length;i++) {
var appointment_type = get_appointment_type_by_id(vals[i]);
if (appointment_type== null) {
console.log("Cannot find appointment type with id: "+vals[i]);
} else {
if (appointment_type.can_be_parallelized) {
max_paralel_time = Math.max(max_paralel_time,appointment_type.default_duration);
} else {
time +=appointment_type.default_duration;
} }
} $.each(checkboxes, function (index, value) {
var checkbox = $(value);
var val = parseInt(checkbox.attr('value'));
if (checkbox.is(":checked") || checkbox.attr('id') == object_id) {
var appointment_type = appointment_types_data[val];
if (!appointment_type.can_be_parallelized) {
result += appointment_type.default_duration
}
}
});
return result;
} }
time = Math.max(time, max_paralel_time)
$(outObject).val(time+""); function compute_time(object) {
} var val = parseInt(object.attr('value'));
$(selectObj ).change(function() { var time = 0;
var object = $(this) var appointment_type = appointment_types_data[val];
if (appointment_types_data===null) { if (appointment_type == null) {
$.get(api_call, function(data) { console.log("Cannot find appointment type with id: " + val);
appointment_types_data= data.appointment_types; } else {
compute_time(object); time = appointment_type.default_duration;
}); if (appointment_type.can_be_parallelized) {
} else { if (object.is(":checked")) {
compute_time(object); global_parallel_time = Math.max(global_parallel_time, time);
} else {
global_parallel_time = recompute_parallel_time();
}
} else {
if (object.is(":checked")) {
global_sequential_time += time;
} else {
global_sequential_time -= time;
}
}
global_time = Math.max(global_parallel_time, global_sequential_time);
$(outObject).val(global_time + "");
}
} }
});
$(checkboxes).change(function () {
var object = $(this);
if (appointment_types_data === null) {
$.get(api_call, function (data) {
appointment_types_data = {};
$.each(data.appointment_types, function (index, appointment_type) {
appointment_types_data[appointment_type.id] = appointment_type;
});
global_parallel_time = recompute_parallel_time(object);
global_sequential_time = recompute_sequential_time(object);
compute_time(object)
});
} else {
compute_time(object);
}
});
} }
function visit_dates_begaviour(startDateInput, endDateInput) { function visit_dates_behaviour(startDateInput, endDateInput) {
$(startDateInput).change(function () { $(startDateInput).change(function () {
var object = $(this); var object = $(this);
try { try {
......
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
}); });
appointment_type_begaviour($("[name='appointment_types']"), $("[name='length']"), "{% url 'web.api.appointment_types' %}"); appointment_type_behaviour($("input[name='appointment_types']"), $("input[name='length']"), "{% url 'web.api.appointment_types' %}");
</script> </script>
{% include "includes/datetimepicker.js.html" %} {% include "includes/datetimepicker.js.html" %}
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
"autoWidth": false "autoWidth": false
}); });
}); });
appointment_type_begaviour($("[name='appointment_types']"), $("[name='length']"), "{% url 'web.api.appointment_types' %}"); appointment_type_behaviour($("input[name='appointment-appointment_types']"), $("input[name='appointment-length']"), "{% url 'web.api.appointment_types' %}");
</script> </script>
{% include "includes/datetimepicker.js.html" %} {% include "includes/datetimepicker.js.html" %}
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<script src="{% static 'js/visit.js' %}"></script> <script src="{% static 'js/visit.js' %}"></script>
<script> <script>
visit_dates_begaviour($("[name='datetime_begin']"),$("[name='datetime_end']")); visit_dates_behaviour($("[name='datetime_begin']"),$("[name='datetime_end']"));
</script> </script>
{% include "includes/datepicker.js.html" %} {% include "includes/datepicker.js.html" %}
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
{% load filters %} {% load filters %}
{% block styles %} {% block styles %}
{{ block.super }} {{ block.super }}
<!-- DataTables --> <!-- DataTables -->
<link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}"> <link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}">
{% include "includes/datepicker.css.html" %} {% include "includes/datepicker.css.html" %}
{% endblock styles %} {% endblock styles %}
{% block ui_active_tab %}'visits'{% endblock ui_active_tab %} {% block ui_active_tab %}'visits'{% endblock ui_active_tab %}
...@@ -17,189 +17,189 @@ ...@@ -17,189 +17,189 @@
{% block title %}{{ block.super }} - Details of visit ({{ visit.follow_up_title }}) {% endblock %} {% block title %}{{ block.super }} - Details of visit ({{ visit.follow_up_title }}) {% endblock %}
{% block breadcrumb %} {% block breadcrumb %}
{% include "subjects/breadcrumb.html" %} {% include "subjects/breadcrumb.html" %}
{% endblock breadcrumb %} {% endblock breadcrumb %}
{% block maincontent %} {% block maincontent %}
{% block content %} {% block content %}
<div class="box box-info"> <div class="box box-info">
<div class="box-header with-border"> <div class="box-header with-border">
<a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default" <a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default"
onclick="history.back()">Back</a> onclick="history.back()">Back</a>
<a href="{% url 'web.views.subject_visit_details' visit.subject.id %}" type="button" <a href="{% url 'web.views.subject_visit_details' visit.subject.id %}" type="button"
class="btn btn-block btn-default">Subject's visits</a> class="btn btn-block btn-default">Subject's visits</a>
</div> </div>
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">Details of visit <h3 class="box-title">Details of visit
</h3> </h3>
</div> </div>
<form method="post" action="" class="form-horizontal"> <form method="post" action="" class="form-horizontal">
{% csrf_token %} {% csrf_token %}
<div class="box-body"> <div class="box-body">
{% for field in vform %} {% for field in vform %}
<div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}"> <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %} {% if field|is_checkbox %}multi-checkboxes{% endif %}">
<label for="{# TODO #}" class="col-sm-4 control-label"> <label for="{# TODO #}" class="col-sm-4 control-label">
{{ field.label }} {{ field.label }}
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
{{ field|add_class:'form-control' }} {{ field|add_class:'form-control' }}
</div> </div>
{% if field.errors %} {% if field.errors %}
<span class="help-block"> <span class="help-block">
{{ field.errors }} {{ field.errors }}
</span> </span>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
<div class="col-md-6 form-group"> <div class="col-md-6 form-group">
<label class="col-sm-4 control-label"> <label class="col-sm-4 control-label">
Visit finished Visit finished
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
{% if visFinished %} {% if visFinished %}
<div class="btn btn-block">YES</div> <div class="btn btn-block">YES</div>
{% else %} {% else %}
<div class="btn btn-block"> <div class="btn btn-block">
{% if canFinish %} {% if canFinish %}
<a href="{% url 'web.views.visit_mark' vid 'finished' %}" <a href="{% url 'web.views.visit_mark' vid 'finished' %}"
class="btn btn-warning btn-block">Mark as finished</a> class="btn btn-warning btn-block">Mark as finished</a>
{% else %} {% else %}
Waiting for appointments to finish. Waiting for appointments to finish.
{% endif %} {% endif %}
</div>
{% endif %}
</div>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<div class="col-sm-12">
<button type="submit" class="btn btn-block btn-success">Save</button>
</div> </div>
{% endif %} </div><!-- /.box-footer -->
</div> </form>
<div class="box-header with-border">
<h3 class="box-title">Visit's appointments</h3>
</div> </div>
</div><!-- /.box-body -->
<div class="box-footer"> <div>
<div class="col-sm-12"> <a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app">
<button type="submit" class="btn btn-block btn-success">Save</button> <i class="fa fa-plus"></i>
Add new appointment
</a>
</div> </div>
</div><!-- /.box-footer -->
</form>
<div class="box-header with-border"> {% if loApp %}
<h3 class="box-title">Visit's appointments</h3> <table id="table" class="table table-bordered table-striped">
</div> <thead>
<tr>
<th>No.</th>
<th>Type</th>
<th>Date</th>
<th>Time</th>
<th>Length [min]</th>
<th>Responsible</th>
<th>Plan/Modify</th>
</tr>
</thead>
<tbody>
{% for app in loApp %}
<tr>
<td>{{ forloop.counter }}</td>
<td style="background-color:{{ app.color }} !important">
<font COLOR="{{ app.font_color }}">
{% for type in app.appointment_types.all %}
{{ type.code }},
{% endfor %}
</font>
</td>
<td>{{ app.datetime_when | date:"d-M-Y" }}</td>
<td>{{ app.datetime_when | time:"H:i" }}</td>
<td>{{ app.length }}</td>
<td>
{% if app.flying_team %}{{ app.worker_assigned.first_name }}
{{ app.worker_assigned.last_name }}
{% else %} {{ app.flying_team }}
{% endif %}
</td>
<td>
{% ifequal app.status "SCHEDULED" %}
<a href="{% url 'web.views.appointment_edit' app.id %}" type="button"
class="btn btn-block btn-default">Edit</a>
{% else %}
{{ app.status }}
{% endifequal %}
</td>
</tr>
{% endfor %}
<div> </tbody>
<a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app"> </table>
<i class="fa fa-plus"></i> {% else %}
Add new appointment <p>No appointments found.</p>
</a> {% endif %}
</div>
{% if loApp %} <div class="box-header with-border">
<table id="table" class="table table-bordered table-striped"> <h3 class="box-title">Subject's details</h3>
<thead> </div>
<tr>
<th>No.</th>
<th>Type</th>
<th>Date</th>
<th>Time</th>
<th>Length [min]</th>
<th>Responsible</th>
<th>Plan/Modify</th>
</tr>
</thead>
<tbody>
{% for app in loApp %}
<tr>
<td>{{ forloop.counter }}</td>
<td style="background-color:{{ app.color }} !important">
<font COLOR="{{ app.font_color }}">
{% for type in app.appointment_types.all %}
{{ type.code }},
{% endfor %}
</font>
</td>
<td>{{ app.datetime_when | date:"d-M-Y" }}</td>
<td>{{ app.datetime_when | time:"H:i" }}</td>
<td>{{ app.length }}</td>
<td>
{% if app.flying_team %}{{ app.worker_assigned.first_name }}
{{ app.worker_assigned.last_name }}
{% else %} {{ app.flying_team }}
{% endif %}
</td>
<td>
{% ifequal app.status "SCHEDULED" %}
<a href="{% url 'web.views.appointment_edit' app.id %}" type="button"
class="btn btn-block btn-default">Edit</a>
{% else %}
{{ app.status }}
{% endifequal %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No appointments found.</p>
{% endif %}
<div class="box-header with-border">
<h3 class="box-title">Subject's details</h3>
</div>
<form class="form-horizontal"> <form class="form-horizontal">
<div class="box-body"> <div class="box-body">
{% for field in sform %} {% for field in sform %}
<div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}"> <div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}">
<label for="{# TODO #}" class="col-sm-4 control-label"> <label for="{# TODO #}" class="col-sm-4 control-label">
{{ field.label }} {{ field.label }}
</label> </label>
<div class="col-sm-8"> <div class="col-sm-8">
{{ field|disable|add_class:'form-control' }} {{ field|disable|add_class:'form-control' }}
</div> </div>
{% if field.errors %} {% if field.errors %}
<span class="help-block"> <span class="help-block">
{{ field.errors }} {{ field.errors }}
</span> </span>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div><!-- /.box-body --> </div><!-- /.box-body -->
<div class="box-footer"> <div class="box-footer">
<td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button" <td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button"
class="btn btn-block btn-default">Edit subject</a></td> class="btn btn-block btn-default">Edit subject</a></td>
<a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default" onclick="history.back()">Back</a> <a href="{% url 'web.views.subjects' %}" class="btn btn-block btn-default" onclick="history.back()">Back</a>
</div><!-- /.box-footer --> </div><!-- /.box-footer -->
</form> </form>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}
</div> </div>
{% endblock maincontent %} {% endblock maincontent %}
{% block scripts %} {% block scripts %}
{{ block.super }} {{ block.super }}
<script src="{% static 'AdminLTE/plugins/datatables/jquery.dataTables.min.js' %}"></script> <script src="{% static 'AdminLTE/plugins/datatables/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.min.js' %}"></script> <script src="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.min.js' %}"></script>
<script src="{% static 'js/visit.js' %}"></script> <script src="{% static 'js/visit.js' %}"></script>
<script> <script>
visit_dates_begaviour($("[name='datetime_begin']"),$("[name='datetime_end']")); visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']"));
</script> </script>
{% include "includes/datepicker.js.html" %} {% include "includes/datepicker.js.html" %}
{% endblock scripts %} {% endblock scripts %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment