DEV: Update emoji-uploader uppy usage (#29340)
Also moves this component to the admin bundle. It is only used in the admin panel, and has dependencies on admin-specific i18n strings.
This commit is contained in:
parent
f79dd5c8b5
commit
856182c7c6
|
@ -33,8 +33,9 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<input
|
<input
|
||||||
|
{{did-insert this.uppyUpload.setup}}
|
||||||
class="hidden-upload-field"
|
class="hidden-upload-field"
|
||||||
disabled={{this.uploading}}
|
disabled={{this.uppyUpload.uploading}}
|
||||||
type="file"
|
type="file"
|
||||||
multiple="true"
|
multiple="true"
|
||||||
accept=".png,.gif"
|
accept=".png,.gif"
|
||||||
|
@ -43,7 +44,7 @@
|
||||||
@translatedLabel={{this.buttonLabel}}
|
@translatedLabel={{this.buttonLabel}}
|
||||||
@icon="plus"
|
@icon="plus"
|
||||||
@action={{this.chooseFiles}}
|
@action={{this.chooseFiles}}
|
||||||
@disabled={{this.uploading}}
|
@disabled={{this.uppyUpload.uploading}}
|
||||||
class="btn-primary"
|
class="btn-primary"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
|
@ -1,16 +1,45 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { notEmpty } from "@ember/object/computed";
|
import { notEmpty } from "@ember/object/computed";
|
||||||
|
import { getOwner } from "@ember/owner";
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
import UppyUploadMixin from "discourse/mixins/uppy-upload";
|
import UppyUpload from "discourse/lib/uppy/uppy-upload";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
const DEFAULT_GROUP = "default";
|
const DEFAULT_GROUP = "default";
|
||||||
|
|
||||||
export default class EmojiUploader extends Component.extend(UppyUploadMixin) {
|
export default class EmojiUploader extends Component {
|
||||||
type = "emoji";
|
uppyUpload = new UppyUpload(getOwner(this), {
|
||||||
uploadUrl = "/admin/customize/emojis";
|
id: "emoji-uploader",
|
||||||
|
type: "emoji",
|
||||||
|
uploadUrl: "/admin/customize/emojis",
|
||||||
|
preventDirectS3Uploads: true,
|
||||||
|
validateUploadedFilesOptions: {
|
||||||
|
imagesOnly: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
perFileData: () => {
|
||||||
|
const payload = {};
|
||||||
|
|
||||||
|
if (!isEmpty(this.name)) {
|
||||||
|
payload.name = this.name;
|
||||||
|
|
||||||
|
// if uploading multiple files, we can't use the name for every emoji
|
||||||
|
this.set("name", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) {
|
||||||
|
payload.group = this.group;
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
},
|
||||||
|
|
||||||
|
uploadDone: (upload) => {
|
||||||
|
this.done(upload, this.group);
|
||||||
|
this.set("name", null);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
@notEmpty("name") hasName;
|
@notEmpty("name") hasName;
|
||||||
@notEmpty("group") hasGroup;
|
@notEmpty("group") hasGroup;
|
||||||
|
@ -19,7 +48,6 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) {
|
||||||
emojiGroups = null;
|
emojiGroups = null;
|
||||||
newEmojiGroups = null;
|
newEmojiGroups = null;
|
||||||
tagName = null;
|
tagName = null;
|
||||||
preventDirectS3Uploads = true;
|
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
super.didReceiveAttrs(...arguments);
|
super.didReceiveAttrs(...arguments);
|
||||||
|
@ -38,38 +66,12 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_perFileData() {
|
|
||||||
const payload = {};
|
|
||||||
|
|
||||||
if (!isEmpty(this.name)) {
|
|
||||||
payload.name = this.name;
|
|
||||||
|
|
||||||
// if uploading multiple files, we can't use the name for every emoji
|
|
||||||
this.set("name", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isEmpty(this.group) && this.group !== DEFAULT_GROUP) {
|
|
||||||
payload.group = this.group;
|
|
||||||
}
|
|
||||||
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
validateUploadedFilesOptions() {
|
|
||||||
return { imagesOnly: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadDone(upload) {
|
|
||||||
this.done(upload, this.group);
|
|
||||||
this.set("name", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
chooseFiles() {
|
chooseFiles() {
|
||||||
this.fileInputEl.click();
|
this.uppyUpload.openPicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed("uploading", "uploadProgress")
|
@discourseComputed("uppyUpload.uploading", "uppyUpload.uploadProgress")
|
||||||
buttonLabel(uploading, uploadProgress) {
|
buttonLabel(uploading, uploadProgress) {
|
||||||
if (uploading) {
|
if (uploading) {
|
||||||
return `${I18n.t("admin.emoji.uploading")} ${uploadProgress}%`;
|
return `${I18n.t("admin.emoji.uploading")} ${uploadProgress}%`;
|
||||||
|
@ -78,7 +80,7 @@ export default class EmojiUploader extends Component.extend(UppyUploadMixin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@discourseComputed("uploading")
|
@discourseComputed("uppyUpload.uploading")
|
||||||
buttonIcon(uploading) {
|
buttonIcon(uploading) {
|
||||||
if (uploading) {
|
if (uploading) {
|
||||||
return "spinner";
|
return "spinner";
|
|
@ -15,7 +15,6 @@
|
||||||
<EmojiUploader
|
<EmojiUploader
|
||||||
@emojiGroups={{this.emojiGroups}}
|
@emojiGroups={{this.emojiGroups}}
|
||||||
@done={{action "emojiUploaded"}}
|
@done={{action "emojiUploaded"}}
|
||||||
@id="emoji-uploader"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
Loading…
Reference in New Issue