diff --git a/roofis2/roomservice/urls.py b/roofis2/roomservice/urls.py index 474f733..8a0dacc 100644 --- a/roofis2/roomservice/urls.py +++ b/roofis2/roomservice/urls.py @@ -12,7 +12,6 @@ urlpatterns = [ path('adminpage', views.admin, name='admin'), path('booking', views.booking, name='booking'), path('search', views.search, name='search'), - path('search', views.location_based_search, name='location-based-search'), + path('location_search', views.location_based_search, name='location-based-search'), + path('filter_search', views.filter_search, name='filter-search')] - path('roomservice', include('roomservice.api.urls')) -] diff --git a/roofis2/roomservice/views.py b/roofis2/roomservice/views.py index 2fffa46..5a15859 100644 --- a/roofis2/roomservice/views.py +++ b/roofis2/roomservice/views.py @@ -1,7 +1,7 @@ from roomservice.models import Room, Favorite, Booking, Staff from .forms import FavoriteForm -import datetime -from django.shortcuts import render, redirect +from django.shortcuts import render +from roomservice.models import Room import logging logger = logging.getLogger(__name__) @@ -15,48 +15,7 @@ def search(request): def booking(request): room_id = request.POST["room"] - room = Room.objects.get(id=room_id) - startdate = datetime.date.today() - weekday = startdate.weekday() - logger.info(weekday) - enddate = startdate + datetime.timedelta(7) - multd = [] - bookings = Booking.objects.filter(room_id=room.id, start_date__gte=startdate, end_date__lte=enddate) - logger.info(bookings) - for booking in bookings: - logger.info(booking) - sdate = booking.start_date - logger.info(sdate) - edate = booking.end_date - logger.info(edate) - stime = booking.start_time.hour - logger.info(stime) - etime = booking.end_time.hour + 1 - logger.info(etime) - if edate != sdate: - break - else: - if weekday == 0: - day = "Monday" - elif weekday == 1: - day = "Tuesday" - elif weekday == 2: - day = "Wednesday" - elif weekday == 3: - day = "Thursday" - elif weekday == 4: - day = "Friday" - elif weekday == 5: - day = "Saturday" - elif weekday == 6: - day = "Sunday" - timediff = etime - stime - if timediff > 1: - while timediff > 1: - multd.append(day + (stime + timediff - 1).__str__() + "-" + (stime + timediff).__str__()) - timediff = timediff - 1 - logger.info(multd) - return render(request, 'booking.jinja', {"title": "rooF(i)S is love rooF(i)S is live!!", "multd": multd}) + return render(request, 'booking.jinja', {"title": "rooF(i)S is love rooF(i)S is live!!", "data": room_id}) def admin(request): @@ -97,3 +56,10 @@ def success(request): def error(request): return render(request, 'error.jinja', {"title": "rooF(i)S is love rooF(i)S is live!!"}) + + +def filter_search(request): + if request.method == "POST": + logger.info(request.POST) + + return render(request, 'search.jinja', {"title": "rooF(i)S is love rooF(i)S is live!!"}) diff --git a/roofis2/static/js/script.js b/roofis2/static/js/script.js new file mode 100644 index 0000000..3fdf481 --- /dev/null +++ b/roofis2/static/js/script.js @@ -0,0 +1,38 @@ +$(document).ready(function () { + updateColors(); +}); + +listOfIds = []; + +function updateColors(booking) { + let list = []; + + if (booking !== undefined) { + let day = (getDayOfWeek(booking.start_date)); + let beginningHour = booking.start_time.substr(0, 2); + let endingHour = booking.end_time.substr(0, 2) - 1; + + console.log(day + beginningHour + "-" + endingHour); + listOfIds.push(day + beginningHour + "-" + endingHour); + + } + + listOfIds.forEach(id => { + $("#"+id).addClass('booked'); + }); +} + +// Accepts a Date object or date string that is recognized by the Date.parse() method +function getDayOfWeek(date) { + var dayOfWeek = new Date(date).getDay(); + return isNaN(dayOfWeek) ? null : ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][dayOfWeek]; +} + +function init(id) { + $.getJSON({url: "/api/booking?room_id="+id, success: function (result) { + result.forEach(booking =>{ + updateColors(booking) + }) + }}); + +} \ No newline at end of file diff --git a/roofis2/templates/base.jinja b/roofis2/templates/base.jinja index 118ebfd..14a2337 100644 --- a/roofis2/templates/base.jinja +++ b/roofis2/templates/base.jinja @@ -8,15 +8,15 @@ {% block title %}{% endblock %} {% endblock %} - + {% block js_extra %}{% endblock %} {# #} - +
diff --git a/roofis2/templates/booking.jinja b/roofis2/templates/booking.jinja index c1e5c18..3b42a57 100644 --- a/roofis2/templates/booking.jinja +++ b/roofis2/templates/booking.jinja @@ -1,11 +1,10 @@ {% extends 'base.jinja' %} {% block content %} -{% for day in multd%} - -{% endfor %} + @@ -114,7 +113,7 @@ - + diff --git a/roofis2/templates/search.jinja b/roofis2/templates/search.jinja index 0fcf368..1344a6d 100644 --- a/roofis2/templates/search.jinja +++ b/roofis2/templates/search.jinja @@ -4,28 +4,72 @@
+

+ +
+ +

+ +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+ + + + +
+ +
- -
- - -
- -
+ +
+ + +
+ +
15:00 - 16:00