group_item.vue 3.9 KB
Newer Older
A
Alfredo Sumaran 已提交
1
<script>
2 3
/* eslint-disable no-alert */

4 5
import eventHub from '../event_hub';

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

      // Skip for buttons
      if (e.target.tagName === 'A' ||
        (e.target.tagName === 'I' && e.target.parentElement.tagName === 'A')) {
      } else {
        if (this.group.hasSubgroups) {
          eventHub.$emit('toggleSubGroups', this.group);
        } else {
          window.location.href = this.group.webUrl;
        }
A
Alfredo Sumaran 已提交
30 31
      }

A
Alfredo Sumaran 已提交
32
      return false;
A
Alfredo Sumaran 已提交
33
    },
A
Alfredo Sumaran 已提交
34 35 36 37 38 39
    onLeaveGroup(e) {
      e.preventDefault();

      if (confirm(`Are you sure you want to leave the "${this.group.fullName}" group?`)) {
        this.leaveGroup();
      }
A
Alfredo Sumaran 已提交
40 41

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

74
          fullPath = gfn.substr(start + length + 3);
75 76 77 78 79 80 81 82 83
        } else {
          fullPath = this.group.fullName;
        }
      } else {
        fullPath = this.group.name;
      }

      return fullPath;
    },
84
  },
A
Alfredo Sumaran 已提交
85 86 87 88
};
</script>

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

    <div class="stats">
110
      <span class="number-projects">
A
Alfredo Sumaran 已提交
111 112 113
        <i aria-hidden="true" class="fa fa-bookmark"></i>
        {{group.numberProjects}}
      </span>
114
      <span class="number-users">
A
Alfredo Sumaran 已提交
115
        <i aria-hidden="true" class="fa fa-users"></i>
116
        {{group.numberUsers}}
A
Alfredo Sumaran 已提交
117
      </span>
118
      <span class="group-visibility">
A
Alfredo Sumaran 已提交
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
        <i aria-hidden="true" class="fa fa-globe"></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
          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">
151
      <a :href="group.webUrl">{{fullPath}}</a>
A
Alfredo Sumaran 已提交
152 153 154 155 156
    </div>

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

158
    <group-folder v-if="group.isOpen" :groups="group.subGroups" :baseGroup="group" />
A
Alfredo Sumaran 已提交
159
  </li>
A
Alfredo Sumaran 已提交
160
</template>