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

Main #219

Closed
wants to merge 3 commits into from
Closed

Main #219

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
52 changes: 52 additions & 0 deletions 5star_review_system/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from flask import Flask, render_template, request, jsonify
import mysql.connector
from datetime import datetime

app = Flask(__name__)

# MySQL configuration
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'password',
'database': 'dataverse'
}

def get_db_connection():
conn = mysql.connector.connect(**db_config)
return conn

@app.route('/')
def index():
# Fetch reviews from the database
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute('SELECT * FROM reviews ORDER BY timestamp DESC')
reviews = cursor.fetchall()
conn.close()

return render_template('index.html', reviews=reviews)

@app.route('/submit-review', methods=['POST'])
def submit_review():
data = request.get_json()

name = data['name']
email = data['email']
rating = int(data['rating'])
review_text = data['review']
timestamp = datetime.now()

conn = get_db_connection()
cursor = conn.cursor()
cursor.execute(
'INSERT INTO reviews (name, email, rating, review, timestamp) VALUES (%s, %s, %s, %s, %s)',
(name, email, rating, review_text, timestamp)
)
conn.commit()
conn.close()

return jsonify({'success': True})

if __name__ == '__main__':
app.run(debug=True)
12 changes: 12 additions & 0 deletions 5star_review_system/db_config.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE DATABASE IF NOT EXISTS dataverse;

USE dataverse;

CREATE TABLE IF NOT EXISTS reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255),
rating INT,
review TEXT,
timestamp DATETIME
);
2 changes: 2 additions & 0 deletions 5star_review_system/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==2.0.2
mysql-connector-python==8.0.26
43 changes: 43 additions & 0 deletions 5star_review_system/satic/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const form = document.getElementById('ratingForm');

form.addEventListener('submit', async function (event) {
event.preventDefault();

const formData = new FormData(form);
const data = {
name: formData.get('name'),
email: formData.get('email'),
rating: formData.get('rating'),
review: formData.get('review')
};

try {
const response = await fetch('/submit-review', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const result = await response.json();

const messageElement = document.getElementById('responseMessage');
if (result.success) {
messageElement.textContent = "Thank you for your review!";
messageElement.style.color = 'green';
form.reset();
} else {
messageElement.textContent = "There was an error submitting your review.";
messageElement.style.color = 'red';
}
} catch (error) {
const messageElement = document.getElementById('responseMessage');
messageElement.textContent = "There was an error submitting your review: " + error.message;
messageElement.style.color = 'red';
}
});
37 changes: 37 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,43 @@
<img src="website/web_images/settings.webp" class="copy" id="default">
</button>
</div>
<div class="feedback-form">
<form id="feedbackForm" action="/submit_feedback" method="post">
<h2>Let Me Know Your Thoughts!</h2>
<input type="text" name="name" placeholder="Your Name" required>
<input type="email" name="email" placeholder="Your Email ID" required>
<textarea name="message" placeholder="Your Message" required></textarea>

<!-- Star Rating Section -->
<div class="star-rating">
<label>Rate Us:</label>
<input type="radio" id="star5" name="rating" value="5">
<label for="star5" title="5 stars">★</label>
<input type="radio" id="star4" name="rating" value="4">
<label for="star4" title="4 stars">★</label>
<input type="radio" id="star3" name="rating" value="3">
<label for="star3" title="3 stars">★</label>
<input type="radio" id="star2" name="rating" value="2">
<label for="star2" title="2 stars">★</label>
<input type="radio" id="star1" name="rating" value="1">
<label for="star1" title="1 star">★</label>
</div>

<button type="submit">Send</button>
</form>
</div>

<div class="feedback-list">
<h2>User Feedback</h2>
{% for feedback in feedback_list %}
<div class="feedback-item">
<p><strong>{{ feedback.name }}</strong> ({{ feedback.rating }} stars)</p>
<p>{{ feedback.message }}</p>
</div>
{% endfor %}
</div>


<button class="top" id="top" onclick="topFunction()"><img src="website/web_images/top.webp" alt=""></button>
<nav id="navbar">
<img src="website/web_images/3dlogo.svg" alt="Dataverse Logo" class="logo" id="normal">
Expand Down
25 changes: 25 additions & 0 deletions website/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@
--angle: 300deg;
}

.star-rating {
display: flex;
flex-direction: row-reverse;
justify-content: center;
}

.star-rating input {
display: none;
}

.star-rating label {
font-size: 2rem;
color: #ccc;
cursor: pointer;
}

.star-rating input:checked ~ label {
color: #ffdd00;
}

.star-rating label:hover,
.star-rating label:hover ~ label {
color: #ffdd00;
}


html {
scroll-behavior: smooth;
Expand Down