forked from RallyCommunity/HierarchicalCardBoard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortfolioHierarchy.js
190 lines (156 loc) · 5.88 KB
/
PortfolioHierarchy.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
Ext.define('Hackathon.HCB.PortfolioHierarchy', {
alias: 'widget.hackathonportfoliohierarchy',
extend: 'Ext.Container',
requires: ['Rally.ui.tooltip.PercentDoneToolTip',
'Rally.data.util.PortfolioItemHelper'],
layout: 'auto',
items:[
{
xtype:'container',
itemId:'header',
cls:'header'
},
{
xtype:'container',
itemId:'bodyContainer'
}
],
cls: 'portfolio-hierarchy-app',
initComponent: function() {
this.callParent(arguments);
this.addEvents('treeitemselected');
this.on('afterrender', function(){
this._attachPercentDoneToolTip();
}, this);
Rally.data.util.PortfolioItemHelper.loadTypeOrDefault({
typeRef: 'PortfolioItem/Strategy', //this.getSetting('type'),
defaultToLowest: false,
success: this.addTreeForType,
scope: this
});
},
_drawHeader: function(){
var header = this.down('#header');
// if(Rally.alm){
// header.add(this._buildHelpComponent());
// }
// header.add(this._buildFilterInfo());
},
addTreeForType: function(record){
this.typeName = record.get('Name');
this._drawHeader();
var tree = this.buildTreeForType(record);
this.down('#bodyContainer').add(tree);
},
buildTreeForType: function(typeRecord){
var config = {
topLevelModel: typeRecord.get('TypePath'),
childModelTypeForRecordFn: this.getChildModelTypeForRecordFn,
parentAttributeForChildRecordFn: this.getParentAttributeForChildRecordFn,
canExpandFn: this.canExpandItem,
enableDragAndDrop: true,
dragDropGroupFn: this.dragDropGroup,
dragThisGroupOnMeFn: this.dragThisGroupOnMe,
shouldRemoveTreeItemWhenDraggedFromTopOfTree: false,
scope: this,
treeItemConfigForRecordFn: this.treeItemConfigForRecord,
topLevelStoreConfig: {
filters: [],
context: {
project: undefined,
workspace: this.context.getWorkspace()._ref
}
},
listeners: {
beforerecordsaved: this.beforeRecordSaved,
itemselected: this._onTreeItemSelected,
scope: this
}
};
return Ext.create('Rally.ui.tree.Tree', config);
},
_onTreeItemSelected: function(treeItem){
this.fireEvent('treeitemselected', treeItem.record);
},
treeItemConfigForRecord: function(record){
return { selectable: true };
},
beforeRecordSaved: function(record, newParentRecord){
if(record.get('_type') == 'hierarchicalrequirement'){
if(newParentRecord.get('_type') === 'hierarchicalrequirement'){
record.set('PortfolioItem', '');
} else {
record.set('Parent', '');
}
}
},
_isRecordBottomPortfolioLevel: function(record){
return record.self.ordinal === 0;
},
_isUserStory: function(record) {
return record.get('_type') == 'hierarchicalrequirement';
},
getChildModelTypeForRecordFn: function(record){
return (this._isRecordBottomPortfolioLevel(record) || this._isUserStory(record))
? 'UserStory'
: 'PortfolioItem/' + record.getField('Children').allowedValueType._refObjectName;
},
getParentAttributeForChildRecordFn: function(record){
return this._isRecordBottomPortfolioLevel(record)? 'PortfolioItem': 'Parent';
},
canExpandItem: function(record){
return record.get('DirectChildrenCount') > 0
|| (record.get('UserStories') && record.get('UserStories').length > 0)
|| (record.get('Children') && record.get('Children').length > 0);
},
dragDropGroup: function(record){
return record.get('_type').toLowerCase();
},
dragThisGroupOnMe: function(record){
if(this._isUserStory(record) || this._isRecordBottomPortfolioLevel(record)){
return 'hierarchicalrequirement';
}
return 'portfolioitem/' + record.getField('Children').allowedValueType._refObjectName.toLowerCase();
},
_attachPercentDoneToolTip: function() {
Ext.create('Rally.ui.tooltip.PercentDoneToolTip', {
target: this.getEl(),
delegate: '.percentDoneContainer',
percentDoneName: 'PercentDoneByStoryCount',
listeners: {
beforeshow: function(tip) {
var treeItemEl = Ext.get(tip.triggerElement).up('.treeItem');
var treeItem = Ext.getCmp(treeItemEl.id);
tip.updateContent(treeItem.getRecord().data);
},
scope: this
}
});
},
_buildHelpComponent:function (config) {
return Ext.create('Ext.Component', Ext.apply({
cls:Rally.util.Test.toBrowserTestCssClass('portfolio-hierarchy-help-container') + ' rally-help-icon',
renderTpl:'<a href="#" title="Launch Help"></a>',
listeners:{
click:{
element:'el',
fn: function(){
Rally.alm.util.Help.launchHelp({
id:268
});
},
stopEvent:true
},
scope:this
}
}, config));
},
_buildFilterInfo: function(){
return Ext.create('Rally.ui.tooltip.FilterInfo', {
projectName: this.getSetting('project') && this.getContext().get('project').Name,
typeName: this.typeName,
scopeUp: this.getSetting('projectScopeUp') == 'true' ,
scopeDown: this.getSetting('projectScopeDown') == 'true'
});
}
});