group_item.vue 5.2 KB
Newer Older
A
Alfredo Sumaran 已提交
1
<script>
2 3
import eventHub from '../event_hub';

A
Alfredo Sumaran 已提交
4 5 6 7 8
export default {
  props: {
    group: {
      type: Object,
      required: true,
9
    },
10 11 12
    baseGroup: {
      type: Object,
      required: false,
A
Alfredo Sumaran 已提交
13
      default: () => ({}),
14
    },
A
Alfredo Sumaran 已提交
15 16 17 18 19
    collection: {
      type: Object,
      required: false,
      default: () => ({}),
    },
20 21
  },
  methods: {
A
Alfredo Sumaran 已提交
22
    onClickRowGroup(e) {
A
Alfredo Sumaran 已提交
23
      e.stopPropagation();
A
Alfredo Sumaran 已提交
24 25

      // Skip for buttons
A
Alfredo Sumaran 已提交
26
      if (!(e.target.tagName === 'A') && !(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
A
Alfredo Sumaran 已提交
27 28 29
        if (this.group.hasSubgroups) {
          eventHub.$emit('toggleSubGroups', this.group);
        } else {
A
Alfredo Sumaran 已提交
30
          window.location.href = this.group.groupPath;
A
Alfredo Sumaran 已提交
31
        }
A
Alfredo Sumaran 已提交
32 33
      }
    },
A
Alfredo Sumaran 已提交
34 35 36
    onLeaveGroup(e) {
      e.preventDefault();

37
      // eslint-disable-next-line no-alert
A
Alfredo Sumaran 已提交
38 39 40 41 42
      if (confirm(`Are you sure you want to leave the "${this.group.fullName}" group?`)) {
        this.leaveGroup();
      }
    },
    leaveGroup() {
A
Alfredo Sumaran 已提交
43
      eventHub.$emit('leaveGroup', this.group, this.collection);
44
    },
A
Alfredo Sumaran 已提交
45 46
  },
  computed: {
47 48 49
    groupDomId() {
      return `group-${this.group.id}`;
    },
A
Alfredo Sumaran 已提交
50 51 52 53
    rowClass() {
      return {
        'group-row': true,
        'is-open': this.group.isOpen,
54
        'has-subgroups': this.group.hasSubgroups,
A
Alfredo Sumaran 已提交
55 56 57
        'no-description': !this.group.description,
      };
    },
A
Alfredo Sumaran 已提交
58 59 60 61 62 63 64 65
    visibilityIcon() {
      return {
        fa: true,
        'fa-globe': this.group.visibility === 'public',
        'fa-shield': this.group.visibility === 'internal',
        'fa-lock': this.group.visibility === 'private',
      };
    },
66 67 68 69 70
    fullPath() {
      let fullPath = '';

      if (this.group.isOrphan) {
        // check if current group is baseGroup
A
Alfredo Sumaran 已提交
71
        if (Object.keys(this.baseGroup).length > 0 && this.baseGroup !== this.group) {
72 73 74 75 76 77 78 79
          // 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);
80
          const extraPrefixChars = 3;
81

82
          fullPath = gfn.substr(start + length + extraPrefixChars);
83 84 85 86 87 88 89 90 91
        } else {
          fullPath = this.group.fullName;
        }
      } else {
        fullPath = this.group.name;
      }

      return fullPath;
    },
92 93 94
    hasGroups() {
      return Object.keys(this.group.subGroups).length > 0;
    },
95
  },
A
Alfredo Sumaran 已提交
96 97 98 99
};
</script>

<template>
100
  <li
A
Alfredo Sumaran 已提交
101
    @click.stop="onClickRowGroup"
102
    :id="groupDomId"
A
Alfredo Sumaran 已提交
103
    :class="rowClass"
104
    >
A
Alfredo Sumaran 已提交
105 106 107 108
    <div
      class="group-row-contents">
      <div
        class="controls">
109 110 111 112
        <a
          v-if="group.canEdit"
          class="edit-group btn"
          :href="group.editPath">
113 114 115 116 117
          <i
            class="fa fa-cogs"
            aria-hidden="true"
          >
          </i>
118
        </a>
A
Alfredo Sumaran 已提交
119 120
        <a
          @click="onLeaveGroup"
121 122 123
          :href="group.leavePath"
          class="leave-group btn"
          title="Leave this group">
A
Alfredo Sumaran 已提交
124
          <i
125
            class="fa fa-sign-out"
A
Alfredo Sumaran 已提交
126
            aria-hidden="true"
127
          >
A
Alfredo Sumaran 已提交
128
          </i>
129 130
        </a>
      </div>
A
Alfredo Sumaran 已提交
131 132 133 134 135
      <div
        class="stats">
        <span
          class="number-projects">
          <i
136
            class="fa fa-bookmark"
A
Alfredo Sumaran 已提交
137
            aria-hidden="true"
138
          >
A
Alfredo Sumaran 已提交
139
          </i>
140 141
          {{group.numberProjects}}
        </span>
A
Alfredo Sumaran 已提交
142 143 144
        <span
          class="number-users">
          <i
145
            class="fa fa-users"
A
Alfredo Sumaran 已提交
146
            aria-hidden="true"
147
          >
A
Alfredo Sumaran 已提交
148
          </i>
149 150
          {{group.numberUsers}}
        </span>
A
Alfredo Sumaran 已提交
151 152 153
        <span
          class="group-visibility">
          <i
154
            :class="visibilityIcon"
A
Alfredo Sumaran 已提交
155
            aria-hidden="true"
156
          >
A
Alfredo Sumaran 已提交
157
          </i>
158 159
        </span>
      </div>
A
Alfredo Sumaran 已提交
160 161 162 163 164
      <div
        class="folder-toggle-wrap">
        <span
          class="folder-caret"
          v-if="group.hasSubgroups">
165 166
          <i
            v-if="group.isOpen"
167 168 169
            class="fa fa-caret-down"
            aria-hidden="true"
          >
A
Alfredo Sumaran 已提交
170
          </i>
171 172
          <i
            v-if="!group.isOpen"
173 174 175
            class="fa fa-caret-right"
            aria-hidden="true"
          >
A
Alfredo Sumaran 已提交
176
          </i>
177 178 179 180 181
        </span>
        <span class="folder-icon">
          <i
            v-if="group.isOpen"
            class="fa fa-folder-open"
182 183
            aria-hidden="true"
          >
A
Alfredo Sumaran 已提交
184
          </i>
185 186
          <i
            v-if="!group.isOpen"
A
Alfredo Sumaran 已提交
187 188 189
            class="fa fa-folder"
            aria-hidden="true">
          </i>
190 191
        </span>
      </div>
A
Alfredo Sumaran 已提交
192 193 194
      <div
        class="avatar-container s40 hidden-xs">
        <a
A
Alfredo Sumaran 已提交
195
          :href="group.groupPath">
A
Alfredo Sumaran 已提交
196 197 198 199
          <img
            class="avatar s40"
            :src="group.avatarUrl"
          />
200 201
        </a>
      </div>
A
Alfredo Sumaran 已提交
202 203 204
      <div
        class="title">
        <a
A
Alfredo Sumaran 已提交
205
          :href="group.groupPath">{{fullPath}}</a>
206
        <template v-if="group.permissions.humanGroupAccess">
207 208
        as
        <span class="access-type">{{group.permissions.humanGroupAccess}}</span>
209
        </template>
210
      </div>
A
Alfredo Sumaran 已提交
211 212
      <div
        class="description">{{group.description}}</div>
A
Alfredo Sumaran 已提交
213
    </div>
A
Alfredo Sumaran 已提交
214 215 216 217 218
    <group-folder
      v-if="group.isOpen && hasGroups"
      :groups="group.subGroups"
      :baseGroup="group"
    />
A
Alfredo Sumaran 已提交
219
  </li>
A
Alfredo Sumaran 已提交
220
</template>