Skip to content

Commit

Permalink
batch actions for Accept and Decline in Shared with me
Browse files Browse the repository at this point in the history
  • Loading branch information
elizavetaRa committed Jun 8, 2021
1 parent 52feb0f commit 2f3c0c1
Showing 1 changed file with 112 additions and 2 deletions.
114 changes: 112 additions & 2 deletions packages/web-app-files/src/components/BatchActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,32 @@
<translate>Delete</translate>
</oc-button>
</div>
<div v-if="canAccept">
<oc-button id="accept-shares-btn" key="accept-shares-btn" @click="acceptShares()">
<oc-icon name="add" />
<translate>Accept</translate>
</oc-button>
</div>
<div v-if="canDecline">
<oc-button id="decline-shares-btn" key="decline-shares-btn" @click="declineShares()">
<oc-icon name="not_interested" />
<translate>Decline</translate>
</oc-button>
</div>
</oc-grid>
</div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import { mapGetters, mapActions, mapMutations } from 'vuex'
import MixinRoutes from '../mixins/routes'
import MixinDeleteResources from '../mixins/deleteResources'
import { cloneStateObject } from '../helpers/store'
import { canBeMoved } from '../helpers/permissions'
import { checkRoute } from '../helpers/route'
import { shareStatus } from '../helpers/shareStatus'
import { buildSharedResource } from '../helpers/resources'
export default {
mixins: [MixinRoutes, MixinDeleteResources],
Expand Down Expand Up @@ -102,13 +116,41 @@ export default {
},
canDelete() {
if (this.isPublicFilesRoute) {
if (this.isPublicFilesRoute && !checkRoute(['files-shared-with-me'], this.$route.name)) {
return this.currentFolder.canBeDeleted()
}
if (checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}
return true
},
canAccept() {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}
let canAccept = true
this.selectedFiles.forEach(file => {
if (file.status === shareStatus.accepted) {
canAccept = false
}
})
return canAccept
},
canDecline() {
if (!checkRoute(['files-shared-with-me'], this.$route.name)) {
return false
}
let canDecline = true
this.selectedFiles.forEach(file => {
if (file.status === shareStatus.declined) canDecline = false
})
return canDecline
},
displayBulkActions() {
return this.$route.meta.hasBulkActions && this.selectedFiles.length > 0
}
Expand All @@ -117,6 +159,12 @@ export default {
methods: {
...mapActions('Files', ['removeFilesFromTrashbin', 'resetFileSelection', 'setHighlightedFile']),
...mapActions(['showMessage']),
...mapMutations('Files', [
'LOAD_FILES',
'SELECT_RESOURCES',
'CLEAR_CURRENT_FILES_LIST',
'UPDATE_RESOURCE'
]),
restoreFiles(resources = this.selectedFiles) {
for (const resource of resources) {
Expand Down Expand Up @@ -189,6 +237,68 @@ export default {
})
}
})
},
acceptShares() {
this.selectedFiles.forEach(resource => {
this.triggerShareAction(resource, 'POST')
})
},
declineShares() {
this.selectedFiles.forEach(resource => {
this.triggerShareAction(resource, 'DELETE')
})
},
async triggerShareAction(resource, type) {
try {
// exec share action
let response = await this.$client.requests.ocs({
service: 'apps/files_sharing',
action: `api/v1/shares/pending/${resource.share.id}`,
method: type
})
// exit on failure
if (response.status !== 200) {
throw new Error(response.statusText)
}
// get updated share from response or re-fetch it
let share = null
// oc10
if (parseInt(response.headers.get('content-length')) > 0) {
response = await response.json()
if (response.ocs.data.length > 0) {
share = response.ocs.data[0]
}
} else {
// ocis
const { shareInfo } = await this.$client.shares.getShare(resource.share.id)
share = shareInfo
}
// update share in store
if (share) {
const sharedResource = await buildSharedResource(
share,
true,
!this.isOcis,
this.configuration.server,
this.getToken
)
this.UPDATE_RESOURCE(sharedResource)
this.SELECT_RESOURCES([])
}
} catch (error) {
// this.loadResources()
this.showMessage({
title: this.$gettext('Error while changing share state'),
desc: error.message,
status: 'danger',
autoClose: {
enabled: true
}
})
}
}
}
}
Expand Down

0 comments on commit 2f3c0c1

Please sign in to comment.