Skip to content
Open

Hw 5 #27

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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/JS_Template.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/easycode.ignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions data/polls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[
{
"id": "poll_1",
"question": "What is your favorite programming language?",
"category": "technology",
"options": [
{ "text": "JavaScript", "votes": 67 },
{ "text": "Python", "votes": 52 },
{ "text": "Java", "votes": 23 },
{ "text": "C++", "votes": 8 }
],
"totalVotes": 150
},
{
"id": "poll_2",
"question": "Which social media platform do you use the most?",
"category": "lifestyle",
"options": [
{ "text": "Facebook", "votes": 98 },
{ "text": "Instagram", "votes": 84 },
{ "text": "Twitter", "votes": 70 },
{ "text": "LinkedIn", "votes": 28 }
],
"totalVotes": 280
},
{
"id": "poll_3",
"question": "What is your favorite color?",
"category": "lifestyle",
"options": [
{ "text": "Blue", "votes": 38 },
{ "text": "Green", "votes": 29 },
{ "text": "Red", "votes": 19 },
{ "text": "Yellow", "votes": 9 }
],
"totalVotes": 95
},
{
"id": "poll_4",
"question": "Which business strategy is most important for startups?",
"category": "business",
"options": [
{ "text": "Product-Market Fit", "votes": 145 },
{ "text": "Marketing & Sales", "votes": 87 },
{ "text": "Team Building", "votes": 63 },
{ "text": "Funding", "votes": 41 }
],
"totalVotes": 336
},
{
"id": "poll_5",
"question": "What's your preferred streaming service?",
"category": "entertainment",
"options": [
{ "text": "Netflix", "votes": 156 },
{ "text": "YouTube", "votes": 134 },
{ "text": "Disney+", "votes": 78 },
{ "text": "Amazon Prime", "votes": 92 }
],
"totalVotes": 460
},
{
"id": "poll_6",
"question": "Which AI tool do you use most frequently?",
"category": "technology",
"options": [
{ "text": "ChatGPT", "votes": 189 },
{ "text": "Claude", "votes": 67 },
{ "text": "Gemini", "votes": 43 },
{ "text": "Copilot", "votes": 28 }
],
"totalVotes": 327
},
{
"id": "poll_7",
"question": "What's your favorite movie genre?",
"category": "entertainment",
"options": [
{ "text": "Action", "votes": 112 },
{ "text": "Comedy", "votes": 98 },
{ "text": "Drama", "votes": 76 },
{ "text": "Sci-Fi", "votes": 54 }
],
"totalVotes": 340
},
{
"id": "poll_8",
"question": "Which remote work tool is most essential?",
"category": "business",
"options": [
{ "text": "Zoom", "votes": 134 },
{ "text": "Slack", "votes": 89 },
{ "text": "Microsoft Teams", "votes": 76 },
{ "text": "Discord", "votes": 43 }
],
"totalVotes": 342
}
]
72 changes: 69 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,77 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple HTML Page</title>
<link rel="stylesheet" href="./style/style.css">
<script src="./src/main.js" defer></script>
<title>Polling Website</title>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<script src="src/main.js"></script>
<div class="container">
<div class="create-poll-header">
<a href="report.html" class="create-poll-btn stats-btn">View Stats</a>
<a href="#create-poll-modal" class="create-poll-btn">Create Poll</a>
</div>

<div class="search-bar">
<input type="text" class="search-input" placeholder="Search polls...">
<select class="category-dropdown">
<option value="">Category</option>
<option value="business">Business</option>
<option value="lifestyle">Lifestyle</option>
<option value="technology">Technology</option>
<option value="entertainment">Entertainment</option>
</select>
</div>

<div class="poll-grid">
<!-- Polls will be loaded dynamically by JavaScript -->
</div>
</div>

<!-- Create Poll Modal -->
<div id="create-poll-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Create Poll</h2>
<a href="#" class="close-btn">&times;</a>
</div>
<form class="poll-form" action="#" method="post">
<div class="form-group">
<label for="question">Question</label>
<input type="text" id="question" name="question" placeholder="Enter your question" required>
</div>

<div class="form-group">
<label for="category">Category</label>
<select id="category" name="category" required>
<option value="">Select category</option>
<option value="business">Business</option>
<option value="lifestyle">Lifestyle</option>
<option value="technology">Technology</option>
<option value="entertainment">Entertainment</option>
</select>
</div>

<div class="form-group">
<label>Options</label>
<div class="options-container">
<input type="text" class="option-input" name="option1" placeholder="Option 1" required>
<input type="text" class="option-input" name="option2" placeholder="Option 2" required>
<input type="text" class="option-input" name="option3" placeholder="Option 3">
<input type="text" class="option-input" name="option4" placeholder="Option 4">
</div>
<button type="button" class="add-option-btn">Add option</button>
</div>

<div class="modal-actions">
<a href="#" class="cancel-btn">Cancel</a>
<button type="submit" class="create-btn">Create</button>
</div>
</form>
</div>
</div>

<!-- Voting modals will be created dynamically by JavaScript -->

</body>
</html>
105 changes: 105 additions & 0 deletions report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Polls Report - WebDataRocks</title>
<link rel="stylesheet" href="style/style.css">
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
</head>
<body>
<div class="container">
<div class="analytics-header">
<h1 class="analytics-title">Polls Report</h1>
<div class="nav-links">
<a href="index.html" class="nav-link secondary">Back to Polls</a>
</div>
</div>

<div class="analytics-section">
<h2 class="section-title">Detailed Poll Data</h2>
<div id="wdr-component" class="pivot-container"></div>
</div>
</div>

<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async () => {
let allPolls = [];

try {
const response = await fetch('/data/polls.json');
const pollsData = await response.json();
allPolls = [...pollsData];
} catch (error) {
console.error('Error loading initial polls:', error);
}

const localPolls = localStorage.getItem('localPolls');
if (localPolls) {
try {
const parsedLocalPolls = JSON.parse(localPolls);
allPolls = [...allPolls, ...parsedLocalPolls];
} catch (error) {
console.error('Error parsing local polls from localStorage:', error);
}
}

const transformedData = [];
allPolls.forEach(poll => {
poll.options.forEach(option => {
transformedData.push({
"Poll ID": poll.id,
"Question": poll.question,
"Category": poll.category,
"Option Text": option.text,
"Votes": option.votes,
});
});
});

const pivot = new WebDataRocks({
container: "#wdr-component",
toolbar: true,
report: {
dataSource: {
data: transformedData
},
"slice": {
"rows": [
{
"uniqueName": "Category"
},
{
"uniqueName": "Question"
},
{
"uniqueName": "Option Text"
}
],
"columns": [
{
"uniqueName": "[Measures]"
}
],
"measures": [
{
"uniqueName": "Votes",
"aggregation": "sum",
"caption": "Votes per Option"
}
]
},
"options": {
"grid": {
"title": "Polls Data Report",
"showGrandTotals": "on"
}
}
}
});
});
</script>
</body>
</html>
Loading