gitlab-org--gitlab-foss/app/assets/javascripts/groups/components/group_item.vue

221 lines
5.2 KiB
Vue
Raw Normal View History

<script>
import eventHub from '../event_hub';
export default {
props: {
group: {
type: Object,
required: true,
},
baseGroup: {
type: Object,
required: false,
2017-05-31 20:41:55 +00:00
default: () => ({}),
},
2017-06-06 14:01:42 +00:00
collection: {
type: Object,
required: false,
default: () => ({}),
},
},
methods: {
2017-05-30 22:01:48 +00:00
onClickRowGroup(e) {
2017-05-31 02:23:03 +00:00
e.stopPropagation();
2017-05-30 22:01:48 +00:00
// Skip for buttons
2017-05-31 02:23:03 +00:00
if (!(e.target.tagName === 'A') && !(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
2017-05-30 22:01:48 +00:00
if (this.group.hasSubgroups) {
eventHub.$emit('toggleSubGroups', this.group);
} else {
2017-06-16 08:54:20 +00:00
window.location.href = this.group.groupPath;
2017-05-30 22:01:48 +00:00
}
2017-05-16 14:29:38 +00:00
}
},
2017-05-30 08:12:06 +00:00
onLeaveGroup(e) {
e.preventDefault();
// eslint-disable-next-line no-alert
2017-05-30 08:12:06 +00:00
if (confirm(`Are you sure you want to leave the "${this.group.fullName}" group?`)) {
this.leaveGroup();
}
},
leaveGroup() {
2017-06-06 14:01:42 +00:00
eventHub.$emit('leaveGroup', this.group, this.collection);
},
2017-05-16 14:29:38 +00:00
},
computed: {
groupDomId() {
return `group-${this.group.id}`;
},
2017-05-16 14:29:38 +00:00
rowClass() {
return {
'group-row': true,
'is-open': this.group.isOpen,
'has-subgroups': this.group.hasSubgroups,
2017-05-16 14:29:38 +00:00
'no-description': !this.group.description,
};
},
2017-05-30 22:22:30 +00:00
visibilityIcon() {
return {
fa: true,
'fa-globe': this.group.visibility === 'public',
'fa-shield': this.group.visibility === 'internal',
'fa-lock': this.group.visibility === 'private',
};
},
fullPath() {
let fullPath = '';
if (this.group.isOrphan) {
// check if current group is baseGroup
2017-06-06 14:01:42 +00:00
if (Object.keys(this.baseGroup).length > 0 && this.baseGroup !== this.group) {
// Remove baseGroup prefix from our current group.fullName. e.g:
// baseGroup.fullName: `level1`
// group.fullName: `level1 / level2 / level3`
// Result: `level2 / level3`
const gfn = this.group.fullName;
const bfn = this.baseGroup.fullName;
const length = bfn.length;
const start = gfn.indexOf(bfn);
const extraPrefixChars = 3;
fullPath = gfn.substr(start + length + extraPrefixChars);
} else {
fullPath = this.group.fullName;
}
} else {
fullPath = this.group.name;
}
return fullPath;
},
2017-06-01 00:45:05 +00:00
hasGroups() {
return Object.keys(this.group.subGroups).length > 0;
},
},
};
</script>
<template>
<li
2017-05-30 22:01:48 +00:00
@click.stop="onClickRowGroup"
:id="groupDomId"
2017-05-16 14:29:38 +00:00
:class="rowClass"
>
2017-06-07 08:45:48 +00:00
<div
class="group-row-contents">
<div
class="controls">
<a
v-if="group.canEdit"
class="edit-group btn"
:href="group.editPath">
<i
class="fa fa-cogs"
aria-hidden="true"
>
</i>
</a>
2017-06-07 08:45:48 +00:00
<a
@click="onLeaveGroup"
:href="group.leavePath"
class="leave-group btn"
title="Leave this group">
2017-06-07 08:45:48 +00:00
<i
class="fa fa-sign-out"
2017-06-07 08:45:48 +00:00
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
</a>
</div>
2017-06-07 08:45:48 +00:00
<div
class="stats">
<span
class="number-projects">
<i
class="fa fa-bookmark"
2017-06-07 08:45:48 +00:00
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
{{group.numberProjects}}
</span>
2017-06-07 08:45:48 +00:00
<span
class="number-users">
<i
class="fa fa-users"
2017-06-07 08:45:48 +00:00
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
{{group.numberUsers}}
</span>
2017-06-07 08:45:48 +00:00
<span
class="group-visibility">
<i
:class="visibilityIcon"
2017-06-07 08:45:48 +00:00
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
</span>
</div>
2017-06-07 08:45:48 +00:00
<div
class="folder-toggle-wrap">
<span
class="folder-caret"
v-if="group.hasSubgroups">
<i
v-if="group.isOpen"
class="fa fa-caret-down"
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
<i
v-if="!group.isOpen"
class="fa fa-caret-right"
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
</span>
<span class="folder-icon">
<i
v-if="group.isOpen"
class="fa fa-folder-open"
aria-hidden="true"
>
2017-06-07 08:45:48 +00:00
</i>
<i
v-if="!group.isOpen"
2017-06-07 08:45:48 +00:00
class="fa fa-folder"
aria-hidden="true">
</i>
</span>
</div>
2017-06-07 08:45:48 +00:00
<div
class="avatar-container s40 hidden-xs">
<a
2017-06-16 08:54:20 +00:00
:href="group.groupPath">
2017-06-07 08:45:48 +00:00
<img
class="avatar s40"
:src="group.avatarUrl"
/>
</a>
</div>
2017-06-07 08:45:48 +00:00
<div
class="title">
<a
2017-06-16 08:54:20 +00:00
:href="group.groupPath">{{fullPath}}</a>
<template v-if="group.permissions.humanGroupAccess">
as
<span class="access-type">{{group.permissions.humanGroupAccess}}</span>
</template>
</div>
2017-06-07 08:45:48 +00:00
<div
class="description">{{group.description}}</div>
2017-05-16 14:29:38 +00:00
</div>
2017-06-07 08:45:48 +00:00
<group-folder
v-if="group.isOpen && hasGroups"
:groups="group.subGroups"
:baseGroup="group"
/>
2017-05-09 23:10:19 +00:00
</li>
</template>