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 |
a13b1c2d
|
Jan Pašek
|
certificatesPerPage: 20,
|
9 |
6db8a3cb
|
Jan Pašek
|
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 |
a13b1c2d
|
Jan Pašek
|
successMessage: '',
|
16 |
|
|
filtering: {
|
17 |
|
|
type: {
|
18 |
|
|
RootCA: false,
|
19 |
|
|
IntermediateCA: false,
|
20 |
|
|
EndCertificate: false,
|
21 |
|
|
},
|
22 |
|
|
usage: {
|
23 |
|
|
CA: false,
|
24 |
|
|
authentication: false,
|
25 |
|
|
digitalSignature: false,
|
26 |
|
|
SSL: false,
|
27 |
|
|
},
|
28 |
|
|
CN: "",
|
29 |
|
|
}
|
30 |
dd56c333
|
Jan Pašek
|
},
|
31 |
6db8a3cb
|
Jan Pašek
|
methods: {
|
32 |
|
|
onNextPage: async function () {
|
33 |
|
|
this.currentPage++;
|
34 |
|
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
35 |
|
|
},
|
36 |
a13b1c2d
|
Jan Pašek
|
reloadData: async function() {
|
37 |
|
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
38 |
|
|
},
|
39 |
6db8a3cb
|
Jan Pašek
|
onPreviousPage: async function () {
|
40 |
|
|
this.currentPage--;
|
41 |
|
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
42 |
|
|
},
|
43 |
|
|
loadPage: async function (page, perPage) {
|
44 |
|
|
// download a list of all available certificates and display them in the table
|
45 |
|
|
try {
|
46 |
a13b1c2d
|
Jan Pašek
|
var params = {
|
47 |
|
|
page: page - 1,
|
48 |
|
|
per_page: perPage
|
49 |
|
|
};
|
50 |
|
|
var filtering = this.getFilterParameter();
|
51 |
|
|
if (filtering != null) params.filtering = filtering;
|
52 |
6db8a3cb
|
Jan Pašek
|
const response = await axios.get(API_URL + "certificates", {
|
53 |
a13b1c2d
|
Jan Pašek
|
params: params
|
54 |
6db8a3cb
|
Jan Pašek
|
});
|
55 |
|
|
if (response.data["success"]) {
|
56 |
|
|
this.certificates = [];
|
57 |
|
|
response.data["data"].forEach(item => certificateListingApp.certificates.push(item));
|
58 |
|
|
this.hasPreviousPage = page > 1;
|
59 |
|
|
this.hasNextPage = await this.checkIfNextPage(page, this.certificatesPerPage);
|
60 |
|
|
}
|
61 |
|
|
} catch (error) {
|
62 |
|
|
console.log(error);
|
63 |
|
|
}
|
64 |
|
|
},
|
65 |
a13b1c2d
|
Jan Pašek
|
getFilterParameter: function () {
|
66 |
|
|
var type = [];
|
67 |
|
|
if (this.filtering.type.EndCertificate) type.push("end");
|
68 |
|
|
if (this.filtering.type.RootCA) type.push("root");
|
69 |
|
|
if (this.filtering.type.IntermediateCA) type.push("inter");
|
70 |
|
|
|
71 |
|
|
var usage = [];
|
72 |
|
|
if (this.filtering.usage.CA) usage.push("CA");
|
73 |
|
|
if (this.filtering.usage.SSL) usage.push("SSL");
|
74 |
|
|
if (this.filtering.usage.digitalSignature) usage.push("digitalSignature");
|
75 |
|
|
if (this.filtering.usage.authentication) usage.push("authentication");
|
76 |
|
|
|
77 |
|
|
var filtering = {};
|
78 |
|
|
if (usage.length > 0) filtering.usage = usage;
|
79 |
|
|
if (type.length > 0) filtering.type = type;
|
80 |
|
|
|
81 |
|
|
if (this.filtering.CN.length > 0) filtering.CN = this.filtering.CN;
|
82 |
|
|
|
83 |
|
|
if (this.filtering.hasOwnProperty("type") ||
|
84 |
|
|
this.filtering.hasOwnProperty("usage") ||
|
85 |
|
|
this.filtering.hasOwnProperty("CN"))
|
86 |
|
|
return filtering;
|
87 |
|
|
else
|
88 |
|
|
return null;
|
89 |
|
|
},
|
90 |
|
|
clearFilters: async function () {
|
91 |
|
|
this.filtering = {
|
92 |
|
|
type: {
|
93 |
|
|
RootCA: false,
|
94 |
|
|
IntermediateCA: false,
|
95 |
|
|
EndCertificate: false,
|
96 |
|
|
},
|
97 |
|
|
usage: {
|
98 |
|
|
CA: false,
|
99 |
|
|
authentication: false,
|
100 |
|
|
digitalSignature: false,
|
101 |
|
|
SSL: false,
|
102 |
|
|
},
|
103 |
|
|
CN: "",
|
104 |
|
|
}
|
105 |
|
|
await this.reloadData();
|
106 |
|
|
},
|
107 |
6db8a3cb
|
Jan Pašek
|
checkIfNextPage: async function(page, perPage) {
|
108 |
|
|
try {
|
109 |
|
|
const response = await axios.get(API_URL + "certificates", {
|
110 |
|
|
params: {
|
111 |
|
|
page: page,
|
112 |
|
|
per_page: perPage
|
113 |
|
|
}
|
114 |
|
|
});
|
115 |
|
|
if (response.data["success"]) {
|
116 |
|
|
return response.data["data"].length > 0;
|
117 |
|
|
}
|
118 |
|
|
return false;
|
119 |
|
|
} catch (error) {
|
120 |
|
|
return false;
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
},
|
124 |
37a8e8ec
|
Jan Pašek
|
mounted: async function () {
|
125 |
dd56c333
|
Jan Pašek
|
const params = window.location.search;
|
126 |
|
|
if (params !== "") {
|
127 |
|
|
const urlParams = new URLSearchParams(params);
|
128 |
|
|
if (urlParams.get("success") != null) this.successMessage = urlParams.get("success");
|
129 |
81e73700
|
Jan Pašek
|
|
130 |
dd56c333
|
Jan Pašek
|
// the following code is necessary to dismiss the alert when the page is reloaded
|
131 |
|
|
const nextURL = '/static/index.html';
|
132 |
|
|
const nextTitle = 'X.509 Certificate Management';
|
133 |
|
|
const nextState = {additionalInformation: 'Updated the URL with JS'};
|
134 |
81e73700
|
Jan Pašek
|
|
135 |
dd56c333
|
Jan Pašek
|
// This will create a new entry in the browser's history, without reloading
|
136 |
|
|
window.history.pushState(nextState, nextTitle, nextURL);
|
137 |
81e73700
|
Jan Pašek
|
|
138 |
dd56c333
|
Jan Pašek
|
// This will replace the current entry in the browser's history, without reloading
|
139 |
|
|
window.history.replaceState(nextState, nextTitle, nextURL);
|
140 |
e75db9cd
|
Jan Pašek
|
}
|
141 |
|
|
|
142 |
dd56c333
|
Jan Pašek
|
// download a list of all available certificates and display them in the table
|
143 |
6db8a3cb
|
Jan Pašek
|
await this.loadPage(1, this.certificatesPerPage);
|
144 |
|
|
this.loading = false;
|
145 |
dd56c333
|
Jan Pašek
|
}
|
146 |
|
|
});
|