From 9403ad00d85c314ae79961e2651e3858c6afeefa Mon Sep 17 00:00:00 2001 From: 1arp Date: Sun, 13 Dec 2020 22:35:07 +0530 Subject: [PATCH 1/4] added option to upload files when asking a doubt --- app/models/doubt.js | 3 ++- .../components/file-upload-minio/component.js | 9 ++++++++ .../player-ask-doubt-modal/component.js | 13 ++++++++++++ .../player-ask-doubt-modal/template.hbs | 21 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/models/doubt.js b/app/models/doubt.js index 2e053baa1..65e66d03a 100644 --- a/app/models/doubt.js +++ b/app/models/doubt.js @@ -12,5 +12,6 @@ export default DS.Model.extend({ comments: DS.hasMany('comment'), feedbacks: DS.hasMany('doubt-feedback'), resolvedById: DS.attr(), - createdAt: DS.attr('date') + createdAt: DS.attr('date'), + file_link: DS.attr() }) \ No newline at end of file diff --git a/app/pods/components/file-upload-minio/component.js b/app/pods/components/file-upload-minio/component.js index b4bdb357d..7d2e9f3c6 100644 --- a/app/pods/components/file-upload-minio/component.js +++ b/app/pods/components/file-upload-minio/component.js @@ -33,6 +33,15 @@ export default FileField.extend({ } }) + if(this.maxSize){ + if(files[0].size/1024 > this.maxSize){ + alert("file is way too large") + this.enableUpload(false) + }else{ + this.enableUpload(true) + } + } + if(this.onProgress) { uploader.on('progress', e => { this.onProgress(e) diff --git a/app/pods/components/player/player-ask-doubt-modal/component.js b/app/pods/components/player/player-ask-doubt-modal/component.js index 3ffd5cee8..ea495e8ec 100644 --- a/app/pods/components/player/player-ask-doubt-modal/component.js +++ b/app/pods/components/player/player-ask-doubt-modal/component.js @@ -18,4 +18,17 @@ export default class AskDoubtModal extends Component { if (!this.doubt.isNew) this.onClose() } + canUpload = true; + + @action + uploaded(e) { + this.set("doubt.file_link",e) + this.set('triggerUpload', false) + } + + @action + uploadFailed () { + alert(`Can't Upload file.`) + this.set('triggerUpload', false) + } } diff --git a/app/pods/components/player/player-ask-doubt-modal/template.hbs b/app/pods/components/player/player-ask-doubt-modal/template.hbs index 0615bdba6..1ce24f2d4 100644 --- a/app/pods/components/player/player-ask-doubt-modal/template.hbs +++ b/app/pods/components/player/player-ask-doubt-modal/template.hbs @@ -32,6 +32,27 @@ @text={{doubt.body}} />
Describe your problem thoroughly. You can drag and drop images in your description.
+
+ {{#if doubt.file_link}} + + Download File + + + {{yield}} + {{else}} +
+ + Upload File: + + {{file-upload-minio triggerUpload=triggerUpload onComplete=(action 'uploaded') onError=(action 'uploadFailed') enableUpload=(action (mut this.canUpload)) maxSize=5120 }} +
+ + + + {{/if}} +
{{yield}} {{else}} From 2b19d9e892dccb064ee61a82f5112593889227a2 Mon Sep 17 00:00:00 2001 From: 1arp Date: Sun, 20 Dec 2020 05:07:16 +0530 Subject: [PATCH 3/4] added deafult size limit to file-upload-minio --- app/pods/components/file-upload-minio/component.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/pods/components/file-upload-minio/component.js b/app/pods/components/file-upload-minio/component.js index 7d2e9f3c6..a20277d25 100644 --- a/app/pods/components/file-upload-minio/component.js +++ b/app/pods/components/file-upload-minio/component.js @@ -7,6 +7,7 @@ import Uploader from 'ember-uploader/uploaders/uploader'; export default FileField.extend({ uploader: null, files: null, + maxSize: 10240, session: service(), didUpdateAttrs () { this._super(...arguments) @@ -33,13 +34,11 @@ export default FileField.extend({ } }) - if(this.maxSize){ - if(files[0].size/1024 > this.maxSize){ - alert("file is way too large") - this.enableUpload(false) - }else{ - this.enableUpload(true) - } + if(files[0].size/1024 > this.maxSize){ + alert("file is way too large") + this.enableUpload(false) + }else{ + this.enableUpload(true) } if(this.onProgress) { From b1ae99f44ce9161dd12e104ff4507ffdf5709792 Mon Sep 17 00:00:00 2001 From: 1arp Date: Thu, 24 Dec 2020 10:52:08 +0530 Subject: [PATCH 4/4] space after comma --- app/pods/components/player/player-ask-doubt-modal/component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pods/components/player/player-ask-doubt-modal/component.js b/app/pods/components/player/player-ask-doubt-modal/component.js index 9ba408631..19579b1b3 100644 --- a/app/pods/components/player/player-ask-doubt-modal/component.js +++ b/app/pods/components/player/player-ask-doubt-modal/component.js @@ -22,7 +22,7 @@ export default class AskDoubtModal extends Component { @action uploaded(e) { - this.set("doubt.file_link",e) + this.set("doubt.file_link", e) this.set('triggerUpload', false) }