Skip to content

Commit

Permalink
Merge pull request #6156 from owncloud/app_apis
Browse files Browse the repository at this point in the history
Move common app logic to useAppDefaults composable
  • Loading branch information
kulmann authored Jan 19, 2022
2 parents 6fca4a3 + f87a301 commit ab6974b
Show file tree
Hide file tree
Showing 30 changed files with 433 additions and 95 deletions.
27 changes: 16 additions & 11 deletions packages/web-app-draw-io/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ import { basename } from 'path'
import queryString from 'query-string'
import { DateTime } from 'luxon'
import { DavPermission, DavProperty } from 'web-pkg/src/constants'
import { useAppDefaults } from 'web-pkg/src/composables/useAppDefaults'
export default {
name: 'DrawIoEditor',
setup() {
return {
...useAppDefaults({
applicationName: 'draw-io'
})
}
},
data: () => ({
loading: true,
filePath: '',
Expand All @@ -38,7 +46,7 @@ export default {
url = 'https://embed.diagrams.net',
theme = 'minimal',
autosave = false
} = this.$store.state.apps.fileEditors.find((editor) => editor.app === 'draw-io').config || {}
} = this.applicationConfig
return { url, theme, autosave: autosave ? 1 : 0 }
},
iframeSource() {
Expand All @@ -56,7 +64,7 @@ export default {
}
},
created() {
this.filePath = this.$route.params.filePath
this.filePath = this.currentFileContext.path
this.fileExtension = this.filePath.split('.').pop()
this.checkPermissions()
window.addEventListener('message', (event) => {
Expand Down Expand Up @@ -87,8 +95,7 @@ export default {
})
},
checkPermissions() {
this.$client.files
.fileInfo(this.filePath, [DavProperty.Permissions])
this.getFileInfo(this.filePath, [DavProperty.Permissions])
.then((v) => {
this.isReadOnly =
v.fileInfo[DavProperty.Permissions].indexOf(DavPermission.Updateable) === -1
Expand All @@ -99,8 +106,7 @@ export default {
})
},
load() {
this.$client.files
.getFileContents(this.filePath, { resolveWithResponseObject: true })
this.getFileContents(this.filePath, { resolveWithResponseObject: true })
.then((resp) => {
this.currentETag = resp.headers.ETag
this.$refs.drawIoEditor.contentWindow.postMessage(
Expand All @@ -117,7 +123,7 @@ export default {
})
},
importVisio() {
const url = this.$client.files.getFileUrl(this.filePath)
const url = this.getFileUrl(this.filePath)
const headers = new Headers({
Authorization: 'Bearer ' + this.getToken,
'X-Requested-With': 'XMLHttpRequest'
Expand Down Expand Up @@ -161,10 +167,9 @@ export default {
})
},
save(payload) {
this.$client.files
.putFileContents(this.filePath, payload.xml, {
previousEntityTag: this.currentETag
})
this.putFileContents(this.filePath, payload.xml, {
previousEntityTag: this.currentETag
})
.then((resp) => {
this.currentETag = resp.ETag
this.$refs.drawIoEditor.contentWindow.postMessage(
Expand Down
37 changes: 18 additions & 19 deletions packages/web-app-draw-io/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@ import App from './App.vue'

const routes = [
{
name: 'edit',
path: '/edit/:filePath',
name: 'draw-io',
path: '/:contextRouteName/:filePath*',
components: {
fullscreen: App
},
meta: { hideHeadbar: true }
meta: {
hideHeadbar: true,
patchCleanPath: true
}
}
]

const routesForFileExtensions = [
'files-spaces-storage',
'files-common-favorites',
'files-shares-with-others',
'files-shares-with-me',
'files-public-files'
]

const appInfo = {
name: 'Draw.io',
id: 'draw-io',
Expand All @@ -20,31 +31,19 @@ const appInfo = {
{
extension: 'drawio',
newTab: true,
routeName: 'draw-io-edit',
routeName: 'draw-io',
newFileMenu: {
menuTitle($gettext) {
return $gettext('New draw.io document…')
}
},
routes: [
'files-spaces-storage',
'files-common-favorites',
'files-shares-with-others',
'files-shares-with-me',
'files-public-files'
]
routes: routesForFileExtensions
},
{
extension: 'vsdx',
newTab: true,
routeName: 'draw-io-edit',
routes: [
'files-spaces-storage',
'files-common-favorites',
'files-shares-with-others',
'files-shares-with-me',
'files-public-files'
]
routeName: 'draw-io',
routes: routesForFileExtensions
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref, computed, ComputedRef, unref } from '@vue/composition-api'
import { MaybeRef } from '../utils'
import { MaybeRef } from 'web-pkg/src/utils'

interface PaginationOptions<T> {
page: MaybeRef<number>
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/composables/useSort/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ref, computed, ComputedRef, unref } from '@vue/composition-api'
import { MaybeRef, MaybeReadonlyRef } from '../utils'
import { MaybeRef, MaybeReadonlyRef } from 'web-pkg/src/utils'

export enum SortDir {
Desc = 'desc',
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-files/src/composables/utils/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
ArchiverService,
archiverService as defaultArchiverService,
ClientService,
clientService as defaultClientService
} from '../../services'

import { ArchiverService, archiverService as defaultArchiverService } from '../../services'
import { ClientService, clientService as defaultClientService } from 'web-pkg/src/services'
import { major } from 'semver'
import { RuntimeError } from 'web-runtime/src/container/error'

Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/helpers/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './asset'
export * from './filter'
export * from './privatePreviewBlob'
export * from './publicPreviewUrl'
export * from './resource'
export * from './sameResource'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { encodePath } from 'web-pkg/src/utils'
import { clientService, cacheService } from '../../services'
import { cacheService } from '../../services'
import { clientService } from 'web-pkg/src/services'
import { buildQueryString } from './common'
import isEqual from 'lodash-es/isEqual'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { buildQueryString } from './common'
import { clientService } from '../../services'
import { clientService } from 'web-pkg/src/services'

interface PublicPreviewUrlOptions {
resource: {
Expand Down
2 changes: 2 additions & 0 deletions packages/web-app-files/src/helpers/resource/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// TODO: add more fields to the resource interface. Extend into different resource types: FileResource, FolderResource, ShareResource, IncomingShareResource, OutgoingShareResource, ...
export interface Resource {
id: number | string
path: string
downloadURL?: string
}
4 changes: 3 additions & 1 deletion packages/web-app-files/src/helpers/user/avatarUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { cacheService, clientService } from '../../services'
import { cacheService } from '../../services'
import { clientService } from 'web-pkg/src/services'

import { ImageDimension } from '../../constants'

interface AvatarUrlOptions {
Expand Down
29 changes: 12 additions & 17 deletions packages/web-app-files/src/mixins/fileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,18 @@ export default {
filePath
})

const routeOpts = {
name: editor.routeName || editor.app,
params: {
filePath,
fileId,
mode,
contextRouteName: this.$route.name
}
}

if (editor.newTab) {
const path = this.$router.resolve({
name: editor.routeName,
params: {
filePath,
fileId,
mode
}
}).href
const path = this.$router.resolve(routeOpts).href
const target = `${editor.routeName}-${filePath}`
const win = window.open(path, target)
// in case popup is blocked win will be null
Expand All @@ -149,15 +152,7 @@ export default {
return
}

this.$router.push({
name: editor.routeName || editor.app,
params: {
filePath,
fileId,
mode,
contextRouteName: this.$route.name
}
})
this.$router.push(routeOpts)
},

// TODO: Make user-configurable what is a defaultAction for a filetype/mimetype
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/search/sdk/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SearchList, SearchResult } from 'search/src/types'
import ListComponent from '../../components/Search/List.vue'
import { clientService } from '../../services'
import { clientService } from 'web-pkg/src/services'
import { buildResource } from '../../helpers/resources'
import { Component } from 'vue'
import { DavProperties } from 'web-pkg/src/constants'
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/search/sdk/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SearchPreview, SearchResult } from 'search/src/types'
import PreviewComponent from '../../components/Search/Preview.vue'
import { clientService } from '../../services'
import { clientService } from 'web-pkg/src/services'
import { buildResource } from '../../helpers/resources'
import { Cache } from 'web-pkg/src/cache'
import { debounce } from 'web-pkg/src/decorator'
Expand Down
1 change: 0 additions & 1 deletion packages/web-app-files/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './archiver'
export * from './cache'
export * from './client'
export { default as Registry } from './registry'
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ describe('isSameResource', () => {
test('evaluates to false if one of the resources is nullish', () => {
expect(isSameResource(null, null)).toBe(false)
expect(isSameResource(undefined, undefined)).toBe(false)
expect(isSameResource(null, { id: 1 })).toBe(false)
expect(isSameResource(undefined, { id: 1 })).toBe(false)
expect(isSameResource({ id: 1 }, null)).toBe(false)
expect(isSameResource({ id: 1 }, undefined)).toBe(false)
expect(isSameResource(null, { id: 1, path: '' })).toBe(false)
expect(isSameResource(undefined, { id: 1, path: '' })).toBe(false)
expect(isSameResource({ id: 1, path: '' }, null)).toBe(false)
expect(isSameResource({ id: 1, path: '' }, undefined)).toBe(false)
})
test('evaluates to false if ids are of different types', () => {
expect(isSameResource({ id: 1 }, { id: '1' })).toBe(false)
expect(isSameResource({ id: 1, path: '' }, { id: '1', path: '' })).toBe(false)
})
test('evaluates to false if ids are different values', () => {
expect(isSameResource({ id: 1 }, { id: 2 })).toBe(false)
expect(isSameResource({ id: '1' }, { id: '2' })).toBe(false)
expect(isSameResource({ id: 1, path: '' }, { id: 2, path: '' })).toBe(false)
expect(isSameResource({ id: '1', path: '' }, { id: '2', path: '' })).toBe(false)
})
test('evaluates to true if ids are the same', () => {
expect(isSameResource({ id: 1 }, { id: 1 })).toBe(true)
expect(isSameResource({ id: '1' }, { id: '1' })).toBe(true)
expect(isSameResource({ id: 1, path: '' }, { id: 1, path: '' })).toBe(true)
expect(isSameResource({ id: '1', path: '' }, { id: '1', path: '' })).toBe(true)
})
})
2 changes: 1 addition & 1 deletion packages/web-app-files/tests/unit/search/sdk.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createLocalVue } from '@vue/test-utils'
import { SDKSearch } from '../../../src/search'
import { clientService } from '../../../src/services'
import { clientService } from 'web-pkg/src/services'
import Vuex from 'vuex'
import VueRouter from 'vue-router'

Expand Down
Loading

0 comments on commit ab6974b

Please sign in to comment.