DEV: Update uppy-image-uploader uppy mixin usage (#29366)
This commit is contained in:
parent
7acf9e6caf
commit
adef7081a2
|
@ -12,6 +12,7 @@
|
||||||
>
|
>
|
||||||
{{d-icon "far-image"}}
|
{{d-icon "far-image"}}
|
||||||
<PickFilesButton
|
<PickFilesButton
|
||||||
|
@registerFileInput={{this.uppyUpload.setup}}
|
||||||
@fileInputDisabled={{this.disabled}}
|
@fileInputDisabled={{this.disabled}}
|
||||||
@fileInputClass="hidden-upload-field"
|
@fileInputClass="hidden-upload-field"
|
||||||
@acceptedFormatsOverride="image/*"
|
@acceptedFormatsOverride="image/*"
|
||||||
|
@ -34,11 +35,11 @@
|
||||||
/>
|
/>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<span class="btn {{unless this.uploading 'hidden'}}">{{i18n
|
<span class="btn {{unless this.uppyUpload.uploading 'hidden'}}">{{i18n
|
||||||
"upload_selector.uploading"
|
"upload_selector.uploading"
|
||||||
}}
|
}}
|
||||||
{{this.uploadProgress}}%</span>
|
{{this.uppyUpload.uploadProgress}}%</span>
|
||||||
<span class="btn {{unless this.processing 'hidden'}}">{{i18n
|
<span class="btn {{unless this.uppyUpload.processing 'hidden'}}">{{i18n
|
||||||
"upload_selector.processing"
|
"upload_selector.processing"
|
||||||
}}</span>
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { or } from "@ember/object/computed";
|
import { or } from "@ember/object/computed";
|
||||||
|
import { getOwner } from "@ember/owner";
|
||||||
import { next } from "@ember/runloop";
|
import { next } from "@ember/runloop";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
|
@ -12,16 +13,47 @@ import lightbox, {
|
||||||
setupLightboxes,
|
setupLightboxes,
|
||||||
} from "discourse/lib/lightbox";
|
} from "discourse/lib/lightbox";
|
||||||
import { authorizesOneOrMoreExtensions } from "discourse/lib/uploads";
|
import { authorizesOneOrMoreExtensions } from "discourse/lib/uploads";
|
||||||
import UppyUploadMixin from "discourse/mixins/uppy-upload";
|
import UppyUpload from "discourse/lib/uppy/uppy-upload";
|
||||||
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
@classNames("image-uploader")
|
@classNames("image-uploader")
|
||||||
export default class UppyImageUploader extends Component.extend(
|
export default class UppyImageUploader extends Component {
|
||||||
UppyUploadMixin
|
@or("notAllowed", "uppyUpload.uploading", "uppyUpload.processing") disabled;
|
||||||
) {
|
|
||||||
@or("notAllowed", "uploading", "processing") disabled;
|
uppyUpload = null;
|
||||||
|
|
||||||
|
@on("init")
|
||||||
|
setupUppyUpload() {
|
||||||
|
// The uppyUpload configuration depends on arguments. In classic components like
|
||||||
|
// this one, the arguments are not available during field initialization, so we have to
|
||||||
|
// defer until init(). When this component is glimmer-ified in future, this can be turned
|
||||||
|
// into a simple field initializer.
|
||||||
|
this.uppyUpload = new UppyUpload(getOwner(this), {
|
||||||
|
id: this.id,
|
||||||
|
type: this.type,
|
||||||
|
additionalParams: this.additionalParams,
|
||||||
|
validateUploadedFilesOptions: { imagesOnly: true },
|
||||||
|
uploadDone: (upload) => {
|
||||||
|
this.setProperties({
|
||||||
|
imageFilesize: upload.human_filesize,
|
||||||
|
imageFilename: upload.original_filename,
|
||||||
|
imageWidth: upload.width,
|
||||||
|
imageHeight: upload.height,
|
||||||
|
});
|
||||||
|
|
||||||
|
// the value of the property used for imageUrl should be set
|
||||||
|
// in this callback. this should be done in cases where imageUrl
|
||||||
|
// is bound to a computed property of the parent component.
|
||||||
|
if (this.onUploadDone) {
|
||||||
|
this.onUploadDone(upload);
|
||||||
|
} else {
|
||||||
|
this.set("imageUrl", upload.url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@discourseComputed("siteSettings.enable_experimental_lightbox")
|
@discourseComputed("siteSettings.enable_experimental_lightbox")
|
||||||
experimentalLightboxEnabled(experimentalLightboxEnabled) {
|
experimentalLightboxEnabled(experimentalLightboxEnabled) {
|
||||||
|
@ -81,28 +113,6 @@ export default class UppyImageUploader extends Component.extend(
|
||||||
return imageUrl.split("/").slice(-1)[0];
|
return imageUrl.split("/").slice(-1)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
validateUploadedFilesOptions() {
|
|
||||||
return { imagesOnly: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
uploadDone(upload) {
|
|
||||||
this.setProperties({
|
|
||||||
imageFilesize: upload.human_filesize,
|
|
||||||
imageFilename: upload.original_filename,
|
|
||||||
imageWidth: upload.width,
|
|
||||||
imageHeight: upload.height,
|
|
||||||
});
|
|
||||||
|
|
||||||
// the value of the property used for imageUrl should be set
|
|
||||||
// in this callback. this should be done in cases where imageUrl
|
|
||||||
// is bound to a computed property of the parent component.
|
|
||||||
if (this.onUploadDone) {
|
|
||||||
this.onUploadDone(upload);
|
|
||||||
} else {
|
|
||||||
this.set("imageUrl", upload.url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@on("didRender")
|
@on("didRender")
|
||||||
_applyLightbox() {
|
_applyLightbox() {
|
||||||
if (this.experimentalLightboxEnabled) {
|
if (this.experimentalLightboxEnabled) {
|
||||||
|
|
Loading…
Reference in New Issue