-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JanAckermann
committed
Feb 14, 2022
1 parent
31af475
commit 0f60588
Showing
12 changed files
with
526 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/web-app-files/src/mixins/spaces/actions/setSpaceImage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
}) | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
packages/web-app-files/src/mixins/spaces/actions/setSpaceMarkdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
}) | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
packages/web-app-files/src/mixins/spaces/actions/uploadSpaceImage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.