Skip to content

a4-sarah-olson #21

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
36 changes: 9 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
Assignment 4 - Components
===
**WPI Badminton Attendance Tracker**

Due: October 4th, by 11:59 AM.
Sarah Olson
A4 Components
link: https://stackblitz.com/edit/a4-sarah-olson?embed=1&file=index.html&hideExplorer=1&hideNavigation=1&view=preview
Note: if clicking the link above results in the page saying "Cannot GET /", clicking "Editor" then "Preview" in the bottom right corner of the browser should allow the page to load.

For this assignment you will re-implement the client side portion of *either* A2 or A3 using either React or Svelte components. If you choose A3 you only need to use components for the data display / updating; you can leave your login UI as is.
I created a web app for Badminton Club members who are using their participation in this course as a gym credit to track their progress toward their grade goal. First the user either enters or creates account information, so that they can only see their progress, and login in. The user then enters their target grade and the dates + amount of hours they attended on each day to keep track of the user's progress toward their grading goal.

[Svelte Tutorial](https://github.com/cs-4241-23/cs-4241-23.github.io/blob/main/using.svelte.md)
[React Tutorial](https://github.com/cs-4241-23/cs-4241-23.github.io/blob/main/using.react.md)
The user can also edit their grading goal and delete entries they make.

This project can be implemented on any hosting service (Glitch, DigitalOcean, Heroku etc.), however, you must include all files in your GitHub repo so that the course staff can view them.
The most obvious change compared to A3 and A2 is that this iteration uses Svelte rather than pure HTML and JS. I also reverted back to locally storing in the server rather than using MongoDB (like A2), but kept the accesibility, server, and style benefits from A3.

Deliverables
---
Initially, adding the new technology proved to be quite useful, being able to split up the pages with all the JS, HTML, and CSS for certain sections and having it all in one place and being able to edit it all at once proved to be helpful. But I ran into big issues with having those seperate components functioning as one, with still some features from A3 (mainly seperate pages) missing. If I was more farmiliar with Svelte from the begining, I think I would have had A3 structured differently to work better.

Do the following to complete this assignment:

1. Implement your project with the above requirements.
3. Test your project to make sure that when someone goes to your main page on Glitch/Heroku/etc., it displays correctly.
4. Ensure that your project has the proper naming scheme `a4-firstname-lastname` so we can find it.
5. Fork this repository and modify the README to the specifications below. Be sure to add *all* project files.
6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a4-firstname-lastname`.

Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions)
---

## Your Web Application Title

your hosting link e.g. http://a4-charlieroberts.glitch.me

Include a very brief summary of your project here and what you changed / added to assignment #3. Briefly (3–4 sentences) answer the following question: did the new technology improve or hinder the development experience?

Unlike previous assignments, this assignment will be solely graded on whether or not you successfully complete it. Partial credit will be generously given.
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>WPI Badminton Tracker</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"moduleResolution": "bundler",
"target": "ESNext",
"module": "ESNext",
/**
* svelte-preprocess cannot figure out whether you have
* a value or a type, so tell TypeScript to enforce using
* `import type` instead of `import` for Types.
*/
"verbatimModuleSyntax": true,
"isolatedModules": true,
"resolveJsonModule": true,
/**
* To have warnings / errors of the Svelte compiler at the
* correct position, enable source maps by default.
*/
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types.
*/
"checkJs": true
},
/**
* Use global.d.ts instead of compilerOptions.types
* to avoid limiting type declarations.
*/
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "a4-sarah-olson",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "node server.js",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"svelte": "^4.0.5",
"vite": "^4.4.5"
},
"dependencies": {
"express": "^4.18.2",
"vite-express": "^0.10.0"
}
}
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
142 changes: 142 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import express from 'express'
import ViteExpress from 'vite-express'

const app = express()

const hoursTilGrade = [{ "A": 28 }, { "B": 24 }, { "C": 21 }]

const appdata = [

]

let currentGoal = ""
let hoursTilGoal = 0
let ogHoursTilGoal = 0

app.use( express.json() )
//app.use( express.static('public') )

app.use( (req,res,next) => {
//console.log(req)
next()
})


app.get('/getTable', (req, res) => {
res.json(appdata)
})

app.get('/getGrade', (req,res) => {
res.json(currentGoal)
})

app.post('/setGoal', (req, res) => {
const body = req.body
const currGoal = body.goal

console.log(currGoal, body)

hoursTilGrade.forEach(d => {
for (let g in d) {
if (g === currGoal) {
hoursTilGoal = d[g]
break
}
}
})

currentGoal = currGoal
ogHoursTilGoal = hoursTilGoal

// body['current_goal'] = currGoal
// body['hours_til_goal'] = hoursTilGoal
console.log("KKKKKKKKK", currentGoal)
res.json(currentGoal)
})

app.post('/editGoal', (req, res) => {
const body = req.body
const newGoal = req.body.goal

console.log(newGoal)

let newGoalNum = 0
let differenceToChange = 0

if (newGoal !== currentGoal) {

hoursTilGrade.forEach(d => {
for (let g in d) {
if (g === newGoal) {
newGoalNum = d[g]
differenceToChange = newGoalNum - ogHoursTilGoal
break
}
}
})

let hoursTilGoaNew = ogHoursTilGoal + differenceToChange

currentGoal = newGoal
ogHoursTilGoal = hoursTilGoaNew

console.log(differenceToChange)
//go thru and edit all of the remianings
appdata.forEach(d => {
d.remaining += differenceToChange
})
}

console.log(newGoal, appdata)
res.json(currentGoal)
})


app.post('/deleteEntry', (req, res) => {

const info = req.body.info
//const index = indexObj.idx

//need to edit all entries after the index
//console.log(req)
//console.log(appdata[index])
let index = 0;
for(let i = 0; i < appdata.length; i++){
if(appdata[i] === info){
index = i
break
}
}
console.log(info, index)
let differenceToChange = parseFloat(info.hours)

for (let i = index; i < appdata.length; i++) {
appdata[i].remaining += differenceToChange
}

console.log(appdata)
appdata.splice(parseInt(index), 1)
if(appdata.length === 0)
hoursTilGoal = ogHoursTilGoal
console.log(appdata)

res.json(appdata)
})

app.post('/addHours', (req, res) => {
const body = req.body




if(appdata.length > 0){
hoursTilGoal = appdata[appdata.length - 1].remaining
}

body['remaining'] = hoursTilGoal - body.hours
appdata.push(body)
res.json(appdata)
})


ViteExpress.listen(app, 3000)
103 changes: 103 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<script>
import svelteLogo from './assets/svelte.svg'
import viteLogo from '/vite.svg'
import GoalSide from './lib/GoalSide.svelte'
import TableSide from './lib/TableSide.svelte'

const validGrades = ['A', 'B', 'C', 'NR']
const tableHeaders = ['Date', 'Hours', 'Time Remaining Until Goal', 'Delete']

</script>

<html lang="en" data-theme="light">
<head>
<title>Attendance Display - WPI Badminton Club Grade Tracker</title>
<meta charset="utf-8" />
<meta
name="description"
content="A page showing the grade goal and hours attended for WPI Badminton Club students"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- get rid of favicon error -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
</head>

<body>

<p class="gradeRules">
If you are taking Badminton Club for Gym Credit you receive your grade
based on the amount of hours you attend.
</p>

<p class="underline">
Below highlights your current progress toward your previously established
grade goal
</p>

<div class="infoBox" id="infoBox">
<div class="sideBySide">
<div>
<GoalSide />
</div>

<div>
<TableSide />
</div>
</div>
</div>
</body>
</html>

<style>
body {
font-family: "Roboto", sans-serif;
font-size: 22px;
padding: 70px;
color: black;
flex-direction: column;
}

p {
text-align: center;
color: white
}

/* h1 {
outline-width: 10px;
color: rgb(179, 0, 0);

text-align: center;

border-width: 3px;
border-style: solid;
border-color: #ff5353;
} */

.sideBySide {
/* visibility: hidden; */
display: flex;
justify-content: space-evenly;
flex-wrap: nowrap;

border-color: rgb(169, 31, 31);
border-width: 3px;
border-style: solid;
padding: 30px;
}

/* nav {
color: black;
}

.pure-menu-link {
color: black;
border-color: rgb(176, 40, 40);
border-width: 3px;
border-style: solid;
text-decoration: underline;
} */
</style>
Loading