Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

root / src / app / app.component.ts @ 2c8d373c

Historique | Voir | Annoter | Télécharger (6,01 ko)

1 f3d5fa3b Eric Seigne
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 54800558 Eric Seigne
37 f3d5fa3b Eric Seigne
            console.log("Version locale : ", this.appVersion);
38
            setString("serverJSON", JSON.stringify(r));
39
            if (this.versionCompare(r.APPversion, this.appVersion) > 0) {
40 54800558 Eric Seigne
                console.log("On propose la mise à jour ...");
41 f3d5fa3b Eric Seigne
                //On affiche la page de mise à jour
42
                this._activatedUrl = "/upgrade";
43
                this.routerExtensions.navigate(["/upgrade"]);
44 54800558 Eric Seigne
                return;
45 f3d5fa3b Eric Seigne
            }
46 2c8d373c Eric Seigne
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
56 f3d5fa3b Eric Seigne
        }, (e) => {
57
            console.log("getJSON Error", e);
58 2c8d373c Eric Seigne
            dialogs.alert({
59
                title: "Erreur de communication",
60
                message: "Le serveur principal de ClicAlbum est injoignable, veuillez re-essayer dans quelques minutes et si ça ne marche toujours pas envoyez nous un petit message à contact@abuledu.org merci :-)",
61
                okButtonText: "Ok"
62
            }).then(() => {
63
            });
64 f3d5fa3b Eric Seigne
        });
65
66
        this._sideDrawerTransition = new SlideInOnTopTransition();
67
68
        this.router.events
69
            .pipe(filter((event: any) => event instanceof NavigationEnd))
70
            .subscribe((event: NavigationEnd) => this._activatedUrl = event.urlAfterRedirects);
71
    }
72
73
    get sideDrawerTransition(): DrawerTransitionBase {
74
        return this._sideDrawerTransition;
75
    }
76
77
    isComponentSelected(url: string): boolean {
78
        return this._activatedUrl === url;
79
    }
80
81
    onNavItemTap(navItemRoute: string): void {
82
        this.routerExtensions.navigate([navItemRoute], {
83
            transition: {
84
                name: "fade"
85
            }
86
        });
87
88
        const sideDrawer = <RadSideDrawer>app.getRootView();
89
        sideDrawer.closeDrawer();
90
    }
91
92
        /**
93
     * Compares two software version numbers (e.g. "1.7.1" or "1.2b").
94
     *
95
     * This function was born in http://stackoverflow.com/a/6832721.
96
     *
97
     * @param {string} v1 The first version to be compared.
98
     * @param {string} v2 The second version to be compared.
99
     * @param {object} [options] Optional flags that affect comparison behavior:
100
     * lexicographical: (true/[false]) compares each part of the version strings lexicographically instead of naturally;
101
     *                  this allows suffixes such as "b" or "dev" but will cause "1.10" to be considered smaller than "1.2".
102
     * zeroExtend: ([true]/false) changes the result if one version string has less parts than the other. In
103
     *             this case the shorter string will be padded with "zero" parts instead of being considered smaller.
104
     *
105
     * @returns {number|NaN}
106
     * - 0 if the versions are equal
107
     * - a negative integer iff v1 < v2
108
     * - a positive integer iff v1 > v2
109
     * - NaN if either version string is in the wrong format
110
     */
111
    versionCompare(v1, v2) {
112
        var lexicographical = false,
113
            zeroExtend = true,
114
            v1parts = (v1 || "0").split('.'),
115
            v2parts = (v2 || "0").split('.');
116
117
        function isValidPart(x) {
118
            return (lexicographical ? /^\d+[A-Za-zαß]*$/ : /^\d+[A-Za-zαß]?$/).test(x);
119
        }
120
121
        if (!v1parts.every(isValidPart) || !v2parts.every(isValidPart)) {
122
            return NaN;
123
        }
124
125
        if (zeroExtend) {
126
            while (v1parts.length < v2parts.length) v1parts.push("0");
127
            while (v2parts.length < v1parts.length) v2parts.push("0");
128
        }
129
130
        if (!lexicographical) {
131
            v1parts = v1parts.map(function (x) {
132
                var match = (/[A-Za-zαß]/).exec(x);
133
                return Number(match ? x.replace(match[0], "." + x.charCodeAt(match.index)) : x);
134
            });
135
            v2parts = v2parts.map(function (x) {
136
                var match = (/[A-Za-zαß]/).exec(x);
137
                return Number(match ? x.replace(match[0], "." + x.charCodeAt(match.index)) : x);
138
            });
139
        }
140
141
        for (var i = 0; i < v1parts.length; ++i) {
142
            if (v2parts.length == i) {
143
                return 1;
144
            }
145
146
            if (v1parts[i] == v2parts[i]) {
147
                continue;
148
            }
149
            else if (v1parts[i] > v2parts[i]) {
150
                return 1;
151
            }
152
            else {
153
                return -1;
154
            }
155
        }
156
157
        if (v1parts.length != v2parts.length) {
158
            return -1;
159
        }
160
161
        return 0;
162
    }
163
}
Redmine Appliance - Powered by TurnKey Linux