angularjs-file-upload-rails 1.1.0 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -1
- data/angularjs-file-upload.gemspec +1 -1
- data/app/assets/javascripts/angularjs-file-upload.js +33 -21
- data/lib/angularjs-file-upload/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb70a719506f44ab6f69a15b0eaf560faa90cb9d
|
4
|
+
data.tar.gz: cc88a54f125d537375f4b16988b1564d97728d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4161dab606fd0d2d9e05b4652d3bcbdf8e8433c4fc47c622efbf9d1be01b7f9215a4e7a078c029dade375c12184e6ece84605dbc2654908db38f0499a2d2620
|
7
|
+
data.tar.gz: e41661d20c722e602ffed5ffd2124ab676e5774061251891e9774a3d12ece76c126511317996c5cb25ef444a2fcd8d703ec3d26fe164ed876b9a5c329420a96f
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ A gem that uses [angular-file-upload](https://github.com/nervgh/angular-file-upl
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'angularjs-file-upload', '~> 1.
|
12
|
+
gem 'angularjs-file-upload-rails', '~> 1.1.5'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -33,6 +33,66 @@ Include it in your JavaScript manifest (e.g. `application.js`)
|
|
33
33
|
```
|
34
34
|
\* *be sure that angular is required before angularjs-file-upload*
|
35
35
|
|
36
|
+
## Read more
|
37
|
+
|
38
|
+
read more about the options in [angular-file-upload-wiki](https://github.com/nervgh/angular-file-upload/wiki/Introduction)
|
39
|
+
|
40
|
+
## Basic example
|
41
|
+
|
42
|
+
\* *assuming that you have setup an ```angularjs``` correctly in your rails app
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
gem 'angularjs-file-upload-rails', '~> 1.1.5'
|
46
|
+
gem 'carrierwave'
|
47
|
+
gem 'rails', '4.1.5'
|
48
|
+
```
|
49
|
+
|
50
|
+
Setup your carrierwave gem as discribed in the [carrierwave-readme](https://github.com/carrierwaveuploader/carrierwave)
|
51
|
+
|
52
|
+
add ```angularjs-file-upload-rails``` to your gem file
|
53
|
+
add
|
54
|
+
|
55
|
+
```javascript
|
56
|
+
//= require angularjs-file-upload
|
57
|
+
```
|
58
|
+
|
59
|
+
to ```application.js```
|
60
|
+
|
61
|
+
in the angular file
|
62
|
+
|
63
|
+
```javascript
|
64
|
+
angular
|
65
|
+
.module('app', ['angularFileUpload'])
|
66
|
+
.controller('AppController', function($scope, FileUploader) {
|
67
|
+
$scope.uploader = new FileUploader({url: '<your controller path>'});
|
68
|
+
});
|
69
|
+
```
|
70
|
+
|
71
|
+
in your view
|
72
|
+
|
73
|
+
```html
|
74
|
+
<div ng-app="app">
|
75
|
+
<div ng-controller="AppController">
|
76
|
+
<input type="file" nv-file-select uploader="uploader"/><br/>
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
```
|
80
|
+
|
81
|
+
in your controller
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
class UsersController < ApplicationController
|
85
|
+
|
86
|
+
def create
|
87
|
+
user = User.new()
|
88
|
+
//other params
|
89
|
+
user.picture = params[:file]
|
90
|
+
user.save
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
36
96
|
## Contributing
|
37
97
|
|
38
98
|
1. Fork it
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.require_paths = ["lib"]
|
17
|
+
spec.require_paths = ["lib", "app"]
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "rails", "~> 3.1"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
angular-file-upload v1.1.
|
2
|
+
angular-file-upload v1.1.5
|
3
3
|
https://github.com/nervgh/angular-file-upload
|
4
4
|
*/
|
5
5
|
(function(angular, factory) {
|
@@ -344,7 +344,7 @@ module
|
|
344
344
|
FileUploader.prototype._getFilters = function(filters) {
|
345
345
|
if (angular.isUndefined(filters)) return this.filters;
|
346
346
|
if (angular.isArray(filters)) return filters;
|
347
|
-
var names = filters.
|
347
|
+
var names = filters.match(/[^\s,]+/g);
|
348
348
|
return this.filters.filter(function(filter) {
|
349
349
|
return names.indexOf(filter.name) !== -1;
|
350
350
|
}, this);
|
@@ -400,12 +400,14 @@ module
|
|
400
400
|
/**
|
401
401
|
* Transforms the server response
|
402
402
|
* @param {*} response
|
403
|
+
* @param {Object} headers
|
403
404
|
* @returns {*}
|
404
405
|
* @private
|
405
406
|
*/
|
406
|
-
FileUploader.prototype._transformResponse = function(response) {
|
407
|
+
FileUploader.prototype._transformResponse = function(response, headers) {
|
408
|
+
var headersGetter = this._headersGetter(headers);
|
407
409
|
angular.forEach($http.defaults.transformResponse, function(transformFn) {
|
408
|
-
response = transformFn(response);
|
410
|
+
response = transformFn(response, headersGetter);
|
409
411
|
});
|
410
412
|
return response;
|
411
413
|
};
|
@@ -421,17 +423,10 @@ module
|
|
421
423
|
|
422
424
|
if (!headers) return parsed;
|
423
425
|
|
424
|
-
function trim(string) {
|
425
|
-
return string.replace(/^\s+/, '').replace(/\s+$/, '');
|
426
|
-
}
|
427
|
-
function lowercase(string) {
|
428
|
-
return string.toLowerCase();
|
429
|
-
}
|
430
|
-
|
431
426
|
angular.forEach(headers.split('\n'), function(line) {
|
432
427
|
i = line.indexOf(':');
|
433
|
-
key =
|
434
|
-
val =
|
428
|
+
key = line.slice(0, i).trim().toLowerCase();
|
429
|
+
val = line.slice(i + 1).trim();
|
435
430
|
|
436
431
|
if (key) {
|
437
432
|
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
@@ -440,6 +435,20 @@ module
|
|
440
435
|
|
441
436
|
return parsed;
|
442
437
|
};
|
438
|
+
/**
|
439
|
+
* Returns function that returns headers
|
440
|
+
* @param {Object} parsedHeaders
|
441
|
+
* @returns {Function}
|
442
|
+
* @private
|
443
|
+
*/
|
444
|
+
FileUploader.prototype._headersGetter = function(parsedHeaders) {
|
445
|
+
return function(name) {
|
446
|
+
if (name) {
|
447
|
+
return parsedHeaders[name.toLowerCase()] || null;
|
448
|
+
}
|
449
|
+
return parsedHeaders;
|
450
|
+
};
|
451
|
+
};
|
443
452
|
/**
|
444
453
|
* The XMLHttpRequest transport
|
445
454
|
* @param {FileItem} item
|
@@ -458,7 +467,7 @@ module
|
|
458
467
|
});
|
459
468
|
});
|
460
469
|
|
461
|
-
form.append(item.alias, item._file);
|
470
|
+
form.append(item.alias, item._file, item.file.name);
|
462
471
|
|
463
472
|
xhr.upload.onprogress = function(event) {
|
464
473
|
var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
|
@@ -467,7 +476,7 @@ module
|
|
467
476
|
|
468
477
|
xhr.onload = function() {
|
469
478
|
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
|
470
|
-
var response = that._transformResponse(xhr.response);
|
479
|
+
var response = that._transformResponse(xhr.response, headers);
|
471
480
|
var gist = that._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
472
481
|
var method = '_on' + gist + 'Item';
|
473
482
|
that[method](item, response, xhr.status, headers);
|
@@ -476,14 +485,14 @@ module
|
|
476
485
|
|
477
486
|
xhr.onerror = function() {
|
478
487
|
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
|
479
|
-
var response = that._transformResponse(xhr.response);
|
488
|
+
var response = that._transformResponse(xhr.response, headers);
|
480
489
|
that._onErrorItem(item, response, xhr.status, headers);
|
481
490
|
that._onCompleteItem(item, response, xhr.status, headers);
|
482
491
|
};
|
483
492
|
|
484
493
|
xhr.onabort = function() {
|
485
494
|
var headers = that._parseHeaders(xhr.getAllResponseHeaders());
|
486
|
-
var response = that._transformResponse(xhr.response);
|
495
|
+
var response = that._transformResponse(xhr.response, headers);
|
487
496
|
that._onCancelItem(item, response, xhr.status, headers);
|
488
497
|
that._onCompleteItem(item, response, xhr.status, headers);
|
489
498
|
};
|
@@ -519,7 +528,9 @@ module
|
|
519
528
|
|
520
529
|
angular.forEach(item.formData, function(obj) {
|
521
530
|
angular.forEach(obj, function(value, key) {
|
522
|
-
|
531
|
+
var element = angular.element('<input type="hidden" name="' + key + '" />');
|
532
|
+
element.val(value);
|
533
|
+
form.append(element);
|
523
534
|
});
|
524
535
|
});
|
525
536
|
|
@@ -549,8 +560,8 @@ module
|
|
549
560
|
} catch (e) {}
|
550
561
|
|
551
562
|
var xhr = {response: html, status: 200, dummy: true};
|
552
|
-
var response = that._transformResponse(xhr.response);
|
553
563
|
var headers = {};
|
564
|
+
var response = that._transformResponse(xhr.response, headers);
|
554
565
|
|
555
566
|
that._onSuccessItem(item, response, xhr.status, headers);
|
556
567
|
that._onCompleteItem(item, response, xhr.status, headers);
|
@@ -1155,7 +1166,7 @@ module
|
|
1155
1166
|
* Event handler
|
1156
1167
|
*/
|
1157
1168
|
FileDrop.prototype.onDragLeave = function(event) {
|
1158
|
-
if (event.
|
1169
|
+
if (event.currentTarget !== this.element[0]) return;
|
1159
1170
|
this._preventAndStop(event);
|
1160
1171
|
angular.forEach(this.uploader._directives.over, this._removeOverClass, this);
|
1161
1172
|
};
|
@@ -1316,5 +1327,6 @@ module
|
|
1316
1327
|
}
|
1317
1328
|
};
|
1318
1329
|
}])
|
1330
|
+
|
1319
1331
|
return module;
|
1320
|
-
}));
|
1332
|
+
}));
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angularjs-file-upload-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marthyn Olthof
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -77,6 +77,7 @@ post_install_message:
|
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|
79
79
|
- lib
|
80
|
+
- app
|
80
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
82
|
requirements:
|
82
83
|
- - '>='
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
version: '0'
|
90
91
|
requirements: []
|
91
92
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.5
|
93
94
|
signing_key:
|
94
95
|
specification_version: 4
|
95
96
|
summary: It supports drag-n-drop upload, upload progress, validation filters and a
|