|
2 | 2 | <link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
|
3 | 3 | <link rel="import" href="../iron-image/iron-image.html">
|
4 | 4 | <link rel="import" href="../overlay-container/animated-overlay-behavior.html">
|
| 5 | +<link rel="import" href="../paper-progress/paper-progress.html"> |
5 | 6 |
|
6 | 7 | <!--
|
7 | 8 | `file-uploader`
|
|
69 | 70 | font-size: 13px;
|
70 | 71 | }
|
71 | 72 |
|
72 |
| - .progress-bar-container { |
| 73 | + #paperProgress { |
| 74 | + bottom: 0; |
73 | 75 | height: 4px;
|
74 |
| - background: #ddd; |
75 |
| - width: 100%; |
76 |
| - position: absolute; |
77 | 76 | 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); |
85 | 80 | }
|
86 | 81 | </style>
|
87 | 82 |
|
88 | 83 | <div class="content">
|
89 | 84 | <iron-image sizing="cover" src$="[[_currentFileDataURL]]"></iron-image>
|
90 | 85 |
|
91 | 86 | <div class="details">
|
92 |
| - <div class="caption">Uploading to</div> |
| 87 | + <div class="caption">Uploading...</div> |
93 | 88 | <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> |
95 | 90 | <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> |
99 | 92 | </div>
|
100 | 93 | </div>
|
101 | 94 |
|
|
112 | 105 |
|
113 | 106 | properties: {
|
114 | 107 |
|
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 |
| - |
127 | 108 | // General upload progress
|
128 | 109 | progress: {
|
129 | 110 | type: Number,
|
| 111 | + notify: true, |
130 | 112 | observer: '_progressChanged',
|
131 | 113 | },
|
132 | 114 |
|
133 |
| - // array of files |
| 115 | + // Array of files |
134 | 116 | files: {
|
135 |
| - type: Array, |
136 |
| - // observer: '_filesChanged', |
| 117 | + type: Array |
137 | 118 | },
|
138 | 119 |
|
139 |
| - // array of files progress weakmap |
| 120 | + // Weakmap of files progress weakmap |
140 | 121 | filesProgress: {
|
141 | 122 | type: Object,
|
142 | 123 | },
|
143 | 124 |
|
144 | 125 | uploadingToText: {
|
145 | 126 | 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 |
147 | 139 | },
|
148 | 140 |
|
149 | 141 | /**
|
|
178 | 170 | }
|
179 | 171 | },
|
180 | 172 |
|
181 |
| - _filesChanged(change) { |
182 |
| - const files = change.base; |
183 |
| - this.opened = files && files.length; |
184 |
| - }, |
185 |
| - |
186 | 173 | _progressChanged() {
|
187 | 174 | this.refresh();
|
188 | 175 | },
|
189 | 176 |
|
| 177 | + _filesChanged() { |
| 178 | + this.opened = this.files && this.files.length; |
| 179 | + }, |
| 180 | + |
190 | 181 | _currentFileChanged(currentFile) {
|
191 | 182 | if (currentFile) {
|
192 | 183 | const isImage = /image\/.*/.exec(currentFile.type);
|
| 184 | + |
193 | 185 | if (isImage) {
|
194 | 186 | this._currentFileDataURL = URL.createObjectURL(currentFile);
|
195 | 187 | }
|
196 | 188 | }
|
197 | 189 | },
|
198 | 190 |
|
199 |
| - _computeNthFileUploading(currentFile) { |
200 |
| - return this._getUploadedFiles().length + 1; |
201 |
| - }, |
202 |
| - |
203 |
| - _computeProgressBarStyle(progress) { |
204 |
| - return `transform: scaleX(${progress / 100})`; |
205 |
| - }, |
206 |
| - |
207 | 191 | _stopTapped() {
|
208 |
| - this.fire('stop'); |
| 192 | + this.fire('upload-stop'); |
209 | 193 | },
|
210 | 194 |
|
| 195 | + /** |
| 196 | + * Return the file that is currently being uploaded. |
| 197 | + */ |
211 | 198 | _getFileInProgress() {
|
212 | 199 | return (this.files || []).filter(file => {
|
213 | 200 | const progress = this.filesProgress.get(file);
|
214 | 201 | const isUploading = typeof progress === 'number' && progress < 100;
|
215 |
| - // console.log(file.name, progress) |
216 | 202 | return isUploading;
|
217 | 203 | })[0];
|
218 | 204 | },
|
219 | 205 |
|
| 206 | + /** |
| 207 | + * Return already uploaded files. |
| 208 | + */ |
220 | 209 | _getUploadedFiles() {
|
221 | 210 | return (this.files || []).filter(file => {
|
222 | 211 | return this.filesProgress.get(file) === 100;
|
223 | 212 | });
|
| 213 | + }, |
| 214 | + |
| 215 | + _computeCurrentUploadIndex(currentFile) { |
| 216 | + return this._getUploadedFiles().length + 1; |
224 | 217 | }
|
225 | 218 |
|
226 | 219 | });
|
|
0 commit comments