mirror of
https://github.com/go-gitea/gitea
synced 2024-12-12 08:43:39 +01:00
348d1d0f32
Migrated a handful Vue components to the `setup` syntax using composition api as it has better Typescript support and is becoming the new default in the Vue ecosystem. - [x] ActionRunStatus.vue - [x] ActivityHeatmap.vue - [x] ContextPopup.vue - [x] DiffFileList.vue - [x] DiffFileTree.vue - [x] DiffFileTreeItem.vue - [x] PullRequestMergeForm.vue - [x] RepoActivityTopAuthors.vue - [x] RepoCodeFrequency.vue - [x] RepoRecentCommits.vue - [x] ScopedAccessTokenSelector.vue Left some larger components untouched for now to not go to crazy in this single PR: - [ ] DiffCommitSelector.vue - [ ] RepoActionView.vue - [ ] RepoContributors.vue - [ ] DashboardRepoList.vue - [ ] RepoBranchTagSelector.vue
60 lines
2.2 KiB
Vue
60 lines
2.2 KiB
Vue
<script lang="ts" setup>
|
|
import {onMounted, onUnmounted} from 'vue';
|
|
import {loadMoreFiles} from '../features/repo-diff.ts';
|
|
import {diffTreeStore} from '../modules/stores.ts';
|
|
|
|
const store = diffTreeStore();
|
|
|
|
onMounted(() => {
|
|
document.querySelector('#show-file-list-btn').addEventListener('click', toggleFileList);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
document.querySelector('#show-file-list-btn').removeEventListener('click', toggleFileList);
|
|
});
|
|
|
|
function toggleFileList() {
|
|
store.fileListIsVisible = !store.fileListIsVisible;
|
|
}
|
|
|
|
function diffTypeToString(pType) {
|
|
const diffTypes = {
|
|
1: 'add',
|
|
2: 'modify',
|
|
3: 'del',
|
|
4: 'rename',
|
|
5: 'copy',
|
|
};
|
|
return diffTypes[pType];
|
|
}
|
|
|
|
function diffStatsWidth(adds, dels) {
|
|
return `${adds / (adds + dels) * 100}%`;
|
|
}
|
|
|
|
function loadMoreData() {
|
|
loadMoreFiles(store.linkLoadMore);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<ol class="diff-stats tw-m-0" ref="root" v-if="store.fileListIsVisible">
|
|
<li v-for="file in store.files" :key="file.NameHash">
|
|
<div class="tw-font-semibold tw-flex tw-items-center pull-right">
|
|
<span v-if="file.IsBin" class="tw-ml-0.5 tw-mr-2">{{ store.binaryFileMessage }}</span>
|
|
{{ file.IsBin ? '' : file.Addition + file.Deletion }}
|
|
<span v-if="!file.IsBin" class="diff-stats-bar tw-mx-2" :data-tooltip-content="store.statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
|
|
<div class="diff-stats-add-bar" :style="{ 'width': diffStatsWidth(file.Addition, file.Deletion) }"/>
|
|
</span>
|
|
</div>
|
|
<!-- todo finish all file status, now modify, add, delete and rename -->
|
|
<span :class="['status', diffTypeToString(file.Type)]" :data-tooltip-content="diffTypeToString(file.Type)"> </span>
|
|
<a class="file tw-font-mono" :href="'#diff-' + file.NameHash">{{ file.Name }}</a>
|
|
</li>
|
|
<li v-if="store.isIncomplete" class="tw-pt-1">
|
|
<span class="file tw-flex tw-items-center tw-justify-between">{{ store.tooManyFilesMessage }}
|
|
<a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
|
|
</span>
|
|
</li>
|
|
</ol>
|
|
</template>
|