1
|
Vue.use(VueLoading);
|
2
|
Vue.component('loading', VueLoading)
|
3
|
|
4
|
// certificate listing app VUE instance
|
5
|
var certificateListingApp = new Vue({
|
6
|
el: "#certificateListingPage",
|
7
|
data: {
|
8
|
certificatesPerPage: 2,
|
9
|
hasNextPage: false,
|
10
|
hasPreviousPage: false,
|
11
|
currentPage: 1,
|
12
|
loading: true,
|
13
|
// list of all certificates to be displayed in the list
|
14
|
certificates: [],
|
15
|
successMessage: ''
|
16
|
},
|
17
|
methods: {
|
18
|
onNextPage: async function () {
|
19
|
this.currentPage++;
|
20
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
21
|
},
|
22
|
onPreviousPage: async function () {
|
23
|
this.currentPage--;
|
24
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
25
|
},
|
26
|
loadPage: async function (page, perPage) {
|
27
|
// download a list of all available certificates and display them in the table
|
28
|
try {
|
29
|
const response = await axios.get(API_URL + "certificates", {
|
30
|
params: {
|
31
|
page: page - 1,
|
32
|
per_page: perPage
|
33
|
}
|
34
|
});
|
35
|
if (response.data["success"]) {
|
36
|
this.certificates = [];
|
37
|
response.data["data"].forEach(item => certificateListingApp.certificates.push(item));
|
38
|
this.hasPreviousPage = page > 1;
|
39
|
this.hasNextPage = await this.checkIfNextPage(page, this.certificatesPerPage);
|
40
|
}
|
41
|
} catch (error) {
|
42
|
console.log(error);
|
43
|
}
|
44
|
},
|
45
|
checkIfNextPage: async function(page, perPage) {
|
46
|
try {
|
47
|
const response = await axios.get(API_URL + "certificates", {
|
48
|
params: {
|
49
|
page: page,
|
50
|
per_page: perPage
|
51
|
}
|
52
|
});
|
53
|
if (response.data["success"]) {
|
54
|
return response.data["data"].length > 0;
|
55
|
}
|
56
|
return false;
|
57
|
} catch (error) {
|
58
|
return false;
|
59
|
}
|
60
|
}
|
61
|
},
|
62
|
mounted: async function () {
|
63
|
const params = window.location.search;
|
64
|
if (params !== "") {
|
65
|
const urlParams = new URLSearchParams(params);
|
66
|
if (urlParams.get("success") != null) this.successMessage = urlParams.get("success");
|
67
|
|
68
|
// the following code is necessary to dismiss the alert when the page is reloaded
|
69
|
const nextURL = '/static/index.html';
|
70
|
const nextTitle = 'X.509 Certificate Management';
|
71
|
const nextState = {additionalInformation: 'Updated the URL with JS'};
|
72
|
|
73
|
// This will create a new entry in the browser's history, without reloading
|
74
|
window.history.pushState(nextState, nextTitle, nextURL);
|
75
|
|
76
|
// This will replace the current entry in the browser's history, without reloading
|
77
|
window.history.replaceState(nextState, nextTitle, nextURL);
|
78
|
}
|
79
|
|
80
|
// download a list of all available certificates and display them in the table
|
81
|
await this.loadPage(1, this.certificatesPerPage);
|
82
|
this.loading = false;
|
83
|
}
|
84
|
});
|