finish up attachment setting (right now only for admin section only)

This commit is contained in:
Henry Jameson 2023-04-24 21:57:31 +03:00
parent 9aaa8a86f5
commit e0fbeee88e
5 changed files with 75 additions and 31 deletions

View File

@ -23,6 +23,11 @@ const mediaUpload = {
} }
}, },
methods: { methods: {
onClick () {
if (this.uploadReady) {
this.$refs.input.click()
}
},
uploadFile (file) { uploadFile (file) {
const self = this const self = this
const store = this.$store const store = this.$store
@ -69,10 +74,15 @@ const mediaUpload = {
this.multiUpload(target.files) this.multiUpload(target.files)
} }
}, },
props: [ props: {
'dropFiles', dropFiles: Object,
'disabled' disabled: Boolean,
], normalButton: Boolean,
acceptTypes: {
type: String,
default: '*/*'
}
},
watch: { watch: {
dropFiles: function (fileInfos) { dropFiles: function (fileInfos) {
if (!this.uploading) { if (!this.uploading) {

View File

@ -1,8 +1,10 @@
<template> <template>
<label <component
class="media-upload" class="media-upload"
:class="{ disabled: disabled }" :is="normalButton ? 'button' : 'label'"
:class="{ disabled: disabled, ['media-upload button-default btn']: normalButton }"
:title="$t('tool_tip.media_upload')" :title="$t('tool_tip.media_upload')"
@click="onClick"
> >
<FAIcon <FAIcon
v-if="uploading" v-if="uploading"
@ -15,6 +17,10 @@
class="new-icon" class="new-icon"
icon="upload" icon="upload"
/> />
<template v-if="normalButton">
{{ ' ' }}
{{ uploading ? $t('general.loading') : $t('tool_tip.media_upload') }}
</template>
<input <input
v-if="uploadReady" v-if="uploadReady"
class="hidden-input-file" class="hidden-input-file"
@ -22,8 +28,10 @@
type="file" type="file"
multiple="true" multiple="true"
@change="change" @change="change"
ref="input"
:accept="acceptTypes"
> >
</label> </component>
</template> </template>
<script src="./media_upload.js"></script> <script src="./media_upload.js"></script>
@ -32,10 +40,12 @@
@import "../../variables"; @import "../../variables";
.media-upload { .media-upload {
cursor: pointer; // We use <label> for interactivity... i wonder if it's fine
.hidden-input-file { .hidden-input-file {
display: none; display: none;
} }
} }
label.media-upload {
cursor: pointer; // We use <label> for interactivity... i wonder if it's fine
}
</style> </style>

View File

@ -7,10 +7,10 @@ export default {
...Setting, ...Setting,
props: { props: {
...Setting.props, ...Setting.props,
type: { acceptTypes: {
type: Array, type: String,
required: false, required: false,
default: [] default: 'image/*'
} }
}, },
components: { components: {
@ -22,6 +22,7 @@ export default {
...Setting.computed, ...Setting.computed,
attachment () { attachment () {
const path = this.realDraftMode ? this.draft : this.state const path = this.realDraftMode ? this.draft : this.state
// The "server" part is primarily for local dev, but could be useful for alt-domain or multiuser usage.
const url = path.includes('://') ? path : this.$store.state.instance.server + path const url = path.includes('://') ? path : this.$store.state.instance.server + path
return { return {
mimetype: fileTypeExt(url), mimetype: fileTypeExt(url),

View File

@ -20,24 +20,8 @@
{{ backendDescriptionDescription + ' ' }} {{ backendDescriptionDescription + ' ' }}
</p> </p>
<div class="attachment-input"> <div class="attachment-input">
<Attachment <div>{{ $t('settings.url') }}</div>
class="attachment"
:compact="compact"
:attachment="attachment"
size="small"
hide-description
@setMedia="onMedia"
@naturalSizeLoad="onNaturalSizeLoad"
/>
<div class="controls"> <div class="controls">
<media-upload
normal-button
ref="mediaUpload"
class="media-upload-icon"
:drop-files="dropFiles"
@uploaded="setMediaFile"
@upload-failed="uploadFailed"
/>
<input <input
:id="path" :id="path"
class="string-input" class="string-input"
@ -52,6 +36,27 @@
/> />
<ProfileSettingIndicator :is-profile="isProfileSetting" /> <ProfileSettingIndicator :is-profile="isProfileSetting" />
</div> </div>
<div>{{ $t('settings.preview') }}</div>
<Attachment
class="attachment"
:compact="compact"
:attachment="attachment"
size="small"
hide-description
@setMedia="onMedia"
@naturalSizeLoad="onNaturalSizeLoad"
/>
<div class="controls">
<MediaUpload
ref="mediaUpload"
class="media-upload-icon"
:drop-files="dropFiles"
@uploaded="setMediaFile"
@upload-failed="uploadFailed"
normal-button
:accept-types="acceptTypes"
/>
</div>
</div> </div>
<DraftButtons /> <DraftButtons />
</span> </span>
@ -63,8 +68,24 @@
.AttachmentSetting { .AttachmentSetting {
.attachment { .attachment {
display: block; display: block;
width: 20em; width: 100%;
height: 15em; height: 15em;
margin-bottom: 0.5em;
}
.attachment-input {
margin-left: 1em;
display: flex;
flex-direction: column;
width: 20em;
}
.controls {
margin-bottom: 0.5em;
input, button {
width: 100%;
}
} }
} }
</style> </style>

View File

@ -519,6 +519,8 @@
"loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")", "loop_video_silent_only": "Loop only videos without sound (i.e. Mastodon's \"gifs\")",
"mutes_tab": "Mutes", "mutes_tab": "Mutes",
"play_videos_in_modal": "Play videos in a popup frame", "play_videos_in_modal": "Play videos in a popup frame",
"url": "URL",
"preview": "Preview",
"file_export_import": { "file_export_import": {
"backup_restore": "Settings backup", "backup_restore": "Settings backup",
"backup_settings": "Backup settings to file", "backup_settings": "Backup settings to file",