Skip to content

Commit 52613b0

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

File tree

4 files changed

+62
-25
lines changed

4 files changed

+62
-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: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,32 @@ 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 {
167+
handler: () => this.$_fileActions_openLink(externalAppsActions[0].name, resource.fileId)
168+
}
169+
}
170+
171+
// fallback: system actions
172+
return this.$_fileActions_systemActions.filter(filterCallback)
151173
},
152174

153175
$_fileActions_getAllAvailableActions(resource) {
@@ -176,35 +198,40 @@ export default {
176198
return []
177199
}
178200

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

183204
return appProviders.map((app) => {
184205
const label = this.$gettext('Open in %{ appName }')
185206
return {
207+
name: app.name,
186208
img: app.icon,
187209
componentType: 'oc-button',
188210
class: `oc-files-actions-${app.name}-trigger`,
189211
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-
},
212+
canBeDefault: defaultApplication === app.name,
213+
handler: () => this.$_fileActions_openLink(app, resource.fileId),
205214
label: () => this.$gettextInterpolate(label, { appName: app.name })
206215
}
207216
})
217+
},
218+
219+
$_fileActions_openLink(appName, resourceId) {
220+
const routeData = this.$router.resolve({
221+
name: 'external-apps',
222+
params: {
223+
file_id: resourceId,
224+
app: appName
225+
},
226+
// public-token retrieval is weak, same as packages/web-app-files/src/index.js:106
227+
query: {
228+
...(this.isPublicPage && {
229+
'public-token': (this.$route.params.item || '').split('/')[0]
230+
})
231+
}
232+
})
233+
// TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
234+
window.open(routeData.href, '_blank')
208235
}
209236
}
210237
}

0 commit comments

Comments
 (0)