aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/views/RepositoryTree.vue
blob: 80a5c3b118cec0dd301ff932601ed6c54ebebc72 (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
<template>
	<RepositoryNavbar active-page="tree" :repository="repository" />
	<div class="row mx-0 vld-parent">
		<Loading
			v-model:active="is_loading" :height="24"
			:width="24" color="#ffffff"
			:opacity="0" />
		<div class="col ms-4 ps-4 ps-sm-5 mt-3">
			<RepositoryTreeTree
				:repository="repository" :path="path"
				:tree="tree" v-if="type === 'tree'" />
			<RepositoryTreeBlob
				:repository="repository" :path="path"
				:content="blob_content" v-else />
		</div>
	</div>
</template>

<script>
import RepositoryNavbar from "../components/RepositoryNavbar";
import RepositoryTreeTree from "../components/RepositoryTreeTree";
import RepositoryTreeBlob from "../components/RepositoryTreeBlob";
import Loading from "vue-loading-overlay";
import 'vue-loading-overlay/dist/vue-loading.css';
import { ref } from "vue";

export default {
	name: "RepositoryTree",
	components: {
		RepositoryNavbar,
		Loading,
		RepositoryTreeTree,
		RepositoryTreeBlob
	},
	props: {
		repository: {
			type: String,
			required: true
		},
		pathArr: {
			type: Array,
			required: true
		}
	},
	watch: {
		pathArr()
		{
			this.fetchTree();
		}
	},
	setup(props)
	{
		const type = ref("");
		const tree = ref({});
		const blob_content = ref("");
		const is_loading = ref(true);
		const path = ref("");

		const fetchTree = async () =>
		{
			path.value = props.pathArr ? props.pathArr.join("/") : undefined;
			const data = await (await fetch(`${window.location.protocol}//${window.location.host}/api/v1/repos/${props.repository}/tree${path.value ? "?path=" + path.value : ""}`)).json();
			
			console.log(path.value);
			type.value = data["data"]["type"];

			if(data["data"]["type"] === "tree") {
				const tree_data = data["data"]["tree"];

				let tree_trees = Object.entries(tree_data).filter((entry) => entry[1].type === "tree");
				tree_trees = tree_trees.sort((a, b) => a[0].localeCompare(b[0]));

				let tree_blobs = Object.entries(tree_data).filter((entry) => entry[1].type === "blob");
				tree_blobs = tree_blobs.sort((a, b) => a[0].localeCompare(b[0]));

				tree.value = Object.fromEntries(tree_trees.concat(tree_blobs));
			}
			else {
				blob_content.value = data["data"]["content"];
			}

			is_loading.value = false;
		};

		return {
			type,
			tree,
			blob_content,
			is_loading,
			path,
			fetchTree
		};
	},
	mounted()
	{
		console.log("VAFAAAN öaöaöaö");
		this.fetchTree();
	}
};
</script>