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) {
var appointment_types_data = null;
function get_appointment_type_by_id(id) {
for (var i=0 ;i <appointment_types_data.length;i++) {
if (id == appointment_types_data[i].id) {
return appointment_types_data[i];
}
function appointment_type_behaviour(checkboxes, outObject, api_call) {
var appointment_types_data = null;
var global_sequential_time = 0;
var global_time = 0;
var global_parallel_time = 0;
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 compute_time(object) {
var vals = object.val();
var time = 0;
var max_paralel_time = 0;
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;
function recompute_sequential_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 += appointment_type.default_duration
}
}
});
return result;
}
time = Math.max(time, max_paralel_time)
$(outObject).val(time+"");
}
$(selectObj ).change(function() {
var object = $(this)
if (appointment_types_data===null) {
$.get(api_call, function(data) {
appointment_types_data= data.appointment_types;
compute_time(object);
});
} else {
compute_time(object);
function compute_time(object) {
var val = parseInt(object.attr('value'));
var time = 0;
var appointment_type = appointment_types_data[val];
if (appointment_type == null) {
console.log("Cannot find appointment type with id: " + val);
} else {
time = appointment_type.default_duration;
if (appointment_type.can_be_parallelized) {
if (object.is(":checked")) {
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 () {
var object = $(this);
try {
......
......@@ -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>
{% include "includes/datetimepicker.js.html" %}
......
......@@ -120,7 +120,7 @@
"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>
{% include "includes/datetimepicker.js.html" %}
......
......@@ -76,7 +76,7 @@
<script src="{% static 'js/visit.js' %}"></script>
<script>
visit_dates_begaviour($("[name='datetime_begin']"),$("[name='datetime_end']"));
visit_dates_behaviour($("[name='datetime_begin']"),$("[name='datetime_end']"));
</script>
{% include "includes/datepicker.js.html" %}
......
......@@ -3,11 +3,11 @@
{% load filters %}
{% block styles %}
{{ block.super }}
<!-- DataTables -->
<link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}">
{{ block.super }}
<!-- DataTables -->
<link rel="stylesheet" href="{% static 'AdminLTE/plugins/datatables/dataTables.bootstrap.css' %}">
{% include "includes/datepicker.css.html" %}
{% include "includes/datepicker.css.html" %}
{% endblock styles %}
{% block ui_active_tab %}'visits'{% endblock ui_active_tab %}
......@@ -17,189 +17,189 @@
{% block title %}{{ block.super }} - Details of visit ({{ visit.follow_up_title }}) {% endblock %}
{% block breadcrumb %}
{% include "subjects/breadcrumb.html" %}
{% include "subjects/breadcrumb.html" %}
{% endblock breadcrumb %}
{% block maincontent %}
{% block content %}
<div class="box box-info">
<div class="box-header with-border">
<a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default"
onclick="history.back()">Back</a>
<a href="{% url 'web.views.subject_visit_details' visit.subject.id %}" type="button"
class="btn btn-block btn-default">Subject's visits</a>
</div>
{% block content %}
<div class="box box-info">
<div class="box-header with-border">
<a href="{% url 'web.views.visits' %}" class="btn btn-block btn-default"
onclick="history.back()">Back</a>
<a href="{% url 'web.views.subject_visit_details' visit.subject.id %}" type="button"
class="btn btn-block btn-default">Subject's visits</a>
</div>
<div class="box-header with-border">
<h3 class="box-title">Details of visit
<div class="box-header with-border">
<h3 class="box-title">Details of visit
</h3>
</div>
</h3>
</div>
<form method="post" action="" class="form-horizontal">
{% csrf_token %}
<div class="box-body">
{% for field in vform %}
<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">
{{ field.label }}
</label>
<div class="col-sm-8">
{{ field|add_class:'form-control' }}
</div>
{% if field.errors %}
<span class="help-block">
<form method="post" action="" class="form-horizontal">
{% csrf_token %}
<div class="box-body">
{% for field in vform %}
<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">
{{ field.label }}
</label>
<div class="col-sm-8">
{{ field|add_class:'form-control' }}
</div>
{% if field.errors %}
<span class="help-block">
{{ field.errors }}
</span>
{% endif %}
</div>
{% endfor %}
<div class="col-md-6 form-group">
<label class="col-sm-4 control-label">
Visit finished
</label>
<div class="col-sm-8">
{% if visFinished %}
<div class="btn btn-block">YES</div>
{% else %}
<div class="btn btn-block">
{% if canFinish %}
<a href="{% url 'web.views.visit_mark' vid 'finished' %}"
class="btn btn-warning btn-block">Mark as finished</a>
{% else %}
Waiting for appointments to finish.
{% endif %}
{% endif %}
</div>
{% endfor %}
<div class="col-md-6 form-group">
<label class="col-sm-4 control-label">
Visit finished
</label>
<div class="col-sm-8">
{% if visFinished %}
<div class="btn btn-block">YES</div>
{% else %}
<div class="btn btn-block">
{% if canFinish %}
<a href="{% url 'web.views.visit_mark' vid 'finished' %}"
class="btn btn-warning btn-block">Mark as finished</a>
{% else %}
Waiting for appointments to finish.
{% 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>
{% endif %}
</div>
</div><!-- /.box-footer -->
</form>
<div class="box-header with-border">
<h3 class="box-title">Visit's appointments</h3>
</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>
<a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app">
<i class="fa fa-plus"></i>
Add new appointment
</a>
</div>
</div><!-- /.box-footer -->
</form>
<div class="box-header with-border">
<h3 class="box-title">Visit's appointments</h3>
</div>
{% if loApp %}
<table id="table" class="table table-bordered table-striped">
<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>
<a href="{% url 'web.views.appointment_add' vid %}" class="btn btn-app">
<i class="fa fa-plus"></i>
Add new appointment
</a>
</div>
</tbody>
</table>
{% else %}
<p>No appointments found.</p>
{% endif %}
{% if loApp %}
<table id="table" class="table table-bordered table-striped">
<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 %}
</tbody>
</table>
{% else %}
<p>No appointments found.</p>
{% endif %}
<div class="box-header with-border">
<h3 class="box-title">Subject's details</h3>
</div>
<div class="box-header with-border">
<h3 class="box-title">Subject's details</h3>
</div>
<form class="form-horizontal">
<div class="box-body">
{% for field in sform %}
<div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}">
<label for="{# TODO #}" class="col-sm-4 control-label">
{{ field.label }}
</label>
<form class="form-horizontal">
<div class="box-body">
{% for field in sform %}
<div class="col-md-6 form-group {% if field.errors %}has-error{% endif %}">
<label for="{# TODO #}" class="col-sm-4 control-label">
{{ field.label }}
</label>
<div class="col-sm-8">
{{ field|disable|add_class:'form-control' }}
</div>
<div class="col-sm-8">
{{ field|disable|add_class:'form-control' }}
</div>
{% if field.errors %}
<span class="help-block">
{% if field.errors %}
<span class="help-block">
{{ field.errors }}
</span>
{% endif %}
</div>
{% endfor %}
</div><!-- /.box-body -->
{% endif %}
</div>
{% endfor %}
</div><!-- /.box-body -->
<div class="box-footer">
<td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button"
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>
</div><!-- /.box-footer -->
</form>
</div>
<div class="box-footer">
<td><a href="{% url 'web.views.subject_edit' visit.subject.id %}" type="button"
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>
</div><!-- /.box-footer -->
</form>
</div>
</form>
{% endblock %}
</form>
{% endblock %}
</div>
</div>
{% endblock maincontent %}
{% block scripts %}
{{ block.super }}
{{ block.super }}
<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 'js/visit.js' %}"></script>
<script>
visit_dates_begaviour($("[name='datetime_begin']"),$("[name='datetime_end']"));
</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 'js/visit.js' %}"></script>
<script>
visit_dates_behaviour($("[name='datetime_begin']"), $("[name='datetime_end']"));
</script>
{% include "includes/datepicker.js.html" %}
{% include "includes/datepicker.js.html" %}
{% 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