data-service.ts
4.91 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { Menu } from './define-menu';
import { Unit } from './define-unit';
import { Qa } from './define-qa';
import { Keyword } from './define-keyword';
import { Contents } from './define-contents';
import { Storage } from '@ionic/storage';
/*
Generated class for the DataService provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class DataService {
st: Storage;
st_res: string;
contents: Contents;
menu: Menu[];
unit: Unit[];
subject: Qa[];
extunit: Unit[];
extqa: Qa[];
keyword: Keyword[];
constructor(st: Storage) {
this.st = st;
this.contents = new Contents;
this.menu = this.contents.menu;
this.unit = this.contents.unit;
this.subject = this.contents.qa;
this.extunit = this.contents.extunit;
this.extqa = this.contents.extqa;
this.keyword = this.contents.keyword;
}
public getMenuFirst(): Menu[]{
var menuFirst: Menu[] = new Array();
for (var i = 0; i < this.menu.length; i++) {
if (this.menu[i].grade === '1') {
menuFirst.push(this.menu[i]);
}
}
return menuFirst;
}
public getMenuSecond(): Menu[]{
var menuSecond: Menu[] = new Array();
for (var i = 0; i < this.menu.length; i++) {
if (this.menu[i].grade === '2') {
menuSecond.push(this.menu[i]);
}
}
return menuSecond;
}
public getMenuThird(): Menu[]{
var menuThird: Menu[] = new Array();
for (var i = 0; i < this.menu.length; i++) {
if (this.menu[i].grade === '3') {
menuThird.push(this.menu[i]);
}
}
return menuThird;
}
public getUnitNum(menuId: number): number {
var num = 0;
var chk = -1;
for (var i = 0; i < this.unit.length; i++) {
if (this.unit[i].menuId === menuId) {
if(chk != this.unit[i].unitId)
{
num++;
chk = this.unit[i].unitId;
}
}
}
return num;
}
public getUnit(menuId: number, unitId:number): Unit[] {
var subjectList: Unit[] = new Array();
for (var i = 0; i < this.unit.length; i++) {
if ((this.unit[i].unitId === unitId) && (this.unit[i].menuId === menuId)) {
subjectList.push(this.unit[i]);
}
}
return subjectList;
}
public getExtUnit(menuId: number): Unit[] {
var subjectList: Unit[] = new Array();
for (var i = 0; i < this.extunit.length; i++) {
if (this.extunit[i].menuId === menuId) {
subjectList.push(this.extunit[i]);
}
}
return subjectList;
}
public getQaCnt(menuId:number): number {
var num = 0;
for (var i = 0; i < this.subject.length; i++) {
if (this.subject[i].menuId === menuId) {
num++;
}
}
return num;
}
public getExtQaCnt(menuId:number): number {
var num = 0;
for (var i = 0; i < this.extqa.length; i++) {
if (this.extqa[i].menuId === menuId) {
num++;
}
}
return num;
}
public getQa(menuId: number, unitId: number): Qa[] {
var qaItem: Qa[] = new Array();
for (var i = 0; i < this.subject.length; i++) {
if ((this.subject[i].menuId === menuId) && (this.subject[i].unitId === unitId)) {
qaItem.push(this.subject[i]);
}
}
return qaItem;
}
public getExtqa(menuId: number, unitId: number): Qa[] {
var qaItem: Qa[] = new Array();
for (var i = 0; i < this.extqa.length; i++) {
if ((this.extqa[i].menuId === menuId) && (this.extqa[i].unitId === unitId)) {
qaItem.push(this.extqa[i]);
}
}
return qaItem;
}
public getKeyword(menuId: number): Keyword {
var key: Keyword;
for (var i = 0; i < this.keyword.length; i++) {
if (this.keyword[i].menuId === menuId) {
key = this.keyword[i];
}
}
return key;
}
public saveDone(key: string) {
this.st.get(key).then(val => {
if (val == "done") {
} else {
this.st.set(key, "done");
}
});
}
public saveInfo(key: string, value: string) {
this.st.get(key).then(val => {
if (val == null) {
this.st.set(key, value);
} else {
var svdata = val.toString().split(":");
var nwdata = value.split(":");
if(+svdata[0] < +nwdata[0])
{
this.st.set(key, value);
}
}
});
}
public savePositiveInfo(key: string, value: string) {
this.st.get(key).then(val => {
this.st.set(key, value);
});
}
public getInfo(key: string): any {
return this.st.get(key);
}
}