Skip to content

Commit

Permalink
Load and display quick actions
Browse files Browse the repository at this point in the history
To provide a quick way of executing certain actions, we have implemented quick actions.
Every extension can define own quick action by creating an object called quickActions and exporting it.
Quick actions are then displayed in the actions column inside of the files list.
  • Loading branch information
LukasHirt committed Jun 4, 2020
1 parent f5d0596 commit 59374aa
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 186 deletions.
1 change: 1 addition & 0 deletions apps/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@babel/preset-env": "^7.6.0",
"@babel/register": "^7.6.0",
"babel-loader": "^8.0.6",
"copy-to-clipboard": "^3.3.1",
"core-js": "3.6.4",
"css-loader": "^3.1.0",
"intersection-observer": "^0.7.0",
Expand Down
17 changes: 11 additions & 6 deletions apps/files/src/components/AllFilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</div>
<div
:class="{ 'uk-visible@s': !_sidebarOpen, 'uk-hidden': _sidebarOpen }"
class="uk-text-nowrap uk-text-meta uk-width-small uk-margin-right"
class="uk-text-nowrap uk-text-meta uk-width-small"
>
<sortable-column-header
:aria-label="$gettext('Sort files by updated time')"
Expand All @@ -45,7 +45,7 @@
@click="toggleSort('mdateMoment')"
>
<translate
translate-context="Short column label in files able for the time at which a file was modified"
translate-context="Short column label in files table for the time at which a file was modified"
>Updated</translate
>
</sortable-column-header>
Expand Down Expand Up @@ -91,6 +91,9 @@
{{ formDateFromNow(rowItem.mdate) }}
</div>
</template>
<template #rowActions="{ item: rowItem }">
<quick-actions :actions="app.quickActions" :item="rowItem" />
</template>
<template #noContentMessage>
<no-content-message v-if="!$_isFavoritesList" icon="folder">
<template #message
Expand Down Expand Up @@ -155,11 +158,12 @@ import FileList from './FileList.vue'
import Indicators from './FilesLists/Indicators.vue'
import FileItem from './FileItem.vue'
import NoContentMessage from './NoContentMessage.vue'
import { mapGetters, mapActions, mapState } from 'vuex'
import QuickActions from './FilesLists/QuickActions.vue'
import SortableColumnHeader from './FilesLists/SortableColumnHeader.vue'
import { mapGetters, mapActions, mapState } from 'vuex'
import Mixins from '../mixins'
import FileActions from '../fileactions'
import SortableColumnHeader from './FilesLists/SortableColumnHeader.vue'
import intersection from 'lodash/intersection'
import { shareTypes, userShareTypes } from '../helpers/shareTypes'
import { getParentPaths } from '../helpers/path'
Expand All @@ -171,7 +175,8 @@ export default {
Indicators,
FileItem,
NoContentMessage,
SortableColumnHeader
SortableColumnHeader,
QuickActions
},
mixins: [Mixins, FileActions],
props: {
Expand Down Expand Up @@ -199,7 +204,7 @@ export default {
}
},
computed: {
...mapState(['route']),
...mapState(['route', 'app']),
...mapGetters('Files', [
'loadingFolder',
'activeFiles',
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/components/Collaborators/SharedFilesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
translate-context="Owner table column"
v-text="$gettext('Owner')"
/>
<div class="uk-visible@s uk-text-nowrap uk-text-meta uk-width-small uk-margin-right">
<div class="uk-visible@s uk-text-nowrap uk-text-meta uk-width-small">
<sortable-column-header
:aria-label="$gettext('Sort files by share time')"
:is-active="fileSortField == 'shareTimeMoment'"
Expand All @@ -53,6 +53,7 @@
<translate translate-context="Share time column in files table">Share time</translate>
</sortable-column-header>
</div>
<div class="oc-icon" />
</template>
<template #rowColumns="{ item }">
<div class="uk-text-truncate uk-width-expand">
Expand Down
17 changes: 14 additions & 3 deletions apps/files/src/components/FileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
/>
</div>
<slot name="headerColumns" />
<div class="uk-margin-small-right oc-icon" />
<div
v-if="$scopedSlots.rowActions"
class="uk-text-nowrap uk-text-meta uk-text-right uk-width-small"
>
<translate translate-context="Short column label in files table for the actions"
>Actions</translate
>
</div>
</oc-grid>
<div v-if="!loading" id="files-list-container" class="uk-flex-1 uk-overflow-auto">
<RecycleScroller
Expand Down Expand Up @@ -61,7 +68,11 @@
/>
</div>
<slot name="rowColumns" :item="rowItem" :index="index" />
<div class="uk-text-right uk-margin-left uk-margin-small-right">
<div
class="uk-flex uk-flex-middle uk-flex-right"
:class="{ 'uk-width-small': $scopedSlots.rowActions }"
>
<slot name="rowActions" :item="rowItem" />
<oc-button
:id="actionsDropdownButtonId(rowItem.viewId, active)"
class="files-list-row-show-actions"
Expand Down Expand Up @@ -101,7 +112,7 @@ import { mapGetters, mapActions, mapState } from 'vuex'
import { RecycleScroller } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
const RowActionsDropdown = () => import('./FilesLists/RowActionsDropdown.vue')
import RowActionsDropdown from './FilesLists/RowActionsDropdown.vue'
export default {
name: 'FileList',
Expand Down
43 changes: 43 additions & 0 deletions apps/files/src/components/FilesLists/QuickActions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div>
<oc-button
v-for="action in actions"
:id="`files-quick-action-${action.id}`"
:key="action.label"
:aria-label="$gettext(action.label)"
variation="raw"
@click.native.stop="
action.handler({ item, client: $client, capabilities, alert: showMessage })
"
>
<oc-icon :name="action.icon" aria-hidden="true" size="small" class="uk-flex" />
</oc-button>
</div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
export default {
name: 'QuickActions',
props: {
actions: {
type: Object,
required: true
},
item: {
type: Object,
required: true
}
},
computed: {
...mapGetters(['capabilities'])
},
methods: {
...mapActions(['showMessage'])
}
}
</script>
3 changes: 2 additions & 1 deletion apps/files/src/components/Trashbin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class="uk-text-nowrap uk-text-meta uk-width-small"
>
<sortable-column-header
class="uk-align-right uk-margin-right"
class="uk-align-right"
:aria-label="$gettext('Sort files by deletion time')"
:is-active="fileSortField === 'deleteTimestampMoment'"
:is-desc="fileSortDirectionDesc"
Expand All @@ -36,6 +36,7 @@
</translate>
</sortable-column-header>
</div>
<div class="oc-icon" />
</template>
<template #rowColumns="{ item }">
<div class="uk-text-truncate uk-width-expand">
Expand Down
42 changes: 42 additions & 0 deletions apps/files/src/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'core-js/stable'
import 'regenerator-runtime/runtime'
import moment from 'moment'
import copyToClipboard from 'copy-to-clipboard'

import FilesApp from './components/FilesApp.vue'
import FileInfoVersions from './components/FileInfoVersions.vue'
Expand Down Expand Up @@ -217,11 +219,51 @@ const routes = [
}
]

const quickActions = {
publicLink: {
id: 'public-link',
label: $gettext('Create and copy public link'),
icon: 'link',
handler: ctx => {
// FIXME: Translate name
const params = { name: 'Quick action link' }
const expirationDate = ctx.capabilities.files_sharing.public.expire_date

if (expirationDate.enabled) {
params.expireDate = moment()
.add(parseInt(expirationDate.days, 10), 'days')
.endOf('day')
.toISOString()
}

return new Promise((resolve, reject) => {
ctx.client.shares
.shareFileWithLink(ctx.item.path, params)
.then(res => {
copyToClipboard(res.shareInfo.url)
ctx.alert({
title: $gettext('Public link created'),
desc: $gettext(
'Public link has been successfully created and copied into your clipboard.'
),
status: 'success'
})
resolve()
})
.catch(e => {
reject(e)
})
})
}
}
}

const translations = translationsJson
export default define({
appInfo,
store,
routes,
navItems,
quickActions,
translations
})
Loading

0 comments on commit 59374aa

Please sign in to comment.