TableView.vue 5.1 KB
Newer Older
wanli's avatar
wanli committed
1
<template>
wanli's avatar
wanli committed
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
  <div class="fm-table">
    <table class="table table-sm">
      <thead>
        <tr>
          <th class="w-65" v-on:click="sortBy('name')">
            {{ lang.manager.table.name }}
            <template v-if="sortSettings.field === 'name'">
              <i
                class="fas fa-sort-amount-down"
                v-show="sortSettings.direction === 'down'"
              />
              <i
                class="fas fa-sort-amount-up"
                v-show="sortSettings.direction === 'up'"
              />
            </template>
          </th>
          <th class="w-10" v-on:click="sortBy('size')">
            {{ lang.manager.table.size }}
            <template v-if="sortSettings.field === 'size'">
              <i
                class="fas fa-sort-amount-down"
                v-show="sortSettings.direction === 'down'"
              />
              <i
                class="fas fa-sort-amount-up"
                v-show="sortSettings.direction === 'up'"
              />
            </template>
          </th>
          <th class="w-10" v-on:click="sortBy('type')">
            {{ lang.manager.table.type }}
            <template v-if="sortSettings.field === 'type'">
              <i
                class="fas fa-sort-amount-down"
                v-show="sortSettings.direction === 'down'"
              />
              <i
                class="fas fa-sort-amount-up"
                v-show="sortSettings.direction === 'up'"
              />
            </template>
          </th>
          <th class="w-auto" v-on:click="sortBy('date')">
            {{ lang.manager.table.date }}
            <template v-if="sortSettings.field === 'date'">
              <i
                class="fas fa-sort-amount-down"
                v-show="sortSettings.direction === 'down'"
              />
              <i
                class="fas fa-sort-amount-up"
                v-show="sortSettings.direction === 'up'"
              />
            </template>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr v-if="!isRootPath">
          <td colspan="4" class="fm-content-item" v-on:click="levelUp">
            <i class="fas fa-level-up-alt" />
          </td>
        </tr>
        <tr
          v-for="(directory, index) in directories"
          v-bind:key="`d-${index}`"
          v-bind:class="{
            'table-info': checkSelect('directories', directory.path),
          }"
          v-on:click="selectItem('directories', directory.path, $event)"
          v-on:contextmenu.prevent="contextMenu(directory, $event)"
        >
          <td
            class="fm-content-item unselectable"
            v-bind:class="acl && directory.acl === 0 ? 'text-hidden' : ''"
            v-on:dblclick="selectDirectory(directory.path)"
          >
            <i class="far fa-folder" /> {{ directory.basename }}
          </td>
          <td />
          <td>{{ lang.manager.table.folder }}</td>
          <td>
            {{ timestampToDate(directory.timestamp) }}
          </td>
        </tr>
        <tr
          v-for="(file, index) in files"
          v-bind:key="`f-${index}`"
          v-bind:class="{ 'table-info': checkSelect('files', file.path) }"
          v-on:click="selectItem('files', file.path, $event)"
          v-on:dblclick="selectAction(file.path, file.extension)"
          v-on:contextmenu.prevent="contextMenu(file, $event)"
        >
          <td
            class="fm-content-item unselectable"
            v-bind:class="acl && file.acl === 0 ? 'text-hidden' : ''"
          >
            <i class="far" v-bind:class="extensionToIcon(file.extension)" />
            {{ file.filename ? file.filename : file.basename }}
          </td>
          <td>{{ bytesToHuman(file.size) }}</td>
          <td>
            {{ file.extension }}
          </td>
          <td>
            {{ timestampToDate(file.timestamp) }}
          </td>
        </tr>
      </tbody>
    </table>
  </div>
wanli's avatar
wanli committed
114 115 116
</template>

<script>
wanli's avatar
wanli committed
117 118 119
import translate from "@/utils/translate";
import helper from "@/utils/helper";
import managerHelper from "./mixins/manager";
wanli's avatar
wanli committed
120 121

export default {
wanli's avatar
wanli committed
122
  name: "table-view",
wanli's avatar
wanli committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  mixins: [translate, helper, managerHelper],
  props: {
    manager: { type: String, required: true },
  },
  computed: {
    /**
     * Sort settings
     * @returns {*}
     */
    sortSettings() {
      return this.$store.state.fm[this.manager].sort;
    },
  },
  methods: {
    /**
     * Sort by field
     * @param field
     */
    sortBy(field) {
wanli's avatar
wanli committed
142 143 144 145
      this.$store.dispatch(`fm/${this.manager}/sortBy`, {
        field,
        direction: null,
      });
wanli's avatar
wanli committed
146 147 148 149 150 151
    },
  },
};
</script>

<style lang="scss">
wanli's avatar
wanli committed
152 153 154 155 156 157 158 159
.fm-table {
  thead th {
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
    cursor: pointer;
    border-top: none;
wanli's avatar
wanli committed
160

wanli's avatar
wanli committed
161 162 163
    &:hover {
      background-color: #f8f9fa;
    }
wanli's avatar
wanli committed
164

wanli's avatar
wanli committed
165 166 167 168
    & > i {
      padding-left: 0.5rem;
    }
  }
wanli's avatar
wanli committed
169

wanli's avatar
wanli committed
170 171 172 173 174
  td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
wanli's avatar
wanli committed
175

wanli's avatar
wanli committed
176 177 178
  tr:hover {
    background-color: #f8f9fa;
  }
wanli's avatar
wanli committed
179

wanli's avatar
wanli committed
180 181 182
  .w-10 {
    width: 10%;
  }
wanli's avatar
wanli committed
183

wanli's avatar
wanli committed
184 185 186
  .w-65 {
    width: 65%;
  }
wanli's avatar
wanli committed
187

wanli's avatar
wanli committed
188 189 190 191
  .fm-content-item {
    cursor: pointer;
    max-width: 1px;
  }
wanli's avatar
wanli committed
192

wanli's avatar
wanli committed
193 194 195 196
  .text-hidden {
    color: #cdcdcd;
  }
}
wanli's avatar
wanli committed
197
</style>