@@ -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 . name , 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