forked from RallyCommunity/RallyTreeGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRallyTreeProxy.js
200 lines (162 loc) · 6.11 KB
/
RallyTreeProxy.js
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
188
189
190
191
192
193
194
195
196
197
198
199
200
(function (global) {
Ext.define("Rally.data.WsapiTreeProxy", {
requires: ["Rally.data.WsapiReader"],
extend: "Rally.data.WsapiRestProxy",
topLevelModels: null, //["HierarchicalRequirement"],
childModels: null, //["HierarchicalRequirement"],
isRoot: false,
model: null,
constructor: function ctor(config) {
var me = this;
Ext.apply(me, config);
me.reader = Ext.create("Rally.data.WsapiReader", {
root: "HierarchicalRequirement",
totalProperty: "TotalResultCount"
});
//console.log("For Artifacts", me.topLevelModels, me.childModels);
//debugger;
},
read: function read(operation, callback, scope) {
var me = this;
//console.log("Calling WTP Read", operation);
if (me.isRoot) {
me._readRoot(operation, callback, scope);
} else {
me._readChildren(operation, callback, scope);
}
},
_readRoot: function _readRoot(operation, callback, scope) {
var loadedArtifacts = {},
me = this,
processCB = Ext.bind(this._processResults, {filterFn: me.filterFn, loadedArtifacts: loadedArtifacts, operation: operation, callback: callback, scope: scope}),
i= 0, ii = me.topLevelModels.length;
//console.log("Reading Root");
var iHateJsScoping = function iHateJsScoping(type) {
var sorter = [{
property: "Rank",
direction: "ASC"
}];
Rally.data.TreeModelFactory.getModel({
type: type,
canExpandFn: me.canExpandFn,
success: function onSuccess(model) {
var query = model.buildParentQueryFn(model, null);
if (me.wsapiStoreOptions.query) {
query = query.and(me.wsapiStoreOptions.query);
}
var wsapi = Ext.create("Rally.data.WsapiDataStore", {
autoLoad: false,
model: model,
pageSize: me.wsapiStoreOptions.limit,
startPage: me.wsapiStoreOptions.page,
page: me.wsapiStoreOptions.page,
start: me.wsapiStoreOptions.start,
limit: me.wsapiStoreOptions.limit,
isPaging: me.wsapiStoreOptions.isPaging,
filters: query,
sorters: model.superclass.self.typeName.toLowerCase() !== "testcase" ? sorter : null,
listeners: {
load: function loaded(store, data, success) {
processCB(store, data, type);
}
}
});
wsapi.loadPage(me.wsapiStoreOptions.page);
}
});
};
for (; i < ii; i++) {
loadedArtifacts[me.topLevelModels[i].toLowerCase()] = 0;
iHateJsScoping(me.topLevelModels[i].toLowerCase());
}
},
_readChildren: function _readChildren(operation, callback, scope) {
var loadedArtifacts = {},
me = this,
processCB = Ext.bind(this._processResults, {
filterFn: me.filterFn,
loadedArtifacts: loadedArtifacts,
operation: operation,
callback: callback,
scope: scope}),
i= 0, ii = me.childModels.length;
//console.log("Reading Children");
var iHateJsScoping = function iHateJsScoping(type) {
var sorter = [{
property: "Rank",
direction: "ASC"
}];
Rally.data.TreeModelFactory.getModel({
canExpandFn: me.canExpandFn,
type: type,
success: function onSuccess(model) {
Ext.create("Rally.data.WsapiDataStore", {
autoLoad: true,
filters: model.buildParentQueryFn(model, operation.node),
sorters: model.superclass.self.typeName.toLowerCase() !== "testcase" ? sorter : null,
model: model,
listeners: {
load: function loaded(store, data, success) {
//console.log("Loaded Children", type, store, data, success);
processCB(store, data, type);
}
}
});
}
});
};
for (; i < ii; i++) {
//console.log("Fetching children of type", me.childModels[i], i, ii);
loadedArtifacts[me.childModels[i].toLowerCase()] = 0;
iHateJsScoping(me.childModels[i].toLowerCase());
}
},
_processResults: function (store, data, artifactType) {
//console.log("Loaded " + artifactType, data, this);
if (this.loadedArtifacts[artifactType.toLowerCase()]) {
//console.log("Already processed, abort");
return;
}
if (typeof this.operation.resultSet === "undefined") {
this.operation.resultSet = [];
}
if (typeof this.operation.totalResultCount === "undefined") {
this.operation.totalResultCount = 0;
}
var i, ii, k, done = true;
this.operation.totalResultCount = this.operation.totalResultCount + store.getTotalCount();
if (data) {
for (i = 0, ii = data.length; i < ii; i ++) {
//console.log("Data processing", typeof data[i], data[i]);
data[i].data.cls = data[i].raw._type.split("/").join("").toLowerCase();
data[i].data.href = Rally.util.Navigation.createRallyDetailUrl(data[i].data);
if (data[i].data.href.indexOf("#") !== 1) {
data[i].data.href = "/#" + data[i].data.href;
}
data[i].data.hrefTarget = "_top";
if (this.filterFn(data[i])) {
this.operation.resultSet.push(data[i]);
}
}
}
this.loadedArtifacts[artifactType] = 1;
for (k in this.loadedArtifacts) {
if (this.loadedArtifacts.hasOwnProperty(k)) {
done = done && this.loadedArtifacts[k];
}
}
if (done) {
//console.log("Done");
this.operation.records = this.operation.resultSet;
this.operation.setCompleted();
this.operation.setSuccessful();
//console.dir(this.operation);
//debugger;
Ext.callback(this.callback, this.scope || this, [this.operation]);
}
}
//getProxy: function () {
//return {buildExtractors: function() {}};
//}
});
}(this));