Skip to content

Commit

Permalink
Merge pull request #40 from RallyCommunity/fix_sort
Browse files Browse the repository at this point in the history
Fix issue trying to sort by non sortable fields
  • Loading branch information
krmorse authored May 18, 2018
2 parents 950452b + fea2284 commit cddb861
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CustomChartApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Ext.define('CustomChartApp', {
field = model.getField(this.getSetting('aggregationField')),
sorters = [];

if (field && field.getType() !== 'collection') {
if (field && field.getType() !== 'collection' && field.sortable) {
sorters.push({
property: this.getSetting('aggregationField'),
direction: 'ASC'
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:"{point.name}: <b>{point.percentage:.1f}%</b>"},plotOptions:{pie:{allowPointSelect:!0,cursor:"pointer",dataLabels:{enabled:!0,format:"<b>{point.name}</b>: {point.percentage:.1f} %",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(),a=i&&e.getField(i);a&&a.hasAllowedValues()&&_.contains(["state","rating","string"],a.getType())?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=[],e=this._getTypesSetting(),i=e[0];return e.length>1&&t.push("ModelType"),Rally.data.ModelTypes.isArtifact(i)&&(t.push("Owner"),Rally.data.ModelTypes.isPortfolioItem(i)||"task"===i.toLowerCase()?t.push("State"):t.push("ScheduleState")),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()&&e.push({property:this.getSetting("aggregationField"),direction:"ASC"}),e},_getFilters:function(){var t=[],e=this.getContext().getTimeboxScope();return this.getSetting("query")&&t.push(Rally.data.QueryFilter.fromQueryString(this.getSetting("query"))),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())},_onModelsLoaded:function(t){this.models=_.values(t);var e=this.models[0],i=this._getStackingSetting(),a=i&&e.getField(i);a&&a.hasAllowedValues()&&_.contains(["state","rating","string"],a.getType())?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=[],e=this._getTypesSetting(),i=e[0];return e.length>1&&t.push("ModelType"),Rally.data.ModelTypes.isArtifact(i)&&(t.push("Owner"),Rally.data.ModelTypes.isPortfolioItem(i)||"task"===i.toLowerCase()?t.push("State"):t.push("ScheduleState")),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();return this.getSetting("query")&&t.push(Rally.data.QueryFilter.fromQueryString(this.getSetting("query"))),e&&_.any(this.models,e.isApplicable,e)&&t.push(e.getQueryFilter()),t}});

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

});
Expand Down
4 changes: 2 additions & 2 deletions deploy/App-uncompressed.html
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@
field = model.getField(this.getSetting('aggregationField')),
sorters = [];

if (field && field.getType() !== 'collection') {
if (field && field.getType() !== 'collection' && field.sortable) {
sorters.push({
property: this.getSetting('aggregationField'),
direction: 'ASC'
Expand All @@ -902,7 +902,7 @@
Rally.launchApp('CustomChartApp', {
name:"Custom Chart",
parentRepos:"",
version:"1.2.1"
version:"1.2.2"
});

});
Expand Down
Loading

0 comments on commit cddb861

Please sign in to comment.