Projekt

Obecné

Profil

Stáhnout (5.51 KB) Statistiky
| Větev: | Tag: | Revize:
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: 20,
9
        hasNextPage: false,
10
        hasPreviousPage: false,
11
        currentPage: 1,
12
        displayFilters: false,
13
        loading: true,
14
        // list of all certificates to be displayed in the list
15
        certificates: [],
16
        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
    },
32
    methods: {
33
        onNextPage: async function () {
34
            this.currentPage++;
35
            await this.loadPage(this.currentPage, this.certificatesPerPage);
36
        },
37
        reloadData: async function() {
38
            await this.loadPage(this.currentPage, this.certificatesPerPage);
39
        },
40
        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
                var params = {
48
                    page: page - 1,
49
                    per_page: perPage
50
                };
51
                var filtering = this.getFilterParameter();
52
                if (filtering != null) params.filtering = filtering;
53
                const response = await axios.get(API_URL + "certificates", {
54
                    params: params
55
                });
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
        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
        toggleFilters: function (){
92
            this.displayFilters = ~this.displayFilters;
93
        },
94
        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
        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
    mounted: async function () {
129
        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

    
134
            // 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

    
139
            // This will create a new entry in the browser's history, without reloading
140
            window.history.pushState(nextState, nextTitle, nextURL);
141

    
142
            // This will replace the current entry in the browser's history, without reloading
143
            window.history.replaceState(nextState, nextTitle, nextURL);
144
        }
145

    
146
        // download a list of all available certificates and display them in the table
147
        await this.loadPage(1, this.certificatesPerPage);
148
        this.loading = false;
149
    }
150
});
(9-9/11)