debian-mirror-gitlab/app/assets/javascripts/sidebar/components/participants/participants.vue

138 lines
3.5 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2020-01-01 13:55:28 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-12-13 13:39:08 +05:30
import { __, n__, sprintf } from '~/locale';
import tooltip from '~/vue_shared/directives/tooltip';
import userAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
export default {
directives: {
tooltip,
},
components: {
userAvatarImage,
GlLoadingIcon,
},
props: {
loading: {
type: Boolean,
required: false,
default: false,
2018-10-15 14:42:47 +05:30
},
2018-12-13 13:39:08 +05:30
participants: {
type: Array,
required: false,
default: () => [],
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
numberOfLessParticipants: {
type: Number,
required: false,
default: 7,
2018-03-17 18:26:18 +05:30
},
2020-03-13 15:44:24 +05:30
showParticipantLabel: {
type: Boolean,
required: false,
default: true,
},
2018-12-13 13:39:08 +05:30
},
data() {
return {
isShowingMoreParticipants: false,
};
},
computed: {
lessParticipants() {
return this.participants.slice(0, this.numberOfLessParticipants);
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
visibleParticipants() {
return this.isShowingMoreParticipants ? this.participants : this.lessParticipants;
},
hasMoreParticipants() {
return this.participants.length > this.numberOfLessParticipants;
},
toggleLabel() {
let label = '';
if (this.isShowingMoreParticipants) {
label = __('- show less');
} else {
label = sprintf(__('+ %{moreCount} more'), {
moreCount: this.participants.length - this.numberOfLessParticipants,
});
}
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
return label;
},
participantLabel() {
return sprintf(
n__('%{count} participant', '%{count} participants', this.participants.length),
{ count: this.loading ? '' : this.participantCount },
);
},
participantCount() {
return this.participants.length;
},
},
methods: {
toggleMoreParticipants() {
this.isShowingMoreParticipants = !this.isShowingMoreParticipants;
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
onClickCollapsedIcon() {
this.$emit('toggleSidebar');
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div>
2018-10-15 14:42:47 +05:30
<div
2020-03-13 15:44:24 +05:30
v-if="showParticipantLabel"
2018-10-15 14:42:47 +05:30
v-tooltip
2018-11-08 19:23:39 +05:30
:title="participantLabel"
class="sidebar-collapsed-icon"
2018-10-15 14:42:47 +05:30
data-container="body"
data-placement="left"
2018-11-08 19:23:39 +05:30
data-boundary="viewport"
2018-10-15 14:42:47 +05:30
@click="onClickCollapsedIcon"
>
2019-02-15 15:39:39 +05:30
<i class="fa fa-users" aria-hidden="true"> </i>
<gl-loading-icon v-if="loading" class="js-participants-collapsed-loading-icon" />
<span v-else class="js-participants-collapsed-count"> {{ participantCount }} </span>
2018-03-17 18:26:18 +05:30
</div>
2020-03-13 15:44:24 +05:30
<div v-if="showParticipantLabel" class="title hide-collapsed">
2018-12-05 23:21:45 +05:30
<gl-loading-icon
2018-03-17 18:26:18 +05:30
v-if="loading"
:inline="true"
class="js-participants-expanded-loading-icon"
/>
{{ participantLabel }}
</div>
<div class="participants-list hide-collapsed">
<div
v-for="participant in visibleParticipants"
:key="participant.id"
class="participants-author js-participants-author"
>
2019-02-15 15:39:39 +05:30
<a :href="participant.web_url" class="author-link">
2018-03-17 18:26:18 +05:30
<user-avatar-image
:lazy="true"
:img-src="participant.avatar_url"
:size="24"
:tooltip-text="participant.name"
2018-11-08 19:23:39 +05:30
css-classes="avatar-inline"
2018-03-17 18:26:18 +05:30
tooltip-placement="bottom"
/>
</a>
</div>
</div>
2019-02-15 15:39:39 +05:30
<div v-if="hasMoreParticipants" class="participants-more hide-collapsed">
2018-03-17 18:26:18 +05:30
<button
type="button"
2020-04-22 19:07:51 +05:30
class="btn-transparent btn-link js-toggle-participants-button"
2018-03-17 18:26:18 +05:30
@click="toggleMoreParticipants"
>
{{ toggleLabel }}
</button>
</div>
</div>
</template>