Skip to content

Commit 35cc735

Browse files
author
Nicolas Joyard
committed
Enable showing download details
1 parent 9df47c1 commit 35cc735

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

client/downloads.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ define([
5959
}
6060

6161

62+
var showDetails = [];
6263
var contentListConfig = {
6364
resource: resources.downloads,
6465
dataMapper: function(downloads) {
65-
return { downloads: downloads };
66+
return {
67+
downloads: downloads.map(function(download) {
68+
download.showDetails = showDetails.indexOf(download._id) !== -1;
69+
return download;
70+
})
71+
};
6672
},
6773

6874
root: {
@@ -97,6 +103,22 @@ define([
97103

98104
"!cancel/:id": function(view, err, req, next) {
99105
resources.downloads.cancel(req.match.id);
106+
next();
107+
},
108+
109+
"!details/:id": function(view, err, req, next) {
110+
var download = view.$(".download[data-id='" + req.match.id + "']");
111+
var visible = download.classList.toggle("show-details");
112+
var idx = showDetails.indexOf(req.match.id);
113+
114+
if (idx !== -1) {
115+
showDetails.splice(idx, 1);
116+
}
117+
118+
if (visible) {
119+
showDetails.push(req.match.id);
120+
}
121+
100122
next();
101123
}
102124
}
@@ -114,6 +136,7 @@ define([
114136
renderApplet(appletView);
115137

116138
var downloadsView = ui.view("downloads");
139+
var showDetails = [];
117140

118141
contentListConfig.fetcher = getDownloadsFetcher();
119142
ui.helpers.setupContentList(downloadsView, contentListConfig);

client/public/style/downloads.less

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
1-
.download .progress {
2-
flex-basis: 100%;
1+
.download {
2+
.progress {
3+
flex-basis: 100%;
4+
}
5+
6+
.files {
7+
display: none;
8+
list-style-type: none;
9+
color: @mlGray;
10+
margin: @contentBoxMargin;
11+
12+
.file {
13+
display: flex;
14+
flex-flow: row;
15+
16+
.size {
17+
margin-left: auto;
18+
text-align: right;
19+
}
20+
}
21+
}
22+
23+
&.show-details .files {
24+
display: block;
25+
}
326
}
427

528
.download[data-state="error"] .progress {

client/templates/downloadlist.ist

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
@define "downloads-download"
2-
li.list-item.download[data-id={{ _id }}][data-state={{ state }}]
2+
li \
3+
[data-id={{ _id }}] \
4+
[data-state={{ state }}] \
5+
[class=list-item download{{ showDetails ? " show-details" : "" }}]
36
.list-item-head
47
@with size ? 100 * downloaded / size : 0
58
@use "progress-bar"
@@ -27,8 +30,19 @@
2730
@icon icon
2831
"{{ size === -1 ? '-' : humanSize(size, 'B') }}"
2932

33+
ul.list-item-details.files
34+
@eachkey files
35+
li.file
36+
.name "{{ key }}"
37+
.size "{{ humanSize(value, 'B') }}"
38+
39+
3040
@if-right "downloads:change"
3141
.list-item-actions
42+
a.action-with-icon[href={{ uri("#!downloads/details/%s", _id) }}]
43+
@icon "more"
44+
"Details"
45+
3246
@if state !== "paused" && state !== "complete" && state !== "error"
3347
a.action-with-icon[title=Pause][href={{ uri("#!downloads/pause/%s", _id) }}]
3448
@icon "pause"

http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ httpProvider.init = function(mongoose, logger, config) {
361361

362362
HTTPDownloadSchema.virtual("files").get(function() {
363363
var files = {};
364-
files[this.path] = this.size;
364+
files[path.relative(incoming, this.path)] = this.size;
365365
return files;
366366
});
367367

0 commit comments

Comments
 (0)