aboutsummaryrefslogtreecommitdiff
path: root/packages/client/src/components/RepositoryTreeTree.vue
blob: 89ffb81268b80fafc6b5c351405ffd3350230fc0 (plain)
1
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
114
<template>
	<table id="tree" class="fs-5">
		<thead>
			<tr>
				<th>Name</th>
				<th>Last commit</th>
				<th>Last updated</th>
			</tr>
		</thead>
		<tbody>
			<tr v-if="path !== ''" @click="$router.push(`/${repository}/tree/${path.split('/').slice(0, -1).join('/') }`)">
				<td
					class="d-flex align-items-center">
					<div class="tree-entry-padding" />
					..
				</td>
				<td />
				<td />
			</tr>
			<tr
				v-for="(entry, entry_name, index) in tree" :key="index"
				@click="$router.push(`/${repository}/tree${path ? '/' + path : ''}/${entry_name}`)">
				<td class="d-flex align-items-center">
					<svg
						xmlns="http://www.w3.org/2000/svg" height="18px"
						viewBox="0 0 24 24" width="18px"
						fill="#FFFFFF" v-if="entry['type'] === 'tree'"
						preserveAspectRatio="xMidYMin">
						<path d="M0 0h24v24H0z" fill="none" />
						<path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z" />
					</svg>
					<span v-else class="tree-entry-padding" />
					<a @click="stopClick" :href="`/${repository}/tree${path ? '/' + path : ''}/${entry_name}`">{{ entry_name }}</a>
				</td>
				<td>
					<a @click="routeToCommit(entry.last_commit.id, $event)" :href="`/${repository}/log/${entry.last_commit.id}`">
						{{ entry.last_commit.message }}
					</a>
				</td>
				<td>
					{{ getPrettyLastUpdated(entry.last_commit.time) }}
				</td>
			</tr>
		</tbody>
	</table>
</template>

<script>
const { formatDistance } = require("date-fns");

export default {
	name: "RepositoryTreeTree",
	props: {
		repository: {
			type: String,
			required: true
		},
		path: {
			type: String,
			required: true
		},
		tree: {
			type: Object,
			required: true
		}
	},
	methods: {
		stopClick(event) {
			event.preventDefault();
		},
		routeToCommit(commit_id, event) {
			event.stopPropagation();
			event.preventDefault();
			this.$router.push(`/${this.repository}/log/${commit_id}`);
		},
		getPrettyLastUpdated(date) {
			return formatDistance(new Date(), new Date(date));
		}
	}
};
</script>

<style lang="scss" scoped>
@use "../scss/colors";
@import "../scss/bootstrap";

#tree {
	border-spacing: 0;
	th {
		padding-bottom: 5px;
		color: colors.$secondary;
		text-align: start;
		padding-right: 20px;
	}
	tbody tr:hover {
		background-color: lighten(colors.$background, 10%);
	}
	td {
		padding-top: 5px;
		padding-bottom: 5px;
		padding-right: 2vw;
		&:nth-child(2) a, &:nth-child(3) {
			font-weight: 300;
		}
	}
	.tree-entry-padding, svg {
		width: 18px;
		padding-right: 5px;
	}
	a {
		padding-right: 18px;
	}
}
</style>