Skip to content

Commit

Permalink
Add set as space img/md action
Browse files Browse the repository at this point in the history
  • Loading branch information
JanAckermann committed Feb 14, 2022
1 parent 31af475 commit 0f60588
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 132 deletions.
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/setSpaceImage'
import SetSpaceMarkdown from '../../mixins/spaces/actions/setSpaceMarkdown'
export default {
name: 'ContextActions',
Expand All @@ -60,7 +62,9 @@ export default {
Restore,
ShowActions,
ShowDetails,
ShowShares
ShowShares,
SetSpaceImage,
SetSpaceMarkdown
],
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.$_setSpaceMarkdown_items
].filter((item) => item.isEnabled(this.filterParams))
},
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 short description')
},
handler: this.$_editDescription_trigger,
isEnabled: () => false, // @TODO enable as soon as backend supports this
isEnabled: () => true,
componentType: 'oc-button',
class: 'oc-files-actions-edit-description-trigger'
}
Expand Down
68 changes: 68 additions & 0 deletions packages/web-app-files/src/mixins/spaces/actions/setSpaceImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { isLocationSpacesActive } from '../../../router'
import { clientService } from 'web-pkg/src/services'
import { mapMutations } from 'vuex'

export default {
computed: {
$_setSpaceImage_items() {
return [
{
name: 'set-space-image',
icon: 'image-edit',
handler: this.$_setSpaceImage_trigger,
label: () => {
return this.$gettext('Set as space image')
},
isEnabled: ({ resources }) => {
if (resources.length !== 1) {
return false
}
if (!resources[0].mimeType?.startsWith('image/')) {
return false
}
return isLocationSpacesActive(this.$router, 'files-spaces-project')
},
canBeDefault: false,
componentType: 'oc-button',
class: 'oc-files-actions-set-space-image-trigger'
}
]
}
},
methods: {
...mapMutations('Files', ['UPDATE_RESOURCE_FIELD']),
$_setSpaceImage_trigger({ resources }) {
const graphClient = clientService.graphAuthenticated(this.configuration.server, this.getToken)
const id = this.$route.params.spaceId
return graphClient.drives
.updateDrive(
id,
{
special: [
{
specialFolder: {
name: 'image'
},
id: Buffer.from(resources[0].id, 'base64').toString().split(':').pop()
}
]
},
{}
)
.then(({ data }) => {
this.UPDATE_RESOURCE_FIELD({
id,
field: 'spaceImageData',
value: data.special.find((special) => special.specialFolder.name === 'image')
})
})
.catch((error) => {
this.showMessage({
title: this.$gettext('Set space image failed…'),
desc: error,
status: 'danger'
})
})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { isLocationSpacesActive } from '../../../router'
import { clientService } from 'web-pkg/src/services'
import { mapMutations } from 'vuex'

export default {
computed: {
$_setSpaceMarkdown_items() {
return [
{
name: 'set-space-markdown',
icon: 'markdown',
handler: this.$_setSpaceMarkdown_trigger,
label: () => {
return this.$gettext('Set as space description')
},
isEnabled: ({ resources }) => {
if (resources.length !== 1) {
return false
}
if (resources[0].extension !== 'md') {
return false
}
return isLocationSpacesActive(this.$router, 'files-spaces-project')
},
canBeDefault: false,
componentType: 'oc-button',
class: 'oc-files-actions-set-space-markdown-trigger'
}
]
}
},
methods: {
...mapMutations('Files', ['UPDATE_RESOURCE_FIELD']),
$_setSpaceMarkdown_trigger({ resources }) {
const graphClient = clientService.graphAuthenticated(this.configuration.server, this.getToken)
const id = this.$route.params.spaceId
return graphClient.drives
.updateDrive(
id,
{
special: [
{
specialFolder: {
name: 'readme'
},
id: Buffer.from(resources[0].id, 'base64').toString().split(':').pop()
}
]
},
{}
)
.then(({ data }) => {
this.UPDATE_RESOURCE_FIELD({
id,
field: 'spaceReadmeData',
value: data.special.find((special) => special.specialFolder.name === 'readme')
})
})
.catch((error) => {
this.showMessage({
title: this.$gettext('Set space description failed…'),
desc: error,
status: 'danger'
})
})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { mapMutations } from 'vuex'
import { clientService } from 'web-pkg/src/services'

export default {
data: function () {
return {
selectedSpace: null
}
},
computed: {
$_uploadSpaceImage_items() {
return [
{
name: 'upload-space-image',
icon: 'image-add',
handler: this.$_uploadSpaceImage_trigger,
label: () => {
return this.$gettext('Upload space image')
},
isEnabled: ({ spaces }) => spaces.length === 1,
componentType: 'oc-button',
class: 'oc-files-actions-upload-space-image-trigger'
}
]
}
},
methods: {
...mapMutations('Files', ['UPDATE_RESOURCE_FIELD']),
$_uploadSpaceImage_trigger({ spaces }) {
if (spaces.length !== 1) {
return
}

this.selectedSpace = spaces[0]
this.$refs.spaceImageInput.click()
},
$_uploadSpaceImage(ev) {
const graphClient = clientService.graphAuthenticated(this.configuration.server, this.getToken)
const file = ev.currentTarget.files[0]

const extraHeaders = {}
if (file.lastModifiedDate) {
extraHeaders['X-OC-Mtime'] = '' + file.lastModifiedDate.getTime() / 1000
} else if (file.lastModified) {
extraHeaders['X-OC-Mtime'] = '' + file.lastModified / 1000
}

this.$client.files
.putFileContents(`spaces/${this.selectedSpace.id}/${file.name}`, file, {
headers: extraHeaders,
overwrite: true
})
.then((image) => {
graphClient.drives
.updateDrive(
this.selectedSpace.id,
{
special: [
{
specialFolder: {
name: 'image'
},
id: Buffer.from(image['OC-FileId'], 'base64').toString().split(':').pop()
}
]
},
{}
)
.then(({ data }) => {
this.UPDATE_RESOURCE_FIELD({
id: this.selectedSpace.id,
field: 'spaceImageData',
value: data.special.find((special) => special.specialFolder.name === 'image')
})
})
.catch((error) => {
this.showMessage({
title: this.$gettext('Upload space image failed…'),
desc: error,
status: 'danger'
})
})
})
}
}
}
Loading

0 comments on commit 0f60588

Please sign in to comment.