/
partyUpload.js
88 lines (70 loc) · 1.83 KB
/
partyUpload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import ngFileUpload from 'ng-file-upload';
import 'angular-sortable-view';
import 'ng-img-crop/compile/minified/ng-img-crop';
import 'ng-img-crop/compile/minified/ng-img-crop.css';
import { Meteor } from 'meteor/meteor';
import template from './partyUpload.html';
import { Thumbs, upload } from '../../../api/images';
class PartyUpload {
constructor($scope, $reactive) {
'ngInject';
$reactive(this).attach($scope);
this.uploaded = [];
this.subscribe('thumbs', () => [
this.getReactively('files', true) || []
]);
this.helpers({
thumbs() {
return Thumbs.find({
originalStore: 'images',
originalId: {
$in: this.getReactively('files', true) || []
}
});
}
});
}
addImages(files) {
if (files.length) {
this.currentFile = files[0];
const reader = new FileReader;
reader.onload = this.$bindToContext((e) => {
this.cropImgSrc = e.target.result;
this.myCroppedImage = '';
});
reader.readAsDataURL(files[0]);
} else {
this.cropImgSrc = undefined;
}
}
save() {
upload(this.myCroppedImage, this.currentFile.name, this.$bindToContext((file) => {
this.uploaded.push(file);
if (!this.files || !this.files.length) {
this.files = [];
}
this.files.push(file._id);
this.reset();
}), (e) => {
console.log('Oops, something went wrong', e);
});
}
reset() {
this.cropImgSrc = undefined;
this.myCroppedImage = '';
}
}
const name = 'partyUpload';
// create a module
export default angular.module(name, [
angularMeteor,
ngFileUpload,
'ngImgCrop',
'angular-sortable-view'
]).component(name, {
template,
controllerAs: name,
controller: PartyUpload
});