-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transfer table ownership frontend
- Loading branch information
Showing
7 changed files
with
329 additions
and
0 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
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,107 @@ | ||
<template> | ||
<NcModal v-if="showModal" | ||
size="normal" | ||
@close="actionCancel"> | ||
<div class="modal__content"> | ||
<div class="row"> | ||
<div class="col-4"> | ||
<h2>{{ t('tables', 'Transfer table') }}</h2> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<TransferForm :newOwnerUserId="newOwnerUserId" @add="addTransfer"/> | ||
Check warning on line 12 in src/modules/modals/TransferTable.vue GitHub Actions / eslint
|
||
</div> | ||
<div class="row"> | ||
<div class="fix-col-4 space-T justify-between"> | ||
<NcButton v-if="!prepareTransferTable" type="error" @click="prepareTransferTable = true"> | ||
{{ t('tables', 'Transfer') }} | ||
</NcButton> | ||
<NcButton v-if="prepareTransferTable" | ||
:wide="true" | ||
type="error" | ||
@click="transferMe"> | ||
{{ t('tables', 'I really want to transfer this table!') }} | ||
</NcButton> | ||
</div> | ||
</div> | ||
</div> | ||
</NcModal> | ||
</template> | ||
|
||
<script> | ||
import { NcModal, NcButton } from '@nextcloud/vue' | ||
import TransferForm from '../sidebar/partials/TransferForm.vue' | ||
import shareAPI from '../sidebar/mixins/shareAPI.js' | ||
import { showSuccess } from '@nextcloud/dialogs' | ||
import '@nextcloud/dialogs/dist/index.css' | ||
import { mapGetters } from 'vuex' | ||
import { getCurrentUser } from '@nextcloud/auth' | ||
import permissionsMixin from '../../shared/components/ncTable/mixins/permissionsMixin.js' | ||
export default { | ||
name: 'TransferTable', | ||
components: { | ||
NcModal, | ||
NcButton, | ||
TransferForm, | ||
}, | ||
mixins: [shareAPI, permissionsMixin], | ||
props: { | ||
showModal: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
table: { | ||
type: Object, | ||
default: null, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
prepareTransferTable: false, | ||
loading: false, | ||
newOwnerUserId: '', | ||
} | ||
}, | ||
computed: { | ||
...mapGetters(['activeElement', 'isView']), | ||
getTranslatedDescription() { | ||
return t('tables', 'Do you really want to transfer the table "{table}"?', { table: this.table?.title }) | ||
}, | ||
}, | ||
methods: { | ||
actionCancel() { | ||
this.reset() | ||
this.$emit('close') | ||
}, | ||
reset() { | ||
this.prepareDeleteTable = false | ||
}, | ||
async transferMe() { | ||
console.info(this.table) | ||
console.info(getCurrentUser().uid) | ||
const transferId = this.table.id | ||
let activeTableId | ||
if (this.activeElement){ | ||
activeTableId = this.isView ? this.activeElement.id : this.activeElement.tableId | ||
this.prepareTransferTable = false | ||
} | ||
const res = await this.$store.dispatch('transferTable', { tableId: this.table.id, newOwnerUserId: 'test', userId: getCurrentUser().uid}) | ||
Check failure on line 89 in src/modules/modals/TransferTable.vue GitHub Actions / eslint
|
||
if (res) { | ||
showSuccess(t('tables', 'Table "{emoji}{table}" transfered', { emoji: this.table?.icon ? this.table?.icon + ' ' : '', table: this.table?.title })) | ||
// if the actual table was transfered, go to startpage | ||
if (transferId === activeTableId) { | ||
await this.$router.push('/').catch(err => err) | ||
} | ||
this.actionCancel() | ||
} | ||
}, | ||
async addTransfer(id) { | ||
this.newOwnerUserId = id | ||
}, | ||
}, | ||
} | ||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
<template> | ||
<div class="row space-B"> | ||
<h3>{{ t('tables', 'Share with accounts') }}</h3> | ||
<NcSelect id="transfer-ownership-select" style="width: 100%;" :loading="loading" :options="options" | ||
:placeholder="t('tables', 'User…')" :searchable="true" label="displayName" @search="asyncFind"> | ||
<template #no-options> | ||
{{ t('tables', 'No recommendations. Start typing.') }} | ||
</template> | ||
<template #noResult> | ||
{{ noResultText }} | ||
</template> | ||
</NcSelect> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { generateOcsUrl } from '@nextcloud/router' | ||
import { getCurrentUser } from '@nextcloud/auth' | ||
import axios from '@nextcloud/axios' | ||
import debounce from 'debounce' | ||
import { NcSelect } from '@nextcloud/vue' | ||
import { mapState } from 'vuex' | ||
import formatting from '../../../shared/mixins/formatting.js' | ||
import ShareTypes from '../mixins/shareTypesMixin.js' | ||
export default { | ||
name: 'TransferForm', | ||
components: { | ||
NcSelect, | ||
}, | ||
mixins: [ShareTypes, formatting], | ||
props: { | ||
newOwnerUserId: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
query: '', | ||
loading: false, | ||
minSearchStringLength: 1, | ||
maxAutocompleteResults: 20, | ||
recommendations: [], | ||
suggestions: [], | ||
} | ||
}, | ||
computed: { | ||
...mapState(['tables', 'tablesLoading']), | ||
isValidQuery() { | ||
return this.query && this.query.trim() !== '' && this.query.length > this.minSearchStringLength | ||
}, | ||
options() { | ||
if (this.isValidQuery) { | ||
return this.suggestions | ||
} | ||
return this.recommendations | ||
}, | ||
noResultText() { | ||
if (this.loading) { | ||
return t('tables', 'Searching …') | ||
} | ||
return t('tables', 'No elements found.') | ||
}, | ||
}, | ||
mounted() { | ||
this.getRecommendations() | ||
}, | ||
methods: { | ||
addShare(id) { | ||
this.newOwnerUserId = id | ||
}, | ||
async asyncFind(query) { | ||
this.query = query.trim() | ||
if (this.isValidQuery) { | ||
this.loading = true | ||
await this.debounceGetSuggestions(query) | ||
} | ||
}, | ||
async getSuggestions(search) { | ||
this.loading = true | ||
const shareType = [ | ||
this.SHARE_TYPES.SHARE_TYPE_USER, | ||
] | ||
const request = await axios.get(generateOcsUrl('apps/files_sharing/api/v1/sharees'), { | ||
params: { | ||
format: 'json', | ||
itemType: 'file', | ||
search, | ||
perPage: this.maxAutocompleteResults, | ||
shareType, | ||
}, | ||
}) | ||
const data = request.data.ocs.data | ||
const exact = data.exact | ||
data.exact = [] | ||
const rawExactSuggestions = Object.values(exact).reduce((arr, elem) => arr.concat(elem), []) | ||
const rawSuggestions = Object.values(data).reduce((arr, elem) => arr.concat(elem), []) | ||
const exactSuggestions = this.filterOutCurrentUser(rawExactSuggestions) | ||
.map(share => this.formatForSelect(share)) | ||
const suggestions = this.filterOutCurrentUser(rawSuggestions) | ||
.map(share => this.formatForSelect(share)) | ||
this.suggestions = exactSuggestions.concat(suggestions) | ||
this.loading = false | ||
console.info('suggestions', this.suggestions) | ||
}, | ||
debounceGetSuggestions: debounce(function (...args) { | ||
this.getSuggestions(...args) | ||
}, 300), | ||
async getRecommendations() { | ||
this.loading = true | ||
const request = await axios.get(generateOcsUrl('apps/files_sharing/api/v1/sharees_recommended'), { | ||
params: { | ||
format: 'json', | ||
itemType: 'file', | ||
}, | ||
}) | ||
const exact = request.data.ocs.data.exact | ||
// flatten array of arrays | ||
const rawRecommendations = Object.values(exact).reduce((arr, elem) => arr.concat(elem), []) | ||
this.recommendations = this.filterOutCurrentUser(rawRecommendations) | ||
.map(share => this.formatForSelect(share)) | ||
this.loading = false | ||
console.info('recommendations', this.recommendations) | ||
}, | ||
filterOutCurrentUser(shares) { | ||
return shares.reduce((arr, share) => { | ||
if (typeof share !== 'object') { | ||
return arr | ||
} | ||
try { | ||
if (share.value.shareWith === getCurrentUser().uid) { | ||
return arr | ||
} | ||
arr.push(share) | ||
} catch { | ||
return arr | ||
} | ||
return arr | ||
}, []) | ||
}, | ||
formatForSelect(result) { | ||
return { | ||
user: result.uuid || result.value.shareWith, | ||
displayName: result.name || result.label, | ||
icon: 'icon-user', | ||
key: result.uuid || result.label, | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.multiselect { | ||
width: 100% !important; | ||
max-width: 100% !important; | ||
} | ||
</style> |
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
Oops, something went wrong.