Projekt

Obecné

Profil

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