summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/components/group_item.vue
blob: 356a95c05ca820109deb9ca2b8376eff92f82a16 (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
<script>
import identicon from '../../vue_shared/components/identicon.vue';
import eventHub from '../event_hub';

import itemCaret from './item_caret.vue';
import itemTypeIcon from './item_type_icon.vue';
import itemStats from './item_stats.vue';
import itemActions from './item_actions.vue';

export default {
  components: {
    identicon,
    itemCaret,
    itemTypeIcon,
    itemStats,
    itemActions,
  },
  props: {
    parentGroup: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    group: {
      type: Object,
      required: true,
    },
  },
  computed: {
    groupDomId() {
      return `group-${this.group.id}`;
    },
    rowClass() {
      return {
        'is-open': this.group.isOpen,
        'has-children': this.hasChildren,
        'has-description': this.group.description,
        'being-removed': this.group.isBeingRemoved,
      };
    },
    hasChildren() {
      return this.group.childrenCount > 0;
    },
    hasAvatar() {
      return this.group.avatarUrl !== null;
    },
    isGroup() {
      return this.group.type === 'group';
    },
  },
  methods: {
    onClickRowGroup(e) {
      const NO_EXPAND_CLS = 'no-expand';
      if (!(e.target.classList.contains(NO_EXPAND_CLS) ||
            e.target.parentElement.classList.contains(NO_EXPAND_CLS))) {
        if (this.hasChildren) {
          eventHub.$emit('toggleChildren', this.group);
        } else {
          gl.utils.visitUrl(this.group.relativePath);
        }
      }
    },
  },
};
</script>

<template>
  <li
    @click.stop="onClickRowGroup"
    :id="groupDomId"
    :class="rowClass"
    class="group-row"
    >
    <div
      class="group-row-contents">
      <item-actions
        v-if="isGroup"
        :group="group"
        :parent-group="parentGroup"
      />
      <item-stats
        :item="group"
      />
      <div
        class="folder-toggle-wrap">
        <item-caret
          :is-group-open="group.isOpen"
        />
        <item-type-icon
          :item-type="group.type"
          :is-group-open="group.isOpen"
        />
      </div>
      <div
        class="avatar-container s40 hidden-xs"
        :class="{ 'content-loading': group.isChildrenLoading }"
      >
        <a
          :href="group.relativePath"
          class="no-expand"
        >
          <img
            v-if="hasAvatar"
            class="avatar s40"
            :src="group.avatarUrl"
          />
          <identicon
            v-else
            :entity-id=group.id
            :entity-name="group.name"
          />
        </a>
      </div>
      <div
        class="title">
        <a
          :href="group.relativePath"
          class="no-expand">{{group.fullName}}</a>
        <span
          v-if="group.permission"
          class="access-type"
        >
          {{s__('GroupsTreeRole|as')}} {{group.permission}}
        </span>
      </div>
      <div
        class="description">{{group.description}}</div>
    </div>
    <group-folder
      v-if="group.isOpen && hasChildren"
      :parent-group="group"
      :groups="group.children"
    />
  </li>
</template>