aboutsummaryrefslogtreecommitdiff
path: root/packages/client/src/components/RepositoryTreeTree.vue
blob: 21f957025064f36a8759284f1fa052a571e9bec0 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<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="flex-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="flex-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.date) }}
				</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";

table {
	border-spacing: 0;
	width: 100%;
	margin-bottom: 1rem;
	tbody {
		vertical-align: inherit;
		tr {
			&:hover {
				background-color: lighten(colors.$background, 5%);
			}
			td {
				padding-bottom: 1em;
				&:nth-child(2) a, &:nth-child(3) {
					font-weight: 300;
				}
				padding-top: 5px;
				padding-bottom: 5px;
				padding-right: 2vw;
			}
		}
	}
	thead {
		vertical-align: bottom;
	}
	th {
		text-align: start;
		padding-bottom: 1em;
		color: colors.$secondary;
	}
	> :not(caption) > * > * {
		padding: 0.2rem 1rem;
		border-bottom-width: 1px;
	}
	.tree-entry-padding, svg {
		width: 18px;
		padding-right: 5px;
	}
}

#log {
	padding-left: 0;
}

@media (max-width: 576px) {
	table > :not(caption) > * > * {
		padding: 0.1rem;
	}
}
.flex-center {
	display: flex;
	align-items: center;
}
</style>