Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

v1 #42

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

This file was deleted.

27 changes: 0 additions & 27 deletions api/optimeet/groups/migrations/0004_preferences.py

This file was deleted.

27 changes: 8 additions & 19 deletions api/optimeet/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,24 @@ class Group(models.Model):

class UserGroup(models.Model):
user_id = models.CharField(max_length=64)
group_id = models.ForeignKey(Group, on_delete=models.DO_NOTHING, default="")
group_id = models.ForeignKey(Group, on_delete=models.CASCADE, default="")
class Meta:
unique_together = [["group_id","user_id"]]

class Recommendations(models.Model):
group_id = models.ForeignKey(Group, models.DO_NOTHING)
group_id = models.ForeignKey(Group, models.CASCADE)
activity_id = models.CharField(max_length=50)
place_name = models.CharField(max_length=50)
place_url = models.CharField(max_length=100)
times = models.JSONField()

loc_lat = models.FloatField()
loc_long = models.FloatField()

class Preferences(models.Model):
group_id = models.ForeignKey(Group, on_delete=models.DO_NOTHING, default="")
group_id = models.ForeignKey(Group, on_delete=models.CASCADE, default="")
user_id = models.CharField(max_length=64, blank=True)

categories = models.JSONField()
times = models.JSONField()
category = models.JSONField()
subcategory = models.JSONField()
time = models.JSONField()

lat = models.FloatField()
lon = models.FloatField()
radius = models.FloatField()

class Votes(models.Model):
rec_id = models.ForeignKey(Recommendations, on_delete=models.DO_NOTHING)
group_id = models.ForeignKey(Group, on_delete=models.DO_NOTHING, default="")
user_id = models.CharField(max_length=64)

class Meta:
unique_together = [["rec_id", "user_id"]]
loc_lat = models.FloatField()
loc_long = models.FloatField()
10 changes: 1 addition & 9 deletions api/optimeet/groups/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers
from . import models
from .models import UserGroup, Votes
from .models import UserGroup
from random import randint

def rnd_id(): return randint(1000000000,9999999999)
Expand Down Expand Up @@ -41,11 +41,3 @@ def create(self, validated_data):

return super(PreferencesSerializer, self).create(validated_data)

class VotesSerializer(serializers.ModelSerializer):
class Meta:
model = models.Votes
fields = '__all__'

def create(self, validated_data):
validated_data['group_id'] = self.context['group_id']
return super(VotesSerializer, self).create(validated_data)
4 changes: 2 additions & 2 deletions api/optimeet/groups/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
path('<str:group_id>/users/<str:user_id>/prefs/', views.add_preference_to_group),
#path('usergroups/', views.UserGroupListAPIView.as_view(), name='usergroup-list'),#get all usergroup
#path('usergroups/<str:user_id>/', views.UserGroupListAPIView.as_view(), name='usergroup-byuser'),#get usergroup by user_id
path("<str:group_id>/recs/", views.get_recommendation),
path("<str:group_id>/votes/", views.votes, name='votes')
path("<str:group_id>/recs", views.get_recommendation)

]
23 changes: 1 addition & 22 deletions api/optimeet/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def add_users_to_group(request, group_id):
@csrf_exempt
@api_view(['POST'])
def add_preference_to_group(request, group_id, user_id, format=None):
# Check if the user group exists
# Check if the user group exists
try:
group = models.Group.objects.get(group_id=group_id)

Expand All @@ -88,27 +88,6 @@ def add_preference_to_group(request, group_id, user_id, format=None):

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

@csrf_exempt
@api_view(['GET', 'POST'])
def votes(request, group_id):
if request.method == 'GET':
votes = models.Votes.objects.filter(group_id=group_id)
serializer = serializers.VotesSerializer(votes, many=True)
return Response(serializer.data)
elif request.method == 'POST':
try:
group = models.Group.objects.get(pk=group_id)
except models.Group.DoesNotExist:
raise Http404

serializer = serializers.VotesSerializer(data = request.data, context={'group_id': group})

if serializer.is_valid():
serializer.save()
return Response(status=status.HTTP_201_CREATED)

return Response(status=status.HTTP_400_BAD_REQUEST)

# #for testing
# class UserGroupListAPIView(APIView):
# def get(request, self):
Expand Down
3 changes: 3 additions & 0 deletions web/meetup-facilitator/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Activities from './pages/Activities'
import LocationComponent from './components/LocationComponent'
import TimeMain from './components/TimeMain'
import TimeHour from './components/TimeHour'
import Recommendation from './components/Recommendation'
import Preferences from './pages/Preferences'
import Join from './pages/Join'

Expand All @@ -16,6 +17,8 @@ function App() {
<Router>
<Routes>
<Route path='/' element={<Home/>} />
<Route path='/activities' element={<Activities/>} />
Copy link
Contributor

@ctlchan ctlchan Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be needed since everything is in the preferences route.

<Route path='/recommendations/:group_id' element={<Recommendation/>}/>
<Route path='/login' element={<Login/>} />
<Route path='/preferences/:group_id' element={<Preferences/>}/>
<Route path='/join/:group_id' element={<Join/>}/>
Expand Down
6 changes: 6 additions & 0 deletions web/meetup-facilitator/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function Navbar() {
return (
<div className=' w-screen bg-gray-400 flex items-center justify-between p-4 absolute top-0 left-0'>
<div className="flex items-center">Optimeet</div>
<ul>
<li><a href="/activities">Activities</a></li>
</ul>
<ul>
<li><a href="/recommendation">Recommendation</a></li>
</ul>
<div className="user-info flex justify-evenly items-center gap-4">
<div className="name">{name}</div>
<img src={pictureURL} className="profilePicture w-10 h-10 rounded-full" ></img>
Expand Down
69 changes: 69 additions & 0 deletions web/meetup-facilitator/src/components/RecGoogleMap.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useEffect, useRef } from 'react';


function RecGoogleMap({ coordinates, recommendations }) {
const mapContainerRef = useRef(null);
const map = useRef(null);
const markers = useRef([]);
const infoWindow = useRef(null);

useEffect(() => {
if (!window.google) {
const errorMessage = 'Error: Google Maps API not loaded.';
console.error(errorMessage);
return;
}

if (coordinates && coordinates.length > 0) {
map.current = new window.google.maps.Map(mapContainerRef.current, {
center: { lat: coordinates[0].lat, lng: coordinates[0].lng },
zoom: 12,
});

markers.current.forEach(marker => marker.setMap(null));
markers.current = [];

infoWindow.current = new window.google.maps.InfoWindow({
maxWidth: 200, // Set max width to control the size of the InfoWindow
});

coordinates.forEach(({ lat, lng }, index) => {
const marker = new window.google.maps.Marker({
position: { lat, lng },
map: map.current,
});

markers.current.push(marker);

marker.addListener('mouseover', () => {
if (recommendations && recommendations[index]) {
const content = recommendations[index].place_name;
console.log('Hovered Place Name:', content);

infoWindow.current.setContent(`<div style="font-size: 16px; color: black;">${content}</div>`);

// Disable the close button ('x') on the info window
infoWindow.current.setOptions({
disableAutoPan: true, // Disable auto-panning
maxWidth: 200,
});

infoWindow.current.open(map.current, marker);
}
});

marker.addListener('mouseout', () => {
infoWindow.current.close();
});
});
}
}, [coordinates, recommendations]);

return (
<div>
<div ref={mapContainerRef} style={{ width: '1000px', height: '800px' }} />
</div>
);
}

export default RecGoogleMap;
50 changes: 50 additions & 0 deletions web/meetup-facilitator/src/components/RecPopup.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

import React, { useState } from 'react';

const RecPopup = ({ closeModal, times, onSelect, sampleCoordinates }) => {

const [selectedButton, setSelectedButton] = useState(null);


const handleButtonClick = (buttonId) => {
setSelectedButton(buttonId);
};


return (
<div className="fixed inset-0 flex items-center justify-center">
<div className="fixed inset-0 bg-black opacity-80" onClick={closeModal}></div>

<div className="bg-white p-8 rounded-lg shadow-md relative z-10">
<h2 className="text-xl font-bold mb-4 text-gray-700">Choose a time</h2>

{times.map((time, index) => (
<div
key={index}
className={`rounded-lg p-4 mb-4 cursor-pointer ${
selectedButton === index ? 'border-2 border-green-500 text-gray-700 bg-gray-300' : 'bg-gray-300'
}`}
onClick={() => {
handleButtonClick(index);
onSelect(time);

}}
>
<p className={selectedButton === index ? 'text-gray-700' : ''}>
{time}
</p>
</div>
))}

<button
className="mt-4 bg-slate-700 text-white py-2 px-4 rounded-md"
onClick={closeModal}
>
Close
</button>
</div>
</div>
);
};

export default RecPopup;
Loading