Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions appGlobals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
import psycopg2
from psycopg2.extensions import cursor
from psycopg2 import connect
import logging
import os


class RADSADatabaseCursor(cursor):
""" Object for wrapping the psycopg2 cursor class for RADSA. """

def execute(self, sql, args=None):

try:
# Execute the provided SQL
cursor.execute(self, sql, args)

except Exception as e:
# Log the occurrence
logging.exception("Error encountered querying database - {}:{}".format(e.__class__.__name__, e))

# Rollback the transaction
self.connection.rollback()


# Set up baseOpts to be sent to each HTML template
baseOpts = {
"HOST_URL": os.getenv("HOST_URL", "https://localhost:5000")
}

# Establish DB connection
conn = psycopg2.connect(os.getenv("DATABASE_URL", "postgres:///ra_sched"))
conn = connect(
os.getenv("DATABASE_URL", "postgres:///ra_sched"),
cursor_factory=RADSADatabaseCursor
)

# Set up various global variables
UPLOAD_FOLDER = "./static"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MarkupSafe==1.1.1
oauth2client==4.1.2
oauthlib==2.1.0
pika==1.2.0
protobuf==3.13.0
protobuf==3.15.0
psycopg2==2.9.1
pyasn1==0.4.2
pyasn1-modules==0.2.1
Expand Down
13 changes: 0 additions & 13 deletions schedule/static/editSched.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,6 @@
color: var(--blue);
}

.datepicker {
max-width: 90%;
}

.datepicker-days .table-condensed {
width: 100%;
}

.datepicker.datepicker-dropdown.dropdown-menu {
width: 20%;
max-width: 568px; /*500px - 32px*/
border-width: 3px;
}
.badge {
margin: 5px auto;
}
Expand Down
36 changes: 27 additions & 9 deletions schedule/static/editSched.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,38 @@ function editSchedMoveCalendar(direction) {
}

// Adjust the datepicker in the run scheduler modal to look at the next month.
$('#runNoDutyDates').datepicker('setEndDate', new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth()+1, 0));
$('#runNoDutyDates').datepicker('setStartDate', new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth(), 1));

// Set the selection to the 15th of the month to update the view when the
// the date picker is loaded. This will ensure that the proper month is
// shown to the user on focus.
//$('#runNoDutyDates').datepicker('setDate', new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth(), 1);)
//$('#runNoDutyDates').datepicker('clearDates');

resetDatePicker(
new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth(), 1),
new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth()+1, 0),
[]
);
}

function editSchedMovePrev() { editSchedMoveCalendar(-1) }
function editSchedMoveToday() { editSchedMoveCalendar( 0) }
function editSchedMoveNext() { editSchedMoveCalendar( 1) }

function resetDatePicker(start, end, disabledDates) {

console.log(start);
console.log(end);
let opts = {
dateFormat: "d",
maxDate: start,
minDate: end,
mode: "multiple",
conjunction: ", "
}
console.log(opts)

$("#runNoDutyDates").flatpickr().destroy()

$("#runNoDutyDates").flatpickr(opts);

$("#runNoDutyDates").flatpickr(opts).redraw()

}

function initEditSchedCal() {
initCal({
height: "75%",
Expand Down
52 changes: 32 additions & 20 deletions schedule/templates/schedule/editSched.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
<link rel="stylesheet" href="{{url_for('schedule_bp.static', filename='editSched.css')}}">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/css/bootstrap-select.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.min.css" />

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">




{% endblock %}

Expand Down Expand Up @@ -127,8 +131,8 @@ <h3 class="modal-title">Run Scheduler: <span id="runModalLongTitle" style="font-
<label for="runNoDutyDates">
Select the days that where no duties should be assigned.
</label>
<div class="input-group date form-group" id="datepicker" data-provider="datepicker">
<input type="text" class="form-control datepicker" id="runNoDutyDates" name="runNoDutyDates"
<div class="input-group form-group" id="datepicker" data-provider="datepicker">
<input type="text" class="form-control flatpickr flatpickr-input" id="runNoDutyDates" name="runNoDutyDates"
placeholder="Select no duty days..." required />
<span class="input-group-addon">
<i class="fa fa-lg fa-calendar"></i>
Expand Down Expand Up @@ -293,7 +297,7 @@ <h3 class="modal-title">Scheduler Request <span id="schedReqID"></span></h3>
<script src="{{url_for('static', filename='fullCal.js')}}"></script>
<script src="{{url_for('schedule_bp.static', filename='editSched.js')}}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script>
{# Convert Python's date objects to Javascript's date objects #}
const schoolYearStart = new Date(
Expand Down Expand Up @@ -321,23 +325,31 @@ <h3 class="modal-title">Scheduler Request <span id="schedReqID"></span></h3>
});
$('#runRAList').selectpicker('selectAll');

$(function() {
$('#datepicker').datepicker({
multidate: true,
format: "d",
datesDisabled: [],
language: 'en',
multidateSeparator: ", ",
assumeNearbyYear: true,
clearBtn: true,
disableTouchKeyboard: false,
startDate: '1', // First day of the month
endDate: new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth()+1, 0), // Last day of the month
}).on('changeDate', function(e) {
// `e` here contains the extra attributes
$(this).find('.input-group-addon .count').text(' ' + e.dates.length);
<!-- $(function() {-->
<!-- $('#datepicker').datepicker({-->
<!-- multidate: true,-->
<!-- format: "d",-->
<!-- datesDisabled: [],-->
<!-- language: 'en',-->
<!-- multidateSeparator: ", ",-->
<!-- assumeNearbyYear: true,-->
<!-- clearBtn: true,-->
<!-- disableTouchKeyboard: false,-->
<!-- startDate: '1', // First day of the month-->
<!-- endDate: new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth()+1, 0), // Last day of the month-->
<!-- }).on('changeDate', function(e) {-->
<!-- // `e` here contains the extra attributes-->
<!-- $(this).find('.input-group-addon .count').text(' ' + e.dates.length);-->
<!-- });-->
<!-- });-->

$("#runNoDutyDates").flatpickr({
dateFormat: "d",
maxDate: new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth()+1, 0),
minDate: new Date(appConfig.calDate.getFullYear(), appConfig.calDate.getMonth(), 1),
mode: "multiple",
conjunction: ", "
});
});

</script>
{% endblock %}