-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-travels.page.ts
111 lines (96 loc) · 3.08 KB
/
next-travels.page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { Component, OnInit } from '@angular/core';
import { NavController, ModalController} from '@ionic/angular';
import { Router } from '@angular/router';
import { AddTravelService } from '../add-travel.service';
import { UserInfoService } from '../user-info.service';
import { Storage } from '@ionic/storage';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { MyurlsService } from '../myurls.service';
@Component({
selector: 'app-next-travels',
templateUrl: './next-travels.page.html',
styleUrls: ['./next-travels.page.scss'],
})
export class NextTravelsPage implements OnInit {
slideOpts = {
initialSlide: 1,
speed: 400
};
tsa = [];
noItem = false;
constructor(public navCtrl: NavController,
public modalCtrl: ModalController,
public router: Router,
public ats: AddTravelService,
public userInfo: UserInfoService,
public storage: Storage,
private http: HttpClient,
private url: MyurlsService) {
this.load();
}
ngOnInit() {
}
load() {
/*this.storage.get('travels').then( (array: any[]) => {
if (!(array === null || array === [])) {
this.sortTravelsByDate(array);
} else {
this.noItem = true;
}
});*/
const headers: any = new HttpHeaders({ 'Content-Type': 'application/json' }),
options: any = {key: 'nextTravels', params: {login: this.userInfo.info.login}};
this.http.post(this.url.retrieveUrl, JSON.stringify(options), headers)
.subscribe((array: any) => {
if (!(array === null || array === [])) {
this.sortTravelsByDate(array);
} else {
this.noItem = true;
}
this.storage.get('travels').then( (tab: any[]) => {
if (!(tab === null)) {
tab = array;
} else {
array = [tab];
}
this.storage.set('travels', tab).then( () => {
});
});
},
(error: any) => {
console.log(error);
});
}
goBack() {
this.navCtrl.back();
}
sortTravelsByDate(array: any[]) {
if (!(array === undefined)) {
if (!(array.length === 0)) {
array.forEach((elm: any, index) => {
const elmDate: string = elm.Date;
const date = new Date();
if ((date.getFullYear() <= Number(elmDate.split('-')[0])) &&
(date.getMonth() <= Number(elmDate.split('-')[1]) - 1) &&
(date.getDate() <= Number(elmDate.split('-')[2]))) {
this.tsa.push(elm);
}
});
}
}
}
receivePartners() {
}
showPartners(index: number) {
const headers: any = new HttpHeaders({ 'Content-Type': 'application/json' }),
options: any = {key: 'partners', params: {idTrajet: this.tsa[index].IdTrajet}};
this.http.post(this.url.retrieveUrl, JSON.stringify(options), headers)
.subscribe((data: any) => {
this.ats.data.Data = {partners: data, id: this.tsa[index].IdTrajet};
this.router.navigateByUrl('/popover-component');
},
(error: any) => {
console.log(error);
});
}
}