Skip to content

Commit

Permalink
Add set as space img/md action (#6410)
Browse files Browse the repository at this point in the history
Add set as space image and readme actions
  • Loading branch information
Jan authored Mar 1, 2022
1 parent 4d58f7a commit 2e24276
Show file tree
Hide file tree
Showing 33 changed files with 1,585 additions and 230 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Allow updating space image and description

We have implemented multiple ways to update the image and description of a space.

https://github.com/owncloud/web/pull/6410
https://github.com/owncloud/web/issues/6377
12 changes: 8 additions & 4 deletions packages/web-app-files/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
:items="breadcrumbs"
>
<template #contextMenu>
<context-actions
v-if="currentFolder && breadcrumbs.length > 1"
:items="[currentFolder]"
/>
<context-actions v-if="showContextActions" :items="[currentFolder]" />
</template>
</oc-breadcrumb>
<h1 class="oc-invisible-sr" v-text="pageTitle" />
Expand Down Expand Up @@ -105,6 +102,13 @@ export default {
...mapGetters('Files', ['files', 'currentFolder', 'selectedFiles', 'publicLinkPassword']),
...mapState('Files', ['areHiddenFilesShown']),
showContextActions() {
if (this.isSpacesProjectLocation) {
return this.currentFolder && this.breadcrumbs.length > 2
}
return this.currentFolder && this.breadcrumbs.length > 1
},
currentPath() {
const path = this.$route.params.item || ''
if (path.endsWith('/')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import Restore from '../../mixins/actions/restore'
import ShowActions from '../../mixins/actions/showActions'
import ShowDetails from '../../mixins/actions/showDetails'
import ShowShares from '../../mixins/actions/showShares'
import SetSpaceImage from '../../mixins/spaces/actions/setImage'
import SetSpaceReadme from '../../mixins/spaces/actions/setReadme'
export default {
name: 'ContextActions',
Expand All @@ -60,7 +62,9 @@ export default {
Restore,
ShowActions,
ShowDetails,
ShowShares
ShowShares,
SetSpaceImage,
SetSpaceReadme
],
props: {
Expand Down Expand Up @@ -159,7 +163,9 @@ export default {
...this.$_rename_items,
...this.$_restore_items,
...this.$_acceptShare_items,
...this.$_declineShare_items
...this.$_declineShare_items,
...this.$_setSpaceImage_items,
...this.$_setSpaceReadme_items
].filter((item) => item.isEnabled(this.filterParams))
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
<template>
<oc-list id="oc-spaces-actions-sidebar" class-name="oc-mt-s">
<action-menu-item
v-for="(action, index) in actions"
:key="`action-${index}`"
:action="action"
:items="resources"
class="oc-py-xs"
<div>
<portal v-if="$data.$_editReadmeContent_modalOpen" to="app.runtime.modal">
<oc-modal
focus-trap-initial="#description-input-area"
:title="$gettext('Edit description for space') + ' ' + resources[0].name"
:button-cancel-text="$gettext('Cancel')"
:button-confirm-text="$gettext('Confirm')"
@confirm="$_editReadmeContent_editReadmeContentSpace"
@cancel="$_editReadmeContent_closeModal"
>
<template #content>
<label v-translate class="oc-label" for="description-input-area">Space description</label>
<textarea
id="description-input-area"
v-model="$data.$_editReadmeContent_content"
class="oc-width-1-1 oc-height-1-1 oc-text-input"
rows="30"
></textarea>
</template>
</oc-modal>
</portal>
<input
id="space-image-upload-input"
ref="spaceImageInput"
type="file"
name="file"
multiple
tabindex="-1"
accept="image/*"
@change="$_uploadImage_uploadImageSpace"
/>
</oc-list>
<oc-list id="oc-spaces-actions-sidebar" class-name="oc-mt-s">
<action-menu-item
v-for="(action, index) in actions"
:key="`action-${index}`"
:action="action"
:items="resources"
class="oc-py-xs"
/>
</oc-list>
</div>
</template>

<script>
Expand All @@ -18,14 +50,16 @@ import Delete from '../../../mixins/spaces/actions/delete'
import Disable from '../../../mixins/spaces/actions/disable'
import Restore from '../../../mixins/spaces/actions/restore'
import EditDescription from '../../../mixins/spaces/actions/editDescription'
import EditReadmeContent from '../../../mixins/spaces/actions/editReadmeContent'
import UploadImage from '../../../mixins/spaces/actions/uploadImage'
export default {
name: 'SpaceActions',
title: ($gettext) => {
return $gettext('Actions')
},
components: { ActionMenuItem },
mixins: [Rename, Delete, EditDescription, Disable, Restore],
mixins: [Rename, Delete, EditDescription, EditReadmeContent, Disable, Restore, UploadImage],
computed: {
...mapGetters('Files', ['highlightedFile']),
Expand All @@ -37,6 +71,8 @@ export default {
return [
...this.$_rename_items,
...this.$_editDescription_items,
...this.$_uploadImage_items,
...this.$_editReadmeContent_items,
...this.$_restore_items,
...this.$_delete_items,
...this.$_disable_items
Expand All @@ -47,6 +83,11 @@ export default {
</script>

<style lang="scss">
#space-image-upload-input {
position: absolute;
left: -99999px;
}
#oc-spaces-actions-sidebar {
> li a,
> li a:hover {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
<div id="oc-space-details-sidebar">
<div class="oc-space-details-sidebar-image oc-text-center">
<oc-spinner v-if="loadImageTask.isRunning" />
<img
v-else-if="spaceImage"
:src="'data:image/jpeg;base64,' + spaceImage"
alt=""
class="oc-mb-m"
/>
<div v-else-if="spaceImage" class="oc-position-relative">
<img :src="'data:image/jpeg;base64,' + spaceImage" alt="" class="oc-mb-m" />
</div>
<oc-icon
v-else
name="layout-grid"
Expand Down Expand Up @@ -79,8 +76,13 @@ export default {
return
}
const webDavPathComponents = ref.space.spaceImageData.webDavUrl.split('/')
const path = webDavPathComponents
.slice(webDavPathComponents.indexOf(ref.space.id) + 1)
.join('/')
const fileContents = yield ref.$client.files.getFileContents(
buildWebDavSpacesPath(ref.space.id, ref.space.spaceImageData.name),
buildWebDavSpacesPath(ref.space.id, path),
{ responseType: 'arrayBuffer' }
)
Expand Down
7 changes: 5 additions & 2 deletions packages/web-app-files/src/mixins/spaces/actions/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ export default {
.then(() => {
this.hideModal()
this.REMOVE_FILE({ id })
this.showMessage({
title: this.$gettext('Space was deleted successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Deleting space failed…'),
desc: error,
title: this.$gettext('Failed to delete space'),
status: 'danger'
})
})
Expand Down
7 changes: 5 additions & 2 deletions packages/web-app-files/src/mixins/spaces/actions/disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ export default {
field: 'disabled',
value: true
})
this.showMessage({
title: this.$gettext('Space was disabled successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Disabling space failed…'),
desc: error,
title: this.$gettext('Failed to disable space'),
status: 'danger'
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default {
name: 'editDescription',
icon: 'pencil',
label: () => {
return this.$gettext('Change description')
return this.$gettext('Change subtitle')
},
handler: this.$_editDescription_trigger,
isEnabled: () => false, // @TODO enable as soon as backend supports this
isEnabled: ({ resources }) => resources.length === 1,
componentType: 'oc-button',
class: 'oc-files-actions-edit-description-trigger'
}
Expand All @@ -38,11 +38,11 @@ export default {

const modal = {
variation: 'passive',
title: this.$gettext('Change description for space') + ' ' + resources[0].name,
title: this.$gettext('Change subtitle for space') + ' ' + resources[0].name,
cancelText: this.$gettext('Cancel'),
confirmText: this.$gettext('Confirm'),
hasInput: true,
inputLabel: this.$gettext('Space description'),
inputLabel: this.$gettext('Space subtitle'),
inputValue: resources[0].description,
onCancel: this.hideModal,
onConfirm: (description) =>
Expand All @@ -63,11 +63,14 @@ export default {
field: 'description',
value: description
})
this.showMessage({
title: this.$gettext('Space subtitle was changed successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Renaming space description failed…'),
desc: error,
title: this.$gettext('Failed to change space subtitle'),
status: 'danger'
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { mapActions, mapMutations, mapState } from 'vuex'

export default {
data: function () {
return {
$_editReadmeContent_modalOpen: false,
$_editReadmeContent_content: ''
}
},
computed: {
...mapState('Files', ['currentFolder']),
$_editReadmeContent_items() {
return [
{
name: 'editReadmeContent',
icon: 'markdown',
label: () => {
return this.$gettext('Edit description')
},
handler: this.$_editReadmeContent_trigger,
isEnabled: ({ resources }) => {
if (resources.length !== 1) {
return false
}

return resources[0].spaceReadmeData
},
componentType: 'oc-button',
class: 'oc-files-actions-edit-readme-content-trigger'
}
]
}
},
methods: {
...mapActions([
'createModal',
'hideModal',
'setModalInputErrorMessage',
'showMessage',
'toggleModalConfirmButton'
]),
...mapMutations('Files', ['UPDATE_RESOURCE_FIELD']),

$_editReadmeContent_trigger({ resources }) {
if (resources.length !== 1) {
return
}
const webDavPathComponents = resources[0].spaceReadmeData.webDavUrl.split('/')
const path = webDavPathComponents.slice(webDavPathComponents.indexOf('dav') + 1).join('/')

this.$client.files.getFileContents(path).then((readmeContent) => {
this.$data.$_editReadmeContent_modalOpen = true
this.$data.$_editReadmeContent_content = readmeContent
})
},

$_editReadmeContent_editReadmeContentSpace() {
const space = this.currentFolder
const webDavPathComponents = space.spaceReadmeData.webDavUrl.split('/')
const path = webDavPathComponents.slice(webDavPathComponents.indexOf('dav') + 1).join('/')

return this.$client.files
.putFileContents(path, this.$data.$_editReadmeContent_content)
.then((readmeMetaData) => {
this.$_editReadmeContent_closeModal()
this.UPDATE_RESOURCE_FIELD({
id: space.id,
field: 'spaceReadmeData',
value: { ...space.spaceReadmeData, ...{ etag: readmeMetaData.ETag } }
})
this.showMessage({
title: this.$gettext('Space description was edited successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to edit space description'),
status: 'danger'
})
})
},

$_editReadmeContent_closeModal() {
this.$data.$_editReadmeContent_modalOpen = false
}
}
}
7 changes: 5 additions & 2 deletions packages/web-app-files/src/mixins/spaces/actions/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ export default {
field: 'name',
value: name
})
this.showMessage({
title: this.$gettext('Space name was changed successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Renaming space failed…'),
desc: error,
title: this.$gettext('Failed to rename space'),
status: 'danger'
})
})
Expand Down
7 changes: 5 additions & 2 deletions packages/web-app-files/src/mixins/spaces/actions/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ export default {
field: 'disabled',
value: false
})
this.showMessage({
title: this.$gettext('Space was restored successfully')
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Restoring space failed…'),
desc: error,
title: this.$gettext('Failed to restore space'),
status: 'danger'
})
})
Expand Down
Loading

0 comments on commit 2e24276

Please sign in to comment.