summaryrefslogtreecommitdiffstats
path: root/web_src/js/components/DiffFileTreeItem.vue
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /web_src/js/components/DiffFileTreeItem.vue
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'web_src/js/components/DiffFileTreeItem.vue')
-rw-r--r--web_src/js/components/DiffFileTreeItem.vue97
1 files changed, 97 insertions, 0 deletions
diff --git a/web_src/js/components/DiffFileTreeItem.vue b/web_src/js/components/DiffFileTreeItem.vue
new file mode 100644
index 0000000..0f6e543
--- /dev/null
+++ b/web_src/js/components/DiffFileTreeItem.vue
@@ -0,0 +1,97 @@
+<script>
+import {SvgIcon} from '../svg.js';
+import {diffTreeStore} from '../modules/stores.js';
+
+export default {
+ components: {SvgIcon},
+ props: {
+ item: {
+ type: Object,
+ required: true,
+ },
+ },
+ data: () => ({
+ store: diffTreeStore(),
+ collapsed: false,
+ }),
+ methods: {
+ getIconForDiffType(pType) {
+ const diffTypes = {
+ 1: {name: 'octicon-diff-added', classes: ['text', 'green']},
+ 2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
+ 3: {name: 'octicon-diff-removed', classes: ['text', 'red']},
+ 4: {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
+ 5: {name: 'octicon-diff-renamed', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
+ };
+ return diffTypes[pType];
+ },
+ },
+};
+</script>
+<template>
+ <!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
+ <a
+ v-if="item.isFile" class="item-file"
+ :class="{'selected': store.selectedItem === '#diff-' + item.file.NameHash, 'viewed': item.file.IsViewed}"
+ :title="item.name" :href="'#diff-' + item.file.NameHash"
+ >
+ <!-- file -->
+ <SvgIcon name="octicon-file"/>
+ <span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
+ <SvgIcon :name="getIconForDiffType(item.file.Type).name" :class="getIconForDiffType(item.file.Type).classes"/>
+ </a>
+ <div v-else class="item-directory" :title="item.name" @click.stop="collapsed = !collapsed">
+ <!-- directory -->
+ <SvgIcon :name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"/>
+ <SvgIcon class="text primary" name="octicon-file-directory-fill"/>
+ <span class="gt-ellipsis">{{ item.name }}</span>
+ </div>
+
+ <div v-if="item.children?.length" v-show="!collapsed" class="sub-items">
+ <DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem"/>
+ </div>
+</template>
+<style scoped>
+a, a:hover {
+ text-decoration: none;
+ color: var(--color-text);
+}
+
+.sub-items {
+ display: flex;
+ flex-direction: column;
+ gap: 1px;
+ margin-left: 13px;
+ border-left: 1px solid var(--color-secondary);
+}
+
+.sub-items .item-file {
+ padding-left: 18px;
+}
+
+.item-file.selected {
+ color: var(--color-text);
+ background: var(--color-active);
+ border-radius: 4px;
+}
+
+.item-file.viewed {
+ color: var(--color-text-light-3);
+}
+
+.item-file,
+.item-directory {
+ display: flex;
+ align-items: center;
+ gap: 0.25em;
+ padding: 3px 6px;
+}
+
+.item-file:hover,
+.item-directory:hover {
+ color: var(--color-text);
+ background: var(--color-hover);
+ border-radius: 4px;
+ cursor: pointer;
+}
+</style>