summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/groups/components/group_item.vue
blob: 08cf628e71f85a6d79f5d771f84d16085a666629 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<script>
import eventHub from '../event_hub';

export default {
  props: {
    group: {
      type: Object,
      required: true,
    },
    baseGroup: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  methods: {
    onClickRowGroup(e) {
      e.stopPropagation();

      // Skip for buttons
      if (!(e.target.tagName === 'A') && !(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
        if (this.group.hasSubgroups) {
          eventHub.$emit('toggleSubGroups', this.group);
        } else {
          window.location.href = this.group.webUrl;
        }
      }
    },
    onLeaveGroup(e) {
      e.preventDefault();

      // eslint-disable-next-line no-alert
      if (confirm(`Are you sure you want to leave the "${this.group.fullName}" group?`)) {
        this.leaveGroup();
      }
    },
    leaveGroup() {
      eventHub.$emit('leaveGroup', this.group.leavePath);
    },
  },
  computed: {
    groupDomId() {
      return `group-${this.group.id}`;
    },
    rowClass() {
      return {
        'group-row': true,
        'is-open': this.group.isOpen,
        'has-subgroups': this.group.hasSubgroups,
        'no-description': !this.group.description,
      };
    },
    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
        if (this.baseGroup) {
          // 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;
    },
    hasGroups() {
      return Object.keys(this.group.subGroups).length > 0;
    },
  },
};
</script>

<template>
  <li
    @click.stop="onClickRowGroup"
    :id="groupDomId"
    :class="rowClass"
    >
    <div class="controls">
      <a
        v-show="group.canEdit"
        class="edit-group btn"
        :href="group.editPath">
        <i aria-hidden="true" class="fa fa-cogs"></i>
      </a>
      <a @click="onLeaveGroup"
        :href="group.leavePath"
        class="leave-group btn"
        title="Leave this group">
        <i aria-hidden="true" class="fa fa-sign-out"></i>
      </a>
    </div>

    <div class="stats">
      <span class="number-projects">
        <i aria-hidden="true" class="fa fa-bookmark"></i>
        {{group.numberProjects}}
      </span>
      <span class="number-users">
        <i aria-hidden="true" class="fa fa-users"></i>
        {{group.numberUsers}}
      </span>
      <span class="group-visibility">
        <i aria-hidden="true" :class="visibilityIcon"></i>
      </span>
    </div>

    <div class="folder-toggle-wrap">
      <span class="folder-caret">
        <i
          v-show="group.isOpen"
          class="fa fa-caret-down" />
        <i
          v-show="!group.isOpen"
          class="fa fa-caret-right" />
      </span>

      <span class="folder-icon">
        <i
          v-show="group.isOpen"
          class="fa fa-folder-open"
          aria-hidden="true"></i>
        <i
          v-show="!group.isOpen"
          class="fa fa-folder"></i>
      </span>
    </div>

    <div class="avatar-container s40">
      <a href="/h5bp">
        <img class="avatar s40 hidden-xs" src="http://localhost:3000/uploads/group/avatar/2/logo-extra-whitespace.png" alt="Logo extra whitespace">
      </a>
    </div>

    <div class="title">
      <a :href="group.webUrl">{{fullPath}}</a>
    </div>

    <div class="description">
      {{group.description}}
    </div>

    <group-folder v-if="group.isOpen && hasGroups" :groups="group.subGroups" :baseGroup="group" />
  </li>
</template>