Skip to content

Commit

Permalink
fixup! Import file FileAction 28 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: greta <[email protected]>
  • Loading branch information
GretaD committed Oct 26, 2023
1 parent 7cf2329 commit 85d76de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/files-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,44 @@
*/
import { generateUrl } from '@nextcloud/router'
import { translate as t } from '@nextcloud/l10n'
import { registerFileAction, FileAction } from '@nextcloud/files'
import { registerFileAction, FileAction, Permission } from '@nextcloud/files'
import ContactSvg from '@mdi/svg/svg/account-multiple.svg?raw'
const mime = 'text/vcard'
const name = 'contacts-import'
const nextcloudVersionIs28 = parseInt(OC.config.version.split('.')[0]) === 28
const nextcloudVersionIsGreaterThanOr28 = parseInt(OC.config.version.split('.')[0]) >= 28

Check warning on line 28 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L28

Added line #L28 was not covered by tests

window.addEventListener('DOMContentLoaded', () => {
if (!nextcloudVersionIs28 && OCA.Files && OCA.Files.fileActions) {
OCA.Files.fileActions.registerAction({
name,
displayName: t('contacts', 'Import'),
mime,
permissions: OC.PERMISSION_READ,
iconClass: 'icon-contacts-dark',
actionHandler(fileName, context) {
const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}`
window.location = generateUrl(`/apps/contacts/import?file=${absPath}`)
},
})
OCA.Files.fileActions.setDefault(mime, name)
return
}
console.error('Unable to register vcf import action')
})
if (!nextcloudVersionIsGreaterThanOr28) {
window.addEventListener('DOMContentLoaded', () => {

Check warning on line 31 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L31

Added line #L31 was not covered by tests
if (OCA.Files && OCA.Files.fileActions) {
OCA.Files.fileActions.registerAction({

Check warning on line 33 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L33

Added line #L33 was not covered by tests
name,
displayName: t('contacts', 'Import'),
mime,
permissions: OC.PERMISSION_READ,
iconClass: 'icon-contacts-dark',
actionHandler(fileName, context) {

Check warning on line 39 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L39

Added line #L39 was not covered by tests
const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}`
window.location = generateUrl(`/apps/contacts/import?file=${absPath}`)

Check warning on line 41 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L41

Added line #L41 was not covered by tests
},
})
OCA.Files.fileActions.setDefault(mime, name)
return

Check warning on line 45 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L44-L45

Added lines #L44 - L45 were not covered by tests
}
console.error('Unable to register vcf import action')

Check warning on line 47 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L47

Added line #L47 was not covered by tests
})
}

if (nextcloudVersionIs28) {
if (nextcloudVersionIsGreaterThanOr28) {
registerFileAction(new FileAction({
name,
displayName() {
return t('contacts', 'Import')

Check warning on line 54 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L52-L54

Added lines #L52 - L54 were not covered by tests
},
default: 'default',
mime,
permissions: OC.PERMISSION_READ,
iconClass: 'icon-contacts-dark',
enabled: (nodes) => {
return nodes.every((node) => node.permissions & Permission.READ)

Check warning on line 59 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L58-L59

Added lines #L58 - L59 were not covered by tests
},
iconSvgInline: () => ContactSvg,
actionHandler(fileName, context) {

Check warning on line 62 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L61-L62

Added lines #L61 - L62 were not covered by tests
const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}`
window.location = generateUrl(`/apps/contacts/import?file=${absPath}`)

Check warning on line 64 in src/files-action.js

View check run for this annotation

Codecov / codecov/patch

src/files-action.js#L64

Added line #L64 was not covered by tests
Expand Down
1 change: 1 addition & 0 deletions src/init.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};

0 comments on commit 85d76de

Please sign in to comment.