-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathRepositories.vue
More file actions
118 lines (114 loc) · 3.41 KB
/
Repositories.vue
File metadata and controls
118 lines (114 loc) · 3.41 KB
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
<template>
<div>
<div v-if="noResultsFound" class="unavailable-message">No matching repositories found.</div>
<LoadingSpan v-if="pageLoading" message="Loading repositories" />
<GTable v-else id="shed-search-results" :items="repositories" :fields="fields">
<template v-slot:cell(name)="{ item, toggleDetails }">
<GLink href="#" @click.prevent="toggleDetails">{{ item.name }}</GLink>
<div>{{ item.description }}</div>
</template>
<template v-slot:row-details="{ item }">
<RepositoryDetails :repo="item" :toolshed-url="toolshedUrl" />
</template>
</GTable>
</div>
</template>
<script>
import { Services } from "../services";
import GLink from "@/components/BaseComponents/GLink.vue";
import GTable from "@/components/Common/GTable.vue";
import LoadingSpan from "@/components/LoadingSpan.vue";
import RepositoryDetails from "@/components/Toolshed/RepositoryDetails/Index.vue";
const READY = 0;
const LOADING = 1;
const COMPLETE = 2;
export default {
components: {
LoadingSpan,
GLink,
GTable,
RepositoryDetails,
},
props: {
query: {
type: String,
required: true,
},
scrolled: {
type: Boolean,
required: true,
},
toolshedUrl: {
type: String,
required: true,
},
},
data() {
return {
repositories: [],
fields: [
{ key: "name", label: "Name", sortable: true },
{ key: "owner", label: "Owner", sortable: true },
{ key: "times_downloaded", label: "Downloaded", sortable: true },
{ key: "last_updated", label: "Updated", sortable: true },
],
page: 1,
pageSize: 50,
pageState: READY,
error: null,
};
},
computed: {
pageLoading() {
return this.pageState === LOADING;
},
noResultsFound() {
return this.repositories.length === 0 && !this.pageLoading;
},
},
watch: {
toolshedUrl() {
this.load();
},
query() {
this.load();
},
scrolled() {
if (this.scrolled && this.pageState === READY) {
this.load(this.page + 1);
}
},
},
created() {
this.services = new Services();
this.load();
},
methods: {
load(page = 1) {
this.page = page;
this.pageState = LOADING;
if (page == 1) {
this.repositories = [];
}
this.services
.getRepositories({
tool_shed_url: this.toolshedUrl,
q: this.query,
page: this.page,
page_size: this.pageSize,
})
.then((incoming) => {
this.repositories = this.repositories.concat(incoming);
if (incoming.length < this.pageSize) {
this.pageState = COMPLETE;
} else {
this.pageState = READY;
}
})
.catch((errorMessage) => {
this.$emit("onError", errorMessage);
});
},
},
};
</script>