code.gitea.io/gitea@v1.21.7/web_src/js/components/DiffFileList.vue (about)

     1  <script>
     2  import {loadMoreFiles} from '../features/repo-diff.js';
     3  import {diffTreeStore} from '../modules/stores.js';
     4  
     5  export default {
     6    data: () => {
     7      return {store: diffTreeStore()};
     8    },
     9    mounted() {
    10      document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
    11    },
    12    unmounted() {
    13      document.getElementById('show-file-list-btn').removeEventListener('click', this.toggleFileList);
    14    },
    15    methods: {
    16      toggleFileList() {
    17        this.store.fileListIsVisible = !this.store.fileListIsVisible;
    18      },
    19      diffTypeToString(pType) {
    20        const diffTypes = {
    21          1: 'add',
    22          2: 'modify',
    23          3: 'del',
    24          4: 'rename',
    25          5: 'copy',
    26        };
    27        return diffTypes[pType];
    28      },
    29      diffStatsWidth(adds, dels) {
    30        return `${adds / (adds + dels) * 100}%`;
    31      },
    32      loadMoreData() {
    33        loadMoreFiles(this.store.linkLoadMore);
    34      }
    35    },
    36  };
    37  </script>
    38  <template>
    39    <ol class="diff-stats gt-m-0" ref="root" v-if="store.fileListIsVisible">
    40      <li v-for="file in store.files" :key="file.NameHash">
    41        <div class="gt-font-semibold gt-df gt-ac pull-right">
    42          <span v-if="file.IsBin" class="gt-ml-1 gt-mr-3">{{ store.binaryFileMessage }}</span>
    43          {{ file.IsBin ? '' : file.Addition + file.Deletion }}
    44          <span v-if="!file.IsBin" class="diff-stats-bar gt-mx-3" :data-tooltip-content="store.statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
    45            <div class="diff-stats-add-bar" :style="{ 'width': diffStatsWidth(file.Addition, file.Deletion) }"/>
    46          </span>
    47        </div>
    48        <!-- todo finish all file status, now modify, add, delete and rename -->
    49        <span :class="['status', diffTypeToString(file.Type)]" :data-tooltip-content="diffTypeToString(file.Type)">&nbsp;</span>
    50        <a class="file gt-mono" :href="'#diff-' + file.NameHash">{{ file.Name }}</a>
    51      </li>
    52      <li v-if="store.isIncomplete" class="gt-pt-2">
    53        <span class="file gt-df gt-ac gt-sb">{{ store.tooManyFilesMessage }}
    54          <a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
    55        </span>
    56      </li>
    57    </ol>
    58  </template>