extunit.ts
2.46 KB
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
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { ExtqaPage } from '../extqa/extqa';
import { DataService } from '../../providers/data-service';
import { Unit } from '../../providers/define-unit';
/*
Generated class for the Extunit page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
*/
@Component({
selector: 'page-extunit',
templateUrl: 'extunit.html'
})
export class ExtunitPage {
menuId:number;
allNum: number;
title: string;
list1: Unit[];
list1state: Array<String> = new Array();
list1num: number;
currentItem: Unit;
positiveCnt: number;
constructor(public navCtrl: NavController, public navParams: NavParams, private dataSevice: DataService) {
this.menuId = navParams.get("menuId");
this.title = navParams.get("title");
this.currentItem = null;
this.list1 = dataSevice.getExtUnit(this.menuId);
this.list1num = this.list1.length;
this.updateStatus();
}
ionViewDidLoad() {
console.log('ionViewDidLoad ExtunitPage');
}
ionViewWillEnter() {
if(this.currentItem != null)
{
var key: string;
key = this.menuId + ":" + this.currentItem.unitId;
this.dataSevice.getInfo(key)
.then(data => {
this.updateStatus();
});
}
}
ionViewWillLeave(){
var key: string;
var value: string;
key = this.menuId.toString() + "ext";
value = this.positiveCnt.toString();
this.dataSevice.savePositiveInfo(key, value);
}
itemSelected(item: Unit) {
this.currentItem = item;
this.navCtrl.push(ExtqaPage,{menuId: this.menuId, unitId: item.unitId, title:item.unitName});
}
updateStatus()
{
var promiseArray1 = new Array();
for (var i = 0; i < this.list1num; i++) {
var key: string;
key = this.menuId + ":" + this.list1[i].unitId;
promiseArray1.push(this.dataSevice.getInfo(key));
}
Promise.all(promiseArray1)
.then(val =>
{
for(var i = 0; i< this.list1num; i++)
{
this.list1state[i] = val[i];
if(val[i] != null)
{
var svdata = val[i].toString().split(":");
this.list1state[i] = svdata[1] + "問中" + svdata[0] + "問正解!";
this.positiveCnt = +svdata[0];
}
}
});
}
}