Skip to content

Commit

Permalink
enh: share context via api request
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Apr 11, 2024
1 parent 30bf0f4 commit 3ff2750
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
21 changes: 14 additions & 7 deletions src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
</div>
<div class="col-4" style="display: inline-flex;">
<NcIconPicker :close-on-select="true" @select="setIcon">
<NcButton
type="tertiary"
:aria-label="t('tables', 'Select an icon for application')"
:title="t('tables', 'Select icon')"
@click.prevent>
<NcButton type="tertiary" :aria-label="t('tables', 'Select an icon for application')"
:title="t('tables', 'Select icon')" @click.prevent>
<template #icon>
<NcIconSvgWrapper :svg="icon.svg" />
</template>
Expand All @@ -36,7 +33,7 @@
<div class="col-4">
{{ t('tables', 'Resources') }}
</div>
<NcContextResource :resources.sync="resources" />
<NcContextResource :resources.sync="resources" :receivers.sync="receivers" />
</div>

<div class="row space-R">
Expand Down Expand Up @@ -90,6 +87,7 @@ export default {
description: '',
errorTitle: false,
resources: [],
receivers: [],
}
},
computed: {
Expand All @@ -113,6 +111,7 @@ export default {
this.setIcon(this.localContext.iconName)
this.description = context.description
this.resources = context ? [...this.getContextResources(context)] : []
this.receivers = context && context?.sharing ? [...context.sharing] : []
}
},
},
Expand Down Expand Up @@ -145,7 +144,14 @@ export default {
description: this.description,
nodes: dataResources,
}
const res = await this.$store.dispatch('updateContext', { id: this.contextId, data })
const share = {
nodeType: 'context',
nodeId: this.contextId,
receiverType: 'user',
displayMode: 2,
}
const res = await this.$store.dispatch('updateContext', { id: this.contextId, data, share, receivers: this.receivers })
if (res) {
showSuccess(t('tables', 'Updated context "{contextTitle}".', { contextTitle: this.title }))
this.actionCancel()
Expand All @@ -159,6 +165,7 @@ export default {
this.icon.name = 'equalizer'
this.description = ''
this.resources = context ? [...this.getContextResources(context)] : []
this.receivers = context && context?.sharing ? [...context.sharing] : []
},
getContextResources(context) {
const resources = []
Expand Down
40 changes: 21 additions & 19 deletions src/shared/components/ncContextResource/NcContextResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div>
<ResourceForm :resources="localResource" @add="addResource" />
<ResourceList :resources="localResource" @remove="removeResource" />
<ResourceSharees :select-users="true" :select-groups="false" :sharees.sync="currentSharees" />
<ResourceSharees :select-users="true" :select-groups="false" :receivers="localReceivers" @update="updateReceivers" />
<ResourceSharePermissions :resources="localResource" />
</div>
</div>
Expand Down Expand Up @@ -35,7 +35,7 @@ export default {
type: Array,
default: () => ([]),
},
sharees: {
receivers: {
type: Array,
default: () => ([]),
},
Expand All @@ -45,22 +45,14 @@ export default {
return {
loading: false,
contextResource: this.resources,
// currentSharees: [...this.sharees],
currentSharees: [
{
user: 'user2',
displayName: 'user2',
icon: 'icon-user',
isUser: true,
key: 'users-user2',
},
{
user: 'user1',
displayName: 'user1',
icon: 'icon-user',
isUser: true,
key: 'users-user1',
},
contextReceivers: [
// {
// user: 'user2',

Check failure on line 50 in src/shared/components/ncContextResource/NcContextResource.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// displayName: 'user2',

Check failure on line 51 in src/shared/components/ncContextResource/NcContextResource.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// icon: 'icon-user',

Check failure on line 52 in src/shared/components/ncContextResource/NcContextResource.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// isUser: true,

Check failure on line 53 in src/shared/components/ncContextResource/NcContextResource.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// key: 'users-user2',

Check failure on line 54 in src/shared/components/ncContextResource/NcContextResource.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Unexpected tab character
// },
],
}
},
Expand All @@ -75,6 +67,14 @@ export default {
this.$emit('update:resources', v)
},
},
localReceivers: {
get() {
return this.contextReceivers
},
set(v) {
this.$emit('update:receivers', v)
},
},
},
methods: {
Expand All @@ -85,7 +85,9 @@ export default {
addResource(resource) {
this.contextResource.push(resource)
this.localResource = this.contextResource
},
updateReceivers(receivers) {
this.localReceivers = receivers
},
},
Expand Down
8 changes: 4 additions & 4 deletions src/shared/components/ncContextResource/ResourceSharees.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
mixins: [ShareTypes, formatting],
props: {
sharees: {
receivers: {
type: Array,
default: () => ([]),
},
Expand All @@ -58,8 +58,8 @@ export default {
minSearchStringLength: 1,
maxAutocompleteResults: 20,
suggestions: [],
preExistingSharees: [...this.sharees],
localSharees: this.sharees.map(userObject => userObject.user),
preExistingSharees: [...this.receivers],
localSharees: this.receivers.map(userObject => userObject.user),
}
},
Expand All @@ -70,7 +70,7 @@ export default {
},
set(v) {
this.localSharees = v.map(userObject => userObject.user)
this.$emit('update:sharees', v)
this.$emit('update', v)
},
},
Expand Down
7 changes: 6 additions & 1 deletion src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,16 @@ export default new Vuex.Store({

return true
},
async updateContext({ state, commit, dispatch }, { id, data }) {
async updateContext({ state, commit, dispatch }, { id, data, share, receivers }) {
let res = null

try {
res = await axios.put(generateOcsUrl('/apps/tables/api/2/contexts/' + id), data)
for (const receiver of receivers) {
share.receiverType = receiver.isUser ? 'user' : 'group'
share.receiver = receiver.user
await axios.post(generateUrl('/apps/tables/share'), share)
}
} catch (e) {
displayError(e, t('tables', 'Could not update application.'))
return false
Expand Down

0 comments on commit 3ff2750

Please sign in to comment.