summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/participants/participants.vue
blob: 0a945fc7fd52b1af2b52777c3de6b8f1a83eb2f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script>
  import { __, n__, sprintf } from '~/locale';
  import tooltip from '~/vue_shared/directives/tooltip';
  import loadingIcon from '~/vue_shared/components/loading_icon.vue';
  import userAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';

  export default {
    directives: {
      tooltip,
    },
    components: {
      loadingIcon,
      userAvatarImage,
    },
    props: {
      loading: {
        type: Boolean,
        required: false,
        default: false,
      },
      participants: {
        type: Array,
        required: false,
        default: () => [],
      },
      numberOfLessParticipants: {
        type: Number,
        required: false,
        default: 7,
      },
    },
    data() {
      return {
        isShowingMoreParticipants: false,
      };
    },
    computed: {
      lessParticipants() {
        return this.participants.slice(0, this.numberOfLessParticipants);
      },
      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,
          });
        }

        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;
      },
      onClickCollapsedIcon() {
        this.$emit('toggleSidebar');
      },
    },
  };
</script>

<template>
  <div>
    <div
      class="sidebar-collapsed-icon"
      v-tooltip
      data-container="body"
      data-placement="left"
      data-boundary="viewport"
      :title="participantLabel"
      @click="onClickCollapsedIcon"
    >
      <i
        class="fa fa-users"
        aria-hidden="true"
      >
      </i>
      <loading-icon
        v-if="loading"
        class="js-participants-collapsed-loading-icon"
      />
      <span
        v-else
        class="js-participants-collapsed-count"
      >
        {{ participantCount }}
      </span>
    </div>
    <div class="title hide-collapsed">
      <loading-icon
        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"
      >
        <a
          class="author_link"
          :href="participant.web_url"
        >
          <user-avatar-image
            :lazy="true"
            :img-src="participant.avatar_url"
            css-classes="avatar-inline"
            :size="24"
            :tooltip-text="participant.name"
            tooltip-placement="bottom"
          />
        </a>
      </div>
    </div>
    <div
      v-if="hasMoreParticipants"
      class="participants-more hide-collapsed"
    >
      <button
        type="button"
        class="btn-transparent btn-blank js-toggle-participants-button"
        @click="toggleMoreParticipants"
      >
        {{ toggleLabel }}
      </button>
    </div>
  </div>
</template>