Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 6db8a3cb

Přidáno uživatelem Jan Pašek před téměř 4 roky(ů)

Re #8706 - Pagination implemented

Zobrazit rozdíly:

static/js/index.js
5 5
var certificateListingApp = new Vue({
6 6
    el: "#certificateListingPage",
7 7
    data: {
8
        certificatesPerPage: 2,
9
        hasNextPage: false,
10
        hasPreviousPage: false,
11
        currentPage: 1,
8 12
        loading: true,
9 13
        // list of all certificates to be displayed in the list
10 14
        certificates: [],
11 15
        successMessage: ''
12 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
    },
13 62
    mounted: async function () {
14 63
        const params = window.location.search;
15 64
        if (params !== "") {
......
29 78
        }
30 79

  
31 80
        // download a list of all available certificates and display them in the table
32
        try {
33
            const response = await axios.get(API_URL + "certificates");
34
            if (response.data["success"]) {
35
                response.data["data"].forEach(item => certificateListingApp.certificates.push(item))
36
            }
37
            certificateListingApp.loading = false;
38
        } catch (error) {
39
            console.log(error);
40
            certificateListingApp.loading = false;
41
        }
81
        await this.loadPage(1, this.certificatesPerPage);
82
        this.loading = false;
42 83
    }
43 84
});

Také k dispozici: Unified diff