Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-Fall2023-Team-3 into update-filter-functionality
  • Loading branch information
Dhiren-NYU committed Nov 8, 2023
2 parents 3eb6137 + 4d3bffd commit e0d23bc
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CheerUp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"""
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView

urlpatterns = [
path(
"", RedirectView.as_view(pattern_name="events:index", permanent=False)
), # this will change later
path("admin/", admin.site.urls),
path("events/", include("events.urls")),
path("locations/", include("location.urls")),
Expand Down
18 changes: 18 additions & 0 deletions accounts/templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
background-color: #1e87d0; /* Darker background color on button press */
}

.signup-text {
text-align: left;
margin-top: 20px;
font-size: 16px;
}

.signup-link {
color: #3498db;
text-decoration: none;
}

.signup-link:hover {
text-decoration: underline;
}

</style>


Expand All @@ -72,6 +87,9 @@ <h2 class="title">Log In</h2>
{{ form.as_p }}
<button type="submit" class="btn btn-primary" id="login-button">Login</button>
</form>
<div class="signup-text">
Are you new to CheerUp? <a href="{% url 'signup' %}" class="signup-link">Sign up now</a>
</div>
</div>


Expand Down
25 changes: 23 additions & 2 deletions accounts/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# from django.test import TestCase
from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User

# Create your tests here.

class LoginViewTestCase(TestCase):
def setUp(self):
# Create a user for testing login
self.username = "testuser"
self.password = "securepassword123"
User.objects.create_user(
self.username, email="test@example.com", password=self.password
)

def test_login_page_renders(self):
# Test if login page renders correctly
response = self.client.get(reverse("login"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "registration/login.html")

def test_form_displayed(self):
# Test if the login form is in the context
response = self.client.get(reverse("login"))
self.assertIn("form", response.context)
14 changes: 11 additions & 3 deletions events/static/events/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ async function initMap() {
});
const responseEvent = await fetch('events/');
const responseLocation = await fetch('locations/');


const eventHtml = document.getElementsByClassName('event-name');
let eventIds = [];
for(let i =0; i<eventHtml.length;i++){
eventIds[i]= Number(eventHtml[i].getAttribute('id'));
}
const event_data = await responseEvent.json();
const location_objects = await responseLocation.json();
console.log(location_objects);
const location_data = event_data.location_data;
const locations = location_objects.locations;
const locationmap = new Map();
Expand All @@ -19,12 +23,15 @@ async function initMap() {
let duplicateLocationsMap = {};
for(let i=0; i<location_data.length;i++){
let loc = location_data[i].fields;
if(eventIds.includes(event_data.location_data[i].pk)){
if(!duplicateLocationsMap[loc.event_location]){
duplicateLocationsMap[loc.event_location] = [];
}
duplicateLocationsMap[loc.event_location].push({name:loc.event_name,id:event_data.location_data[i].pk});
}
}
for(let i =0; i<location_data.length;i++){
if(eventIds.includes(event_data.location_data[i].pk)){
let lat = -1, lng = -1;
if(locationmap.get(location_data[i].fields.event_location)!=null){
lat = locationmap.get(location_data[i].fields.event_location)[0];
Expand All @@ -46,7 +53,7 @@ async function initMap() {
var eventNameDiv = document.createElement('div');
eventNameDiv.className = "eventnameDiv";
eventNameDiv.addEventListener("click", function(e){
window.location.href += `${locEvent.id}`;
window.location.href = window.location.origin+"/events/"+`${locEvent.id}`;
});
eventNameDiv.innerHTML = `${locEvent.name}`+"\n";

Expand All @@ -62,6 +69,7 @@ async function initMap() {
infoWindow.open(map, marker);
});
}
}

}

Expand Down
40 changes: 29 additions & 11 deletions events/templates/events/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,48 @@ <h1>Cheer↑</h1>
</div>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<nav class="navbar navbar-expand-lg navbar-light bg-light px-5">
<!-- Brand/logo -->
<a class="navbar-brand" href="#">Cheer↑</a>
<a class="navbar-brand" href="{% url 'events:index' %}">Cheer↑</a>

<!-- Toggler/collapsible Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<!-- Navbar links -->
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="#">Find Out Events</a>
<a class="nav-link" href="{% url 'events:index' %}">Find Out Events</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">My events</a>
<a class="nav-link" href="{% url 'events:create-event' %}">Create a Event</a>
</li>
<li class="nav-item">
<!-- <li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</li> -->
</ul>
<ul class="navbar-nav">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">Hello {{ user.username }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}?next={{ request.path }}">Log out</a>
</li>
{% else %}
<li class="nav-item">
{% if request.resolver_match.url_name == 'signup' %} <!-- Check if current path is the signup page -->
<a class="nav-link" href="{% url 'login' %}?next={% url 'events:index' %}">Log in</a>
{% else %}
<a class="nav-link" href="{% url 'login' %}?next={{ request.path }}">Log in</a>
{% endif %}
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'signup' %}?next={{ request.path }}">Sign up</a>
</li>
{% endif %}
</ul>
</div>
</nav>
Expand Down
54 changes: 42 additions & 12 deletions events/templates/events/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,48 @@ <h1>Cheer↑</h1>
</div>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<nav class="navbar navbar-expand-lg navbar-light bg-light px-5">
<!-- Brand/logo -->
<a class="navbar-brand" href="#">Cheer↑</a>
<a class="navbar-brand" href="{% url 'events:index' %}">Cheer↑</a>

<!-- Toggler/collapsible Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<!-- Navbar links -->
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="#">Find Out Events</a>
<a class="nav-link" href="{% url 'events:index' %}">Find Out Events</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">My events</a>
<a class="nav-link" href="{% url 'events:create-event' %}">Create a Event</a>
</li>
<li class="nav-item">
<!-- <li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</li> -->
</ul>
<ul class="navbar-nav">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">Hello {{ user.username }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}?next={{ request.path }}">Log out</a>
</li>
{% else %}
<li class="nav-item">
{% if request.resolver_match.url_name == 'signup' %} <!-- Check if current path is the signup page -->
<a class="nav-link" href="{% url 'login' %}?next={% url 'events:index' %}">Log in</a>
{% else %}
<a class="nav-link" href="{% url 'login' %}?next={{ request.path }}">Log in</a>
{% endif %}
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'signup' %}?next={{ request.path }}">Sign up</a>
</li>
{% endif %}
</ul>
</div>
</nav>
Expand Down Expand Up @@ -127,7 +145,7 @@ <h1>Events</h1>
<ul>
{% for event in events %}
<li class="event-item">
<a href="{% url 'events:event-detail' event.id %}"><strong>{{ event.event_name }}</strong></a>
<a id={{event.id}} href="{% url 'events:event-detail' event.id %}" class="event-name"><strong>{{ event.event_name }}</strong></a>
<p>Event Location: {{ event.event_location }}</p>
<p>Start time: {{ event.start_time }}</p>
<p>End Time: {{ event.end_time }}</p>
Expand Down Expand Up @@ -226,6 +244,18 @@ <h1>Events</h1>

return true;
}

const urlParams = new URLSearchParams(window.location.search);
const error_message = urlParams.get('error_message');

// Display the error message if it exists
if (error_message) {
alert(error_message)
}
// Remove the error message from the URL
urlParams.delete('error_message');
const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
window.history.replaceState({}, document.title, newUrl);
</script>

{% endblock %}
Expand Down
89 changes: 87 additions & 2 deletions events/templates/events/update-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@

{% block extra_styles %}
<style>
/* Loader container */
.loader-container {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7); /* Semi-transparent gray background */
z-index: 9998; /* Ensure it appears behind the loader */
}

/* Loader */
.loader {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 6px solid #f3f3f3;
border-top: 6px solid #3498db;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 2s linear infinite;
z-index: 9999; /* Ensure it appears on top of other elements */
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

.update-event-form label,
.update-event-form textarea {
font-size: 2rem;
Expand All @@ -24,7 +56,9 @@
{% endblock %}

{% block content %}

<div class="loader-container">
<div class="loader"></div>
</div>
<div class="sticky-note-container-mid mt-5">
<form action="{% url 'events:update-event' event.id %}" method="post" class="update-event-form">
{% csrf_token %}
Expand Down Expand Up @@ -65,6 +99,9 @@
<button type="submit" class="btn btn-primary" id="update-event-button">UPDATE EVENT</button>
</fieldset>
</form>
<div class="alert alert-danger" role="alert" id="json-response" style="display: none;">
<pre></pre>
</div>
</div>
{% endblock %}.
{% block extra_scripts %}
Expand Down Expand Up @@ -185,7 +222,6 @@
input.addEventListener('input', async function () {
const query = input.value.toLowerCase();
list.innerHTML = '';
console.log(query)
if (query) {
try {
const response = await fetch(API_ENDPOINT + query);
Expand All @@ -212,5 +248,54 @@
list.innerHTML = '';
}
});

const form = document.querySelector('.update-event-form');
const jsonResponseElement = document.getElementById('json-response');

form.addEventListener('submit', async (event) => {
event.preventDefault();
const loaderContainer = document.querySelector('.loader-container');
// Show the loader and overlay
loaderContainer.style.display = 'block';
// Create a new FormData object to capture form data
const formData = new FormData(form);

try {
const response = await fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value,
},
});
console.log(response)
if (response.status === 400) {
// Display the JSON response with proper formatting
const responseData = await response.json();
// Create an empty string to store the values
let valuesText = "";

// Loop through the key-value pairs and append the values
for (const key in responseData) {
if (responseData.hasOwnProperty(key)) {
valuesText += `${responseData[key]}\n`;
}
}
jsonResponseElement.querySelector('pre').textContent = valuesText;
jsonResponseElement.style.display = 'block';
loaderContainer.style.display = 'none';
} else if (response.status === 200) {
window.location.href = response.url
setTimeout(() => {
// Hide the loader and overlay when loading is complete
loaderContainer.style.display = 'none';
}, 4000);
}
} catch (error) {
console.error(error);
loaderContainer.style.display = 'none';
}
});

</script>
{% endblock %}.

0 comments on commit e0d23bc

Please sign in to comment.