forked from RallyApps/app-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildTraceabilityApp.html
232 lines (189 loc) · 9.52 KB
/
BuildTraceabilityApp.html
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Copyright (c) 2002-2011 Rally Software Development Corp. All rights reserved. -->
<html>
<head>
<meta name="Name" content="App: Build Traceability"/>
<meta name="Version" content="2012.01.14"/>
<meta name="Vendor" content="Rally Software"/>
<script type="text/javascript" src="/apps/1.33/sdk.js?apiVersion=1.29"></script>
<script type="text/javascript">
/*
Copyright (c) 2002-2011 Rally Software Development Corp. All rights reserved.
BuildTraceability.js
*/
function BuildTraceability(rallyDataSource) {
var buildDropdown;
var projectObjectIds = [];
var buildTooltip, table;
//private method that builds table of changeset and artifact info
function display(tableElement, build) {
var tableConfig = {'columnKeys' : ['ID', 'Name', 'State', 'Changeset', 'Changeset Message', 'Release']};
if (table) {
table.destroy();
}
table = new rally.sdk.ui.Table(tableConfig);
var changesets = build.Changesets;
var row = 0;
if (typeof changesets !== "undefined" && changesets.length > 0) {
for (var i = 0; i < changesets.length; i++) {
for (var cnt = 0; cnt < changesets[i].Artifacts.length; cnt++) {
artifact = changesets[i].Artifacts[cnt];
//ensure artifact associated to changeset is in scope
if (dojo.indexOf(projectObjectIds, artifact.Project.ObjectID) !== -1) {
//create link to artifact detail page
table.setCell(row, 0, new rally.sdk.ui.basic.Link({item:artifact}).renderToHtml());
table.setCell(row, 1, artifact.Name);
//task does not have a schedule state
table.setCell(row, 2, artifact.State || artifact.ScheduleState);
//display link if changeset Uri is a "real" link
if (changesets[i].Uri.match(/http/) || changesets[i].Uri.match(/svn/)) {
table.setCell(row, 3, '<a href=' + changesets[i].Uri + ' target="_blank">' + changesets[i].Revision + '</a>');
} else {
table.setCell(row, 3, changesets[i].Revision);
}
table.setCell(row, 4, changesets[i].Message);
if (artifact.Release === null) {
table.setCell(row, 5, "");
} else {
table.setCell(row, 5, artifact.Release.Name);
}
row = row + 1;
}
}
}
} else {
table.addRows([]);
}
if (row === 0) {
document.getElementById('msgDiv').innerHTML = " No artifacts found for this build.";
} else {
document.getElementById('msgDiv').innerHTML = "";
}
table.display(tableElement);
}
//private method that triggers when build dropdown value changes
function onBuildChange(sender, eventArgs) {
if (!sender.getValue() && eventArgs.items && eventArgs.items.length > 0) {
sender.setValue(eventArgs.items[0]._ref);
return;
}
if (typeof buildTooltip !== "undefined") {
buildTooltip.hide();
}
display("mainDiv", eventArgs.item);
}
//private method to create the build dropdown based on query results
function buildCallback(results) {
var buildConfig = {
valueProperty: "_ref",
displayValueProperty: "Number",
label: 'Builds',
showLabel: true
};
if (buildDropdown) {
buildDropdown.destroy();
}
buildDropdown = new rally.sdk.ui.basic.Dropdown(buildConfig, rallyDataSource);
buildDropdown.setItems(results.builds);
buildDropdown.display("build", onBuildChange);
if (results.builds.length === 0) {
buildTooltip = rally.sdk.ui.basic.Tooltip.show("build", "No builds found.", "after");
document.getElementById('msgDiv').innerHTML = "";
}
}
//private method to query for builds if build def value changes
function onBuildDefSelectionChanged(sender, eventArgs) {
if (!eventArgs.value && eventArgs.items && eventArgs.items.length > 0) {
//Set a default if none found
sender.setValue(eventArgs.items[0]._ref);
return;
}
var selectedValue = eventArgs.value;
selectedValue = selectedValue.replace(".js", "");
if (selectedValue === "") {
return;
}
var buildObj = {
type: "Build",
key: "builds",
fetch: 'Number,Message,Revision,Uri,Changesets,Artifacts,Name,FormattedID,ScheduleState,Project,Release,ObjectID,State',
query: "(BuildDefinition = " + selectedValue + ")",
order: 'CreationDate desc',
pagesize: 20
};
rallyDataSource.find(buildObj, buildCallback);
}
// private method to build project query if running inside Rally
// if running app externally, modify this method
function buildProjectQuery() {
var projectQuery = [];
if (rally.sdk.util.Context.isInsideRally()) {
// create an array of project oids in scope
projectObjectIds = '__PROJECT_OIDS_IN_SCOPE__'.split(',');
if (projectObjectIds.length > 0) {
//limit to 100 projects for performance reasons
if (projectObjectIds.length > 100) {
throw "Too many projects in scope. Select a different project.";
}
for (var i = 0; i < projectObjectIds.length; i++) {
projectQuery.push('Projects contains /project/' + projectObjectIds[i]);
}
return new rally.sdk.util.Query.or(projectQuery);
}
// if running app externally, set the projectObjectIds var to array of project oids and return build project query
} else {
throw("App not supported outside Rally without modifying source code.");
//projectObjectIds = [1971104447];
//return "(Projects contains /project/1971104447)";
}
}
//private method to start building controls on page
//page consists of 2 dropdowns (builddef and build dropdowns) and a table
function initPage() {
try {
var projectQuery = buildProjectQuery();
//create build def dropdown
var buildDefConfig = {
type: "BuildDefinition",
attribute: "Name",
fetch: 'Projects',
query: projectQuery,
label: 'Build Definition',
showLabel: true,
order: 'Name'
};
var buildDefDropdown = new rally.sdk.ui.ObjectDropdown(buildDefConfig, rallyDataSource);
buildDefDropdown.display("buildDef", onBuildDefSelectionChanged);
} catch(err) {
throw(err);
}
}
// only public method
this.display = function() {
rally.sdk.ui.AppHeader.setHelpTopic("230");
rally.sdk.ui.AppHeader.showPageTools(true);
initPage();
};
}
</script>
<script type="text/javascript">
rally.addOnLoad(function() {
var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__', '__PROJECT_OID__',
'__PROJECT_SCOPING_UP__', '__PROJECT_SCOPING_DOWN__');
var buildTraceability = new BuildTraceability(rallyDataSource);
buildTraceability.display();
});
</script>
<style type="text/css">
tbody {
font-size: 11px;
}
</style>
</head>
<body>
<span id="buildDef"></span>
<span id="build"> </span>
<div id="mainDiv"> </div>
<div id="msgDiv"></div>
</body>
</html>