Skip to content

Commit a04ba51

Browse files
committed
Use default app from app provider and early returns in fileActions
1 parent 906584f commit a04ba51

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Use default info from app provider
2+
3+
The app provider returns information about the default application per mime type. This information is now respected when triggering the default action for a file.
4+
5+
https://github.com/owncloud/web/issues/5962
6+
https://github.com/owncloud/web/pull/5970

packages/web-app-external/src/App.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ export default {
110110
111111
// fetch iframe params for app and file
112112
const configUrl = this.configuration.server
113-
const appOpenUrl = this.capabilities.files.app_providers[0].open_url.replace('/app', 'app')
114-
const url = configUrl + appOpenUrl + '?file_id=' + this.fileId + '&app_name=' + this.appName
113+
const appOpenUrl = this.capabilities.files.app_providers[0].open_url.replace(/^\/+/, '')
114+
const url =
115+
configUrl +
116+
appOpenUrl +
117+
`?file_id=${this.fileId}` +
118+
(this.appName ? `&app_name=${this.appName}` : '')
115119
116120
const response = await fetch(url, {
117121
method: 'POST',

packages/web-app-external/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const appInfo = {
1515
const routes = [
1616
{
1717
name: 'apps',
18-
path: '/:app/:file_id',
18+
path: '/:file_id/:app?',
1919
components: {
2020
app: App
2121
},

packages/web-app-files/src/mixins/fileActions.js

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,30 @@ export default {
144144
// returns the _first_ action from actions array which we now construct from
145145
// available mime-types coming from the app-provider and existing actions
146146
$_fileActions_triggerDefaultAction(resource) {
147-
const actions = this.$_fileActions_getAllAvailableActions(resource).filter(
148-
(action) => action.canBeDefault
149-
)
150-
actions[0].handler(resource, actions[0].handlerData)
147+
const action = this.$_fileActions_getDefaultAction(resource)
148+
action.handler(resource, action.handlerData)
149+
},
150+
151+
$_fileActions_getDefaultAction(resource) {
152+
const filterCallback = (action) =>
153+
action.canBeDefault && action.isEnabled({ resource, parent: this.currentFolder })
154+
155+
// first priority: handlers from config
156+
const defaultEditorActions = this.$_fileActions_editorActions.filter(filterCallback)
157+
if (defaultEditorActions.length) {
158+
return defaultEditorActions[0]
159+
}
160+
161+
// second priority: `/app/open` endpoint of app provider if available
162+
// FIXME: files app should not know anything about the `external apps` app
163+
const externalAppsActions =
164+
this.$_fileActions_loadExternalAppActions(resource).filter(filterCallback)
165+
if (externalAppsActions.length) {
166+
return externalAppsActions[0]
167+
}
168+
169+
// fallback: system actions
170+
return this.$_fileActions_systemActions.filter(filterCallback)
151171
},
152172

153173
$_fileActions_getAllAvailableActions(resource) {
@@ -176,35 +196,40 @@ export default {
176196
return []
177197
}
178198

179-
const { app_providers: appProviders = [] } = this.mimeTypes.find(
180-
(t) => t.mime_type === mimeType
181-
)
199+
const { app_providers: appProviders = [], default_application: defaultApplication } =
200+
this.mimeTypes.find((t) => t.mime_type === mimeType)
182201

183202
return appProviders.map((app) => {
184203
const label = this.$gettext('Open in %{ appName }')
185204
return {
205+
name: app.name,
186206
img: app.icon,
187207
componentType: 'oc-button',
188208
class: `oc-files-actions-${app.name}-trigger`,
189209
isEnabled: () => true,
190-
canBeDefault: true,
191-
handler: () => {
192-
const routeData = this.$router.resolve({
193-
name: 'external-apps',
194-
params: { app: app.name, file_id: resource.fileId },
195-
// public-token retrieval is weak, same as packages/web-app-files/src/index.js:106
196-
query: {
197-
...(this.isPublicPage && {
198-
'public-token': (this.$route.params.item || '').split('/')[0]
199-
})
200-
}
201-
})
202-
// TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
203-
window.open(routeData.href, '_blank')
204-
},
210+
canBeDefault: defaultApplication === app.name,
211+
handler: () => this.$_fileActions_openLink(app.name, resource.fileId),
205212
label: () => this.$gettextInterpolate(label, { appName: app.name })
206213
}
207214
})
215+
},
216+
217+
$_fileActions_openLink(appName, resourceId) {
218+
const routeData = this.$router.resolve({
219+
name: 'external-apps',
220+
params: {
221+
file_id: resourceId,
222+
app: appName
223+
},
224+
// public-token retrieval is weak, same as packages/web-app-files/src/index.js:106
225+
query: {
226+
...(this.isPublicPage && {
227+
'public-token': (this.$route.params.item || '').split('/')[0]
228+
})
229+
}
230+
})
231+
// TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
232+
window.open(routeData.href, '_blank')
208233
}
209234
}
210235
}

0 commit comments

Comments
 (0)