1 |
dd56c333
|
Jan Pašek
|
Vue.use(VueLoading);
|
2 |
|
|
Vue.component('loading', VueLoading)
|
3 |
e75db9cd
|
Jan Pašek
|
|
4 |
dd56c333
|
Jan Pašek
|
// certificate listing app VUE instance
|
5 |
|
|
var certificateListingApp = new Vue({
|
6 |
|
|
el: "#certificateListingPage",
|
7 |
|
|
data: {
|
8 |
6db8a3cb
|
Jan Pašek
|
certificatesPerPage: 2,
|
9 |
|
|
hasNextPage: false,
|
10 |
|
|
hasPreviousPage: false,
|
11 |
|
|
currentPage: 1,
|
12 |
dd56c333
|
Jan Pašek
|
loading: true,
|
13 |
|
|
// list of all certificates to be displayed in the list
|
14 |
|
|
certificates: [],
|
15 |
|
|
successMessage: ''
|
16 |
|
|
},
|
17 |
6db8a3cb
|
Jan Pašek
|
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 |
37a8e8ec
|
Jan Pašek
|
mounted: async function () {
|
63 |
dd56c333
|
Jan Pašek
|
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 |
81e73700
|
Jan Pašek
|
|
68 |
dd56c333
|
Jan Pašek
|
// 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 |
81e73700
|
Jan Pašek
|
|
73 |
dd56c333
|
Jan Pašek
|
// This will create a new entry in the browser's history, without reloading
|
74 |
|
|
window.history.pushState(nextState, nextTitle, nextURL);
|
75 |
81e73700
|
Jan Pašek
|
|
76 |
dd56c333
|
Jan Pašek
|
// This will replace the current entry in the browser's history, without reloading
|
77 |
|
|
window.history.replaceState(nextState, nextTitle, nextURL);
|
78 |
e75db9cd
|
Jan Pašek
|
}
|
79 |
|
|
|
80 |
dd56c333
|
Jan Pašek
|
// download a list of all available certificates and display them in the table
|
81 |
6db8a3cb
|
Jan Pašek
|
await this.loadPage(1, this.certificatesPerPage);
|
82 |
|
|
this.loading = false;
|
83 |
dd56c333
|
Jan Pašek
|
}
|
84 |
|
|
});
|