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

new pull req #1

Open
wants to merge 4 commits into
base: review
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
59 changes: 59 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Shadows Into Light">
<title>My Roster</title>
</head>
<body>
<div id="container">
<input id="team-input" placeholder="Enter team name">
<button id="team-button">Get Roster</button>
<div id="saved-container">
<span id="saved-bar">
</span>
<button id="showTeam">Show team</button>
</div>
<div id="players"></div>
<button id="dream-team">Show Dream Team</button>
</div>

<script id="players-template" type="text/x-handlebars-template">
{{#each data}}
<div class="player-card">
<p class = "playerName">{{name}}</p>
<p class = "playerJersy">{{jersy}}</p>
<img src="{{img}}" onerror='this.src="https://st3.depositphotos.com/4111759/13425/v/450/depositphotos_134255532-stock-illustration-profile-placeholder-male-default-profile.jpg"')>
<p class = "playerPosition">{{position}}</p>
{{#if dreamTeam}}
<button class="remove-player">Remove from Dream Team</button>
{{else}}
<button class="add-player">Add to Dream Team</button>
{{/if}}
</div>
{{/each}}
</script>
<script id="stats-template" type="text/x-handlebars-template">
<div class="stats">
<span>Points per game: {{this.points}}</span>
<span>Assists per game: {{this.assist}}</span>
<span>Rebounds per game: {{this.rebounds}}</span>
<span>Steals per game: {{this.steals}}</span>
<span>Blocks per game: {{this.blocks}}</span>
</div>
</script>
<script id="saved-template" type="text/x-handlebars-template">
<select name="saved" id="saved-users">
{{#each this}}
<option value="{{this}}">{{this}}</option>
{{/each}}
</select>
</script>
<script src="/handlebars/dist/handlebars.js"></script>
<script src="/jquery/dist/jquery.js"></script>
<script src="render.js"></script>
<script src="main.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const display = new Render()
const teams = []
$('#team-button').on('click', function () {
const input = $('#team-input').val()
$.get(`/teams/${input}`, function (data) {
display.renderData(data)
$('#team-input').val('')
})
})

$('#players').on('click', 'img', function () {
const name = $(this).closest('div').find('.playerName').text()
$.get(`/playerStats/${name}`, (data) => {
display.renderStats(data, this)
})
})

$('#players').on('click', '.add-player', function () {
const $div = $(this).closest('div')
const player = {
name: $div.find('.playerName').text(),
jersy: $div.find('.playerJersy').text(),
position: $div.find('.playerPosition').text(),
img: $div.find('img').attr('src'),
dreamTeam: true
}
$.get(`/dreamTeam`, (data) => {
if (data.some(p => p.name == player.name)) {
alert("already in the dream team")
} else {
$.post(`/roster`, player, (res) => { })
}
})
})

$('#dream-team').on('click', function () {
$.get(`/dreamTeam`, (data) => {
display.renderData(data)
display.renderInput()
})
})

$('#players').on('click', '.remove-player', function () {
const name = $(this).closest('div').find('.playerName').text()
$.ajax({
method: "DELETE",
url: (`/roster/${name}`),
success: (data) => {
display.renderData(data)
display.renderInput()
}
})
})

$('#players').on('click', '.create', function () {
const teamName = $(this).closest('div').find('.teamName').val()
$.get(`/dreamTeam`, (data) => {
localStorage[teamName] = JSON.stringify(data)
teams.push(teamName)
display.renderSaved(teams)
})
})
$('#showTeam').on('click', function () {
const teamName = $('#saved-users').val()
const data = JSON.parse(localStorage[teamName])
display.renderData(data)
})

for(let i in localStorage){
if(typeof localStorage[i] === 'string'){
teams.push(i)
}
}
display.renderSaved(teams)
48 changes: 48 additions & 0 deletions dist/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Render{
constructor(){
}

renderData(data) {
if (data[0] != undefined) {
const source = $('#players-template').html()
const template = Handlebars.compile(source)
const newHTML = template({ data })
$('#players').empty().append(newHTML)
} else {
const newHTML = "<div class='error'> Roster is unavailabe</div>"
$('#players').empty().append(newHTML)
}
}

renderStats(data, img) {
if (data) {
const source = $('#stats-template').html()
const template = Handlebars.compile(source)
const newHTML = template(data)
$(img).closest('div').append(newHTML)
} else {
const newHTML = "<div class='stats' style='color:red'> No stats available</div>"
$(img).closest('div').append(newHTML)
}
}

renderInput(){
$('#players').append('<div><input class="teamName" placeholder="Enter team name"><button class="create">Create team</button></div>')
}

renderSaved(saved){
if(saved[0] != undefined){
$('#saved-bar').empty()
const source = $('#saved-template').html();
const template = Handlebars.compile(source);
const newHTML = template(saved)
$('#saved-bar').append(newHTML)
}else{
$('#saved-bar').append(`
<select name="saved" id="saved-users">
<option value="noTeam">No team saved yet</option>
</select>`)
}
}

}
98 changes: 98 additions & 0 deletions dist/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#container{
font-family: 'Shadows Into Light', serif;
font-size: 20px;
display: grid;
grid-gap: 5px;
grid-template-areas:
"i b s"
"p p p"
"p p p"
"d d d";
}
#team-button{
grid-area: b;
cursor: pointer;
font-family: 'Shadows Into Light', serif;
font-size: 25px;
}
#team-input{
grid-area: i;
font-size: 2vw;
font-family: 'Shadows Into Light', serif;
}
#players{
grid-area: p;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
grid-gap: 10px;
}
.player-card{
width: 100%;
height: 100%;
display: grid;
align-items: center;
justify-items: center;
background-color: #ffeaa7;
border: 1px solid #fdcb6e;
box-shadow: 1px 1px 5px #636e72;
position: relative;
}
img{
background-color: #dfe6e9;
border: 1px solid #b2bec3;
box-shadow: 1px 1px 5px #636e72;
width: 300px;
height: 200px;
cursor: pointer;
}
img:hover{
background-color: #ffffff99;
}
.stats{
display: grid;
justify-items: center;
align-items: center;
position: absolute;
color: black;
background-color: #ffffff99;
top: 33%;
width: 300px;
height: 200px;
}
.error{
color: red;
font-size: 30px;
}
.add-player{
font-family: 'Shadows Into Light', serif;
background-color: #fdcb6e;
border: 1px solid #fdcb6e;
box-shadow: 1px 1px 3px #2c3e50;
cursor: pointer;
}
#dream-team{
font-size: 25px;
font-family: 'Shadows Into Light', serif;
grid-area: d;
cursor: pointer;
height: 5vh;
}
.remove-player{
font-family: 'Shadows Into Light', serif;
background-color: #e74c3c;
border: 1px solid #e74c3c;
box-shadow: 1px 1px 3px #2c3e50;
cursor: pointer;
}
.teamName{
font-family: 'Shadows Into Light', serif;
height: 5vh;
}
.create{
font-family: 'Shadows Into Light', serif;
height: 5vh;
}
#saved-container{
grid-area: s;
}
Loading