group_item.vue 4.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 13
    baseGroup: {
      type: Object,
      required: false,
    },
14 15
  },
  methods: {
A
Alfredo Sumaran 已提交
16
    onClickRowGroup(e) {
A
Alfredo Sumaran 已提交
17
      e.stopPropagation();
A
Alfredo Sumaran 已提交
18 19

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

A
Alfredo Sumaran 已提交
28
      return false;
A
Alfredo Sumaran 已提交
29
    },
A
Alfredo Sumaran 已提交
30 31 32
    onLeaveGroup(e) {
      e.preventDefault();

33
      // eslint-disable-next-line no-alert
A
Alfredo Sumaran 已提交
34 35 36
      if (confirm(`Are you sure you want to leave the "${this.group.fullName}" group?`)) {
        this.leaveGroup();
      }
A
Alfredo Sumaran 已提交
37 38

      return false;
A
Alfredo Sumaran 已提交
39 40 41
    },
    leaveGroup() {
      eventHub.$emit('leaveGroup', this.group.leavePath);
42
    },
A
Alfredo Sumaran 已提交
43 44
  },
  computed: {
45 46 47
    groupDomId() {
      return `group-${this.group.id}`;
    },
A
Alfredo Sumaran 已提交
48 49 50 51
    rowClass() {
      return {
        'group-row': true,
        'is-open': this.group.isOpen,
52
        'has-subgroups': this.group.hasSubgroups,
A
Alfredo Sumaran 已提交
53 54 55
        'no-description': !this.group.description,
      };
    },
A
Alfredo Sumaran 已提交
56 57 58 59 60 61 62 63
    visibilityIcon() {
      return {
        fa: true,
        'fa-globe': this.group.visibility === 'public',
        'fa-shield': this.group.visibility === 'internal',
        'fa-lock': this.group.visibility === 'private',
      };
    },
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    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);

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

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

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

    <div class="stats">
118
      <span class="number-projects">
A
Alfredo Sumaran 已提交
119 120 121
        <i aria-hidden="true" class="fa fa-bookmark"></i>
        {{group.numberProjects}}
      </span>
122
      <span class="number-users">
A
Alfredo Sumaran 已提交
123
        <i aria-hidden="true" class="fa fa-users"></i>
124
        {{group.numberUsers}}
A
Alfredo Sumaran 已提交
125
      </span>
126
      <span class="group-visibility">
A
Alfredo Sumaran 已提交
127
        <i aria-hidden="true" :class="visibilityIcon"></i>
A
Alfredo Sumaran 已提交
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
      </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
          v-show="!group.isOpen"
          class="fa fa-folder" />
      </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">
159
      <a :href="group.webUrl">{{fullPath}}</a>
A
Alfredo Sumaran 已提交
160 161 162 163 164
    </div>

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

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