-
Notifications
You must be signed in to change notification settings - Fork 2
/
SdaDialogDelegateStateVisitor.ts
113 lines (86 loc) · 3.21 KB
/
SdaDialogDelegateStateVisitor.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
112
113
import {JsonObjectVisitor} from "../proxy";
import {BriefcaseVisitor} from "./BriefcaseVisitor";
import {MobileCommentsRecordSetVisitor} from "./MobileCommentsRecordSetVisitor";
import {WorkPackagesRecordSetVisitor} from "./WorkPackagesRecordSetVisitor";
/**
*
*/
export class SdaDialogDelegateStateVisitor implements JsonObjectVisitor {
private _enclosedJsonObject: any;
constructor(state: string | object) {
if (typeof state === 'string') {
this._enclosedJsonObject = JSON.parse(state as string);
} else {
this._enclosedJsonObject = state;
}
}
// --- State Management Helpers --- //
// --- State Import/Export --- //
public enclosedJsonObject() {
return this._enclosedJsonObject;
}
public copyAsJsonObject(): object {
return JSON.parse(this.copyAsJsonString());
}
public copyAsJsonString(): string {
return JSON.stringify(this.enclosedJsonObject());
}
// --- State Management --- //
public addSelectedWorkPackageId(id: string) {
const index = this.enclosedJsonObject().selectedWorkPackageIds.indexOf(id);
if (index === -1) {
this.enclosedJsonObject().selectedWorkPackageIds.push(id);
}
}
public removeSelectedWorkPackageId(id: string) {
const index = this.enclosedJsonObject().selectedWorkPackageIds.indexOf(id);
if (index > -1) {
this.enclosedJsonObject().selectedWorkPackageIds.splice(index, 1);
}
}
public visitBaseUrl(): string {
return this.enclosedJsonObject().baseUrl;
}
public visitAndSetBaseUrl(baseUrl: string) {
this.enclosedJsonObject().baseUrl = baseUrl;
}
public visitBriefcase(): BriefcaseVisitor {
return new BriefcaseVisitor(this.enclosedJsonObject().briefcase);
}
public visitLoginHash(): string {
return this.enclosedJsonObject().loginHash;
}
public visitAndSetLoginHash(loginHash: string) {
this.enclosedJsonObject().loginHash = loginHash;
}
public visitSelectedWorkPackageIds(): string[] {
return this.enclosedJsonObject().selectedWorkPackageIds;
}
public visitAndClearSelectedWorkPackageIds() {
return this.enclosedJsonObject().selectedWorkPackageIds = [];
}
public visitSessionId(): string {
return this.enclosedJsonObject().sessionId;
}
public visitAndSetSessionId(sessionId: string) {
this.enclosedJsonObject().sessionId = sessionId;
}
public visitTenantId(): string {
return this.enclosedJsonObject().tenantId;
}
public visitAndSetTenantId(tenantId: string) {
this.enclosedJsonObject().tenantId = tenantId;
}
public visitUserId(): string {
return this.enclosedJsonObject().userId;
}
public visitAndSetUserId(userId: string) {
this.enclosedJsonObject().userId = userId;
}
public visitMobileCommentsRecordSet(): MobileCommentsRecordSetVisitor {
return new MobileCommentsRecordSetVisitor(this.enclosedJsonObject().mobileComments);
}
public visitWorkPackagesRecordSet(): WorkPackagesRecordSetVisitor {
return new WorkPackagesRecordSetVisitor(this.enclosedJsonObject().workPackages);
}
}