Skip to content

Commit cdf6a20

Browse files
authored
Merge branch 'master' into upload-configs
2 parents 15c91e8 + a93263e commit cdf6a20

File tree

5 files changed

+87
-60
lines changed

5 files changed

+87
-60
lines changed

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
patreon: dr_dimitru
4+
custom: https://paypal.me/veliovgroup

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
.build*
1+
.npm
2+
.DS_Store
3+
.eslintcache
4+
node_modules

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018, dr.dimitru (Dmitriy A.; Veliov Group, LLC)
1+
Copyright (c) 2019, dr.dimitru (Dmitry A.; Veliov Group, LLC)
22
All rights reserved.
33

44
Redistribution and use in source and binary forms,
@@ -28,4 +28,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2828
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2929
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3030
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 73 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
Autoform File
2-
=============
1+
# Autoform File
2+
3+
<a href="https://www.patreon.com/bePatron?u=20396046">
4+
<img src="https://c5.patreon.com/external/logo/[email protected]" width="160">
5+
</a>
6+
7+
```shell
8+
meteor add ostrio:autoform-files
9+
```
10+
11+
## Description
312

4-
### Description
513
Upload and manage files with autoForm via [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files). This package was ported from `yogiben:autoform-file` to use with [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files) instead of the already deprecated CollectionFS.
614

7-
### Quick Start:
15+
## Quick Start:
816

9-
- Install `meteor add ostrio:autoform-files`
10-
- Install `meteor add ostrio:files`, *if not yet installed*
11-
- Add this config to `simpl-schema` NPM package (depending of the language that you are using):
12-
```javascript
17+
1. Install `meteor add ostrio:autoform-files`
18+
2. Install `meteor add ostrio:files`, *if not yet installed*
19+
3. Add this config to `simpl-schema` NPM package (depending of the language that you are using):
20+
21+
```js
1322
SimpleSchema.setDefaultMessages({
1423
initialLanguage: 'en',
1524
messages: {
@@ -19,18 +28,22 @@ SimpleSchema.setDefaultMessages({
1928
}
2029
});
2130
```
22-
- Create your Files Collection (See [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files))
23-
```javascript
31+
32+
4. Create your Files Collection (See [`ostrio:files`](https://github.com/VeliovGroup/Meteor-Files))
33+
34+
```js
35+
import { Meteor } from 'meteor/meteor';
36+
import { FilesCollection } from 'meteor/ostrio:files';
37+
2438
const Images = new FilesCollection({
2539
collectionName: 'Images',
2640
allowClientCode: true, // Required to let you remove uploaded file
2741
onBeforeUpload(file) {
2842
// Allow upload files under 10MB, and only in png/jpg/jpeg formats
2943
if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.ext)) {
3044
return true;
31-
} else {
32-
return 'Please upload image, with size equal or less than 10MB';
3345
}
46+
return 'Please upload image, with size equal or less than 10MB';
3447
}
3548
});
3649

@@ -44,16 +57,18 @@ if (Meteor.isServer) {
4457
});
4558
}
4659
```
60+
4761
__Note:__ If you don't use Mongo Collection instances (`dburles:mongo-collection-instances`), then the `Images` variable must be attached to *Global* scope. And has same name (*case-sensitive*) as `collectionName` option passed into `FilesCollection#insert({collectionName: 'Images'})` method, `Images` in our case.
4862

4963
To start using `dburles:mongo-collection-instances` simply install it:
64+
5065
```shell
5166
meteor add dburles:mongo-collection-instances
5267
```
5368

69+
5. Define your schema and set the `autoform` property like in the example below
5470

55-
- Define your schema and set the `autoform` property like in the example below
56-
```javascript
71+
```js
5772
Schemas = {};
5873
Posts = new Meteor.Collection('posts');
5974
Schemas.Posts = new SimpleSchema({
@@ -89,9 +104,9 @@ The `collection` property must be the same as name of your *FilesCollection* (*c
89104

90105
Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
91106

92-
##### Insert mode:
107+
## Insert mode:
93108

94-
```html
109+
```handlebars
95110
{{> quickForm id="postsInsertForm" collection="Posts" type="insert"}}
96111
<!-- OR -->
97112
{{#autoForm id="postsInsertForm" collection="Posts" type="insert"}}
@@ -109,9 +124,9 @@ Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
109124
{{/autoForm}}
110125
```
111126

112-
##### Update mode:
127+
## Update mode:
113128

114-
```html
129+
```handlebars
115130
{{#if Template.subscriptionsReady }}
116131
{{> quickForm id="postsUpdateForm" collection="Posts" type="update" doc=getPost}}
117132
{{/if}}
@@ -127,13 +142,13 @@ Generate the form with `{{> quickform}}` or `{{#autoform}}` e.g.:
127142

128143
Autoform should be wrapped in `{{#if Template.subscriptionsReady }}` which makes sure that template level subscription is ready. Without it the picture preview won't be shown. You can see update mode example [here](https://github.com/VeliovGroup/meteor-autoform-file/issues/9).
129144

130-
### Accept configuration
145+
## Accept configuration
131146

132-
##### Usage
147+
### Usage
133148

134149
You can configure the file selector, to only allow certain types of files using the `accept` property:
135150

136-
```javascript
151+
```js
137152
Schemas.Posts = new SimpleSchema({
138153
title: {
139154
type: String,
@@ -156,10 +171,13 @@ The accept values works makes use of the native HTML `accept` attribute. Read mo
156171

157172
Please read the section on **custom upload templates** and how to integrate configs like *accept* to your custom template.
158173

159-
### Multiple images // not fully supported yet
174+
## Multiple images
175+
176+
Multiple images — __not fully supported yet__
177+
160178
If you want to use an array of images inside you have to define the autoform on on the [schema key](https://github.com/aldeed/meteor-simple-schema#schema-keys)
161179

162-
```javascript
180+
```js
163181
Schemas.Posts = new SimpleSchema({
164182
title: {
165183
type: String,
@@ -169,7 +187,7 @@ Schemas.Posts = new SimpleSchema({
169187
type: Array,
170188
label: 'Choose file' // <- Optional
171189
},
172-
"pictures.$": {
190+
'pictures.$': {
173191
type: String,
174192
autoform: {
175193
afFieldInput: {
@@ -178,36 +196,37 @@ Schemas.Posts = new SimpleSchema({
178196
}
179197
}
180198
}
181-
})
199+
});
182200
```
183201

184-
### Custom file preview
202+
## Custom file preview
185203

186204
Your custom file preview template data context will be:
187205

188206
- *file* - fileObj instance
189207

190-
```javascript
191-
picture: {
192-
type: String,
193-
autoform: {
194-
afFieldInput: {
195-
type: 'fileUpload',
196-
collection: 'Images',
197-
previewTemplate: 'myFilePreview'
208+
```js
209+
({
210+
picture: {
211+
type: String,
212+
autoform: {
213+
afFieldInput: {
214+
type: 'fileUpload',
215+
collection: 'Images',
216+
previewTemplate: 'myFilePreview'
217+
}
198218
}
199219
}
200-
}
220+
});
201221
```
202222

203-
```html
223+
```handlebars
204224
<template name="myFileUpload">
205225
<a href="{{file.link}}">{{file.original.name}}</a>
206226
</template>
207227
```
208228

209-
210-
### Custom upload template
229+
## Custom upload template
211230

212231
Your custom file upload template data context will be:
213232

@@ -217,20 +236,22 @@ Your custom file upload template data context will be:
217236
- *config* an object containing several configs to upload behavior, such as `accept`
218237
- Other fields from [`FileUpload` instance](https://github.com/VeliovGroup/Meteor-Files/wiki/Insert-(Upload)#fileupload-methods-and-properties)
219238

220-
```javascript
221-
picture: {
222-
type: String,
223-
autoform: {
224-
afFieldInput: {
225-
type: 'fileUpload',
226-
collection: 'Images',
227-
uploadTemplate: 'myFileUpload'
239+
```js
240+
({
241+
picture: {
242+
type: String,
243+
autoform: {
244+
afFieldInput: {
245+
type: 'fileUpload',
246+
collection: 'Images',
247+
uploadTemplate: 'myFileUpload'
248+
}
228249
}
229250
}
230-
}
251+
});
231252
```
232253

233-
```html
254+
```handlebars
234255
<template name="myFileUpload">
235256
{{#with progress}}
236257
<!-- if there is a progress present, we can use it to determine the upload progress -->
@@ -246,15 +267,14 @@ picture: {
246267
</template>
247268
```
248269

249-
##### Note on upload configs:
270+
### Note on upload configs:
250271

251272
If you pass any config, like `accept` your upload data won't be falsey anymore,
252273
so you should update your template to the example above and check for each of the given properties.
253274
This is however backwards-compatible and will not break your older templates if you don't need any of the upload config
254275
introduced in > 2.1.4 releases.
255276

256-
Support this project:
257-
======
258-
This project wouldn't be possible without [ostr.io](https://ostr.io).
277+
## Support this project:
259278

260-
Using [ostr.io](https://ostr.io) you are not only [protecting domain names](https://ostr.io/info/domain-names-protection), [monitoring websites and servers](https://ostr.io/info/monitoring), using [Prerendering for better SEO](https://ostr.io/info/prerendering) of your JavaScript website, but support our Open Source activity, and great packages like this one could be available for free.
279+
- [Become a patron](https://www.patreon.com/bePatron?u=20396046) — support my open source contributions with monthly donation
280+
- Use [ostr.io](https://ostr.io)[Monitoring](https://snmp-monitoring.com), [Analytics](https://ostr.io/info/web-analytics), [WebSec](https://domain-protection.info), [Web-CRON](https://web-cron.info) and [Pre-rendering](https://prerendering.com) for a website

package.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ Package.describe({
22
name: 'ostrio:autoform-files',
33
summary: 'File upload for AutoForm using ostrio:files',
44
description: 'File upload for AutoForm using ostrio:files',
5-
version: '2.1.4',
5+
version: '2.2.0',
66
git: 'https://github.com/VeliovGroup/meteor-autoform-file.git'
77
});
88

9-
Package.onUse(function(api) {
9+
Package.onUse((api) => {
1010
api.versionsFrom('[email protected]');
1111

1212
api.use([
@@ -15,9 +15,9 @@ Package.onUse(function(api) {
1515
'underscore',
1616
'mongo',
1717
'reactive-var',
18-
'templating@1.3.2',
18+
'templating',
1919
20-
'ostrio:files@1.10.2'
20+
'ostrio:files@1.11.2'
2121
]);
2222

2323
api.addFiles([

0 commit comments

Comments
 (0)