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

Vee dev #3

Open
wants to merge 7 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
Binary file added project/src/main/webapp/fonts/Roboto-Bold.ttf
Binary file not shown.
185 changes: 117 additions & 68 deletions project/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,98 +5,147 @@
<meta charset="UTF-8">
<title>HeartBeat</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="script.js"></script>
</head>

<body>
<div id="side-navigation-menu" class="app-font">
<button id="open-menu-button" class="app-button" onclick="openMenu()"><img
src="https://img.icons8.com/ios-filled/35/000000/menu-rounded.png" /></button>
<button id="open-menu-button" class="app-button flex center-xy" onclick="openMenu()"><img
src="https://img.icons8.com/ios-filled/30/000000/menu-rounded.png" /></button>
<div id="side-menu">
<a href="javascript:void(0)" id="close-menu-button" onclick="closeMenu()">&times;</a>
<a href="javascript:void(0)" id="close-menu-button" onclick="closeMenu()"
style="font-size: xx-large;">&times;</a>
<a href="index.html">Home</a>
<a href="playlist.html">Playlist</a>
<a href="index.html">Favorites</a>

<button id="dark-mode-toggle" class="app-button" onclick="darkMode()"><img
src="https://img.icons8.com/material-outlined/40/000000/partly-cloudy-night.png" /></button>
<button id="moon-toggle" class="app-button flex center-xy" onclick="sunToggle(); darkMode();"><img
src="https://img.icons8.com/ios-filled/30/000000/moon-symbol.png" /></button>

<button id="sun-toggle" class="app-button flex center-xy" onclick="moonToggle(); darkMode();"><img
src="https://img.icons8.com/fluent-systems-regular/45/000000/sun.png" /></button>
</div>
</div>

<div id="main" class="app-font">
<h1 id="app-header" class="center-header">
<div id="main-header" class="app-header flex center-xy" style="font-size: xxx-large;">
HeartBeat
</h1>
</div>

<div id="workout-section">
<h1 id="workout-selection-header" class="center-header">
<div id="workout-section" class="flex flex-column center-xy">
<h1 id="workout-selection-header" class="app-header flex center-xy" style="font-size: xx-large; font-weight: bold;">
Workout Selection
</h1>

<div id="workout-selection-section" class="center-content">
<div id="workout-selection">
<button value="Aerobics" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/gymnastics.png" /></button>
<button value="Bench Press" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/bench-press.png" /></button>
<button value="Curls" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/curls-with-dumbbells.png" /></button>
<button value="Jogging" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/running.png" /></button>
<button value="Pilates" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pilates.png" /></button>
<button value="Pull-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pullups.png" /></button>
<button value="Push-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pushups.png" /></button>
<button value="Sit-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-glyphs/50/000000/sit-ups.png" /></button>
<button value="Squats" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/squats.png" /></button>
<button value="Treadmill" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/treadmill.png" /></button>
<button value="Walking" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/walking.png" /></button>
<button value="Weightlift" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/deadlift.png" /></button>
</div>
<div id="workout-selection" class="flex center-y space-between">
<button value="Aerobics" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/gymnastics.png" />
<p>Aerobics</p>
</button>
<button value="Curls" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/curls-with-dumbbells.png" />
<p>Curls</p>
</button>
<button value="Jogging" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/running.png" />
<p>Jogging</p>
</button>
<button value="Pilates" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pilates.png" />
<p>Pilates</p>
</button>
<button value="Pull-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pullups.png" />
<p>Pull-Ups</p>
</button>
<button value="Push-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/pushups.png" />
<p>Push-Ups</p>
</button>
<button value="Sit-Ups" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-glyphs/50/000000/sit-ups.png" />
<p>Sit-Ups</p>
</button>
<button value="Squats" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/squats.png" />
<p>Squats</p>
</button>
<button value="Treadmill" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/treadmill.png" />
<p>Treadmill</p>
</button>
<button value="Walking" onclick="clickWorkout(this.value)"><img
src="https://img.icons8.com/ios-filled/50/000000/walking.png" />
<p>Walking</p>
</button>
</div>

<div id="workout-submission-section">
<h2 id="workout-submission-header" class="center-header">
<div id="workout-submission-section" class="full-width flex flex-column center-xy"
style="padding-bottom: 100px;">
<h3 id="workout-submission-header" class="app-header flex center-xy" style="font-size: x-large;">
Select a workout above or enter one below:
</h2>

<form id="workout-submission" class="center-content">
<label for="workout-select">Selected Workout</label>
<input type="text" id="workout-select" list="workouts">
<datalist id="workouts">
<option value="Aerobics">
<option value="Bench Press">
<option value="Curls">
<option value="Jogging">
<option value="Pilates">
<option value="Pull-Ups">
<option value="Push-Ups">
<option value="Sit-Ups">
<option value="Squats">
<option value="Treadmill">
<option value="Walking">
<option value="Weightlift">
</datalist>

<label for="hours-select">Hours</label>
<input type="number" id="hours-select" min="0">

<label for="mins-select">Minutes</label>
<input type="number" id="mins-select" min="0">

<button id="workout-submit-button" class="app-button" type="submit"><img
src="https://img.icons8.com/fluent-systems-filled/40/000000/enter-2.png" /></button>
</form>
</h3>

<div id="workout-submission-form" class="flex center-y">
<form id="workout-submission" class="flex center-y space-between">
<label for="workout-select">Selected Workout</label>
<input type="text" id="workout-select" list="workouts">
<datalist id="workouts" class="app-font">
<option value="Aerobics">
<option value="Curls">
<option value="Jogging">
<option value="Pilates">
<option value="Pull-Ups">
<option value="Push-Ups">
<option value="Sit-Ups">
<option value="Squats">
<option value="Treadmill">
<option value="Walking">
</datalist>

<label for="hours-select">Hours</label>
<input type="number" id="hours-select" min="0">

<label for="mins-select">Minutes</label>
<input type="number" id="mins-select" min="0">
</form>

<button id="workout-submit-button" class="app-button flex center-xy"
onclick="fetchId(); showPlaylist();"><img
src="https://img.icons8.com/fluent-systems-filled/30/000000/enter-2.png" /></button>
</div>
</div>
</div>

<div id="playlist-section">
<div id="playlist-contents" class="flex flex-column center-xy" style="display: none;">
<h1 id="playlist-header" class="flex center-xy">
Recommended Playlist
</h1>

<h1 id="playlist-title" class="flex center-xy"></h1>

<img id="playlist-thumbnail"></img>

<div id="playlist-buttons" class="flex center-xy space-between" style="height: 100px">
<a id="playlist-link" class="app-button flex center-xy" style="margin-right: 50px;"><img
src="https://img.icons8.com/fluent-systems-filled/30/000000/play.png" /></a>
<button class="app-button flex center-xy" onclick="hidePlaylist()"><img
src="https://img.icons8.com/ios-glyphs/30/000000/refresh--v1.png" /></button>
</div>
</div>
</div>

<footer id="footer" class="flex center-xy">
<button id="scroll-top-button" class="app-button flex center-xy" onclick="backToTop()"><img
src="https://img.icons8.com/ios-filled/30/000000/up--v1.png" /></button>
</footer>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
</body>

</html>
88 changes: 81 additions & 7 deletions project/src/main/webapp/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,106 @@
// See the License for the specific language governing permissions and
// limitations under the License.

/*** Landing Page ***/
/* Enter workout into the selected workout line by pressing on button */
/*** Workout Selection ***/
// Enter a workout into the selected workout line by pressing on a button
function clickWorkout(x) {
document.getElementById("workout-select").value = x;
}

/*** Playlist Page ***/
/*** Playlist ***/
function showPlaylist() {
document.getElementById("playlist-contents").style.display = "flex";
}

function hidePlaylist() {
document.getElementById("playlist-contents").style.display = "none";
}

/*** Side Navigation Menu ***/
/* Set the width of the side navigation to 250px and the left margin of the page content to 250px */
// Set the width of the side navigation to 250px and the left margin of the page content to 250px
function openMenu() {
document.getElementById("side-menu").style.width = "250px";
document.getElementById("side-menu").style.boxShadow = "black 0px 0px 10px";
document.getElementById("main").style.marginLeft = "250px";
}

/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
// Set the width of the side navigation to 0 and the left margin of the page content to 0
function closeMenu() {
document.getElementById("side-menu").style.width = "0";
document.getElementById("side-menu").style.borderRight = "0";
document.getElementById("main").style.marginLeft = "0";
}

/* Activate the dark-mode class in the style sheet on the body */
function sunToggle() {
document.getElementById("moon-toggle").style.display = "none";
document.getElementById("sun-toggle").style.display = "flex";
}

function moonToggle() {
document.getElementById("moon-toggle").style.display = "flex";
document.getElementById("sun-toggle").style.display = "none";
}

function darkMode() {
const x = document.body;
x.classList.toggle("dark-mode");
x.classList.toggle("dark-mode-gray");
}

/*** Footer ***/
//Get the button
let mybutton = document.getElementById("scroll-top-button");

// When the user clicks on the button, scroll to the top of the document
mybutton.addEventListener("click", backToTop);

function backToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}

/*** Spotify ***/
const _getToken = async () => {

const result = await fetch('https://accounts.spotify.com/api/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + btoa(clientId + ':' + clientSecret)

},
body: 'grant_type=client_credentials'
});

const data = await result.json();
return data.access_token;
}
async function fetchId() {
const bpmToPlaylistId = { '90': '5fQuCLAEcNtHbFTdyiEJDd', '120': '0StaxvjifcoNPeIM8stp4p', '128': '28p4zE67Svf2S1OIZlp0rh', '135': '26ZtghULwqbNzZK3yi3Txx', '150': '37i9dQZF1DX0hWmn8d5pRe' };
const workoutNameToBpm = { 'Pilates': '90', 'Jogging': '120', 'Sit-Ups': '128', 'Aerobics': '135', 'Treadmill': '150', };
const workoutElement = document.getElementById('workout-select');
const workoutName = workoutElement.value;
const bpm = workoutNameToBpm[workoutName];
const playlistId = bpmToPlaylistId[bpm];

const accessToken = 'BQCT1earqzC1mA6DQGw8d15isgeIrdp8aNZ92SPiZdGv-Ldq0rZS_rLBGFYk1TvgpkdP0WqbeRDQe8-7puAXQao1-b2yN1nRuKekoaCCegb0rUDtY25BPjp_Oez0ZsJ8Mu5k24YqK1P4BVFOJNWgO30gStRZkfo';


const response = await fetch('https://api.spotify.com/v1/playlists/' + playlistId, {
method: 'GET', headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken
}
});



const responseJson = await response.json();
console.log(responseJson);
const playlistTitleElement = document.getElementById('playlist-title');
playlistTitleElement.innerText = responseJson.name;
const playlistLinkElement = document.getElementById('playlist-link');
playlistLinkElement.href = responseJson.external_urls.spotify;
const playlistThumbnailElement = document.getElementById('playlist-thumbnail');
playlistThumbnailElement.src = responseJson.images[0].url;
}
Loading