repo_file.vue 3.89 KB
Newer Older
1
<script>
2
  import { mapState } from 'vuex';
3
  import timeAgoMixin from '../../vue_shared/mixins/timeago';
4
  import skeletonLoadingContainer from '../../vue_shared/components/skeleton_loading_container.vue';
5
  import newDropdown from './new_dropdown/index.vue';
6
  import fileIcon from '../../vue_shared/components/file_icon.vue';
7

8 9 10 11
  export default {
    mixins: [
      timeAgoMixin,
    ],
12 13
    components: {
      skeletonLoadingContainer,
14
      newDropdown,
15
      fileIcon,
16
    },
17 18 19 20 21
    props: {
      file: {
        type: Object,
        required: true,
      },
22 23 24 25
      showExtraColumns: {
        type: Boolean,
        default: false,
      },
26
    },
27
    computed: {
28 29
      ...mapState([
        'leftPanelCollapsed',
30
      ]),
31 32 33 34 35 36
      isSubmodule() {
        return this.file.type === 'submodule';
      },
      isTree() {
        return this.file.type === 'tree';
      },
37 38 39 40 41
      levelIndentation() {
        return {
          marginLeft: `${this.file.level * 16}px`,
        };
      },
42 43 44
      shortId() {
        return this.file.id.substr(0, 8);
      },
45
      submoduleColSpan() {
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        return !this.leftPanelCollapsed && this.isSubmodule ? 3 : 1;
      },
      fileClass() {
        if (this.file.type === 'blob') {
          if (this.file.active) {
            return 'file-open file-active';
          }
          return this.file.opened ? 'file-open' : '';
        }
        return '';
      },
      changedClass() {
        return {
          'fa-circle unsaved-icon': this.file.changed || this.file.tempFile,
        };
61
      },
62
    },
63
    methods: {
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
      clickFile(row) {
        // Manual Action if a tree is selected/opened
        if (this.file.type === 'tree' && this.$router.currentRoute.path === `/project${row.url}`) {
          this.$store.dispatch('toggleTreeOpen', {
            endpoint: this.file.url,
            tree: this.file,
          });
        }
        this.$router.push(`/project${row.url}`);
      },
    },
    updated() {
      if (this.file.type === 'blob' && this.file.active) {
        this.$el.scrollIntoView();
      }
79
    },
80
  };
81 82 83
</script>

<template>
84 85
  <tr
    class="file"
86 87
    :class="fileClass"
    @click="clickFile(file)">
88
    <td
Phil Hughes's avatar
Phil Hughes committed
89
      class="multi-file-table-name"
90 91
      :colspan="submoduleColSpan"
    >
92 93 94
      <a
        class="repo-file-name"
      >
95 96 97 98 99 100 101 102 103
        <file-icon
          :file-name="file.name"
          :loading="file.loading"
          :folder="file.type === 'tree'"
          :opened="file.opened"
          :style="levelIndentation"
          :size="16"
        >
        </file-icon>
104 105
        {{ file.name }}
      </a>
106 107 108 109 110 111 112 113 114 115 116 117 118
      <new-dropdown
        v-if="isTree"
        :project-id="file.projectId"
        :branch="file.branchId"
        :path="file.path"
        :parent="file"/>
      <i
        class="fa"
        v-if="changedClass"
        :class="changedClass"
        aria-hidden="true"
      >
      </i>
119
      <template v-if="isSubmodule && file.id">
120 121 122 123 124 125 126 127 128 129
        @
        <span class="commit-sha">
          <a
            @click.stop
            :href="file.tree_url"
          >
            {{ shortId }}
          </a>
        </span>
      </template>
130
    </td>
131

132
    <template v-if="showExtraColumns && !isSubmodule">
Phil Hughes's avatar
Phil Hughes committed
133
      <td class="multi-file-table-col-commit-message hidden-sm hidden-xs">
134
        <a
135
          v-if="file.lastCommit.message"
136 137 138 139
          @click.stop
          :href="file.lastCommit.url"
        >
          {{ file.lastCommit.message }}
Jacob Schatz's avatar
Jacob Schatz committed
140
        </a>
141
        <skeleton-loading-container
142
          v-else
143 144
          :small="true"
        />
145
      </td>
146

Phil Hughes's avatar
Phil Hughes committed
147
      <td class="commit-update hidden-xs text-right">
148 149 150 151
        <span
          v-if="file.lastCommit.updatedAt"
          :title="tooltipTitle(file.lastCommit.updatedAt)"
        >
152 153
          {{ timeFormated(file.lastCommit.updatedAt) }}
        </span>
154
        <skeleton-loading-container
155
          v-else
156 157 158
          class="animation-container-right"
          :small="true"
        />
159 160 161
      </td>
    </template>
  </tr>
162
</template>