Skip to content

Commit

Permalink
Allow to update Applications from the Report
Browse files Browse the repository at this point in the history
  • Loading branch information
delarosatrevin committed Dec 8, 2020
1 parent e91ea63 commit e6407c3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 42 deletions.
3 changes: 2 additions & 1 deletion emhub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from glob import glob


__version__ = '0.0.3'
__version__ = '0.0.4'


def create_app(test_config=None):
Expand Down Expand Up @@ -116,6 +116,7 @@ def main():
kwargs['version'] = __version__
kwargs['emhub_title'] = app.config.get('EMHUB_TITLE', '')
kwargs['possible_owners'] = app.dc.get_pi_labs()
kwargs.update(app.dc.get_resources_list())

return flask.render_template('main.html', **kwargs)

Expand Down
9 changes: 7 additions & 2 deletions emhub/data/data_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ def _dateStr(self, datetime):
def get(self, **kwargs):
content_id = kwargs['content_id']
get_func_name = 'get_%s' % content_id.replace('-', '_') # FIXME
dataDict = {} # self.get_resources_list()
get_func = getattr(self, get_func_name, None)
return {} if get_func is None else get_func(**kwargs)
if get_func is not None:
dataDict.update(get_func(**kwargs))
return dataDict

def get_dashboard(self, **kwargs):
dataDict = self.get_resources_list()
Expand Down Expand Up @@ -381,7 +384,9 @@ def get_reports_time_distribution(self, **kwargs):
datetime_from_isoformat(d['end'])
)
func = self.app.dc.booking_to_event
bookings = [func(b) for b in bookings]
bookings = [func(b) for b in bookings
if b.resource.is_microscope]

from emhub.reports import get_booking_counters
counters, cem_counters = get_booking_counters(bookings)

Expand Down
48 changes: 20 additions & 28 deletions emhub/templates/booking_calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ <h3 class="modal-title" id="message-title">Message Title (REPLACE ME) </h3>
var calendar;
var selected_resource = null;
var selected_resource_id = {{ resource_id|tojson }};
var booking_type = 'booking';
var repeat_value = null;

var last_booking = null;
var modify_all = false;
var original_range = null;
Expand All @@ -107,25 +106,25 @@ <h3 class="modal-title" id="message-title">Message Title (REPLACE ME) </h3>
(function(window, document, $, undefined) {
"use strict";

{# $('select').selectpicker();#}
{##}
{# $('.datetimepicker-input').datetimepicker({#}
{# format: 'YYYY/MM/DD'#}
{# });#}
{##}
{# /* Register when the Booking type change */#}
{# $('input[type=radio][name=booking-type-radio]').change(function() {#}
{# booking_type = this.value;#}
{# $('#booking-slot-auth').prop('readonly', this.value != 'slot');#}
{# });#}
{##}
{# $('input[type=radio][name=booking-repeat-radio]').change(function() {#}
{# repeat_value = this.value;#}
{# });#}
{##}
{# $('input[type=radio][name=booking-modify-radio]').change(function() {#}
{# modify_all = this.value == 'yes';#}
{# });#}
$('select').selectpicker();

$('.datetimepicker-input').datetimepicker({
format: 'YYYY/MM/DD'
});

/* Register when the Booking type change */
$('input[type=radio][name=booking-type-radio]').change(function() {
booking_type = this.value;
$('#booking-slot-auth').prop('readonly', this.value != 'slot');
});

$('input[type=radio][name=booking-repeat-radio]').change(function() {
repeat_value = this.value;
});

$('input[type=radio][name=booking-modify-radio]').change(function() {
modify_all = this.value == 'yes';
});

/* initialize the external events
-----------------------------------------------------------------*/
Expand Down Expand Up @@ -400,13 +399,6 @@ <h3 class="modal-title" id="message-title">Message Title (REPLACE ME) </h3>
});
}

/** Get the resource object from its id */
function getResource(resourceId) {
for (var r of resources)
if (r.id == resourceId)
return r;
return null;
}

/** This function is called when a different resource is changed. */
function selectResource(sel) {
Expand Down
42 changes: 33 additions & 9 deletions emhub/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
/* Some variables */
var possible_owners = {{ possible_owners|tojson }};
var is_devel = {{ is_devel|tojson }};
var resources = {{ resources|tojson }};
var booking_type = 'booking';
var repeat_value = null;
var has_calendar = true;


(function(window, document, $, undefined) {
Expand All @@ -139,6 +143,8 @@
/* Register when the Booking type change */
$('input[type=radio][name=booking-type-radio]').change(function() {
booking_type = this.value;
console.log("booking_type: " + booking_type);

$('#booking-slot-auth').prop('readonly', this.value != 'slot');
});

Expand Down Expand Up @@ -213,21 +219,33 @@
});
} // function showUser

/* ---------------- RESOURCE functions ------------------*/
/** Get the resource object from its id */
function getResource(resourceId) {
for (var r of resources)
if (r.id == resourceId)
return r;
return null;
}

/* ---------------- BOOKING functions ------------------ */
/** Helper functions to handle AJAX response or failure */
function handleAjaxDone(jsonResponse) {
let error = null;

if ('bookings_created' in jsonResponse) {
add_bookings(jsonResponse.bookings_created);
if (has_calendar)
add_bookings(jsonResponse.bookings_created);
}
else if ('bookings_updated' in jsonResponse) {
remove_bookings(jsonResponse.bookings_updated);
add_bookings(jsonResponse.bookings_updated);
if (has_calendar) {
remove_bookings(jsonResponse.bookings_updated);
add_bookings(jsonResponse.bookings_updated);
}
}
else if ('bookings_deleted' in jsonResponse) {
remove_bookings(jsonResponse.bookings_deleted);
if (has_calendar)
remove_bookings(jsonResponse.bookings_deleted);
}
else if ('error' in jsonResponse) {
error = jsonResponse.error;
Expand All @@ -240,7 +258,8 @@
showError(error);
else {
$('#booking-modal').modal('hide');
calendar.render();
if (has_calendar)
calendar.render();
}
}

Expand All @@ -251,6 +270,9 @@

/* Show the Booking Form, either for a new booking or an existing one */
function showBookingForm(booking) {
booking_type = booking.type;
repeat_value = booking.repeat_value;

var titlePrefix = null;
if (booking.id == null) { // New booking
titlePrefix = 'Create ';
Expand Down Expand Up @@ -387,11 +409,13 @@
endpoint = "{{ url_for('api.create_booking') }}"
}

var error = validateBooking(booking, true);
if (has_calendar) {
var error = validateBooking(booking, true);

if (error != '') {
showError(error);
return;
if (error != '') {
showError(error);
return;
}
}

delete booking.resource; // resource_id is enough
Expand Down
25 changes: 23 additions & 2 deletions emhub/templates/reports_time_distribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ <h5 class="mb-0 col-8">Reminder: Uncategorized Bookings (Review and Update)</h5>
<tr>
<td><a href="javascript:showBooking({{ b['id'] }})">{{ b['title'] }}</a></td>
<td>{{ b['start'] }}</td>
<td></td>
<td><button class="btn btn-sm btn-outline-light" onclick="javascript:showBooking({{ b['id'] }})"><i class="far fa-edit"></i></button>
</td>
</tr>
{% endfor %}

Expand All @@ -141,7 +142,26 @@ <h5 class="mb-0 col-8">Reminder: Uncategorized Bookings (Review and Update)</h5>

<script>
var bookings = {{ overall.reminder|tojson }};
var last_booking = null;

$('select').selectpicker();

$('.datetimepicker-input').datetimepicker({
format: 'YYYY/MM/DD'
});

/* Register when the Booking type change */
$('input[type=radio][name=booking-type-radio]').change(function() {
booking_type = this.value;
$('#booking-slot-auth').prop('readonly', this.value != 'slot');
});

$('input[type=radio][name=booking-repeat-radio]').change(function() {
repeat_value = this.value;
});

$('input[type=radio][name=booking-modify-radio]').change(function() {
modify_all = this.value == 'yes';
});

$('#table-overall').DataTable({
sDom: 'lrtip',
Expand All @@ -167,6 +187,7 @@ <h5 class="mb-0 col-8">Reminder: Uncategorized Bookings (Review and Update)</h5>
}
last_booking.start = new Date(last_booking.start);
last_booking.end = new Date(last_booking.end);
has_calendar = false;
showBookingForm(last_booking);
}

Expand Down

0 comments on commit e6407c3

Please sign in to comment.