-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move sharing indicators into own component and add extension point
Moved to smaller components Load custom indicators as part of extension Added click handler Use parentPath and add docs Added missing sharesTree getter Extended docs Added props
- Loading branch information
Showing
9 changed files
with
316 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
apps/files/src/components/FilesLists/StatusIndicators/DefaultIndicators.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<template> | ||
<div> | ||
<oc-button | ||
v-for="(indicator, index) in indicators" | ||
:key="index" | ||
class="file-row-share-indicator uk-text-middle" | ||
:class="{ 'uk-margin-xsmall-left' : index > 0 }" | ||
:aria-label="indicator.label" | ||
@click="indicator.handler(item, indicator.id)" | ||
variation="raw" | ||
> | ||
<oc-icon | ||
:name="indicator.icon" | ||
class="uk-text-middle" | ||
size="small" | ||
:variation="indicator.status" | ||
/> | ||
</oc-button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import intersection from 'lodash/intersection' | ||
import { mapGetters } from 'vuex' | ||
import { shareTypes } from '../../../helpers/shareTypes' | ||
import { getParentPaths } from '../../../helpers/path' | ||
const userShareTypes = [shareTypes.user, shareTypes.group, shareTypes.guest, shareTypes.remote] | ||
export default { | ||
name: 'StatusIndicators', | ||
props: { | ||
item: { | ||
type: Object, | ||
required: true | ||
}, | ||
parentPath: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
computed: { | ||
...mapGetters('Files', ['sharesTree']), | ||
indicators () { | ||
const indicators = [] | ||
if (this.isUserShare(this.item)) { | ||
indicators.push({ | ||
id: 'files-sharing', | ||
label: this.shareUserIconLabel(this.item), | ||
icon: 'group', | ||
status: this.shareUserIconVariation(this.item), | ||
handler: this.indicatorHandler | ||
}) | ||
} | ||
if (this.isLinkShare(this.item)) { | ||
indicators.push({ | ||
id: 'file-link', | ||
label: this.shareLinkIconLabel(this.item), | ||
icon: 'link', | ||
status: this.shareLinkIconVariation(this.item), | ||
handler: this.indicatorHandler | ||
}) | ||
} | ||
return indicators | ||
}, | ||
shareTypesIndirect () { | ||
const parentPaths = getParentPaths(this.parentPath, true) | ||
if (parentPaths.length === 0) { | ||
return [] | ||
} | ||
// remove root entry | ||
parentPaths.pop() | ||
const shareTypes = {} | ||
parentPaths.forEach((parentPath) => { | ||
// TODO: optimize for performance by skipping once we got all known types | ||
const shares = this.sharesTree[parentPath] | ||
if (shares) { | ||
shares.forEach((share) => { | ||
// note: no distinction between incoming and outgoing shares as we display the same | ||
// indirect indicator for them | ||
shareTypes[share.info.share_type] = true | ||
}) | ||
} | ||
}) | ||
return Object.keys(shareTypes).map(shareType => parseInt(shareType, 10)) | ||
} | ||
}, | ||
methods: { | ||
isDirectUserShare (item) { | ||
return (intersection(userShareTypes, item.shareTypes).length > 0) | ||
}, | ||
isIndirectUserShare (item) { | ||
return (item.isReceivedShare() || intersection(userShareTypes, this.shareTypesIndirect).length > 0) | ||
}, | ||
isDirectLinkShare (item) { | ||
return (item.shareTypes.indexOf(shareTypes.link) >= 0) | ||
}, | ||
isIndirectLinkShare () { | ||
return (this.shareTypesIndirect.indexOf(shareTypes.link) >= 0) | ||
}, | ||
isUserShare (item) { | ||
return this.isDirectUserShare(item) || this.isIndirectUserShare(item) | ||
}, | ||
isLinkShare (item) { | ||
return this.isDirectLinkShare(item) || this.isIndirectLinkShare(item) | ||
}, | ||
shareUserIconVariation (item) { | ||
return this.isDirectUserShare(item) ? 'active' : 'passive' | ||
}, | ||
shareLinkIconVariation (item) { | ||
return this.isDirectLinkShare(item) ? 'active' : 'passive' | ||
}, | ||
shareUserIconLabel (item) { | ||
return this.isDirectUserShare(item) ? this.$gettext('Directly shared with collaborators') : this.$gettext('Shared with collaborators through one of the parent folders') | ||
}, | ||
shareLinkIconLabel (item) { | ||
return this.isDirectLinkShare(item) ? this.$gettext('Directly shared with links') : this.$gettext('Shared with links through one of the parent folders') | ||
}, | ||
indicatorHandler (item, sideBarName) { | ||
this.$emit('click', item, sideBarName) | ||
} | ||
} | ||
} | ||
</script> |
Oops, something went wrong.