Skip to content

Commit

Permalink
Move quickActions into own file and pass store into context
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasHirt committed Jun 9, 2020
1 parent 59374aa commit dd3ba3d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
14 changes: 1 addition & 13 deletions apps/files/src/components/FilesLists/QuickActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
:key="action.label"
:aria-label="$gettext(action.label)"
variation="raw"
@click.native.stop="
action.handler({ item, client: $client, capabilities, alert: showMessage })
"
@click.native.stop="action.handler({ item, client: $client, store: $store })"
>
<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',
Expand All @@ -30,14 +26,6 @@ export default {
type: Object,
required: true
}
},
computed: {
...mapGetters(['capabilities'])
},
methods: {
...mapActions(['showMessage'])
}
}
</script>
48 changes: 6 additions & 42 deletions apps/files/src/default.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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 All @@ -11,8 +9,9 @@ import FileLinkSidebar from './components/FileLinkSidebar.vue'
import PrivateLink from './components/PrivateLink.vue'
import PublicLink from './components/PublicLinks/PublicLink.vue'
import FilesDrop from './components/PublicLinks/FilesDrop.vue'
import translationsJson from '../l10n/translations.json'

import translationsJson from '../l10n/translations.json'
import quickActionsImport from './quickActions'
const store = require('./store')

// just a dummy function to trick gettext tools
Expand Down Expand Up @@ -219,46 +218,11 @@ 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)
})
})
}
}
}

// Prepare imported modules to be exported
// If we do not define these constants, the export will be undefined
const translations = translationsJson
const quickActions = quickActionsImport

export default define({
appInfo,
store,
Expand Down
49 changes: 49 additions & 0 deletions apps/files/src/quickActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import moment from 'moment'
import copyToClipboard from 'copy-to-clipboard'

// just a dummy function to trick gettext tools
function $gettext(msg) {
return msg
}

function createPublicLink(ctx) {
// FIXME: Translate name
const params = { name: 'Quick action link' }
const capabilities = ctx.store.state.user.capabilities
const expirationDate = 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.store.dispatch('showMessage', {
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)
})
})
}

export default {
publicLink: {
id: 'public-link',
label: $gettext('Create and copy public link'),
icon: 'link',
handler: createPublicLink
}
}
2 changes: 1 addition & 1 deletion changelog/unreleased/load-and-display-quick-actions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Enhancement: Load and display quick actions

We've added an extension point into files apps for quick actions.
By creating and exporting object called quickActions, developers can define an action which will be then displayed in the files list.
By creating and exporting an object called quickActions, developers can define an action which will be then displayed in the files list.

https://github.com/owncloud/phoenix/pull/3573

0 comments on commit dd3ba3d

Please sign in to comment.