diff --git a/backend/RateMyCourse/urls.py b/backend/RateMyCourse/urls.py index a3f6829..9cbc84d 100644 --- a/backend/RateMyCourse/urls.py +++ b/backend/RateMyCourse/urls.py @@ -20,8 +20,8 @@ from django.contrib.staticfiles.views import serve from django.views.generic import RedirectView urlpatterns = [ - # / routes to index2.html - url(r'^$', serve, kwargs={'path': 'index2.html'}), + # / routes to index.html + url(r'^$', serve, kwargs={'path': 'index.html'}), # static files (*.css, *.js, *.jpg etc.) served on / # (assuming Django uses /static/ and /media/ for static/media urls) diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index 2361f25..359edf3 100644 Binary files a/backend/db.sqlite3 and b/backend/db.sqlite3 differ diff --git a/backend/postings/api/serializers.py b/backend/postings/api/serializers.py index b8052b0..af78342 100644 --- a/backend/postings/api/serializers.py +++ b/backend/postings/api/serializers.py @@ -15,8 +15,7 @@ class UniversityReviewSerializer(serializers.ModelSerializer): 'content', ] read_only_fields =[ - 'pk', - 'username' + 'pk' ] # Serializes the generic Review object. @@ -75,4 +74,4 @@ class ProfessorSerializer(serializers.ModelSerializer): ] read_only_fields = [ 'pk' - ] \ No newline at end of file + ] diff --git a/backend/postings/migrations/0002_auto_20180927_1115.py b/backend/postings/migrations/0002_auto_20180927_1115.py new file mode 100644 index 0000000..68acb33 --- /dev/null +++ b/backend/postings/migrations/0002_auto_20180927_1115.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.1 on 2018-09-27 11:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('postings', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='universityreview', + name='date_published', + field=models.DateTimeField(auto_now_add=True), + ), + ] diff --git a/backend/postings/models.py b/backend/postings/models.py index b1d8bb8..f6cf652 100644 --- a/backend/postings/models.py +++ b/backend/postings/models.py @@ -50,6 +50,6 @@ class UniversityReview(models.Model): username = models.CharField(max_length=200) rating = models.IntegerField(default=1) title = models.CharField(max_length=200) - date_published = models.DateField('date published') + date_published = models.DateTimeField(auto_now_add=True) content = models.CharField(max_length=200) \ No newline at end of file diff --git a/frontpage/index.html b/frontpage/index.html index 3b3b033..fdc2fa0 100644 --- a/frontpage/index.html +++ b/frontpage/index.html @@ -3,81 +3,240 @@ - - - - - - - + + + + + + + - - - - + + + + - - - - - -
-
-

Find rated courses

-

The best course reviews by your fellow students!

-
-
-
- -
- + +
+ +
+
+

Software engineering and startups

+

Rijksuniversiteit Groningen

+
+
+
+ + +
+
+
+
+
+ + + - +
+
+
+ +
+
+
- - - - - - - - + + + + + + + + + + + + + diff --git a/frontpage/index2.html b/frontpage/index2.html deleted file mode 100644 index c3e23b5..0000000 --- a/frontpage/index2.html +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
-

Software engineering and startups

-

Rijksuniversiteit Groningen

-
-
-
-
-
-
-

Average user rating

-

3 / 5

- - - - - -
-
-
-

Rating breakdown

-
-
-
5
-
-
-
-
- 80% Complete (danger) -
-
-
-
0
-
-
-
-
4
-
-
-
-
- 80% Complete (danger) -
-
-
-
1
-
-
-
-
3
-
-
-
-
- 80% Complete (danger) -
-
-
-
1
-
-
-
-
2
-
-
-
-
- 80% Complete (danger) -
-
-
-
1
-
-
-
-
1
-
-
-
-
- 80% Complete (danger) -
-
-
-
0
-
-
-
- -
-
-
-
- - - - -
-
-
-
- - - -
- -
-
- - - -
-
-
- -
- - - - - - - - - - - - - - - - diff --git a/frontpage/js/load_reviews.js b/frontpage/js/load_reviews.js index 3902ad8..ed4c725 100644 --- a/frontpage/js/load_reviews.js +++ b/frontpage/js/load_reviews.js @@ -1,28 +1,27 @@ var $ = jQuery; +Handlebars.registerHelper('times', function(n, block) { + var accum = ''; + for(var i = 0; i < n; ++i) + accum += block.fn(i); + return accum; +}); + // Load the handlebars template and use it to append all reviews. function displayReviews(reviews) { var template = Handlebars.compile($("#review_item_handlebars").html()); var container = $("#review_container"); + container.remove(".review_item"); reviews.forEach(function (review) { var review_html = template(review); container.append(review_html); - // If a rating is defined, then hide only those rating stars which are higher than the current rating. - // TODO: remove this check once this is added to the database. - if (typeof(review.rating) !== "undefined") { - $(".js_review_rating").each(function (index) { - if ((index + 1) > review.rating) { - this.hide(); - } - }); - } container.append("

"); }); } function loadReviews () { $.ajax({ - url: "http://localhost:8000/api/postings/", + url: "/api/postings/", method: "GET" }).done(function (response) { displayReviews(response); diff --git a/frontpage/js/main.js b/frontpage/js/main.js index dc305f4..b61dd7d 100644 --- a/frontpage/js/main.js +++ b/frontpage/js/main.js @@ -34,37 +34,4 @@ $(function(){ closeReviewBtn.hide(); }); - - $('.starrr').on('starrr:change', function(e, value){ - ratingsField.val(value); - }); - var i; - for(i = 1; i<6; i++) { - $(".stars").append(""); - } - $(".stars .btn").click(function(e, value) { - $(".starrr").attr("data-rating", this.value); - for (let j = 1; j <= this.value; j++) { - $("#star" + j).removeClass("btn-default btn-grey").addClass("btn-warning"); - } - for (let g = this.value; g <= 5; g++) { - $("#star" + (g+1)).addClass("btn-default btn-grey").removeClass("btn-warning"); - } - }); - - - var d = new Date(); - - var month = d.getMonth()+1; - var day = d.getDate(); - - var output = - - ((''+day).length<2 ? '0' : '') + day + '/' + - ((''+month).length<2 ? '0' : '') + month + '/' + - d.getFullYear(); - $(".date").append(output); - }); \ No newline at end of file diff --git a/frontpage/js/post_review.js b/frontpage/js/post_review.js new file mode 100644 index 0000000..33d0bfc --- /dev/null +++ b/frontpage/js/post_review.js @@ -0,0 +1,47 @@ +var $ = jQuery; + +// Sends POST request to api. +function postReview (data) { + $.ajax({ + url: "api/postings/", + method: "POST", + data: JSON.stringify(data), + contentType: "application/json", + headers: { + 'X-CSRFToken': Cookies.get("csrftoken") + } + }).done(function (response) { + var template = Handlebars.compile($("#review_item_handlebars").html()); + var container = $("#review_container"); + var review_html = template(response); + container.append(review_html); + container.append("

"); + }).fail(function (response) { + console.log(response); + alert("The review could not be sent."); + }).always(function () { + $("#submit_review_form").trigger("reset"); + $('#close-review-box').trigger("click"); + }); +} + +// What to do when the user clicks submit. +function onSubmitReviewClicked () { + var serialized_data = $("#submit_review_form").serializeArray(); + var formatted_data = {}; + for (var i = 0; i < serialized_data.length; i++) { + formatted_data[serialized_data[i]['name']] = serialized_data[i]['value']; + } + console.log(formatted_data); + postReview(formatted_data); +} + +// Add a listener for when the user clicks to submit a review. +$(document.body) + .off("click.submit_review_button") + .on("click.submit_review_button", + "#submit_review_button", + function (event) { + event.preventDefault(); + onSubmitReviewClicked(); + }); \ No newline at end of file