-
-
Notifications
You must be signed in to change notification settings - Fork 332
/
Copy pathcatalog.riot
113 lines (108 loc) · 3.75 KB
/
catalog.riot
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
<!--
Copyright (C) 2016-2021 Jones Magloire @Joxit
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<catalog>
<material-card ref="catalog-tag" class="catalog header">
<div class="material-card-title-action">
<h2>
Repositories of { state.registryName }
<div class="item-count">{ state.nImages } images in { state.nRepositories } repositories</div>
</h2>
</div>
</material-card>
<div if="{ !state.loadend }" class="spinner-wrapper">
<material-spinner></material-spinner>
</div>
<catalog-element each="{ item in state.repositories }" item="{ item }" filter-results="{ props.filterResults }" />
<script>
import CatalogElement from './catalog-element.riot'
import {
Http
} from '../../scripts/http';
import {
getRegistryServers
} from '../../scripts/utils';
export default {
components: {
CatalogElement
},
state: {
registryName: '',
length: 0,
loadend: false,
repositories: [],
registryUrl: ''
},
onBeforeMount(props) {
this.state.registryName = props.registryName;
this.state.catalogElementsLimit = props.catalogElementsLimit;
},
onMounted(props, state) {
this.display(props, state)
},
onUpdated(props, state) {
this.display(props, state);
},
display(props, state) {
if (props.registryUrl === state.registryUrl) {
return;
}
state.registryUrl = props.registryUrl;
let repositories = [];
const self = this;
const oReq = new Http({
onAuthentication: this.props.onAuthentication
});
oReq.addEventListener('load', function () {
if (this.status == 200) {
repositories = JSON.parse(this.responseText).repositories || [];
repositories.sort();
repositories = repositories.reduce(function (acc, e) {
const slash = e.indexOf('/');
if (slash > 0) {
const repoName = e.substring(0, slash) + '/';
if (acc.length == 0 || acc[acc.length - 1].repo != repoName) {
acc.push({
repo: repoName,
images: []
});
}
acc[acc.length - 1].images.push(e);
return acc;
}
acc.push(e);
return acc;
}, []);
} else if (this.status == 404) {
self.props.onNotify('Server not found', true);
} else {
self.props.onNotify(this.responseText);
}
});
oReq.addEventListener('error', function () {
self.props.onNotify(this.getErrorMessage(), true);
});
oReq.addEventListener('loadend', function () {
self.update({
repositories,
nRepositories: repositories.length,
nImages: repositories.reduce((acc, e) => acc + (e.images && e.images.length || 1), 0),
loadend: true
});
});
oReq.open('GET', `${props.registryUrl}/v2/_catalog?n=${state.catalogElementsLimit}`);
oReq.send();
}
}
</script>
</catalog>