Skip to content

Commit

Permalink
Merge pull request #51 from RallyCommunity/fix_pi_state_stack_order
Browse files Browse the repository at this point in the history
Fix stack ordering by pi state
  • Loading branch information
krmorse authored Jul 6, 2018
2 parents 5c90c5f + b23cf44 commit b97ad7c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
13 changes: 11 additions & 2 deletions CustomChartApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ Ext.define('CustomChartApp', {
return Settings.getSettingsFields(this.getContext());
},

_shouldLoadAllowedStackValues: function(stackingField) {
var hasAllowedValues = stackingField && stackingField.hasAllowedValues(),
shouldLoadAllowedValues = hasAllowedValues && (
_.contains(['state', 'rating', 'string'], stackingField.getType()) ||
stackingField.getAllowedValueType() === 'state'
);
return shouldLoadAllowedValues;
},

_onModelsLoaded: function(models) {
this.models = _.values(models);
var model = this.models[0],
stackingSetting = this._getStackingSetting(),
stackingField = stackingSetting && model.getField(stackingSetting);

if (stackingField && stackingField.hasAllowedValues() && _.contains(['state', 'rating', 'string'], stackingField.getType())) {
if (this._shouldLoadAllowedStackValues(stackingField)) {
stackingField.getAllowedValueStore().load().then({
success: function(records) {
this.stackValues = _.invoke(records, 'get', 'StringValue');
Expand Down
4 changes: 2 additions & 2 deletions deploy/App-external.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
Ext.define("PieCalculator",{extend:"Calculator",seriesType:"pie"});
Ext.define("PieChart",{xtype:"piechart",extend:"Rally.ui.chart.Chart",requires:["PieCalculator"],config:{chartConfig:{chart:{type:"pie",plotBackgroundColor:null,plotBorderWidth:null,plotShadow:!1},title:{text:""},tooltip:{headerFormat:"",pointFormat:"<b>{point.name}:</b> {point.percentage:.1f}% ({point.y}/{point.total})"},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,format:"<b>{point.name}:</b> {point.percentage:.1f}% ({point.y}/{point.total})",style:{color:"black"}}}}},calculatorType:"PieCalculator"},constructor:function(t){t=t||{},this.mergeConfig(t),this.callParent([this.config])}});
Ext.define("Settings",{singleton:!0,getSettingsFields:function(e){return[{name:"chartType",xtype:"rallycombobox",plugins:["rallyfieldvalidationui"],fieldLabel:"Chart Type",displayField:"name",valueField:"value",editable:!1,allowBlank:!1,store:Ext.create("Ext.data.Store",{fields:["name","value"],data:[{name:"Bar",value:"barchart"},{name:"Column",value:"columnchart"},{name:"Pie",value:"piechart"}]}),listeners:{change:function(e){e.fireEvent("chartselected",e.getValue(),e.context)}},bubbleEvents:["chartselected"],handlesEvents:{typeselected:function(){this.fireEvent("chartselected",this.getValue())}}},{name:"types",xtype:"rallycombobox",plugins:["rallyfieldvalidationui"],allowBlank:!1,editable:!1,autoSelect:!1,validateOnChange:!1,validateOnBlur:!1,fieldLabel:"Type",shouldRespondToScopeChange:!0,context:e,storeConfig:{model:"TypeDefinition",sorters:[{property:"DisplayName"}],fetch:["DisplayName","TypePath"],filters:[{property:"UserListable",value:!0}],autoLoad:!1,remoteSort:!1,sortOnLoad:!0,remoteFilter:!0},displayField:"DisplayName",valueField:"TypePath",listeners:{change:function(e){e.fireEvent("typeselected",e.getValue(),e.context)},ready:function(e){e.fireEvent("typeselected",e.getValue(),e.context)}},bubbleEvents:["typeselected"],readyEvent:"ready",handlesEvents:{projectscopechanged:function(e){this.refreshWithNewContext(e)}}},{name:"aggregationField",xtype:"rallyfieldcombobox",plugins:["rallyfieldvalidationui"],fieldLabel:"Aggregate By",readyEvent:"ready",allowBlank:!1,validateOnChange:!1,validateOnBlur:!1,width:300,handlesEvents:{typeselected:function(e,t){var a=Ext.Array.from(e)[0];a?this.refreshWithNewModelType(a,t):(this.store.removeAll(),this.reset())}},bubbleEvents:["fieldselected"],listeners:{change:function(e){e.getRecord()&&e.fireEvent("fieldselected",e.getRecord().get("fieldDefinition"))},ready:function(e){e.store.filterBy(function(e){var t=e.get("fieldDefinition"),a=t.attributeDefinition;return a&&!a.Hidden&&(("COLLECTION"!==a.AttributeType||t.isMultiValueCustom())&&!t.isMappedFromArtifact||_.contains(["Tags","Milestones"],t.name))});var t=Ext.Array.map(e.store.getRange(),function(t){return t.get(e.getValueField())});Ext.Array.contains(t,e.getValue())||e.setValue(t[0]),e.getRecord()&&e.fireEvent("fieldselected",e.getRecord().get("fieldDefinition"))}}},{name:"bucketBy",xtype:"rallycombobox",plugins:["rallyfieldvalidationui"],fieldLabel:"Bucket By",displayField:"name",valueField:"value",editable:!1,allowBlank:!1,store:{fields:["name","value"],data:[{name:"Day",value:"day"},{name:"Week",value:"week"},{name:"Month",value:"month"},{name:"Quarter",value:"quarter"},{name:"Year",value:"year"}]},lastQuery:"",hidden:!0,toggleVisibility:function(){"date"===this.selectedFieldType&&"piechart"!==this.selectedChartType?this.show():this.hide()},handlesEvents:{fieldselected:function(e){this.selectedFieldType=e.getType(),this.toggleVisibility()},chartselected:function(e){this.selectedChartType=e,this.toggleVisibility()}}},{name:"aggregationType",xtype:"rallycombobox",plugins:["rallyfieldvalidationui"],fieldLabel:"Aggregation Type",displayField:"name",valueField:"value",editable:!1,allowBlank:!1,width:300,store:{fields:["name","value"],data:[{name:"Accepted Leaf Story Count",value:"acceptedleafcount"},{name:"Accepted Leaf Story Plan Estimate Total",value:"acceptedleafplanest"},{name:"Count",value:"count"},{name:"Plan Estimate Total",value:"estimate"},{name:"Leaf Story Count",value:"leafcount"},{name:"Leaf Story Plan Estimate Total",value:"leafplanest"},{name:"Preliminary Estimate Total",value:"prelimest"},{name:"Refined Estimate Total",value:"refinedest"},{name:"Actuals Total",value:"taskactuals"},{name:"Estimate Total",value:"taskest"}]},lastQuery:"",handlesEvents:{typeselected:function(e){var t=Ext.Array.from(e)[0];Rally.data.ModelFactory.getModel({type:t,success:function(e){this.store.filterBy(function(t){return"count"===t.get("value")||e.hasField(Utils.getFieldForAggregationType(t.get("value")))}),this.store.findRecord("value",this.getValue())||this.setValue("count")},scope:this})}}},{name:"stackField",xtype:"rallyfieldcombobox",plugins:["rallyfieldvalidationui"],fieldLabel:"Stack By",readyEvent:"ready",allowBlank:!1,allowNoEntry:!0,noEntryText:"-- No Stacking --",validateOnChange:!1,validateOnBlur:!1,width:300,hidden:!0,toggleVisibility:function(e){"piechart"===e?(this.hide(),this.select(this.store.getRange()[0])):this.show()},handlesEvents:{chartselected:function(e){this.toggleVisibility(e)},typeselected:function(e,t){var a=Ext.Array.from(e)[0];a&&this.refreshWithNewModelType(a,t)}},listeners:{ready:function(e){e.store.filterBy(function(t){var a=t.get("fieldDefinition"),l=a.attributeDefinition;return t.get(e.getValueField())===e.noEntryValue||l&&!l.Hidden&&a.hasAllowedValues()&&!_.contains(["collection"],a.getType())});var t=Ext.Array.map(e.store.getRange(),function(t){return t.get(e.getValueField())});Ext.Array.contains(t,e.getValue())||e.setValue(t[0])}}},{type:"query"}]}});
Ext.define("CustomChartApp",{extend:"Rally.app.App",componentCls:"app",layout:"fit",config:{defaultSettings:{types:"Defect",chartType:"piechart",aggregationField:"State",aggregationType:"count",bucketBy:"",stackField:"",query:""}},launch:function(){this.getSetting("types")?Rally.data.wsapi.ModelFactory.getModels({types:this._getTypesSetting()}).then({success:this._onModelsLoaded,scope:this}):this.fireEvent("appsettingsneeded")},getSettingsFields:function(){return Settings.getSettingsFields(this.getContext())},_onModelsLoaded:function(t){this.models=_.values(t);var e=this.models[0],i=this._getStackingSetting(),n=i&&e.getField(i);n&&n.hasAllowedValues()&&_.contains(["state","rating","string"],n.getType())?n.getAllowedValueStore().load().then({success:function(t){this.stackValues=_.invoke(t,"get","StringValue"),this._addChart()},scope:this}):this._addChart()},_addChart:function(){var t=this.getContext(),e=["Milestones","Tags"],i=_.pluck(this.models,"typePath"),n={xtype:"rallygridboard",toggleState:"chart",chartConfig:this._getChartConfig(),plugins:[{ptype:"rallygridboardinlinefiltercontrol",showInChartMode:!0,inlineFilterButtonConfig:{stateful:!0,stateId:t.getScopedStateId("filters"),filterChildren:!0,modelNames:i,inlineFilterPanelConfig:{quickFilterPanelConfig:{defaultFields:this._getQuickFilters(),addQuickFilterConfig:{whiteListFields:e}},advancedFilterPanelConfig:{advancedFilterRowsConfig:{propertyFieldConfig:{whiteListFields:e}}}}}},{ptype:"rallygridboardactionsmenu",menuItems:[{text:"Export to CSV...",handler:function(){window.location=Rally.ui.gridboard.Export.buildCsvExportUrl(this.down("rallygridboard").getGridOrBoard())},scope:this}],buttonConfig:{iconCls:"icon-export",toolTipConfig:{html:"Export",anchor:"top",hideDelay:0}}}],context:t,modelNames:i,storeConfig:{filters:this._getFilters()}};this.add(n)},_getQuickFilters:function(){var t=["Owner","State","ScheduleState"],e=this.models[0];return this.models.length>1&&t.push("ModelType"),_.filter(t,function(t){return e.hasField(t)})},_getTypesSetting:function(){return this.getSetting("types").split(",")},_getStackingSetting:function(){return"piechart"!==this.getSetting("chartType")?this.getSetting("stackField"):null},_getChartConfig:function(){var t=this.getSetting("chartType"),e=this._getStackingSetting(),i=this.stackValues,n=this.models[0],a={xtype:t,enableStacking:!!e,chartColors:["#FF8200","#F6A900","#FAD200","#8DC63F","#1E7C00","#337EC6","#005EB8","#7832A5","#DA1884","#C0C0C0"],storeConfig:{context:this.getContext().getDataContext(),limit:1/0,fetch:this._getChartFetch(),sorters:this._getChartSort(),pageSize:2e3},calculatorConfig:{calculationType:this.getSetting("aggregationType"),field:this.getSetting("aggregationField"),stackField:e,stackValues:i,bucketBy:"piechart"===t?null:this.getSetting("bucketBy")}};return n.isArtifact()?(a.storeConfig.models=this._getTypesSetting(),a.storeType="Rally.data.wsapi.artifact.Store"):(a.storeConfig.model=n,a.storeType="Rally.data.wsapi.Store"),a},onTimeboxScopeChange:function(){this.callParent(arguments);var t=this.down("rallygridboard");t&&t.destroy(),this._addChart()},_getChartFetch:function(){var t=this.getSetting("aggregationField"),e=this.getSetting("aggregationType"),i=this._getStackingSetting(),n=["FormattedID","Name",t];return"count"!==e&&n.push(Utils.getFieldForAggregationType(e)),i&&n.push(i),_.contains(n,"Iteration")&&n.push("StartDate"),_.contains(n,"Release")&&n.push("ReleaseStartDate"),n},_getChartSort:function(){var t=this.models[0].getField(this.getSetting("aggregationField")),e=[];return t&&"collection"!==t.getType()&&t.sortable&&e.push({property:this.getSetting("aggregationField"),direction:"ASC"}),e},_getFilters:function(){var t=[],e=this.getContext().getTimeboxScope();if(this.getSetting("query")){var i=this.getSetting("query").replace(/\{user\}/g,this.getContext().getUser()._ref);t.push(Rally.data.QueryFilter.fromQueryString(i))}return e&&_.any(this.models,e.isApplicable,e)&&t.push(e.getQueryFilter()),t}});
Ext.define("CustomChartApp",{extend:"Rally.app.App",componentCls:"app",layout:"fit",config:{defaultSettings:{types:"Defect",chartType:"piechart",aggregationField:"State",aggregationType:"count",bucketBy:"",stackField:"",query:""}},launch:function(){this.getSetting("types")?Rally.data.wsapi.ModelFactory.getModels({types:this._getTypesSetting()}).then({success:this._onModelsLoaded,scope:this}):this.fireEvent("appsettingsneeded")},getSettingsFields:function(){return Settings.getSettingsFields(this.getContext())},_shouldLoadAllowedStackValues:function(t){return t&&t.hasAllowedValues()&&(_.contains(["state","rating","string"],t.getType())||"state"===t.getAllowedValueType())},_onModelsLoaded:function(t){this.models=_.values(t);var e=this.models[0],i=this._getStackingSetting(),a=i&&e.getField(i);this._shouldLoadAllowedStackValues(a)?a.getAllowedValueStore().load().then({success:function(t){this.stackValues=_.invoke(t,"get","StringValue"),this._addChart()},scope:this}):this._addChart()},_addChart:function(){var t=this.getContext(),e=["Milestones","Tags"],i=_.pluck(this.models,"typePath"),a={xtype:"rallygridboard",toggleState:"chart",chartConfig:this._getChartConfig(),plugins:[{ptype:"rallygridboardinlinefiltercontrol",showInChartMode:!0,inlineFilterButtonConfig:{stateful:!0,stateId:t.getScopedStateId("filters"),filterChildren:!0,modelNames:i,inlineFilterPanelConfig:{quickFilterPanelConfig:{defaultFields:this._getQuickFilters(),addQuickFilterConfig:{whiteListFields:e}},advancedFilterPanelConfig:{advancedFilterRowsConfig:{propertyFieldConfig:{whiteListFields:e}}}}}},{ptype:"rallygridboardactionsmenu",menuItems:[{text:"Export to CSV...",handler:function(){window.location=Rally.ui.gridboard.Export.buildCsvExportUrl(this.down("rallygridboard").getGridOrBoard())},scope:this}],buttonConfig:{iconCls:"icon-export",toolTipConfig:{html:"Export",anchor:"top",hideDelay:0}}}],context:t,modelNames:i,storeConfig:{filters:this._getFilters()}};this.add(a)},_getQuickFilters:function(){var t=["Owner","State","ScheduleState"],e=this.models[0];return this.models.length>1&&t.push("ModelType"),_.filter(t,function(t){return e.hasField(t)})},_getTypesSetting:function(){return this.getSetting("types").split(",")},_getStackingSetting:function(){return"piechart"!==this.getSetting("chartType")?this.getSetting("stackField"):null},_getChartConfig:function(){var t=this.getSetting("chartType"),e=this._getStackingSetting(),i=this.stackValues,a=this.models[0],n={xtype:t,enableStacking:!!e,chartColors:["#FF8200","#F6A900","#FAD200","#8DC63F","#1E7C00","#337EC6","#005EB8","#7832A5","#DA1884","#C0C0C0"],storeConfig:{context:this.getContext().getDataContext(),limit:1/0,fetch:this._getChartFetch(),sorters:this._getChartSort(),pageSize:2e3},calculatorConfig:{calculationType:this.getSetting("aggregationType"),field:this.getSetting("aggregationField"),stackField:e,stackValues:i,bucketBy:"piechart"===t?null:this.getSetting("bucketBy")}};return a.isArtifact()?(n.storeConfig.models=this._getTypesSetting(),n.storeType="Rally.data.wsapi.artifact.Store"):(n.storeConfig.model=a,n.storeType="Rally.data.wsapi.Store"),n},onTimeboxScopeChange:function(){this.callParent(arguments);var t=this.down("rallygridboard");t&&t.destroy(),this._addChart()},_getChartFetch:function(){var t=this.getSetting("aggregationField"),e=this.getSetting("aggregationType"),i=this._getStackingSetting(),a=["FormattedID","Name",t];return"count"!==e&&a.push(Utils.getFieldForAggregationType(e)),i&&a.push(i),_.contains(a,"Iteration")&&a.push("StartDate"),_.contains(a,"Release")&&a.push("ReleaseStartDate"),a},_getChartSort:function(){var t=this.models[0].getField(this.getSetting("aggregationField")),e=[];return t&&"collection"!==t.getType()&&t.sortable&&e.push({property:this.getSetting("aggregationField"),direction:"ASC"}),e},_getFilters:function(){var t=[],e=this.getContext().getTimeboxScope();if(this.getSetting("query")){var i=this.getSetting("query").replace(/\{user\}/g,this.getContext().getUser()._ref);t.push(Rally.data.QueryFilter.fromQueryString(i))}return e&&_.any(this.models,e.isApplicable,e)&&t.push(e.getQueryFilter()),t}});

Rally.launchApp('CustomChartApp', {
name:"Custom Chart",
parentRepos:"",
version:"1.2.6"
version:"1.2.7"
});

});
Expand Down
15 changes: 12 additions & 3 deletions deploy/App-uncompressed.html
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,22 @@
return Settings.getSettingsFields(this.getContext());
},

_shouldLoadAllowedStackValues: function(stackingField) {
var hasAllowedValues = stackingField && stackingField.hasAllowedValues(),
shouldLoadAllowedValues = hasAllowedValues && (
_.contains(['state', 'rating', 'string'], stackingField.getType()) ||
stackingField.getAllowedValueType() === 'state'
);
return shouldLoadAllowedValues;
},

_onModelsLoaded: function(models) {
this.models = _.values(models);
var model = this.models[0],
stackingSetting = this._getStackingSetting(),
stackingField = stackingSetting && model.getField(stackingSetting);

if (stackingField && stackingField.hasAllowedValues() && _.contains(['state', 'rating', 'string'], stackingField.getType())) {
if (this._shouldLoadAllowedStackValues(stackingField)) {
stackingField.getAllowedValueStore().load().then({
success: function(records) {
this.stackValues = _.invoke(records, 'get', 'StringValue');
Expand Down Expand Up @@ -937,7 +946,7 @@
Rally.launchApp('CustomChartApp', {
name:"Custom Chart",
parentRepos:"",
version:"1.2.6"
version:"1.2.7"
});

});
Expand Down
Loading

0 comments on commit b97ad7c

Please sign in to comment.