Browse Source

WIP: add songs by others

master
Julio Biason 11 years ago
parent
commit
ea73fe7a0c
  1. 19
      lyricsnode/app.js
  2. 34
      lyricsnode/routes/round.js
  3. 22
      lyricsnode/views/index.html

19
lyricsnode/app.js

@ -3,22 +3,22 @@
* Module dependencies.
*/
var express = require('express')
, round = require('./routes/round')
, http = require('http')
, path = require('path')
, cons = require('consolidate')
, swig = require('swig');
var express = require('express');
var round = require('./routes/round');
var http = require('http');
var path = require('path');
var cons = require('consolidate');
var swig = require('swig');
var app = express();
// all environments
app.engine('.html', cons.swig)
app.engine('.html', cons.swig);
swig.init({
root: path.join(__dirname, 'views'),
root: path.join(__dirname, 'views'),
cache: false,
allowErrors: true
})
});
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
@ -36,6 +36,7 @@ if ('development' == app.get('env')) {
}
app.get('/', round.index);
app.post('/round/others/', round.others);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));

34
lyricsnode/routes/round.js

@ -25,6 +25,10 @@ function acronymize(phrase) {
return letters.join('');
}
/***********************************************************************
* Main page
**********************************************************************/
/**
* Pick a song
*/
@ -42,24 +46,27 @@ function getSong(res) {
throw err;
}
console.log('Retrieving artist for song...')
db.get('SELECT * FROM artists WHERE id = ' + song.artist, function (err, artist) {
if (err) {
throw err;
}
console.log('Retrieving lyrics for song... ')
db.get('SELECT * FROM lyrics WHERE song = ' + song.id, function (err, lyrics) {
if (err) {
throw err;
}
var params = {title: 'Round',
lyrics: lyrics.lyrics,
song_title: song.title,
song_artist: artist.name,
acronym_title: acronymize(song.title),
acronym_artist: acronymize(artist.name),
id: song.id
};
var params = {
title: 'Round',
lyrics: lyrics.lyrics,
song_title: song.title,
song_artist: artist.name,
acronym_title: acronymize(song.title),
acronym_artist: acronymize(artist.name),
id: song.id
};
res.render('index', params);
});
});
@ -69,4 +76,13 @@ function getSong(res) {
exports.index = function (req, res) {
getSong(res);
};
};
/***********************************************************************
* Support for the small box with the "others" picks
**********************************************************************/
exports.others = function (req, res) {
console.log('Artist: ' + req.body.artist);
console.log('Song: ' + req.body.song);
};

22
lyricsnode/views/index.html

@ -1,7 +1,7 @@
{% extends "base.html" %}
{% macro other %}
<form action='/round/others' method='POST'>
<form action='/round/others/' method='POST' id='others'>
<div class='row'>
<div class='large-12 columns'>
<label for='others-artist'>
@ -18,9 +18,7 @@
</div>
<div class='large-12 columns'>
<button class='button secondary radius small'>
Add
</button>
<input type='submit' class='button secondary radius small' value='Add'>
</div>
</div>
</form>
@ -104,3 +102,19 @@
}
</style>
{% endblock %}
{% block scripts %}
<script>
$('#others').on('submit', function() {
$.ajax({
url: '/round/others/',
type: 'POST',
data: $(this).serialize(),
success: function (response) {
console.log(response);
}
});
return false;
});
</script>
{% endblock scripts %}

Loading…
Cancel
Save