-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/code improvements n best practices #87
Feature/code improvements n best practices #87
Conversation
README.md
Outdated
@@ -62,27 +62,25 @@ you can use `[headers]` directive like this. | |||
|
|||
#### Callbacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're here - though it's not strictly incorrect, I would rename this to either "Outputs" or "Events".
README.md
Outdated
@@ -62,27 +62,25 @@ you can use `[headers]` directive like this. | |||
|
|||
#### Callbacks | |||
|
|||
`(onFileUploadFinish)="imageUploaded($event)"`. If `[url]` is specified this event is fired when component gets a response from the server, also in this case event has field `serverResponse` which contains the status code and response from the server `{status, response}`. If `[url]` is not specified it's fired immediately after an image(s) dropped into file-drop zone of choosed in file browser. So what you can do, is not specify `[url]` to handle upload yourself, for exapmple send the image into firebase storage. To get file use `event.file`. | |||
`(uploadFinish)="imageUploaded($event)"`. If `[url]` is specified this event is fired when component gets a response from the server, also in this case event has field `serverResponse` which contains the status code and response from the server `{status, response}`. If `[url]` is not specified it's fired immediately after an image(s) dropped into file-drop zone of choosed in file browser. So what you can do, is not specify `[url]` to handle upload yourself, for exapmple send the image into firebase storage. To get file use `event.file`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention I think we want to go with past tense here: uploadFinished
- the event has already occurred.
The example function here should also by convention be suggested as onUploadFinished($event)
All in all:
(uploadFinished)="onUploadFinished($event)"
README.md
Outdated
|
||
`(onRemove)="imageRemoved($event)"` - this event is fired when remove button was clicked and the image preview was removed. *Note that this library doesn't handle deletion from server so you should do it yourself*. Event passed as the argument is the exact same object that was passed to the `(imageUploaded)` callback when image was added so you can access `serverResponse` to get a key to delete your image from server. | ||
`(remove)="imageRemoved($event)"` - this event is fired when remove or clear button was clicked and the image preview was removed. *Note that this library doesn't handle deletion from server so you should do it yourself*. Event passed as the argument is the exact same object that was passed to the `(imageUploaded)` callback when image was added so you can access `serverResponse` to get a key to delete your image from server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above but (removed)="onRemoved($event)"
README.md
Outdated
|
||
`(isPending)="disableSendButton($event)"` - this event is fired when pending state was changed. Event is just a boolean that represents the pending state. Pending state is `true` when and only when component avaits a response from the server, and `false` othervise. You can use it, for example, to disable send button in your form until all images are uploaded. | ||
`(uploadStateChange)="disableSendButton($event)"` - this event is fired when image upload state was changed. Event is just a boolean that represents the uploading state. Image upload state is `true` when and only when component awaits the response from the server, and `false` otherwise. You can use it, for example, to disable send button in your form until all images are uploaded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above but (uploadStateChanged)="onUploadStateChanged($event)"
src/file-drop.directive.ts
Outdated
|
||
@Directive({ | ||
selector: '[fileDrop]' | ||
}) | ||
export class FileDropDirective { | ||
@Input() accept: string[]; | ||
@Output() isFileOver: EventEmitter<boolean> = new EventEmitter<boolean>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again for conventions I would go with fileOver
src/image-upload/image.service.ts
Outdated
|
||
constructor(private http: Http) { } | ||
|
||
public postImage(url: string, image: File, headers?: any[], partName: string = 'image', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Headers shouldn't be any.
export interface Header {
[name: string]: any;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let it be as Header
itself.
src/image-upload/image.service.ts
Outdated
let key = Object.keys(header)[0]; | ||
options.headers.append(key, header[key]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we can probably just get rid of lines 22 - 28 and replace with options.headers = headers
- if that doesn't work (i'm unsure) then options.headers = new Headers(headers)
should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this options.headers = headers
is not working since Headers
class has a few methods in it so continue with options.headers = new Headers()
but again need to set header in expected format otherwise it goes like this 0:[object Object]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the Headers
constructor accepts { [name: string]: any }[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I've been poking around in angular - it expects either a Headers
object or a dictionary, which is why it wasn't happy with the array.
I suggest we just use this signature wherever we need headers, and get rid of the interface (sorry, I know I asked you to do it):
Headers|{[name: string]: any}
Then the following will work:
myFunc(headers: Headers|{[name: string]: any}) {
const options: any = {};
options.headers = new Headers(headers);
}
The user can pass this in by instantiating their own Headers
object or something like:
const headers: {[name: string]: any} = {
potato: 'cheese',
cheese: 'potato'
};
@Input() buttonCaption: string = 'Select Images'; | ||
@Input() dropBoxMessage: string = 'Drop your images here!'; | ||
@Input() fileTooLargeMessage: string; | ||
@Input() headers: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be any - details in image.service.ts comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, i will set it as Header
.
Note to merger: Squash into a conventional commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remarks as UncleDave's
Thank you for the changes so far, that all looks good - just the Headers issue to address. |
src/image-upload/image.service.ts
Outdated
let key = Object.keys(header)[0]; | ||
options.headers.append(key, header[key]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I've been poking around in angular - it expects either a Headers
object or a dictionary, which is why it wasn't happy with the array.
I suggest we just use this signature wherever we need headers, and get rid of the interface (sorry, I know I asked you to do it):
Headers|{[name: string]: any}
Then the following will work:
myFunc(headers: Headers|{[name: string]: any}) {
const options: any = {};
options.headers = new Headers(headers);
}
The user can pass this in by instantiating their own Headers
object or something like:
const headers: {[name: string]: any} = {
potato: 'cheese',
cheese: 'potato'
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last bit of header tidy!
Need to check with proposed changes. Since |
Changing the format from array to object |
|
Alrighty then! 😆 |
@UncleDave, demo source is updated, need to generate new bundle. |
Okay I'm going to merge this but I still have some changes I'd like to make to headers, don't get offended 😄 |
That's fine @UncleDave 😄 |
#75 implemented
fix: Updated header format
refactor: Updated
@Output
label, import statements, members and methods sequence are alphabetized as per style guide.fix: Moved service file into feature folder along with component
docs: Updated readme