Skip to content

Commit

Permalink
Fix ordering of copied items
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Morse committed Jan 17, 2019
1 parent 39d5706 commit 2aa273c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 30 deletions.
64 changes: 50 additions & 14 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Ext.define('CustomApp', {
defaultSettings: {
portfolioitem : [''],
hierarchicalrequirement : ["ScheduleState","PlanEstimate"],
task : ["State","Estimate","TaskIndex","ToDo","Actuals"]
task : ["State","Estimate","TaskIndex","ToDo","Actuals"],
preserve_rank: true,
}
},

Expand Down Expand Up @@ -136,7 +137,7 @@ Ext.define('CustomApp', {
title: 'Choose Item',
listeners: {
artifactChosen: function(dialog, selectedRecord){
this.down("#item-label").setText(selectedRecord.get('Name'));
this.down("#item-label").setText(selectedRecord.get('FormattedID') + ' - ' + selectedRecord.get('Name'));
this.down("#copy-button").setDisabled(true);
app.itemSelected(selectedRecord);

Expand All @@ -150,6 +151,8 @@ Ext.define('CustomApp', {
// updates the summary message.
itemSelected : function(root) {

app.setLoading('Analyzing hierarchy...');

var config = { model : "PortfolioItem",
fetch : true,
filters : [ { property : "ObjectID", operator : "=", value: root.get("ObjectID") } ]
Expand All @@ -176,8 +179,11 @@ Ext.define('CustomApp', {
// check project selected before enabling.
var projectRef = app.down("#project-picker").getValue();

if (projectRef !== null && projectRef !== "")
if (projectRef !== null && projectRef !== "") {
app.down("#copy-button").setDisabled(false);
}

app.setLoading(false);
});
});
});
Expand Down Expand Up @@ -284,7 +290,8 @@ Ext.define('CustomApp', {
callback: function(result, operation) {
if (operation.success===true) {
app.copyList[item.source.get("_ref")] = result.get("_ref");
app.down("#summary").setText("Created " + result.get("FormattedID"));
app.down("#summary").setText('(' + _.keys(app.copyList).length + ' of ' + app.list.length + '): ' +
"Created " + result.get("FormattedID") + ' - ' + result.get("Name"));
callback(null,result);
} else {
console.log("Error:",operation);
Expand All @@ -301,7 +308,13 @@ Ext.define('CustomApp', {

// reads a rally collection object
readCollection : function( collectionConfig, callback ) {
collectionConfig.reference.getCollection(collectionConfig.type,{fetch:true}).load({
var rank_field = Rally.data.Ranker.getRankField(collectionConfig.reference);
var direction = collectionConfig.direction;

collectionConfig.reference.getCollection(collectionConfig.type, {
fetch: true,
sorters: [ { property: rank_field, direction: direction} ]
}).load({
fetch : true,
callback : function(records,operation,success) {
callback(null,records);
Expand All @@ -313,21 +326,27 @@ Ext.define('CustomApp', {
// recursive method to create a list of all items to be copied.
createList : function(root,callback) {

var config = { model : root.raw._type,
var config = {
model : root.raw._type,
fetch : true,
filters : [ { property : "ObjectID", operator : "=", value: root.get("ObjectID") } ]
};

async.map([config], wsapiQuery, function(err,results) {

var obj = results[0][0];
var direction = "DESC";
app.list.push(obj);
var childRef = null;
if (app.defined(obj.get("Tasks"))) {
childRef = "Tasks";
direction = "DESC";
} else {
if (app.defined(obj.get("Children"))){
if (app.defined(obj.get("Children"))) {
childRef = "Children";
if (/PortfolioItem/.test(root.raw._type)) {
direction = "ASC";
}
} else {
if (app.defined(obj.get("UserStories"))) {
childRef = "UserStories";
Expand All @@ -336,13 +355,22 @@ Ext.define('CustomApp', {
}

if (app.isObject(childRef)) {
var config = { reference : obj, type : childRef };
async.map([config],app.readCollection,function(err,results){
var children = results[0];
async.map(children,app.createList,function(err,results){
callback(null,results);
var config = { reference : obj, type : childRef, direction: direction };
if ( app.getSetting('preserve_rank') && app.getSetting('preserve_rank') != "false" ) {
async.mapSeries([config],app.readCollection,function(err,results){
var children = results[0];
async.mapSeries(children,app.createList,function(err,results){
callback(null,results);
});
});
});
} else {
async.map([config],app.readCollection,function(err,results){
var children = results[0];
async.map(children,app.createList,function(err,results){
callback(null,results);
});
});
}
} else {
callback(null,obj);
}
Expand Down Expand Up @@ -396,6 +424,7 @@ Ext.define('CustomApp', {
model : config.model,
fetch : config.fetch,
filters : config.filters,
sorters: config.sorters,
listeners : {
scope : this,
load : function(store, data) {
Expand Down Expand Up @@ -444,7 +473,14 @@ Ext.define('CustomApp', {
},

getSettingsFields: function() {
return [{
return [
{
name: 'preserve_rank',
xtype: 'rallycheckboxfield',
margin: '10px 0 10px 0',
fieldLabel: 'Maintain Ranks'
},
{
name: 'portfolioitem',
xtype: 'rallyfieldpicker',
autoExpand: true,
Expand Down
Loading

0 comments on commit 2aa273c

Please sign in to comment.