-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetrangeHandler.ts
97 lines (94 loc) · 2.92 KB
/
getrangeHandler.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
import { Injectable, Injector, Inject } from "@angular/core";
import { Http } from "@angular/http";
import { Observable } from "rxjs/Observable";
import {
WiContrib,
WiServiceHandlerContribution,
IContributionTypes,
ActionResult,
IActionResult,
WiContribModelService,
IFieldDefinition,
WiContributionUtils,
IActivityContribution,
IConnectorContribution,
} from "wi-studio/app/contrib/wi-contrib";
import {
IValidationResult,
ValidationResult,
} from "wi-studio/common/models/validation";
@WiContrib({})
@Injectable()
export class getrangeHandler extends WiServiceHandlerContribution {
constructor(private injector: Injector, private http: Http) {
super(injector, http);
}
value = (
fieldName: string,
context: IActivityContribution
): Observable<any> | any => {
if (fieldName === "result") {
let resultField: IFieldDefinition = context.getField("result");
if (resultField.value) {
let sch = JSON.parse(resultField.value);
// check schema object type, and convert to key-value type
if (sch["type"] == "object") {
let data = {};
data["type"] = "object";
data["properties"] = sch["properties"];
let keyval = {};
keyval["key"] = { type: "string" };
keyval["value"] = data;
let item = {};
item["type"] = "object";
item["properties"] = keyval;
let resultschema = {};
resultschema["$schema"] = sch["$schema"];
resultschema["type"] = "array";
resultschema["items"] = item;
return JSON.stringify(resultschema, null, 2);
}
}
}
return null;
};
validate = (
fieldName: string,
context: IActivityContribution
): Observable<IValidationResult> | IValidationResult => {
if (
fieldName === "pageSize" ||
fieldName === "start" ||
fieldName === "bookmark"
) {
let vresult: IValidationResult = ValidationResult.newValidationResult();
let paginationField: IFieldDefinition = context.getField("usePagination");
let valueField: IFieldDefinition = context.getField(fieldName);
if (paginationField.value && paginationField.value === true) {
if (valueField.display && valueField.display.visible == false) {
vresult.setVisible(true);
}
} else {
vresult.setVisible(false);
}
return vresult;
} else if (fieldName === "result") {
let vresult: IValidationResult = ValidationResult.newValidationResult();
let resultField: IFieldDefinition = context.getField("result");
if (resultField.value) {
try {
let valRes;
valRes = JSON.parse(resultField.value);
valRes = JSON.stringify(valRes);
} catch (e) {
vresult.setError(
"FABTIC-GETRANGE-1000",
"Invalid JSON: " + e.toString()
);
}
}
return vresult;
}
return null;
};
}