@widgetic/editor 3.10.49 → 3.10.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/editor",
3
- "version": "3.10.49",
3
+ "version": "3.10.51",
4
4
  "scripts": {
5
5
  "start": "webpack --config webpack.config.js --watch --progress",
6
6
  "build": "webpack --config webpack.config.js",
@@ -9,7 +9,8 @@
9
9
  "version": "grunt release && git add -A lib",
10
10
  "postversion": "git push && npm publish",
11
11
  "genssl": "openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout key.pem -out cert.pem -subj /CN=localhost",
12
- "server": "http-server -S -p 8083"
12
+ "server": "http-server -S -p 8083",
13
+ "deploy": "cd ./lib && rsync * root@zeus.widgetic.com:/opt/widgetic_editor/lib"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@widgetic/spine": "^2.0.3",
@@ -81,44 +81,57 @@ export default class UploadService extends EventsMixin(Service) {
81
81
  }
82
82
 
83
83
  upload(uploadFile) {
84
- // console.log("upload file:", uploadFile);
85
-
86
- this.files.push(
87
- new File({
88
- state: 'new',
89
- size: uploadFile.size,
90
- name: uploadFile.name,
91
- type: parseType(uploadFile.type),
92
- // lastModified: uploadFile.lastModified,
93
- uploadFile,
94
- })
95
- );
84
+ // console.log("on upload file:", uploadFile);
85
+
86
+ // create a new File instance from the uploadFile
87
+ let file = new File({
88
+ state: 'new',
89
+ size: uploadFile.size,
90
+ name: uploadFile.name,
91
+ type: parseType(uploadFile.type),
92
+ lastModified: Date.now(),
93
+ uploadFile,
94
+ });
95
+ console.log("on upload file:", file);
96
+
97
+ // push it to the files array
98
+ this.files.push(file);
99
+
100
+ // increase used quota
96
101
  this.used += uploadFile.size;
102
+
103
+ // broadcast the update of the files array
97
104
  this._broadcast.update();
98
105
  }
99
106
 
100
107
  uploadComplete(uploadFile, instanceId) {
101
108
  // console.log("uploadComplete file:", uploadFile);
109
+
102
110
  if (uploadFile.status === 'error') return;
103
111
 
104
- // read metadata(id here) from the file that's on the server
112
+ // read metadata from the file that's on the server
105
113
  const response = JSON.parse(uploadFile.xhr.response);
106
- // console.log("uploadComplete file on the server:", response.files.data[0])
107
- const id = response.files.data[0].id;
114
+ // console.log("uploadComplete server response:", response);
115
+
116
+ // read file from the response
117
+ let serverFile = response.files.data[0];
118
+ // console.log("uploadComplete file on the server:", serverFile);
108
119
 
109
120
  // read quota from response
110
121
  // this.quota = response.quota.max;
111
122
  this.used = response.quota.used;
112
123
 
124
+ // update the file in the files array with the data from the server
113
125
  this._update(uploadFile, f => {
114
126
  f.state = 'complete';
115
- f.id = id;
116
- f.path = response.files.data[0].path;
127
+ f.id = serverFile.id;
128
+ f.path = serverFile.path;
117
129
  f.url = response.hostUrl + f.path;
118
- // f.lastModified = uploadFile.lastModified;
130
+ f.lastModified = serverFile.lastModified;
119
131
  });
120
132
 
121
- this._broadcast.complete([this.get(id), instanceId]);
133
+ // broadcast the completion of the upload based on the fileId and instanceId
134
+ this._broadcast.complete([this.get(serverFile.id), instanceId]);
122
135
  }
123
136
 
124
137
  accept(file, done) {
@@ -162,10 +175,13 @@ export default class UploadService extends EventsMixin(Service) {
162
175
  }
163
176
 
164
177
  _update(file, transform) {
178
+ // apply the transform function to the file in the array
165
179
  this.files = this.files.map(f => {
166
180
  if (f.uploadFile === file) transform(f);
167
181
  return f;
168
182
  });
183
+
184
+ // broadcast the update of the files array
169
185
  this._broadcast.update();
170
186
  }
171
187
 
@@ -7,7 +7,7 @@ export default {
7
7
  },
8
8
 
9
9
  computed: {
10
- instance: service => Container[service],
10
+ instance: service => Container[service], // get the service instance
11
11
  },
12
12
 
13
13
  oncreate() {
@@ -182,7 +182,7 @@
182
182
  import Dropzone from './dropzone.html';
183
183
  import ScrollPane from './scroll-pane.html';
184
184
  import File from './file.html';
185
- import Service from './service.html';
185
+ import Service from './service.html'; // actually imports services/uploads.js
186
186
 
187
187
  let instanceId = 0;
188
188
 
@@ -220,6 +220,9 @@ export default {
220
220
 
221
221
  // load uploaded files
222
222
  this.refresh();
223
+
224
+ // scroll to uploads files list to bottom
225
+ this.scrollToListBottom();
223
226
  },
224
227
  ondestroy() {
225
228
  this.observer.cancel();
@@ -233,7 +236,7 @@ export default {
233
236
 
234
237
  // on selecting a file square
235
238
  toggle(file) {
236
- console.log("on toggle file:", file);
239
+ // console.log("on toggle file:", file);
237
240
 
238
241
  if (file.error) {
239
242
  this.Uploads.remove(file);
@@ -251,7 +254,7 @@ export default {
251
254
  },
252
255
 
253
256
  refresh(ev) {
254
- console.log("refreshing...");
257
+ // console.log("refreshing...");
255
258
  if (ev) ev.preventDefault();
256
259
 
257
260
  return this.Uploads.getFiles(this.get('filetypes'))
@@ -264,20 +267,37 @@ export default {
264
267
  // if(!a.id.indexOf) return -1;
265
268
  // let noIdA = a.id.substr(a.id.indexOf('_t')+2, 4);
266
269
  // let noIdB = b.id.substr(a.id.indexOf('_t')+2, 4);
267
- // // console.log("noIdA & noIdB: ", noIdA, noIdB, (noIdA >= noIdB));
270
+ // // console.log("noIdA & noIdB: ", noIdA, noIdB, (noIdA - noIdB));
268
271
  // return noIdA - noIdB;
269
272
  // });
270
273
  // console.log("uploadedFiles after sort: ", files);
271
274
 
272
- // sort files by last modified date
275
+ // sort files by last modified(uploadTime) date
273
276
  files = files.sort((a, b) => {
277
+
278
+ // read a lastModified timestamp
274
279
  let x = a.lastModified;
280
+
281
+ // read the lastModified date from the id
282
+ if(!x) x = a.id.substring(a.id.indexOf('_u')+3);
283
+
284
+ // if still not available then set it to 0
275
285
  if(!x) x = 0;
286
+ // a.lastModified = x;
287
+
276
288
 
289
+ // read b lastModified timestamp
277
290
  let y = b.lastModified;
291
+
292
+ // read the lastModified date from the id
293
+ if(!y) y = b.id.substring(b.id.indexOf('_u')+3);
294
+
295
+ // if still not available then set it to 0
278
296
  if(!y) y = 0;
297
+ // b.lastModified = y;
298
+
279
299
 
280
- // console.log("x & y: ", x, y);
300
+ // console.log("x & y: ", a.lastModified, x, b.lastModified, y);
281
301
 
282
302
  return x - y;
283
303
  });
@@ -342,12 +362,20 @@ export default {
342
362
  */
343
363
 
344
364
  _onDropZoneNewUpload(event) {
345
- console.log("on DropZone New Upload:", event);
365
+ // console.log("on DropZone New Upload:", event);
366
+
367
+ // scroll the list to the bottom
368
+ this.scrollToListBottom();
369
+ },
370
+
371
+ // scroll to uploads files list to bottom
372
+ scrollToListBottom() {
373
+ // console.log("on DropZone New Upload:", event);
346
374
  this.refs.scrollPane && this.refs.scrollPane.scrollBottom();
347
375
  },
348
376
 
349
377
  _onDropZoneUpload(event) {
350
- console.log("on DropZone Upload:", event);
378
+ // console.log("on DropZone Upload:", event);
351
379
  this.toggle( event );
352
380
  },
353
381