group_item.vue 4.3 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
    },
15 16
  },
  methods: {
A
Alfredo Sumaran 已提交
17
    onClickRowGroup(e) {
A
Alfredo Sumaran 已提交
18
      e.stopPropagation();
A
Alfredo Sumaran 已提交
19 20

      // Skip for buttons
A
Alfredo Sumaran 已提交
21
      if (!(e.target.tagName === 'A') && !(e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
A
Alfredo Sumaran 已提交
22 23 24 25 26
        if (this.group.hasSubgroups) {
          eventHub.$emit('toggleSubGroups', this.group);
        } else {
          window.location.href = this.group.webUrl;
        }
A
Alfredo Sumaran 已提交
27 28
      }
    },
A
Alfredo Sumaran 已提交
29 30 31
    onLeaveGroup(e) {
      e.preventDefault();

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

      if (this.group.isOrphan) {
        // check if current group is baseGroup
66
        if (Object.keys(this.baseGroup).length > 0) {
67 68 69 70 71 72 73 74
          // 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);
75
          const extraPrefixChars = 3;
76

77
          fullPath = gfn.substr(start + length + extraPrefixChars);
78 79 80 81 82 83 84 85 86
        } else {
          fullPath = this.group.fullName;
        }
      } else {
        fullPath = this.group.name;
      }

      return fullPath;
    },
87 88 89
    hasGroups() {
      return Object.keys(this.group.subGroups).length > 0;
    },
90
  },
A
Alfredo Sumaran 已提交
91 92 93 94
};
</script>

<template>
95
  <li
A
Alfredo Sumaran 已提交
96
    @click.stop="onClickRowGroup"
97
    :id="groupDomId"
A
Alfredo Sumaran 已提交
98
    :class="rowClass"
99
    >
A
Alfredo Sumaran 已提交
100
    <div class="controls">
101
      <a
102
        v-if="group.canEdit"
103 104
        class="edit-group btn"
        :href="group.editPath">
A
Alfredo Sumaran 已提交
105 106
        <i aria-hidden="true" class="fa fa-cogs"></i>
      </a>
A
Alfredo Sumaran 已提交
107 108 109 110
      <a @click="onLeaveGroup"
        :href="group.leavePath"
        class="leave-group btn"
        title="Leave this group">
A
Alfredo Sumaran 已提交
111 112 113 114 115
        <i aria-hidden="true" class="fa fa-sign-out"></i>
      </a>
    </div>

    <div class="stats">
116
      <span class="number-projects">
A
Alfredo Sumaran 已提交
117 118 119
        <i aria-hidden="true" class="fa fa-bookmark"></i>
        {{group.numberProjects}}
      </span>
120
      <span class="number-users">
A
Alfredo Sumaran 已提交
121
        <i aria-hidden="true" class="fa fa-users"></i>
122
        {{group.numberUsers}}
A
Alfredo Sumaran 已提交
123
      </span>
124
      <span class="group-visibility">
A
Alfredo Sumaran 已提交
125
        <i aria-hidden="true" :class="visibilityIcon"></i>
A
Alfredo Sumaran 已提交
126 127 128 129
      </span>
    </div>

    <div class="folder-toggle-wrap">
130
      <span class="folder-caret" v-if="group.hasSubgroups">
A
Alfredo Sumaran 已提交
131
        <i
132
          v-if="group.isOpen"
A
Alfredo Sumaran 已提交
133 134
          class="fa fa-caret-down" />
        <i
135
          v-if="!group.isOpen"
A
Alfredo Sumaran 已提交
136 137 138 139 140
          class="fa fa-caret-right" />
      </span>

      <span class="folder-icon">
        <i
141
          v-if="group.isOpen"
A
Alfredo Sumaran 已提交
142
          class="fa fa-folder-open"
143
          aria-hidden="true"></i>
A
Alfredo Sumaran 已提交
144
        <i
145
          v-if="!group.isOpen"
146
          class="fa fa-folder"></i>
A
Alfredo Sumaran 已提交
147 148 149 150 151 152 153 154 155 156
      </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">
157
      <a :href="group.webUrl">{{fullPath}}</a>
A
Alfredo Sumaran 已提交
158 159 160 161 162
    </div>

    <div class="description">
      {{group.description}}
    </div>
A
Alfredo Sumaran 已提交
163

164
    <group-folder v-if="group.isOpen && hasGroups" :groups="group.subGroups" :baseGroup="group" />
A
Alfredo Sumaran 已提交
165
  </li>
A
Alfredo Sumaran 已提交
166
</template>