mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Refactor library code.
This commit is contained in:
parent
f8f8b9d194
commit
8a8e277201
@ -3,3 +3,5 @@
|
|||||||
background: none
|
background: none
|
||||||
color: $highlight
|
color: $highlight
|
||||||
font-size: 0.8em
|
font-size: 0.8em
|
||||||
|
text-decoration: none
|
||||||
|
padding: 5px
|
||||||
|
|||||||
@ -16,3 +16,26 @@
|
|||||||
right: 10px
|
right: 10px
|
||||||
top: 8px
|
top: 8px
|
||||||
@include button
|
@include button
|
||||||
|
.browser
|
||||||
|
position: absolute
|
||||||
|
height: 100%
|
||||||
|
@include transition(left 0.25s ease-in-out)
|
||||||
|
&[data-pane="2"]
|
||||||
|
left: -$interface-width
|
||||||
|
&[data-pane="3"]
|
||||||
|
left: -$interface-width * 2
|
||||||
|
&[data-pane="4"]
|
||||||
|
left: -$interface-width * 3
|
||||||
|
ul, ol
|
||||||
|
position: absolute
|
||||||
|
width: $interface-width
|
||||||
|
@extend .list
|
||||||
|
height: 100%
|
||||||
|
&:first-child
|
||||||
|
left: 0
|
||||||
|
&:nth-child(2)
|
||||||
|
left: $interface-width
|
||||||
|
&:nth-child(3)
|
||||||
|
left: $interface-width * 2
|
||||||
|
&:nth-child(4)
|
||||||
|
left: $interface-width * 3
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
var Library = can.Control.extend({
|
var Library = can.Control.extend({
|
||||||
|
|
||||||
init: function(element, options) {
|
init: function(element, options) {
|
||||||
this.element = element
|
this.element = element;
|
||||||
|
this.browser = new can.Model({ pane: 1 });
|
||||||
element.html(
|
element.html(
|
||||||
can.view('views/library.ejs')
|
can.view('views/library.ejs', { browser: this.browser })
|
||||||
);
|
);
|
||||||
|
var rootControl = new Pane('#library .root', { show: 'root' })
|
||||||
|
this.panes = new can.List([rootControl]);
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function() {
|
show: function() {
|
||||||
@ -15,13 +18,55 @@ var Library = can.Control.extend({
|
|||||||
$(this.element).removeClass('show');
|
$(this.element).removeClass('show');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
nextPane: function() {
|
||||||
|
this.browser.attr('pane', this.browser.attr('pane') + 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
previousPane: function() {
|
||||||
|
this.browser.attr('pane', this.browser.attr('pane') - 1);
|
||||||
|
},
|
||||||
|
|
||||||
'a.close click': 'hide',
|
'a.close click': 'hide',
|
||||||
|
|
||||||
':page route': function(data) {
|
':page route': function(data) {
|
||||||
console.log(data);
|
|
||||||
if (data.page == 'library') {
|
if (data.page == 'library') {
|
||||||
this.show();
|
this.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var Pane = can.Control.extend({
|
||||||
|
|
||||||
|
init: function(element, data, pane) {
|
||||||
|
this.element = element;
|
||||||
|
this.data = data;
|
||||||
|
this.renderPane[data.show].call(this, data);
|
||||||
|
},
|
||||||
|
|
||||||
|
renderPane: {
|
||||||
|
root: function() {
|
||||||
|
this.element.html(
|
||||||
|
can.view('views/library/root.ejs', {})
|
||||||
|
);
|
||||||
|
},
|
||||||
|
artists: function(data) {
|
||||||
|
Artist.findAll({}, renderCallback('artists'));
|
||||||
|
},
|
||||||
|
albums: function(data) {
|
||||||
|
Album.findAll({ artist: data.artist }, renderCallback('albums'));
|
||||||
|
},
|
||||||
|
songs: function(data) {
|
||||||
|
Song.findAll({ artist: data.artist, album: data.album }, renderCallback('songs'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renderCallback: function(type) {
|
||||||
|
return function(items) {
|
||||||
|
$(this.element).html(
|
||||||
|
can.view('views/library/' + type + '.ejs', { items: items })
|
||||||
|
);
|
||||||
|
}.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|||||||
@ -24,7 +24,7 @@ module MPDClient
|
|||||||
end
|
end
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
[artist, album, title] <=> [other.artist, other.album, other.title]
|
[artist, album, track] <=> [other.artist, other.album, other.track]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
<a class="close" href="#!">Close</a>
|
<a class="close" href="#!">Close</a>
|
||||||
<h1>Library</h1>
|
<h1>Library</h1>
|
||||||
</header>
|
</header>
|
||||||
<ol class="list">
|
<div class="browser" data-pane="<%= browser.attr('pane') %>">
|
||||||
<%== can.view.render('views/library/root.ejs', {}) %>
|
<div class="root"></div>
|
||||||
</ol>
|
<%# can.view.render('views/library/root.ejs', {}) %>
|
||||||
|
</div>
|
||||||
|
|||||||
12
public/views/library/albums.ejs
Normal file
12
public/views/library/albums.ejs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<ol class="albums">
|
||||||
|
<% list(albums, function(album) { %>
|
||||||
|
<li id="<%= album.attr('id') %>">
|
||||||
|
<%== can.route.link(album.attr('title'), {
|
||||||
|
page: 'library',
|
||||||
|
show: 'songs',
|
||||||
|
artist: album.attr('artist'),
|
||||||
|
album: album.attr('album')
|
||||||
|
}) %>
|
||||||
|
</li>
|
||||||
|
<% }) %>
|
||||||
|
</ol>
|
||||||
11
public/views/library/artists.ejs
Normal file
11
public/views/library/artists.ejs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<ol class="artists">
|
||||||
|
<% list(artists, function(artist) { %>
|
||||||
|
<li id="<%= artist.attr('id') %>">
|
||||||
|
<%== can.route.link(artist.attr('name'), {
|
||||||
|
page: 'library',
|
||||||
|
show: 'albums',
|
||||||
|
artist: artist.attr('name')
|
||||||
|
}) %>
|
||||||
|
</li>
|
||||||
|
<% }) %>
|
||||||
|
</ol>
|
||||||
@ -1,3 +1,5 @@
|
|||||||
<li><%== can.route.link('Artists', { page: 'library', mode: 'artists' }) %></li>
|
<ul class="root">
|
||||||
<li><%== can.route.link('Albums', { page: 'library', mode: 'albums' }) %></li>
|
<li><%== can.route.link('Artists', { page: 'library', show: 'artists' }) %></li>
|
||||||
<li><%== can.route.link('Songs', { page: 'library', mode: 'songs' }) %></li>
|
<li><%== can.route.link('Albums', { page: 'library', show: 'albums' }) %></li>
|
||||||
|
<li><%== can.route.link('Songs', { page: 'library', show: 'songs' }) %></li>
|
||||||
|
</ul>
|
||||||
|
|||||||
7
public/views/library/songs.ejs
Normal file
7
public/views/library/songs.ejs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<ol class="songs">
|
||||||
|
<% list(songs, function(song) { %>
|
||||||
|
<li id="<%= song.attr('id') %>">
|
||||||
|
<%= song.attr('title') %>
|
||||||
|
</li>
|
||||||
|
<% }) %>
|
||||||
|
</ol>
|
||||||
Loading…
Reference in New Issue
Block a user