Merge pull request 'html view + .json for track/artist/release' (#1) from feature/more_json_endpoints into develop
Reviewed-on: #1
This commit is contained in:
commit
e41984c67b
@ -22,15 +22,15 @@ app:match("station", "/station/:station(.:json)", json_params(function(self)
|
||||
return handlers.Stationhandler(self)
|
||||
end))
|
||||
|
||||
app:match("track", "/track/:track", json_params(function(self)
|
||||
app:match("track", "/track/:track(.:json)", json_params(function(self)
|
||||
return handlers.Trackhandler(self)
|
||||
end))
|
||||
|
||||
app:match("artist", "/artist/:artist", json_params(function(self)
|
||||
app:match("artist", "/artist/:artist(.:json)", json_params(function(self)
|
||||
return handlers.Artisthandler(self)
|
||||
end))
|
||||
|
||||
app:match("release", "/release/:release", json_params(function(self)
|
||||
app:match("release", "/release/:release(.:json)", json_params(function(self)
|
||||
return handlers.Releasehandler(self)
|
||||
end))
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Artisthandler(self)
|
||||
local artist_id = self.params.artist
|
||||
local json = self.params.json or nil
|
||||
|
||||
-- find the artist
|
||||
local artist = models.Artists:find({ id = artist_id })
|
||||
@ -28,7 +29,7 @@ local function Artisthandler(self)
|
||||
|
||||
-- find all tracks with this artist
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, track.id
|
||||
SELECT track.name AS track_name, track.id AS track_id, track.img_url
|
||||
FROM track_artists
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_artists.track = track.id)
|
||||
@ -43,21 +44,24 @@ local function Artisthandler(self)
|
||||
|
||||
for i, track in ipairs(tracks) do
|
||||
local track_airtimes = 0
|
||||
track["last_airtime"] = ""
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
SELECT airtime
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
artist["tracks"][i]["airtimes"] = {}
|
||||
-- this can probably be done in SQL directly
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(artist["tracks"][i]["airtimes"], airtime)
|
||||
track_airtimes = track_airtimes + 1
|
||||
total_airtimes = total_airtimes + 1
|
||||
|
||||
if airtime.airtime > last_airtime then
|
||||
last_airtime = airtime.airtime
|
||||
end
|
||||
if airtime.airtime > track["last_airtime"] then
|
||||
track["last_airtime"] = airtime.airtime
|
||||
end
|
||||
end
|
||||
artist["tracks"][i]["track_airtimes"] = track_airtimes
|
||||
|
||||
@ -68,7 +72,7 @@ local function Artisthandler(self)
|
||||
INNER JOIN
|
||||
releases AS release ON (track_releases.release = release.id)
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
artist["tracks"][i]["releases"] = {}
|
||||
for k, release in ipairs(releases) do
|
||||
@ -79,7 +83,12 @@ local function Artisthandler(self)
|
||||
artist["total_airtimes"] = total_airtimes
|
||||
artist["last_airtime"] = last_airtime
|
||||
|
||||
return { json = artist }
|
||||
if json then
|
||||
return { json = artist }
|
||||
end
|
||||
|
||||
self.artist = artist
|
||||
return { render = "artist" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Releasehandler(self)
|
||||
local release_id = self.params.release
|
||||
local json = self.params.json or nil
|
||||
|
||||
local release = models.releases:find({ id = release_id })
|
||||
if not release then
|
||||
@ -27,7 +28,7 @@ local function Releasehandler(self)
|
||||
|
||||
-- get all tracks on this release
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, track.id, artist.name AS artist_name
|
||||
SELECT track.name AS track_name, track.id AS track_id, track.img_url, artist.name AS artist_name, artist.id AS artist_id
|
||||
FROM track_releases
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_releases.track = track.id)
|
||||
@ -46,28 +47,36 @@ local function Releasehandler(self)
|
||||
|
||||
for i, track in ipairs(tracks) do
|
||||
local track_airtimes = 0
|
||||
track["last_airtime"] = ""
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
]], track["track_id"])
|
||||
|
||||
release["tracks"][i]["airtimes"] = {}
|
||||
-- this can probably be done in SQL directly
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(release["tracks"][i]["airtimes"], airtime)
|
||||
track_airtimes = track_airtimes + 1
|
||||
total_airtimes = total_airtimes + 1
|
||||
|
||||
if airtime.airtime > last_airtime then
|
||||
last_airtime = airtime.airtime
|
||||
end
|
||||
if airtime.airtime > track["last_airtime"] then
|
||||
track["last_airtime"] = airtime.airtime
|
||||
end
|
||||
end
|
||||
release["tracks"][i]["track_airtimes"] = track_airtimes
|
||||
end
|
||||
release["total_airtimes"] = total_airtimes
|
||||
release["last_airtime"] = last_airtime
|
||||
|
||||
return { json = release }
|
||||
if json then
|
||||
return { json = release }
|
||||
end
|
||||
|
||||
self.release = release
|
||||
return { render = "release" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ local models = autoload("models")
|
||||
|
||||
local function Trackhandler(self)
|
||||
local track_id = self.params.track
|
||||
local json = self.params.json or nil
|
||||
|
||||
local track = models.Tracks:find({ id = track_id })
|
||||
if not track then
|
||||
@ -27,23 +28,27 @@ local function Trackhandler(self)
|
||||
|
||||
-- find the artist for this track
|
||||
local artists = db.query([[
|
||||
SELECT artist.name AS artist_name
|
||||
SELECT artist.name AS artist_name, artist.id AS artist_id
|
||||
FROM track_artists
|
||||
INNER JOIN
|
||||
artists AS artist ON (track_artists.artist = artist.id)
|
||||
artists AS artist ON (track_artists.artist = artist.id)
|
||||
WHERE track_artists.track = ?
|
||||
]], track["id"])
|
||||
|
||||
track["artist"] = artists[1]["artist_name"]
|
||||
track["artist_id"] = artists[1]["artist_id"]
|
||||
|
||||
-- find all airtimes for this track
|
||||
local track_airtimes = 0
|
||||
local last_airtime = ""
|
||||
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime, station AS station_id
|
||||
SELECT airtime, station.id AS station_id, station.name AS station_name
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
INNER JOIN
|
||||
stations AS station ON (airtimes.station = station.id)
|
||||
WHERE track = ?
|
||||
ORDER BY airtime DESC
|
||||
]], track["id"])
|
||||
|
||||
track["airtimes"] = {}
|
||||
@ -72,7 +77,12 @@ local function Trackhandler(self)
|
||||
track["releases"][i] = release
|
||||
end
|
||||
|
||||
return { json = track }
|
||||
if json then
|
||||
return { json = track }
|
||||
end
|
||||
|
||||
self.track = track
|
||||
return { render = "track" }
|
||||
|
||||
end
|
||||
|
||||
|
||||
48
code/views/artist.etlua
Normal file
48
code/views/artist.etlua
Normal file
@ -0,0 +1,48 @@
|
||||
<% render("views.navigation") %>
|
||||
|
||||
<div class="artist" style="background-color: black; width: 900px; margin:0 auto;">
|
||||
|
||||
<h5 class="media-heading" style="color:#fff;">
|
||||
<%= artist.name %>
|
||||
<br>
|
||||
Total airtimes: <%= artist.total_airtimes %>
|
||||
<br>
|
||||
Last airtime: <%= artist.last_airtime %>
|
||||
</h5>
|
||||
|
||||
|
||||
<% for i, track in ipairs(artist.tracks) do %>
|
||||
<div id="playingnowpic">
|
||||
<% if string.len(track.img_url) == 0 then %>
|
||||
<% track.img_url = "blanco.png" %>
|
||||
<% end %>
|
||||
<a href="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>" rel="ia_lightbox">
|
||||
<img style="float:left;margin-right:10px;margin-bottom:0px;height:100px;" src="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>">
|
||||
</a>
|
||||
</div>
|
||||
<div class="media-body">
|
||||
<h5 class="media-heading" style="color:#fff;">
|
||||
<a href="<%= url_for("track", { track = track.track_id }) %>"><span style="color:#ffffff !important;"><%= track.track_name %></span></a>
|
||||
<% if track.info_url then %><% if track.info_url:match("[^.]+$") == "jpg" then %>| <a href="https://intergalactic.fm/images/covers/<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a>
|
||||
<% else %>| <a href="<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a><% end %>
|
||||
<% end %>
|
||||
<br>
|
||||
Track airtimes: <%= track.track_airtimes %>
|
||||
<br>
|
||||
Last aired: <%= track.last_airtime %>
|
||||
<br>
|
||||
Track releases:
|
||||
<div style="padding-right:5px; color:#fff; padding-left:5em;">
|
||||
<% if track.releases then %>
|
||||
<% for i, item in ipairs(track.releases) do %>
|
||||
<a href="<%= url_for("release", { release = item.release_id }) %>" style="color: #ffffff; text-decoration: none;"><%= item.release_name %></a><br>
|
||||
<% if item.label then %>| <%= item.label %><% end %>
|
||||
<% if item.year then %>| <%= item.year %><% end %>
|
||||
<% if item.country then %>| <%= item.country %><% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</h5>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
34
code/views/release.etlua
Normal file
34
code/views/release.etlua
Normal file
@ -0,0 +1,34 @@
|
||||
<% render("views.navigation") %>
|
||||
|
||||
<div class="release" style="background-color: black; width: 900px; margin: auto;">
|
||||
<h5 class="media-heading" style="color:#fff;">
|
||||
<%= release.name %>
|
||||
<br>
|
||||
Total airtimes: <%= release.total_airtimes %>
|
||||
<br>
|
||||
Last airtime: <%= release.last_airtime %>
|
||||
</h5>
|
||||
<% for i, track in ipairs(release.tracks) do %>
|
||||
<div id="playingnowpic">
|
||||
<br>
|
||||
<% if string.len(track.img_url) == 0 then %>
|
||||
<% track.img_url = "blanco.png" %>
|
||||
<% end %>
|
||||
<a href="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>" rel="ia_lightbox">
|
||||
<img style="float:left;margin-right:10px;margin-bottom:0px;height:100px;" src="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>">
|
||||
</a>
|
||||
<h5 class="media-heading" style="color:#fff;">
|
||||
<a href="<%= url_for("artist", { artist = track.artist_id }) %>"><span style="color:#ffffff !important;"><%= track.artist_name %></span></a> -
|
||||
<a href="<%= url_for("track", { track = track.track_id }) %>"><span style="color:#ffffff !important;"><%= track.track_name %></span></a>
|
||||
<% if track.info_url then %><% if track.info_url:match("[^.]+$") == "jpg" then %>| <a href="https://intergalactic.fm/images/covers/<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a>
|
||||
<% else %>| <a href="<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a><% end %>
|
||||
<% end %>
|
||||
<br>
|
||||
Track airtimes: <%= track.track_airtimes %>
|
||||
<br>
|
||||
Last aired: <%= track.last_airtime %>
|
||||
</h5>
|
||||
<br>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
46
code/views/track.etlua
Normal file
46
code/views/track.etlua
Normal file
@ -0,0 +1,46 @@
|
||||
<% render("views.navigation") %>
|
||||
|
||||
<div class="track" style="background-color: black; width: 900px; margin:0 auto;">
|
||||
<div id="playingnowpic">
|
||||
<% if string.len(track.img_url) == 0 then %>
|
||||
<% track.img_url = "blanco.png" %>
|
||||
<% end %>
|
||||
<a href="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>" rel="ia_lightbox">
|
||||
<img style="float:left;margin-right:10px;margin-bottom:0px;height:100px;" src="https://www.intergalactic.fm/images/covers/<%= track.img_url or "blanco.png" %>">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="media-body">
|
||||
<h5 class="media-heading" style="color:#fff;">
|
||||
<a href="<%= url_for("artist", { artist = track.artist_id }) %>"><span style="color:#ffffff !important;"><%= track.artist %></span></a> - <%= track.name %>
|
||||
<% if track.info_url then %><% if track.info_url:match("[^.]+$") == "jpg" then %>| <a href="https://intergalactic.fm/images/covers/<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a>
|
||||
<% else %>| <a href="<%= track.info_url %>"><span style="color:#ffffff !important;"><%= track.info_url %></span></a><% end %>
|
||||
<% end %>
|
||||
<br>
|
||||
<br>
|
||||
Total airtimes: <%= track.total_airtimes %>
|
||||
<br>
|
||||
Last aired: <%= track.last_airtime %>
|
||||
</h5>
|
||||
<br>
|
||||
<p>
|
||||
<span style="padding-right:5px;color:#fff;">
|
||||
<% if track.releases then %>
|
||||
<% for i, item in ipairs(track.releases) do %>
|
||||
<a href="<%= url_for("release", { release = item.release_id }) %>" style="color: #ffffff; text-decoration: none;"><%= item.release_name %></a><br>
|
||||
<% if item.label then %>| <%= item.label %><% end %>
|
||||
<% if item.year then %>| <%= item.year %><% end %>
|
||||
<% if item.country then %>| <%= item.country %><% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</span>
|
||||
</p>
|
||||
<% for i, item in ipairs(track.airtimes) do %>
|
||||
<div style="clear:both;height:5px;"></div>
|
||||
<span style="padding-right:5px;color:#fff;">
|
||||
<%= item.airtime %> on <a href="<%= url_for("station", { station = item.station_id }) %>"> <%= item.station_name %> </a>
|
||||
</span>
|
||||
<br>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue
Block a user