Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

root / src / app / app.component.ts @ f3d5fa3b

Historique | Voir | Annoter | Télécharger (5,53 ko)

1
import { Component, OnInit } from "@angular/core";
2
import { NavigationEnd, Router } from "@angular/router";
3
import { RouterExtensions } from "nativescript-angular/router";
4
import { DrawerTransitionBase, RadSideDrawer, SlideInOnTopTransition } from "nativescript-ui-sidedrawer";
5
import { filter } from "rxjs/operators";
6
import * as app from "tns-core-modules/application";
7
import { getString, setString } from "tns-core-modules/application-settings";
8
import * as appversion from "nativescript-appversion";
9
import { getFile, getImage, getJSON, request, HttpResponse } from "tns-core-modules/http";
10
import * as dialogs from "tns-core-modules/ui/dialogs";
11

    
12
@Component({
13
    selector: "ns-app",
14
    templateUrl: "app.component.html"
15
})
16
export class AppComponent implements OnInit {
17
    private _activatedUrl: string;
18
    private _sideDrawerTransition: DrawerTransitionBase;
19
    public pseudo: string;
20
    public email: string;
21
    public appVersion: string;
22

    
23
    constructor(private router: Router, private routerExtensions: RouterExtensions) {
24
        // Use the component constructor to inject services.
25
        appversion.getVersionName().then((v: string) => {
26
            this.appVersion = v;
27
            setString("appVersion", v);
28
        });
29
    }
30

    
31
    ngOnInit(): void {
32
        this.pseudo = getString("pseudo", "");
33
        this.email = getString("email", "");
34
        getJSON("https://clicalbum.abuledu.net/api.php").then((r: any) => {
35
            console.log("Verification de la version : ", r.APPversion);
36
            console.log("Version locale : ", this.appVersion);
37
            setString("serverJSON", JSON.stringify(r));
38
            if (this.versionCompare(r.APPversion, this.appVersion) > 0) {
39
                //On affiche la page de mise à jour
40
                this._activatedUrl = "/upgrade";
41
                this.routerExtensions.navigate(["/upgrade"]);
42
            }
43
        }, (e) => {
44
            console.log("getJSON Error", e);
45
        });
46

    
47
        if (this.email == "" || this.pseudo == "") {
48
            // alert("L'application n'est pas configurée ...")
49
            this._activatedUrl = "/settings";
50
            this.routerExtensions.navigate(["/settings"]);
51
        }
52
        else {
53
            this._activatedUrl = "/home";
54
        }
55
        this._sideDrawerTransition = new SlideInOnTopTransition();
56

    
57
        this.router.events
58
            .pipe(filter((event: any) => event instanceof NavigationEnd))
59
            .subscribe((event: NavigationEnd) => this._activatedUrl = event.urlAfterRedirects);
60
    }
61

    
62
    get sideDrawerTransition(): DrawerTransitionBase {
63
        return this._sideDrawerTransition;
64
    }
65

    
66
    isComponentSelected(url: string): boolean {
67
        return this._activatedUrl === url;
68
    }
69

    
70
    onNavItemTap(navItemRoute: string): void {
71
        this.routerExtensions.navigate([navItemRoute], {
72
            transition: {
73
                name: "fade"
74
            }
75
        });
76

    
77
        const sideDrawer = <RadSideDrawer>app.getRootView();
78
        sideDrawer.closeDrawer();
79
    }
80

    
81
        /**
82
     * Compares two software version numbers (e.g. "1.7.1" or "1.2b").
83
     *
84
     * This function was born in http://stackoverflow.com/a/6832721.
85
     *
86
     * @param {string} v1 The first version to be compared.
87
     * @param {string} v2 The second version to be compared.
88
     * @param {object} [options] Optional flags that affect comparison behavior:
89
     * lexicographical: (true/[false]) compares each part of the version strings lexicographically instead of naturally;
90
     *                  this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than "1.2".
91
     * zeroExtend: ([true]/false) changes the result if one version string has less parts than the other. In
92
     *             this case the shorter string will be padded with "zero" parts instead of being considered smaller.
93
     *
94
     * @returns {number|NaN}
95
     * - 0 if the versions are equal
96
     * - a negative integer iff v1 < v2
97
     * - a positive integer iff v1 > v2
98
     * - NaN if either version string is in the wrong format
99
     */
100
    versionCompare(v1, v2) {
101
        var lexicographical = false,
102
            zeroExtend = true,
103
            v1parts = (v1 || "0").split('.'),
104
            v2parts = (v2 || "0").split('.');
105

    
106
        function isValidPart(x) {
107
            return (lexicographical ? /^\d+[A-Za-zαß]*$/ : /^\d+[A-Za-zαß]?$/).test(x);
108
        }
109

    
110
        if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
111
            return NaN;
112
        }
113

    
114
        if (zeroExtend) {
115
            while (v1parts.length < v2parts.length) v1parts.push("0");
116
            while (v2parts.length < v1parts.length) v2parts.push("0");
117
        }
118

    
119
        if (!lexicographical) {
120
            v1parts = v1parts.map(function (x) {
121
                var match = (/[A-Za-zαß]/).exec(x);
122
                return Number(match ? x.replace(match[0], "." + x.charCodeAt(match.index)) : x);
123
            });
124
            v2parts = v2parts.map(function (x) {
125
                var match = (/[A-Za-zαß]/).exec(x);
126
                return Number(match ? x.replace(match[0], "." + x.charCodeAt(match.index)) : x);
127
            });
128
        }
129

    
130
        for (var i = 0; i < v1parts.length; ++i) {
131
            if (v2parts.length == i) {
132
                return 1;
133
            }
134

    
135
            if (v1parts[i] == v2parts[i]) {
136
                continue;
137
            }
138
            else if (v1parts[i] > v2parts[i]) {
139
                return 1;
140
            }
141
            else {
142
                return -1;
143
            }
144
        }
145

    
146
        if (v1parts.length != v2parts.length) {
147
            return -1;
148
        }
149

    
150
        return 0;
151
    }
152
}
Redmine Appliance - Powered by TurnKey Linux