Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2 lines
No EOL
1.7 KiB
JavaScript
2 lines
No EOL
1.7 KiB
JavaScript
;'use strict';var AlbumDetailView=View.extend(function AlbumDetailView(){View.call(this);this.list=document.getElementById('list');this.list.addEventListener('click',(evt)=>{var link=evt.target.closest('a[data-file-path]');if(link){this.queueAlbum(link.dataset.filePath);}});this.client.on('databaseChange',()=>this.update());this.update();});AlbumDetailView.prototype.update=function(){return this.getAlbum().then((songs)=>{this.songs=songs;return this.render();});};AlbumDetailView.prototype.destroy=function(){this.client.destroy();View.prototype.destroy.call(this);};AlbumDetailView.prototype.render=function(){return this.list.setModel(this.songs).then(this.onRenderDone);};AlbumDetailView.prototype.getAlbum=function(){var unpaddedIndex=IntlHelper.get('unpaddedIndex');var paddedIndex=IntlHelper.get('paddedIndex');return this.fetch('/api/albums/info/'+decodeURIComponent(this.params.id)).then(response=>response.json()).then(songs=>{var maxDiscNumber=Math.max(songs[songs.length-1].metadata.disccount,songs[songs.length-1].metadata.discnum);return songs.map((song)=>{return{index:maxDiscNumber>1&&song.metadata.discnum&&song.metadata.tracknum?unpaddedIndex.format(song.metadata.discnum)+'.'+
|
|
paddedIndex.format(song.metadata.tracknum):(song.metadata.tracknum?unpaddedIndex.format(song.metadata.tracknum):''),name:song.name,title:song.metadata.title};});});};AlbumDetailView.prototype.queueAlbum=function(filePath){this.fetch('/api/queue/album/'+filePath);};IntlHelper.define('unpaddedIndex','number',{style:'decimal',useGrouping:false,minimumIntegerDigits:1});IntlHelper.define('paddedIndex','number',{style:'decimal',useGrouping:false,minimumIntegerDigits:2});window.view=new AlbumDetailView(); |