Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow registering aliases without components
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 21, 2019
commit 35da0dad93f6a2c0545170a4b4511f69748dcf1e
1 change: 0 additions & 1 deletion src/models/videos.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default {
'video/ogg',
'video/webm',
'video/mp4',
'video/x-matroska',
'video/x-m4v',
'video/x-flv',
'video/quicktime'
Expand Down
53 changes: 35 additions & 18 deletions src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,13 @@ export default {
// store current position
this.currentIndex = this.fileList.findIndex(file => file.name === fileName)

// get saved fileInfo
fileInfo = this.fileList[this.currentIndex]

// override mimetype if existing alias
mime = this.getAliasIfAny(mime)

if (this.components[mime]) {
mime = this.getAliasIfAny(mime)
this.currentFile = {
relativePath,
path,
Expand All @@ -219,9 +223,10 @@ export default {
modal: this.components[mime],
loaded: false
}
this.updatePreviousNext()
} else {
console.error(`The following file could not be displayed because to view matches its mime type`, fileName, fileInfo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this could be easier written?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to be a dev debug. Since no regular user would open the console I guess 🤔
But I've always been terrible at writing error messages, so feel free to suggest a simpler one 😁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skjnldsv Hey no worries. I thought it was just unclear what it said. I am actually struggling understanding: "because to view matches". What about this: "The following file could not be displayed due to it's mime type"?

}

this.updatePreviousNext()
},

/**
Expand Down Expand Up @@ -336,19 +341,13 @@ export default {
return
}

// checking valid handler component data
if (!handler.component || typeof handler.component !== 'object') {
// checking valid handler component data AND no alias (we can register alias without component)
if ((!handler.component || typeof handler.component !== 'object') && !handler.mimesAliases) {
console.error(`The following handler doesn't have proper component`, handler)
return
}

handler.mimes.forEach(mime => {
// checking valid mime
if (this.components[mime]) {
console.error(`The following mime is already registered`, mime, handler)
return
}

const register = ({ mime, handler }) => {
// unregistered handler, let's go!
OCA.Files.fileActions.registerAction({
name: 'view',
Expand All @@ -369,19 +368,37 @@ export default {
this.mimeGroups[handler.group].push(mime)
}

if (handler.mimesAliases) {
Object.keys(handler.mimesAliases).forEach(mime => {
this.mimesAliases[mime] = handler.mimesAliases[mime]
})
}

// set the handler as registered
this.registeredHandlers.push(handler.id)
}

handler.mimes.forEach(mime => {
// checking valid mime
if (this.components[mime]) {
console.error(`The following mime is already registered`, mime, handler)
return
}

register({ mime, handler })

// register mime's component
this.components[mime] = handler.component
Vue.component(handler.component.name, handler.component)
})

if (handler.mimesAliases) {
Object.keys(handler.mimesAliases).forEach(mime => {
// checking valid mime
if (this.components[mime]) {
console.error(`The following mime is already registered`, mime, handler)
return
}

register({ mime, handler })

this.mimesAliases[mime] = handler.mimesAliases[mime]
})
}
},

getPath(fileInfo) {
Expand Down