Skip to content

Commit 6aa48f4

Browse files
committed
Adds loopback-component-storage
1 parent b0e1ab8 commit 6aa48f4

7 files changed

Lines changed: 308 additions & 45 deletions

File tree

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"angular-ui-router": "~0.2.10",
1414
"font-awesome": "~4.1.0",
1515
"angular-formly": "~0.0.14",
16-
"angular-toasty": "git@github.com:beeman/angular-toasty.git"
16+
"angular-toasty": "git@github.com:beeman/angular-toasty.git",
17+
"angular-file-upload": "v0.4.0"
1718
},
1819
"devDependencies": {
1920
"angular-mocks": "1.2.21",

client/app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<!-- build:js(.) scripts/vendor.js -->
3030
<!-- bower:js -->
31+
<script src="bower_components/es5-shim/es5-shim.js"></script>
3132
<script src="bower_components/jquery/dist/jquery.js"></script>
3233
<script src="bower_components/angular/angular.js"></script>
3334
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
@@ -40,6 +41,7 @@
4041
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
4142
<script src="bower_components/angular-formly/dist/formly.min.js"></script>
4243
<script src="bower_components/angular-toasty/js/ng-toasty.js"></script>
44+
<script src="bower_components/angular-file-upload/angular-file-upload.js"></script>
4345
<!-- endbower -->
4446
<!-- endbuild -->
4547

client/app/scripts/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ angular.module('loopbackApp', [
1818
'ui.router',
1919
'lbServices',
2020
'formly',
21-
'toasty'
21+
'toasty',
22+
'angularFileUpload'
2223
])
2324

2425
.controller('LayoutCtrl', function ($scope) {

client/app/scripts/controllers/sandbox.js

Lines changed: 166 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,35 @@ angular.module('loopbackApp')
2828
controller: 'SandboxCtrl'
2929
})
3030

31+
.state('sandbox.storage', {
32+
url: '/storage',
33+
templateUrl: 'views/sandbox/storage.html',
34+
controller: 'SandboxCtrl'
35+
})
36+
3137
.state('sandbox.users', {
3238
url: '/users',
3339
template: '<pre>{{users | json}}</pre>',
3440
controller: function($scope, User) {
35-
$scope.users = User.find({}, function(err, data){
41+
$scope.users = User.find({}, function(err, data) {
3642
console.log(data);
3743
return;
3844
});
3945
}
40-
})
41-
42-
;
46+
});
4347
})
44-
.controller('SandboxCtrl', function ($scope, toasty) {
45-
48+
.controller('SandboxCtrl', function($scope, $http, toasty) {
4649

4750
$scope.items = [{
4851
name: 'Toasts',
4952
sref: '.toasts'
50-
} , {
53+
}, {
5154
name: 'Forms',
5255
sref: '.forms'
53-
} , {
56+
}, {
57+
name: 'Storage',
58+
sref: '.storage'
59+
}, {
5460
name: 'Users',
5561
sref: '.users'
5662
}];
@@ -61,56 +67,173 @@ angular.module('loopbackApp')
6167
};
6268

6369
$scope.toast = function() {
64-
toasty.pop.success({title: $scope.toasty.title, msg: $scope.toasty.text, sound: false});
65-
toasty.pop.warning({title: $scope.toasty.title, msg: $scope.toasty.text, sound: false});
66-
toasty.pop.wait({title: $scope.toasty.title, msg: $scope.toasty.text, sound: false});
67-
toasty.pop.error({title: $scope.toasty.title, msg: $scope.toasty.text, sound: false});
68-
toasty.pop.info({title: $scope.toasty.title, msg: $scope.toasty.text, sound: false});
70+
toasty.pop.success({
71+
title: $scope.toasty.title,
72+
msg: $scope.toasty.text,
73+
sound: false
74+
});
75+
toasty.pop.warning({
76+
title: $scope.toasty.title,
77+
msg: $scope.toasty.text,
78+
sound: false
79+
});
80+
toasty.pop.wait({
81+
title: $scope.toasty.title,
82+
msg: $scope.toasty.text,
83+
sound: false
84+
});
85+
toasty.pop.error({
86+
title: $scope.toasty.title,
87+
msg: $scope.toasty.text,
88+
sound: false
89+
});
90+
toasty.pop.info({
91+
title: $scope.toasty.title,
92+
msg: $scope.toasty.text,
93+
sound: false
94+
});
6995
};
7096

7197

7298
$scope.formData = {};
73-
$scope.formFields = [
74-
{
75-
//the key to be used in the result values {... "username": "johndoe" ... }
76-
key: 'username',
77-
78-
//default value
79-
default: 'uberuser',
80-
type: 'text',
81-
label: 'Username',
82-
placeholder: 'johndoe',
83-
required: true,
84-
disabled: false //default: false
85-
},
86-
{
87-
key: 'password',
88-
type: 'password',
89-
label: 'Password',
90-
required: true,
91-
disabled: false, //default: false
92-
hideExpression: '!username' // hide when username is blank
93-
}
99+
$scope.formFields = [{
100+
//the key to be used in the result values {... "username": "johndoe" ... }
101+
key: 'username',
102+
103+
//default value
104+
default: 'uberuser',
105+
type: 'text',
106+
label: 'Username',
107+
placeholder: 'johndoe',
108+
required: true,
109+
disabled: false //default: false
110+
}, {
111+
key: 'password',
112+
type: 'password',
113+
label: 'Password',
114+
required: true,
115+
disabled: false, //default: false
116+
hideExpression: '!username' // hide when username is blank
117+
}
94118

95119
];
96120

97121
$scope.formOptions = {
98122

99-
//Set the id of the form
100-
uniqueFormId: 'myFormId',
123+
//Set the id of the form
124+
uniqueFormId: 'myFormId',
101125

102-
//Hide the submit button that is added automaticaly
103-
//default: false
104-
hideSubmit: false,
126+
//Hide the submit button that is added automaticaly
127+
//default: false
128+
hideSubmit: false,
105129

106-
//Set the text on the default submit button
107-
//default: Submit
108-
submitCopy: 'Login'
130+
//Set the text on the default submit button
131+
//default: Submit
132+
submitCopy: 'Login'
109133
};
110134

111135
$scope.onSubmit = function() {
112-
console.log('form submitted:', $scope.formData);
136+
console.log('form submitted:', $scope.formData);
137+
};
138+
139+
})
140+
.controller('UploadCtrl', function($scope, $fileUploader) {
141+
142+
// create a uploader with options
143+
var uploader = $scope.uploader = $fileUploader.create({
144+
scope: $scope, // to automatically update the html. Default: $rootScope
145+
url: 'http://localhost:3000/api/containers/upload',
146+
formData: [{
147+
key: 'value'
148+
}],
149+
filters: [
150+
151+
function(item) { // first user filter
152+
console.info('filter1');
153+
console.log(item);
154+
return true;
155+
}
156+
]
157+
});
158+
159+
// ADDING FILTERS
160+
161+
uploader.filters.push(function(item) { // second user filter
162+
console.info('filter2');
163+
console.log(item);
164+
return true;
165+
});
166+
167+
// REGISTER HANDLERS
168+
169+
uploader.bind('afteraddingfile', function(event, item) {
170+
console.info('After adding a file', item);
171+
});
172+
173+
uploader.bind('whenaddingfilefailed', function(event, item) {
174+
console.info('When adding a file failed', item);
175+
});
176+
177+
uploader.bind('afteraddingall', function(event, items) {
178+
console.info('After adding all files', items);
179+
});
180+
181+
uploader.bind('beforeupload', function(event, item) {
182+
console.info('Before upload', item);
183+
});
184+
185+
uploader.bind('progress', function(event, item, progress) {
186+
console.info('Progress: ' + progress, item);
187+
});
188+
189+
uploader.bind('success', function(event, xhr, item, response) {
190+
console.info('Success', xhr, item, response);
191+
$scope.$broadcast('uploadCompleted', item);
192+
});
193+
194+
uploader.bind('cancel', function(event, xhr, item) {
195+
console.info('Cancel', xhr, item);
196+
});
197+
198+
uploader.bind('error', function(event, xhr, item, response) {
199+
console.info('Error', xhr, item, response);
200+
});
201+
202+
uploader.bind('complete', function(event, xhr, item, response) {
203+
console.info('Complete', xhr, item, response);
204+
});
205+
206+
uploader.bind('progressall', function(event, progress) {
207+
console.info('Total progress: ' + progress);
208+
});
209+
210+
uploader.bind('completeall', function(event, items) {
211+
console.info('Complete all', items);
212+
});
213+
214+
})
215+
.controller('FilesCtrl', function($scope, $http) {
216+
217+
$scope.load = function() {
218+
$http.get('http://localhost:3000/api/containers/files').success(function(data) {
219+
console.log(data);
220+
$scope.files = data;
221+
});
222+
};
223+
224+
$scope.delete = function(index, id) {
225+
$http.delete('http://localhost:3000/api/containers/files/' + encodeURIComponent(id)).success(function(data, status, headers) {
226+
console.log(data);
227+
console.log(status);
228+
console.log(headers);
229+
$scope.files.splice(index, 1);
230+
});
113231
};
114232

233+
$scope.$on('uploadCompleted', function(event) {
234+
console.log('uploadCompleted event received');
235+
console.log(event);
236+
$scope.load();
237+
});
115238

116239
});

0 commit comments

Comments
 (0)