mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
UX: Allow users to see filename in image-uploader component. (#7022)
https://meta.discourse.org/t/downsides-of-the-new-logo-ui-in-site-settings/102247/23?u=tgxworld
This commit is contained in:
parent
fa35b555b7
commit
31ffa5f64e
6 changed files with 99 additions and 4 deletions
|
@ -3,6 +3,7 @@ import UploadMixin from "discourse/mixins/upload";
|
||||||
|
|
||||||
export default Ember.Component.extend(UploadMixin, {
|
export default Ember.Component.extend(UploadMixin, {
|
||||||
classNames: ["image-uploader"],
|
classNames: ["image-uploader"],
|
||||||
|
infoHidden: true,
|
||||||
|
|
||||||
@computed("imageUrl")
|
@computed("imageUrl")
|
||||||
backgroundStyle(imageUrl) {
|
backgroundStyle(imageUrl) {
|
||||||
|
@ -13,6 +14,17 @@ export default Ember.Component.extend(UploadMixin, {
|
||||||
return `background-image: url(${imageUrl})`.htmlSafe();
|
return `background-image: url(${imageUrl})`.htmlSafe();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("imageUrl")
|
||||||
|
imageBaseName(imageUrl) {
|
||||||
|
if (Ember.isEmpty(imageUrl)) return;
|
||||||
|
return imageUrl.split("/").slice(-1)[0];
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed("infoHidden", "imageBaseName")
|
||||||
|
showInfo(infoHidden, imageBaseName) {
|
||||||
|
return !infoHidden && imageBaseName;
|
||||||
|
},
|
||||||
|
|
||||||
@computed("backgroundStyle")
|
@computed("backgroundStyle")
|
||||||
hasBackgroundStyle(backgroundStyle) {
|
hasBackgroundStyle(backgroundStyle) {
|
||||||
return !Ember.isEmpty(backgroundStyle.string);
|
return !Ember.isEmpty(backgroundStyle.string);
|
||||||
|
@ -31,6 +43,10 @@ export default Ember.Component.extend(UploadMixin, {
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
toggleInfo() {
|
||||||
|
this.toggleProperty("infoHidden");
|
||||||
|
},
|
||||||
|
|
||||||
trash() {
|
trash() {
|
||||||
this.setProperties({ imageUrl: null, imageId: null });
|
this.setProperties({ imageUrl: null, imageId: null });
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,23 @@
|
||||||
{{d-icon "far-image"}}
|
{{d-icon "far-image"}}
|
||||||
<input class="hidden-upload-field" disabled={{uploading}} type="file" accept="image/*" />
|
<input class="hidden-upload-field" disabled={{uploading}} type="file" accept="image/*" />
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{{#if hasBackgroundStyle}}
|
{{#if hasBackgroundStyle}}
|
||||||
<button {{action "trash"}} class="btn btn-danger pad-left no-text">{{d-icon "far-trash-alt"}}</button>
|
<button {{action "trash"}} class="btn btn-danger pad-left no-text">{{d-icon "far-trash-alt"}}</button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if imageBaseName}}
|
||||||
|
{{d-button icon="info-circle" class="btn image-uploader-info-btn no-text"
|
||||||
|
title="upload_selector.filename"
|
||||||
|
action=(action "toggleInfo")}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<span class="btn {{unless uploading 'hidden'}}">{{i18n 'upload_selector.uploading'}} {{uploadProgress}}%</span>
|
<span class="btn {{unless uploading 'hidden'}}">{{i18n 'upload_selector.uploading'}} {{uploadProgress}}%</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#if showInfo}}
|
||||||
|
<div class="image-uploader-info">
|
||||||
|
<a href={{imageUrl}} target="_blank">{{imageBaseName}}</a>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,53 @@
|
||||||
.uploaded-image-preview {
|
.uploaded-image-preview {
|
||||||
background: $primary center;
|
background: $primary center;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.image-uploader-info {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
background: $primary;
|
||||||
|
text-align: center;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
opacity: 0.6;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: $secondary;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-upload-controls {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-uploader-info-btn {
|
||||||
|
background: none;
|
||||||
|
margin-right: 0;
|
||||||
|
margin-left: auto;
|
||||||
|
|
||||||
|
.d-icon {
|
||||||
|
color: $primary-low;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: none;
|
||||||
|
|
||||||
|
.d-icon {
|
||||||
|
color: $primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.image-uploader.no-repeat {
|
.image-uploader.no-repeat {
|
||||||
|
|
|
@ -332,8 +332,5 @@
|
||||||
.image-upload-controls {
|
.image-upload-controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
.btn {
|
|
||||||
margin-right: 5px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1569,6 +1569,7 @@ en:
|
||||||
select_file: "Select File"
|
select_file: "Select File"
|
||||||
image_link: "link your image will point to"
|
image_link: "link your image will point to"
|
||||||
default_image_alt_text: image
|
default_image_alt_text: image
|
||||||
|
filename: "Filename"
|
||||||
|
|
||||||
search:
|
search:
|
||||||
sort_by: "Sort by"
|
sort_by: "Sort by"
|
||||||
|
|
|
@ -4,7 +4,7 @@ moduleForComponent("image-uploader", { integration: true });
|
||||||
componentTest("with image", {
|
componentTest("with image", {
|
||||||
template: "{{image-uploader imageUrl='/some/upload.png'}}",
|
template: "{{image-uploader imageUrl='/some/upload.png'}}",
|
||||||
|
|
||||||
test(assert) {
|
async test(assert) {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
this.$(".d-icon-far-image").length,
|
this.$(".d-icon-far-image").length,
|
||||||
1,
|
1,
|
||||||
|
@ -16,6 +16,20 @@ componentTest("with image", {
|
||||||
1,
|
1,
|
||||||
"it displays the trash icon"
|
"it displays the trash icon"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
this.$(".image-uploader-info").length,
|
||||||
|
0,
|
||||||
|
"it does not display the image info"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".image-uploader-info-btn");
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
this.$(".image-uploader-info").length,
|
||||||
|
1,
|
||||||
|
"it displays the image info"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,5 +48,11 @@ componentTest("without image", {
|
||||||
0,
|
0,
|
||||||
"it does not display trash icon"
|
"it does not display trash icon"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
this.$(".image-uploader-info-btn").length,
|
||||||
|
0,
|
||||||
|
"it does not display the image info button toggle"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue