Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better sort #195

Merged
merged 2 commits into from
Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,33 @@ app.on('ready', () => {
function sortList (keyA, keyB) {
var aObj = state.trackDict[keyA]
var bObj = state.trackDict[keyB]
// sort by albumartist
// if (aObj.albumartist[0] < bObj.albumartist[0]) return -1
// if (aObj.albumartist[0] > bObj.albumartist[0]) return 1

// sort by artist
if (aObj.artist < bObj.artist) return -1
if (aObj.artist > bObj.artist) return 1
// if (aObj.artist[0] < bObj.artist[0]) return -1
// if (aObj.artist[0] > bObj.artist[0]) return 1

// then by album
if (aObj.album < bObj.album) return -1
if (aObj.album > bObj.album) return 1

// then by disc no
if (aObj.disk.no < bObj.disk.no) return -1
if (aObj.disk.no > bObj.disk.no) return 1

// then by disc no
if (aObj.track.no < bObj.track.no) return -1
if (aObj.track.no > bObj.track.no) return 1

// then by title
if (aObj.title < bObj.title) return -1
if (aObj.title > bObj.title) return 1

// then by filepath
if (aObj.filepath < bObj.filepath) return -1
if (aObj.filepath > bObj.filepath) return 1
return 0
}

Expand Down
28 changes: 25 additions & 3 deletions main/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,37 @@ function parseMetadata (data, cb) {
return cb(null)
}
}

var { title, artist, album, duration } = meta
// delete meta.picture
// console.dir(meta, {colors: true, depth: 5})
var {
albumartist,
title,
artist,
album,
year,
track,
disk,
genre,
duration
} = meta

if (!title) {
var { basename } = data
var ext = path.extname(basename)
title = path.basename(basename, ext)
}

cb(null, {title, artist, album, duration, filepath})
cb(null, {
albumartist,
title,
artist,
album,
duration,
filepath,
year,
track,
disk,
genre
})
})
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"test:deps": "dependency-check ./package.json --entry renderer/index.js --no-dev --ignore-module electron",
"test:lint": "standard | snazzy",
"test-skip:tape": "xvfb-maybe tape test/* | tap-format-spec",
"test:artwork-module": "tape main/lib/**/test.js | tap-format-spec",
"test:main": "tape main/lib/**/test.js | tap-format-spec",
"test:renderer": "tape renderer/**/test.js | tap-format-spec",
"rebuild": "electron-rebuild",
"build": "build --dir",
"dist": "build"
Expand Down
3 changes: 3 additions & 0 deletions renderer/elements/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Table.prototype._render = function (state, emit) {
<tr>
<th>Title</th>
<th class="${styles.time}">Time</th>
<th class="${styles.disk}">Disk</th>
<th class="${styles.track}">Track</th>
<th>Artist</th>
<th>Album</th>
<th class="${styles.year}">Year</th>
</tr>
</thead>
</table>
Expand Down
7 changes: 7 additions & 0 deletions renderer/elements/table/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exports.formatCount = formatCount

function formatCount (countObj) {
if (!countObj.no && !countObj.of) return ''
if (!countObj.of) return countObj.no.toString()
return `${countObj.no} of ${countObj.of}`
}
4 changes: 4 additions & 0 deletions renderer/elements/table/rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var fd = require('format-duration')
var classNames = require('classnames')
var Component = require('cache-component')
var document = require('global/document')
var {formatCount} = require('./lib')
var styles = require('./styles')
// var debounce = require('lodash.debounce')

Expand Down Expand Up @@ -121,8 +122,11 @@ TableRows.prototype._rowMap = function (key, idx) {
className="${classNames(classes)}">
<td>${meta.title}</td>
<td class="${styles.time}">${meta.duration ? fd(meta.duration * 1000) : ''}</td>
<td class="${styles.disk}">${meta.disk ? formatCount(meta.disk) : ''}</td>
<td class="${styles.track}">${meta.track ? formatCount(meta.track) : ''}</td>
<td>${meta.artist}</td>
<td>${meta.album}</td>
<td class="${styles.year}">${meta.year}</td>
</tr>
`
}
Expand Down
22 changes: 20 additions & 2 deletions renderer/elements/table/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = css`
border-right: var(--border);
border-bottom: var(--border);
}
.mediaList td {
border-right: var(--border);
}
.mediaList th:last-child {
border-right: none;
}
Expand All @@ -50,7 +53,8 @@ module.exports = css`

.tableScrollWindow {
flex: 1 0;
overflow: auto;
overflow-y: overlay;
overflow-x: hidden;
will-change: transform;
}

Expand All @@ -70,8 +74,22 @@ module.exports = css`
width: 6em;
}

.mediaList .track {
text-align: right;
width: 7em;
}

.mediaList .disk {
text-align: right;
width: 5em;
}

.mediaList .year {
width: 5em;
}

.mediaList .track {
width: 6em;
width: 7em;
}

.playing {
Expand Down
25 changes: 25 additions & 0 deletions renderer/elements/table/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var test = require('tape')
var {formatCount} = require('./lib')

test('format disk and track objects correctly', function (t) {
var tests = [
{
in: { no: 14, of: 17 },
expect: '14 of 17'
},
{
in: { no: 0, of: 0 },
expect: ''
},
{
in: { no: 5, of: 0 },
expect: '5'
}
]

tests.forEach(function (testCase) {
t.equal(formatCount(testCase.in), testCase.expect, `${JSON.stringify(testCase.in)} formats to ${testCase.expect}`)
})

t.end()
})