-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV: Modernise csv-uploader component
- remove uppy mixin - native class - glimmer component - gjs file format
- Loading branch information
1 parent
b7858ef
commit a7d6841
Showing
4 changed files
with
66 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Component from "@glimmer/component"; | ||
import { getOwner } from "@ember/owner"; | ||
import didInsert from "@ember/render-modifiers/modifiers/did-insert"; | ||
import { inject as service } from "@ember/service"; | ||
import { or } from "truth-helpers"; | ||
import UppyUpload from "discourse/lib/uppy/uppy-upload"; | ||
import icon from "discourse-common/helpers/d-icon"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
|
||
export default class CsvUploader extends Component { | ||
@service dialog; | ||
|
||
uppyUpload = new UppyUpload(getOwner(this), { | ||
type: "csv", | ||
id: "discourse-post-event-csv-uploader", | ||
autoStartUploads: false, | ||
uploadUrl: this.args.uploadUrl, | ||
uppyReady: () => { | ||
this.uppyUpload.uppyWrapper.uppyInstance.on("file-added", () => { | ||
this.dialog.confirm({ | ||
message: i18n(`${this.args.i18nPrefix}.confirmation_message`), | ||
didConfirm: () => this.uppyUpload.startUpload(), | ||
didCancel: () => this.uppyUpload.reset(), | ||
}); | ||
}); | ||
}, | ||
uploadDone: () => { | ||
this.dialog.alert(i18n(`${this.args.i18nPrefix}.success`)); | ||
}, | ||
validateUploadedFilesOptions: { | ||
csvOnly: true, | ||
}, | ||
}); | ||
|
||
get uploadButtonText() { | ||
return this.uppyUpload.uploading | ||
? i18n("uploading") | ||
: i18n(`${this.args.i18nPrefix}.text`); | ||
} | ||
|
||
get uploadButtonDisabled() { | ||
// https://github.com/emberjs/ember.js/issues/10976#issuecomment-132417731 | ||
return this.uppyUpload.uploading || this.uppyUpload.processing | ||
? true | ||
: null; | ||
} | ||
|
||
<template> | ||
<span> | ||
<label class="btn" disabled={{this.uploadButtonDisabled}}> | ||
{{icon "upload"}} {{this.uploadButtonText}} | ||
<input | ||
{{didInsert this.uppyUpload.setup}} | ||
class="hidden-upload-field" | ||
disabled={{this.uppyUpload.uploading}} | ||
type="file" | ||
accept=".csv" | ||
/> | ||
</label> | ||
{{#if (or this.uppyUpload.uploading this.uppyUpload.processing)}} | ||
<span>{{i18n "upload_selector.uploading"}} | ||
{{this.uppyUpload.uploadProgress}}%</span> | ||
{{/if}} | ||
</span> | ||
</template> | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters