-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
230 lines (208 loc) · 8.48 KB
/
index.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
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
/* globals Rally */
// Fix the PreliminaryEstimate renderer to sort by value
Rally.ui.renderer.GridEditorFactory.editorRenderers['PreliminaryEstimate'] = function(field) {
return {
xtype: 'rallyrecordcontexteditor',
field: {
xtype: 'rallycombobox',
allowNoEntry: !field.required,
editable: false,
name: field.name,
storeConfig: {
autoLoad: true,
model: field.name,
remoteFilter: true,
sorters: [{
property: "Value"
}],
listeners: {
load: function() {
return;
}
}
}
}
};
};
Ext.define('Utils.AncestorPiInlineFilter', {
override: 'Rally.ui.inlinefilter.QuickFilterPanel',
portfolioItemTypes: [],
modelName: undefined,
customFilterNamePrefix: "AncestorPiInlineFilter.",
_hasPiAncestor: function(modelName) {
return _.contains(['hierarchicalrequirement', 'userstory', 'defect'], modelName) || Ext.String.startsWith(modelName, 'portfolioitem');
},
_pisAbove: function(modelName) {
var result = [];
if (_.contains(['hierarchicalrequirement', 'userstory', 'defect'], modelName)) {
result = this.portfolioItemTypes
}
else if (Ext.String.startsWith(modelName, 'portfolioitem')) {
var startIndex = _.findIndex(this.portfolioItemTypes, function(piType) {
return piType.get('TypePath').toLowerCase() === modelName;
});
if (startIndex >= 0 && startIndex < this.portfolioItemTypes.length - 1) {
result = this.portfolioItemTypes.slice(startIndex + 1);
}
}
return result;
},
initComponent: function() {
if (!this.dataContext) {
this.dataContext = Rally.getApp().getContext().getDataContext();
}
if (this.modelName) {
this.modelName = this.modelName.toLowerCase();
}
var filterFactoryOverrides = {};
var additionalFields = []
if (this._hasPiAncestor(this.modelName)) {
var pisAbove = this._pisAbove(this.modelName);
_.each(pisAbove, function(piType) {
var typePath = piType.get('TypePath');
var customFilterName = this.customFilterNamePrefix + typePath;
var displayName = 'Portfolio Item / ' + piType.get('Name');
filterFactoryOverrides[customFilterName] = {
xtype: 'ancestorpisearchcombobox',
portfolioItemType: typePath, // The artifact type to search for
piTypesAbove: pisAbove, // List of portfolio item types
artifactTypeName: this.modelName, // The artifact type we are filtering
storeConfig: {
context: this.dataContext,
models: typePath,
autoLoad: true
},
allowNoEntry: true,
noEntryValue: null,
noEntryText: 'No ' + displayName,
emptyText: 'Search ' + displayName + 's...',
allowClear: false,
valueField: 'ObjectUUID', // Must use ObjectUUID to align with the state that is saved by inlinefilterbutton
forceSelection: false
};
additionalFields.push({
name: customFilterName,
displayName: displayName
})
}, this);
// Add the additional fields to the quick filter config
_.merge(this.addQuickFilterConfig, {
additionalFields: additionalFields
}, function(a, b) {
if (_.isArray(a)) {
return _.uniq(a.concat(b), 'name') // Strip duplicates by name that can occur from state
}
});
// Add the corresponding items to the FilterFieldFactory
Ext.override(Rally.ui.inlinefilter.FilterFieldFactory, filterFactoryOverrides);
}
this.callParent(arguments);
},
_createFields: function() {
// Strip out the custom filters from this.fields and this.initialFilters
this.fields = _.filter(this.fields, function(field) {
return this._filterInvalidAncestorFilters(field);
}, this);
this.initialFilters = _.filter(this.initialFilters, function(filter) {
return this._filterInvalidAncestorFilters(filter.name);
}, this);
this.callParent(arguments);
},
/**
* This will exclude any field restored from state that we didn't explicitly add into the Factory
* for the current model type. This prevents changes in model types from trying to build an invalid filter
* for that new model type.
*/
_filterInvalidAncestorFilters: function(name) {
return !Ext.String.startsWith(name, this.customFilterNamePrefix) || Rally.ui.inlinefilter.FilterFieldFactory.hasOwnProperty(name)
}
});
Ext.define('Utils.AncestorPiSearchComboBox', {
alias: 'widget.ancestorpisearchcombobox',
extend: 'Rally.ui.combobox.ArtifactSearchComboBox',
parentField: 'PortfolioItem.Parent.',
artifactTypeName: undefined, // The name of the model that will be filtered
piTypesAbove: [],
statics: {
UUID_REGEX: /([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/
},
constructor: function(config) {
if (config.value) {
Ext.merge(config, {
storeConfig: {
filters: Rally.data.wsapi.Filter.or([{
property: config.valueField, // Compensate for parent constructor assuming that filter value is OidFromRef
value: config.value
}
/*, {
property: 'ObjectID',
operator: '!=',
value: 0
}*/
])
}
});
}
//this.callSuper(arguments);
// Get super super method (skip the extended ArtifactSearchComboBox.constructor()
return this.superclass.superclass['constructor'].apply(this, arguments);
},
initComponent: function() {
this.on('change', function(cmp, newValue, oldValue) {
if (newValue == "") {
this.store.load({
filters: []
})
}
}, this)
return this.callParent(arguments);
},
setValue: function() {
this.callParent(arguments);
},
getFilter: function() {
var value = this.lastValue;
var propertyPrefix = this.propertyPrefix();
var filters = []
// If the value is a UUID, then use it, otherwise ignore values the user might be typing in
if (value && this.statics().UUID_REGEX.test(value)) {
filters.push({
property: propertyPrefix + ".ObjectUUID",
value: value
});
}
else {
filters.push({
property: propertyPrefix,
value: null
});
}
return Rally.data.wsapi.Filter.or(filters);
},
propertyPrefix: function() {
var property;
// Get the path between the selected artifact and the lowest level PI above it
if (this.artifactTypeName === 'hierarchicalrequirement' || this.artifactTypeName === 'userstory') {
property = this.piTypesAbove[0].get('Name');
}
else if (this.artifactTypeName === 'defect') {
property = 'Requirement.' + this.piTypesAbove[0].get('Name');
}
else if (Ext.String.startsWith(this.artifactTypeName, 'portfolioitem')) {
property = 'Parent';
}
if (property) {
// Now add .Parent for every PI level above the lowest until we get to the
// desired PI type
_.forEach(this.piTypesAbove, function(piType) {
if (piType.get('TypePath').toLowerCase() == this.portfolioItemType.toLowerCase()) {
return false;
}
else {
property = property + '.Parent'
}
}, this);
}
return property;
}
});