2019-03-25 22:49:23 +08:00
|
|
|
import * as mpd from "./lib/mpd.js";
|
|
|
|
import * as html from "./lib/html.js";
|
|
|
|
import * as ui from "./lib/ui.js";
|
|
|
|
|
|
|
|
let node;
|
|
|
|
|
|
|
|
function buildHeader(filter) {
|
|
|
|
filter = filter || {};
|
|
|
|
let header = node.querySelector("header");
|
|
|
|
html.clear(header);
|
|
|
|
|
|
|
|
let button = html.button({}, "Music Library", header);
|
|
|
|
button.addEventListener("click", e => listArtists());
|
|
|
|
|
|
|
|
let artist = filter["Artist"];
|
|
|
|
if (artist) {
|
|
|
|
let artistFilter = {"Artist":artist};
|
|
|
|
let button = html.button({}, artist, header);
|
|
|
|
button.addEventListener("click", e => listAlbums(artistFilter));
|
|
|
|
|
|
|
|
let album = filter["Album"];
|
|
|
|
if (album) {
|
|
|
|
let albumFilter = Object.assign({}, artistFilter, {"Album":album});
|
|
|
|
let button = html.button({}, album, header);
|
|
|
|
button.addEventListener("click", e => listSongs(albumFilter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildAlbum(album, filter, parent) {
|
|
|
|
let childFilter = Object.assign({}, filter, {"Album": album});
|
2019-03-26 17:09:26 +08:00
|
|
|
let node = ui.group(ui.GROUP_LIBRARY, album, childFilter, parent);
|
2019-03-25 22:49:23 +08:00
|
|
|
node.addEventListener("click", e => listSongs(childFilter));
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildArtist(artist, filter, parent) {
|
|
|
|
let childFilter = Object.assign({}, filter, {"Artist": artist});
|
2019-03-26 17:09:26 +08:00
|
|
|
let node = ui.group(ui.GROUP_LIBRARY, artist, childFilter, parent);
|
2019-03-25 22:49:23 +08:00
|
|
|
node.addEventListener("click", e => listAlbums(childFilter));
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildSongs(songs, filter) {
|
|
|
|
let ul = node.querySelector("ul");
|
|
|
|
html.clear(ul);
|
2019-03-26 19:35:47 +08:00
|
|
|
ul.classList.remove("tiles");
|
|
|
|
ul.classList.add("grid");
|
2019-03-25 22:49:23 +08:00
|
|
|
|
2019-03-26 17:09:26 +08:00
|
|
|
songs.map(song => ui.song(ui.SONG_LIBRARY, song, ul));
|
2019-03-25 22:49:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function buildAlbums(albums, filter) {
|
|
|
|
let ul = node.querySelector("ul");
|
|
|
|
html.clear(ul);
|
2019-03-26 19:35:47 +08:00
|
|
|
ul.classList.add("tiles");
|
|
|
|
ul.classList.remove("grid");
|
2019-03-25 22:49:23 +08:00
|
|
|
|
|
|
|
albums.map(album => buildAlbum(album, filter, ul));
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildArtists(artists, filter) {
|
|
|
|
let ul = node.querySelector("ul");
|
|
|
|
html.clear(ul);
|
2019-03-26 19:35:47 +08:00
|
|
|
ul.classList.add("tiles");
|
|
|
|
ul.classList.remove("grid");
|
2019-03-25 22:49:23 +08:00
|
|
|
|
|
|
|
artists.map(artist => buildArtist(artist, filter, ul));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function listSongs(filter) {
|
|
|
|
let songs = await mpd.listSongs(filter);
|
|
|
|
buildSongs(songs, filter);
|
|
|
|
buildHeader(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function listAlbums(filter) {
|
|
|
|
let albums = await mpd.listTags("Album", filter);
|
|
|
|
buildAlbums(albums, filter);
|
|
|
|
buildHeader(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function listArtists(filter) {
|
|
|
|
let artists = await mpd.listTags("Artist", filter);
|
|
|
|
buildArtists(artists, filter);
|
|
|
|
buildHeader(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function activate() {
|
|
|
|
listArtists();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function init(n) {
|
|
|
|
node = n;
|
|
|
|
}
|