Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

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

Historique | Voir | Annoter | Télécharger (5,61 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

    
37
            console.log("Version locale : ", this.appVersion);
38
            setString("serverJSON", JSON.stringify(r));
39
            if (this.versionCompare(r.APPversion, this.appVersion) > 0) {
40
                console.log("On propose la mise à jour ...");
41
                //On affiche la page de mise à jour
42
                this._activatedUrl = "/upgrade";
43
                this.routerExtensions.navigate(["/upgrade"]);
44
                return;
45
            }
46
        }, (e) => {
47
            console.log("getJSON Error", e);
48
        });
49

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

    
60
        this.router.events
61
            .pipe(filter((event: any) => event instanceof NavigationEnd))
62
            .subscribe((event: NavigationEnd) => this._activatedUrl = event.urlAfterRedirects);
63
    }
64

    
65
    get sideDrawerTransition(): DrawerTransitionBase {
66
        return this._sideDrawerTransition;
67
    }
68

    
69
    isComponentSelected(url: string): boolean {
70
        return this._activatedUrl === url;
71
    }
72

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

    
80
        const sideDrawer = <RadSideDrawer>app.getRootView();
81
        sideDrawer.closeDrawer();
82
    }
83

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

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

    
113
        if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
114
            return NaN;
115
        }
116

    
117
        if (zeroExtend) {
118
            while (v1parts.length < v2parts.length) v1parts.push("0");
119
            while (v2parts.length < v1parts.length) v2parts.push("0");
120
        }
121

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

    
133
        for (var i = 0; i < v1parts.length; ++i) {
134
            if (v2parts.length == i) {
135
                return 1;
136
            }
137

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

    
149
        if (v1parts.length != v2parts.length) {
150
            return -1;
151
        }
152

    
153
        return 0;
154
    }
155
}
Redmine Appliance - Powered by TurnKey Linux