Chris Shyi 6 years ago
parent
commit
0796e4190d
  1. 42
      spotifyvis/static/spotifyvis/scripts/index.js
  2. 14
      spotifyvis/templates/spotifyvis/index.html
  3. 2
      spotifyvis/tests.py

42
spotifyvis/static/spotifyvis/scripts/index.js

@ -0,0 +1,42 @@
document.getElementById("login-btn").addEventListener("click", function() {
let httpRequest = new XMLHttpRequest();
/*
* Handler for the response
*/
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
// hide the login button
document.getElementById('login').setAttribute("display", "none");
let responseData = JSON.parse(httpRequest.responseText);
let dataList = document.getElementById("data-list");
for (let key in responseData) {
let newLi = document.createElement("li");
let innerList = document.createElement("ul");
let dataLabel = document.createElement("li");
dataLabel.innerText = key;
let dataValue = document.createElement("li");
dataValue.innerText = responseData[key];
innerList.appendChild(dataLabel);
innerList.appendChild(dataValue);
newLi.appendChild(innerList);
dataList.appendChild(newLi);
}
} else {
alert("There was a problem with the login request, please try again!");
}
}
}
httpRequest.open('GET', '/login', true);
httpRequest.send();
});

14
spotifyvis/templates/spotifyvis/index.html

@ -1,4 +1,5 @@
<!DOCTYPE html>
{% load static %}
<html>
<head>
<title>User Login</title>
@ -11,14 +12,25 @@
width: 500px;
}
</style>
</head>
<body>
<div class="container">
<div id="login">
<h1>This is an example of the Authorization Code flow</h1>
<a href="/login" class="btn btn-primary">Log in with Spotify</a>
<a href="/login" class="btn btn-primary">Log In (Original)</a>
<button id="login-btn">Log In</button>
</div>
<div id="data-container">
<ul id="data-list">
</ul>
</div>
</div>
<script src="{% static 'spotifyvis/scripts/index.js' %}"></script>
</body>
</html>

2
spotifyvis/tests.py

@ -1,5 +1,5 @@
from django.test import TestCase
from .views import update_std_dev
from .utils import update_std_dev
import math
# Create your tests here.

Loading…
Cancel
Save