Skip to content

Commit

Permalink
feat: transfer context ownership
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 Mar 19, 2024
1 parent 1b2d9b5 commit 8efc055
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/modules/modals/Modals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<EditTable :table-id="editTable" :show-modal="editTable !== null" @close="editTable = null" />
<TransferTable :table="tableToTransfer" :show-modal="tableToTransfer !== null" @close="tableToTransfer = null" />
<EditContext :context-id="editContext" :show-modal="editContext !== null" @close="editContext = null" />
<TransferContext :context="contextToTransfer" :show-modal="contextToTransfer !== null" @close="contextToTransfer = null" />
</div>
</template>
Expand All @@ -60,6 +61,7 @@ import EditTable from './EditTable.vue'
import EditContext from './EditContext.vue'
import TransferTable from './TransferTable.vue'
import CreateContext from './CreateContext.vue'
import TransferContext from './TransferContext.vue'
export default {
components: {
Expand All @@ -78,6 +80,7 @@ export default {
TransferTable,
CreateContext,
EditContext,
TransferContext,
},
data() {
Expand All @@ -98,6 +101,7 @@ export default {
editTable: null,
editContext: null,
tableToTransfer: null,
contextToTransfer: null,
}
},
Expand Down Expand Up @@ -138,6 +142,7 @@ export default {
// context
subscribe('tables:context:create', () => { this.showModalCreateContext = true })
subscribe('tables:context:edit', contextId => { this.editContext = contextId })
subscribe('tables:context:transfer', context => { this.contextToTransfer = context })
},
unmounted() {
Expand Down Expand Up @@ -165,6 +170,7 @@ export default {
unsubscribe('tables:table:transfer', table => { this.tableToTransfer = table })
unsubscribe('tables:context:create', () => { this.showModalCreateContext = true })
unsubscribe('tables:context:edit', contextId => { this.editContext = contextId })
unsubscribe('tables:context:transfer', context => { this.contextToTransfer = context })
},
}
</script>
89 changes: 89 additions & 0 deletions src/modules/modals/TransferContext.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<NcModal v-if="showModal"
size="normal"
@close="actionCancel">
<div class="modal__content" data-cy="transferContextModal">
<div class="row">
<div class="col-4">
<h2>{{ t('tables', 'Transfer application') }}</h2>
</div>
</div>
<div class="row">
<h3>{{ t('tables', 'Transfer this application to another user') }}</h3>
<NcUserAndGroupPicker :select-users="true" :select-groups="false" :new-owner-user-id.sync="newOwnerId" />
</div>
<div class="row">
<div class="fix-col-4 space-T end">
<NcButton type="warning" :disabled="newOwnerId === ''" data-cy="transferTableButton" @click="transferContext">
{{ t('tables', 'Transfer') }}
</NcButton>
</div>
</div>
</div>
</NcModal>
</template>

<script>
import { NcModal, NcButton } from '@nextcloud/vue'
import { showSuccess } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/dist/index.css'
import permissionsMixin from '../../shared/components/ncTable/mixins/permissionsMixin.js'
import NcUserAndGroupPicker from '../../shared/components/ncUserAndGroupPicker/NcUserAndGroupPicker.vue'
import { mapGetters, mapState } from 'vuex'
import { getCurrentUser } from '@nextcloud/auth'
export default {
name: 'TransferContext',
components: {
NcModal,
NcButton,
NcUserAndGroupPicker,
},
mixins: [permissionsMixin],
props: {
showModal: {
type: Boolean,
default: false,
},
context: {
type: Object,
default: null,
},
},
data() {
return {
loading: false,
newOwnerId: '',
}
},
computed: {
...mapGetters(['getContext']),
...mapState(['activeContextId']),
localContext() {
return this.getContext(this.context.id)
},
userId() {
return getCurrentUser().uid
},
},
methods: {
actionCancel() {
this.$emit('close')
},
async transferContext() {
const transferId = this.context.id
const res = await this.$store.dispatch('transferContext', { id: this.context.id, data: { newOwnerId: this.newOwnerId } })
if (res) {
showSuccess(t('tables', 'Context "{name}" transfered to {user}', { name: this.context?.name, user: this.newOwnerId }))
if (transferId === this.activeContextId) {
await this.$router.push('/').catch(err => err)
}
this.actionCancel()
}
},
},
}
</script>
11 changes: 11 additions & 0 deletions src/modules/navigation/partials/NavigationContextItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
</template>
{{ t('tables', 'Edit application') }}
</NcActionButton>
<NcActionButton v-if="canManageContext(context)" :close-after-click="true" @click="transferContext">
<template #icon>
<FileSwap :size="20" />
</template>
{{ t('tables', 'Transfer application') }}
</NcActionButton>
</template>
</NcAppNavigationItem>
</template>
Expand All @@ -27,6 +33,7 @@ import { mapGetters } from 'vuex'
import TableIcon from 'vue-material-design-icons/Table.vue'
import { emit } from '@nextcloud/event-bus'
import PlaylistEdit from 'vue-material-design-icons/PlaylistEdit.vue'
import FileSwap from 'vue-material-design-icons/FileSwap.vue'
import permissionsMixin from '../../../shared/components/ncTable/mixins/permissionsMixin.js'
import svgHelper from '../../../shared/components/ncIconPicker/mixins/svgHelper.js'
Expand All @@ -35,6 +42,7 @@ export default {
components: {
PlaylistEdit,
FileSwap,
TableIcon,
NcIconSvgWrapper,
NcAppNavigationItem,
Expand Down Expand Up @@ -73,6 +81,9 @@ export default {
async editContext() {
emit('tables:context:edit', this.context.id)
},
async transferContext() {
emit('tables:context:transfer', this.context)
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default {
return this.newOwnerUserId
},
set(v) {
console.info('newOwnerUserId set to ', v)
this.$emit('update:newOwnerUserId', v)
},
},
Expand Down
15 changes: 15 additions & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,21 @@ export default new Vuex.Store({
return true
},

async transferContext({ state, commit, dispatch }, { id, data }) {
try {
await axios.put(generateOcsUrl('/apps/tables/api/2/contexts/' + id + '/transfer'), data)
} catch (e) {
displayError(e, t('tables', 'Could not transfer application.'))
return false
}

const contexts = state.contexts
const index = contexts.findIndex(t => t.id === id)
contexts.splice(index, 1)
commit('setContexts', [...contexts])
return true
},

async removeTable({ state, commit }, { tableId }) {
try {
await axios.delete(generateUrl('/apps/tables/table/' + tableId))
Expand Down

0 comments on commit 8efc055

Please sign in to comment.