Skip to content

Commit d50012c

Browse files
committed
fixes
1 parent 295d26c commit d50012c

File tree

2 files changed

+43
-49
lines changed

2 files changed

+43
-49
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"polymer": "Polymer/polymer#^1.4.0",
77
"input-file": "git@github.com:sharedlabs/input-file.git",
88
"overlay-container": "git@github.com:sharedlabs/overlay-container.git",
9-
"iron-image": "PolymerElements/iron-image#^1.2.5"
9+
"iron-image": "PolymerElements/iron-image#^1.2.5",
10+
"paper-progress": "PolymerElements/paper-progress#^1.0.11"
1011
},
1112
"devDependencies": {
1213
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",

file-uploader-progress.html

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
33
<link rel="import" href="../iron-image/iron-image.html">
44
<link rel="import" href="../overlay-container/animated-overlay-behavior.html">
5+
<link rel="import" href="../paper-progress/paper-progress.html">
56

67
<!--
78
`file-uploader`
@@ -69,33 +70,25 @@
6970
font-size: 13px;
7071
}
7172

72-
.progress-bar-container {
73+
#paperProgress {
74+
bottom: 0;
7375
height: 4px;
74-
background: #ddd;
75-
width: 100%;
76-
position: absolute;
7776
left: 0;
78-
bottom: 0;
79-
}
80-
81-
.progress-bar {
82-
height: 100%;
83-
transform-origin: left top;
84-
background: var(--file-uploader-progress-color, #2196f3);
77+
position: absolute;
78+
width: 100%;
79+
--paper-progress-active-color: var(--file-uploader-progress-color, #2196f3);
8580
}
8681
</style>
8782

8883
<div class="content">
8984
<iron-image sizing="cover" src$="[[_currentFileDataURL]]"></iron-image>
9085

9186
<div class="details">
92-
<div class="caption">Uploading to</div>
87+
<div class="caption">Uploading...</div>
9388
<div class="uploading-to-text">[[uploadingToText]]</div>
94-
<div class="caption">[[_computeNthFileUploading(_currentFile)]] of [[files.length]]</div>
89+
<div class="caption">[[_computeCurrentUploadIndex(_currentFile)]] of [[files.length]]</div>
9590
<button on-tap="_stopTapped">Stop<paper-ripple></paper-ripple></button>
96-
<div class="progress-bar-container">
97-
<div class="progress-bar" style$="[[_computeProgressBarStyle(progress)]]"></div>
98-
</div>
91+
<paper-progress id="paperProgress" indeterminate></paper-progress>
9992
</div>
10093
</div>
10194

@@ -112,38 +105,37 @@
112105

113106
properties: {
114107

115-
// @override the OverlayBehavior property
116-
noCancelOnEscKey: {
117-
type: Boolean,
118-
value: true
119-
},
120-
121-
// @override the OverlayBehavior property
122-
noCancelOnPopState: {
123-
type: Boolean,
124-
value: true
125-
},
126-
127108
// General upload progress
128109
progress: {
129110
type: Number,
111+
notify: true,
130112
observer: '_progressChanged',
131113
},
132114

133-
// array of files
115+
// Array of files
134116
files: {
135-
type: Array,
136-
// observer: '_filesChanged',
117+
type: Array
137118
},
138119

139-
// array of files progress weakmap
120+
// Weakmap of files progress weakmap
140121
filesProgress: {
141122
type: Object,
142123
},
143124

144125
uploadingToText: {
145126
type: String,
146-
value: 'My news widget'
127+
},
128+
129+
// @override the OverlayBehavior property
130+
noCancelOnEscKey: {
131+
type: Boolean,
132+
value: true
133+
},
134+
135+
// @override the OverlayBehavior property
136+
noCancelOnPopState: {
137+
type: Boolean,
138+
value: true
147139
},
148140

149141
/**
@@ -178,49 +170,50 @@
178170
}
179171
},
180172

181-
_filesChanged(change) {
182-
const files = change.base;
183-
this.opened = files && files.length;
184-
},
185-
186173
_progressChanged() {
187174
this.refresh();
188175
},
189176

177+
_filesChanged() {
178+
this.opened = this.files && this.files.length;
179+
},
180+
190181
_currentFileChanged(currentFile) {
191182
if (currentFile) {
192183
const isImage = /image\/.*/.exec(currentFile.type);
184+
193185
if (isImage) {
194186
this._currentFileDataURL = URL.createObjectURL(currentFile);
195187
}
196188
}
197189
},
198190

199-
_computeNthFileUploading(currentFile) {
200-
return this._getUploadedFiles().length + 1;
201-
},
202-
203-
_computeProgressBarStyle(progress) {
204-
return `transform: scaleX(${progress / 100})`;
205-
},
206-
207191
_stopTapped() {
208-
this.fire('stop');
192+
this.fire('upload-stop');
209193
},
210194

195+
/**
196+
* Return the file that is currently being uploaded.
197+
*/
211198
_getFileInProgress() {
212199
return (this.files || []).filter(file => {
213200
const progress = this.filesProgress.get(file);
214201
const isUploading = typeof progress === 'number' && progress < 100;
215-
// console.log(file.name, progress)
216202
return isUploading;
217203
})[0];
218204
},
219205

206+
/**
207+
* Return already uploaded files.
208+
*/
220209
_getUploadedFiles() {
221210
return (this.files || []).filter(file => {
222211
return this.filesProgress.get(file) === 100;
223212
});
213+
},
214+
215+
_computeCurrentUploadIndex(currentFile) {
216+
return this._getUploadedFiles().length + 1;
224217
}
225218

226219
});

0 commit comments

Comments
 (0)