Skip to content

Commit

Permalink
Made DisplayColor a default field to copy
Browse files Browse the repository at this point in the history
  • Loading branch information
wrackzone committed Jan 11, 2017
1 parent c203104 commit dc89451
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Ext.define('CustomApp', {
"Description" : i.get("Description"),
"Owner" : i.get("Owner") !== null ? i.get("Owner")._ref : null,
// "Project" : app.projectRef
"DisplayColor" : !_.isNull(i.get("DisplayColor")) && !_.isUndefined(i.get("DisplayColor")) ?
i.get("DisplayColor") : null
};

copy = app.copyTypeSpecificFields(copy,i);
Expand Down
2 changes: 2 additions & 0 deletions deploy/App-uncompressed.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
"Description" : i.get("Description"),
"Owner" : i.get("Owner") !== null ? i.get("Owner")._ref : null,
// "Project" : app.projectRef
"DisplayColor" : !_.isNull(i.get("DisplayColor")) && !_.isUndefined(i.get("DisplayColor")) ?
i.get("DisplayColor") : null
};

copy = app.copyTypeSpecificFields(copy,i);
Expand Down
2 changes: 1 addition & 1 deletion deploy/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<script type="text/javascript">
Rally.onReady(function () {
var app=null;Ext.define("CustomApp",{extend:"Rally.app.App",componentCls:"app",layout:{type:"table",columns:2},config:{defaultSettings:{portfolioitem:[""],hierarchicalrequirement:["ScheduleState","PlanEstimate"],task:["State","Estimate","TaskIndex","ToDo","Actuals"]}},items:[{xtype:"label",text:"Copy To Project:",padding:"5px"},{id:"project-picker",xtype:"rallyprojectpicker",margin:"5px",model:"Project",field:"Name"},{xtype:"rallybutton",text:"Select Portfolio Item",margin:"5px",handler:function(){app.chooseItem()}},{id:"item-label",xtype:"label",margin:5,style:"font-weight:bold;",text:""},{itemId:"release-label",xtype:"label",padding:5,text:""},{itemId:"release-chooser",xtype:"container",margin:5},{id:"copy-button",xtype:"rallybutton",text:"Copy",margin:"5px",disabled:!0,handler:function(){app.performCopy()}},{id:"summary",xtype:"label",margin:"5px",style:"font-weight:bold;",text:""}],launch:function(){app=this;var fieldsToCopy={portfolioitem:this.getSetting("portfolioitem"),hierarchicalrequirement:this.getSetting("hierarchicalrequirement"),task:this.getSetting("task")};Ext.isEmpty(fieldsToCopy.portfolioitem)||Ext.isArray(fieldsToCopy.portfolioitem)||(fieldsToCopy.portfolioitem=fieldsToCopy.portfolioitem.split(",")),Ext.isEmpty(fieldsToCopy.hierarchicalrequirement)||Ext.isArray(fieldsToCopy.hierarchicalrequirement)||(fieldsToCopy.hierarchicalrequirement=fieldsToCopy.hierarchicalrequirement.split(",")),Ext.isEmpty(fieldsToCopy.task)||Ext.isArray(fieldsToCopy.task)||(fieldsToCopy.task=fieldsToCopy.task.split(",")),app.fieldsToCopy=fieldsToCopy,this._getRequiredFields().then({scope:this,success:function(requiredFields){app.requiredFields=requiredFields,Ext.apply(app.fieldsToCopy,requiredFields),Ext.Array.contains(requiredFields.hierarchicalrequirement,"Release")&&(this.down("#release-label").setText("Default Release:"),this.down("#release-chooser").removeAll(),this.down("#release-chooser").add({xtype:"rallyreleasecombobox",showArrows:!1}))}})},chooseItem:function(){Ext.create("Rally.ui.dialog.ChooserDialog",{artifactTypes:["PortfolioItem"],autoShow:!0,title:"Choose Item",listeners:{artifactChosen:function(selectedRecord){this.down("#item-label").setText(selectedRecord.get("Name")),this.down("#copy-button").setDisabled(!0),app.itemSelected(selectedRecord)},scope:this}})},itemSelected:function(root){var config={model:"PortfolioItem",fetch:!0,filters:[{property:"ObjectID",operator:"=",value:root.get("ObjectID")}]};async.map([config],app.wsapiQuery,function(err,results){var item=results[0][0];app.list=[],async.map([item],app.createList,function(err,results){app.models={},app.types=_.uniq(_.map(app.list,function(l){return l.get("_type")})),async.mapSeries(app.types,app.loadModel,function(err,results){_.each(app.types,function(t,i){app.models[t]=results[i]}),app.down("#summary").setText(app.list.length+" Items to be copied");var projectRef=app.down("#project-picker").getValue();null!==projectRef&&""!==projectRef&&app.down("#copy-button").setDisabled(!1)})})})},performCopy:function(){app.copyList={},app.projectRef=app.down("#project-picker").getValue(),async.mapSeries(app.list,app.copyItem,function(err,results){null===err?app.down("#summary").setText(results.length+" Items copied to "+results[0].get("FormattedID")):app.down("#summary").setText(err,!1)})},copyItem:function(i,callback){var copy={Name:i.get("Name"),Workspace:i.get("Workspace")._ref,Description:i.get("Description"),Owner:null!==i.get("Owner")?i.get("Owner")._ref:null};copy=app.copyTypeSpecificFields(copy,i);var parentRef=app.parentRef(i);if(null!==parentRef){var mappedRef=app.copyList[parentRef.ref];_.isUndefined(mappedRef)||(copy[parentRef.type]=mappedRef)}var model=app.models[i.get("_type")];async.map([{model:model,copy:copy,source:i}],app.createItem,function(err,results){_.isUndefined(err)||_.isNull(err)?callback(null,results[0]):callback(err,null)})},copyTypeSpecificFields:function(copy,item){var type=-1!==item.get("_type").toLowerCase().indexOf("portfolioitem")?"portfolioitem":item.get("_type");if(reference_fields=["Release","Iteration","Owner"],Ext.Array.each(this.fieldsToCopy[type],function(field){var item_release=this._getRelease(item);copy[field]=!Ext.isEmpty(item_release)&&Ext.Array.contains(reference_fields,field)?{_ref:item_release._ref}:item.get(field)},this),item.get("Tags").Count>0){var tags=_.map(item.get("Tags")._tagsNameArray,function(t){return{_ref:t._ref}});copy.Tags=tags}return copy},_getRelease:function(item){var release=item.get("Release");return Ext.isEmpty(release)&&this.down("rallyreleasecombobox")&&(release=this.down("rallyreleasecombobox").getRecord().getData()),release},createItem:function(item,callback){var rec=Ext.create(item.model,item.copy);rec.set("Project",app.projectRef),rec.save({callback:function(result,operation){if(operation.success===!0)app.copyList[item.source.get("_ref")]=result.get("_ref"),app.down("#summary").setText("Created "+result.get("FormattedID")),callback(null,result);else{console.log("Error:",operation);var message="<span class='icon-warning'> </span>Create Error when copying "+item.copy.Name;Ext.isEmpty(operation.error)||Ext.isEmpty(operation.error.errors)||(message+=":<br/>"+operation.error.errors.join("<br/>")),callback(message,null)}}})},readCollection:function(collectionConfig,callback){collectionConfig.reference.getCollection(collectionConfig.type,{fetch:!0}).load({fetch:!0,callback:function(records,operation,success){callback(null,records)}})},createList:function(root,callback){var config={model:root.raw._type,fetch:!0,filters:[{property:"ObjectID",operator:"=",value:root.get("ObjectID")}]};async.map([config],wsapiQuery,function(err,results){var obj=results[0][0];app.list.push(obj);var childRef=null;if(app.defined(obj.get("Tasks"))?childRef="Tasks":app.defined(obj.get("Children"))?childRef="Children":app.defined(obj.get("UserStories"))&&(childRef="UserStories"),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)})})}else callback(null,obj)})},parentRef:function(obj){return _.isObject(obj.get("Parent"))?{type:"Parent",ref:obj.get("Parent")._ref}:_.isObject(obj.get("WorkProduct"))?{type:"WorkProduct",ref:obj.get("WorkProduct")._ref}:_.isObject(obj.get("PortfolioItem"))?{type:"PortfolioItem",ref:obj.get("PortfolioItem")._ref}:null},loadModel:function(type,callback){Rally.data.ModelFactory.getModel({type:type,success:function(model){callback(null,model)}})},isObject:function(obj){return!_.isUndefined(obj)&&!_.isNull(obj)},defined:function(obj){return app.isObject(obj)&&obj.Count>0},wsapiQuery:function(config,callback){Ext.create("Rally.data.WsapiDataStore",{autoLoad:!0,limit:"Infinity",model:config.model,fetch:config.fetch,filters:config.filters,listeners:{scope:this,load:function(store,data){callback(null,data)}}})},_getRequiredFields:function(){var deferred=Ext.create("Deft.Deferred");return Deft.Promise.all([this._getRequiredFieldsForModel("portfolioitem"),this._getRequiredFieldsForModel("hierarchicalrequirement"),this._getRequiredFieldsForModel("task")]).then({scope:this,success:function(results){deferred.resolve({portfolioitem:results[0],hierarchicalrequirement:results[1],task:results[2]})}}),deferred.promise},_getRequiredFieldsForModel:function(model_name){var deferred=Ext.create("Deft.Deferred");return Rally.data.ModelFactory.getModel({type:model_name,success:function(model){var fields=model.getFields(),required_fields=[];Ext.Array.each(fields,function(field){field.required&&!field.readOnly&&required_fields.push(field.name)}),deferred.resolve(required_fields)}}),deferred.promise},getSettingsFields:function(){return[{name:"portfolioitem",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["PortfolioItem/Feature"],margin:"10px 0 10px 0",fieldLabel:"Feature Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"},{name:"hierarchicalrequirement",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["HierarchicalRequirement"],margin:"10px 0 10px 0",fieldLabel:"Story Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"},{name:"task",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["Task"],margin:"10px 0 200px 0",fieldLabel:"Task Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"}]},isExternal:function(){return this.getAppId()===void 0},onSettingsUpdate:function(settings){console.log("onSettingsUpdate",settings),Ext.apply(this,settings),this.launch()}});
var app=null;Ext.define("CustomApp",{extend:"Rally.app.App",componentCls:"app",layout:{type:"table",columns:2},config:{defaultSettings:{portfolioitem:[""],hierarchicalrequirement:["ScheduleState","PlanEstimate"],task:["State","Estimate","TaskIndex","ToDo","Actuals"]}},items:[{xtype:"label",text:"Copy To Project:",padding:"5px"},{id:"project-picker",xtype:"rallyprojectpicker",margin:"5px",model:"Project",field:"Name"},{xtype:"rallybutton",text:"Select Portfolio Item",margin:"5px",handler:function(){app.chooseItem()}},{id:"item-label",xtype:"label",margin:5,style:"font-weight:bold;",text:""},{itemId:"release-label",xtype:"label",padding:5,text:""},{itemId:"release-chooser",xtype:"container",margin:5},{id:"copy-button",xtype:"rallybutton",text:"Copy",margin:"5px",disabled:!0,handler:function(){app.performCopy()}},{id:"summary",xtype:"label",margin:"5px",style:"font-weight:bold;",text:""}],launch:function(){app=this;var fieldsToCopy={portfolioitem:this.getSetting("portfolioitem"),hierarchicalrequirement:this.getSetting("hierarchicalrequirement"),task:this.getSetting("task")};Ext.isEmpty(fieldsToCopy.portfolioitem)||Ext.isArray(fieldsToCopy.portfolioitem)||(fieldsToCopy.portfolioitem=fieldsToCopy.portfolioitem.split(",")),Ext.isEmpty(fieldsToCopy.hierarchicalrequirement)||Ext.isArray(fieldsToCopy.hierarchicalrequirement)||(fieldsToCopy.hierarchicalrequirement=fieldsToCopy.hierarchicalrequirement.split(",")),Ext.isEmpty(fieldsToCopy.task)||Ext.isArray(fieldsToCopy.task)||(fieldsToCopy.task=fieldsToCopy.task.split(",")),app.fieldsToCopy=fieldsToCopy,this._getRequiredFields().then({scope:this,success:function(requiredFields){app.requiredFields=requiredFields,Ext.apply(app.fieldsToCopy,requiredFields),Ext.Array.contains(requiredFields.hierarchicalrequirement,"Release")&&(this.down("#release-label").setText("Default Release:"),this.down("#release-chooser").removeAll(),this.down("#release-chooser").add({xtype:"rallyreleasecombobox",showArrows:!1}))}})},chooseItem:function(){Ext.create("Rally.ui.dialog.ChooserDialog",{artifactTypes:["PortfolioItem"],autoShow:!0,title:"Choose Item",listeners:{artifactChosen:function(selectedRecord){this.down("#item-label").setText(selectedRecord.get("Name")),this.down("#copy-button").setDisabled(!0),app.itemSelected(selectedRecord)},scope:this}})},itemSelected:function(root){var config={model:"PortfolioItem",fetch:!0,filters:[{property:"ObjectID",operator:"=",value:root.get("ObjectID")}]};async.map([config],app.wsapiQuery,function(err,results){var item=results[0][0];app.list=[],async.map([item],app.createList,function(err,results){app.models={},app.types=_.uniq(_.map(app.list,function(l){return l.get("_type")})),async.mapSeries(app.types,app.loadModel,function(err,results){_.each(app.types,function(t,i){app.models[t]=results[i]}),app.down("#summary").setText(app.list.length+" Items to be copied");var projectRef=app.down("#project-picker").getValue();null!==projectRef&&""!==projectRef&&app.down("#copy-button").setDisabled(!1)})})})},performCopy:function(){app.copyList={},app.projectRef=app.down("#project-picker").getValue(),async.mapSeries(app.list,app.copyItem,function(err,results){null===err?app.down("#summary").setText(results.length+" Items copied to "+results[0].get("FormattedID")):app.down("#summary").setText(err,!1)})},copyItem:function(i,callback){var copy={Name:i.get("Name"),Workspace:i.get("Workspace")._ref,Description:i.get("Description"),Owner:null!==i.get("Owner")?i.get("Owner")._ref:null,DisplayColor:_.isNull(i.get("DisplayColor"))||_.isUndefined(i.get("DisplayColor"))?null:i.get("DisplayColor")};copy=app.copyTypeSpecificFields(copy,i);var parentRef=app.parentRef(i);if(null!==parentRef){var mappedRef=app.copyList[parentRef.ref];_.isUndefined(mappedRef)||(copy[parentRef.type]=mappedRef)}var model=app.models[i.get("_type")];async.map([{model:model,copy:copy,source:i}],app.createItem,function(err,results){_.isUndefined(err)||_.isNull(err)?callback(null,results[0]):callback(err,null)})},copyTypeSpecificFields:function(copy,item){var type=-1!==item.get("_type").toLowerCase().indexOf("portfolioitem")?"portfolioitem":item.get("_type");if(reference_fields=["Release","Iteration","Owner"],Ext.Array.each(this.fieldsToCopy[type],function(field){var item_release=this._getRelease(item);copy[field]=!Ext.isEmpty(item_release)&&Ext.Array.contains(reference_fields,field)?{_ref:item_release._ref}:item.get(field)},this),item.get("Tags").Count>0){var tags=_.map(item.get("Tags")._tagsNameArray,function(t){return{_ref:t._ref}});copy.Tags=tags}return copy},_getRelease:function(item){var release=item.get("Release");return Ext.isEmpty(release)&&this.down("rallyreleasecombobox")&&(release=this.down("rallyreleasecombobox").getRecord().getData()),release},createItem:function(item,callback){var rec=Ext.create(item.model,item.copy);rec.set("Project",app.projectRef),rec.save({callback:function(result,operation){if(operation.success===!0)app.copyList[item.source.get("_ref")]=result.get("_ref"),app.down("#summary").setText("Created "+result.get("FormattedID")),callback(null,result);else{console.log("Error:",operation);var message="<span class='icon-warning'> </span>Create Error when copying "+item.copy.Name;Ext.isEmpty(operation.error)||Ext.isEmpty(operation.error.errors)||(message+=":<br/>"+operation.error.errors.join("<br/>")),callback(message,null)}}})},readCollection:function(collectionConfig,callback){collectionConfig.reference.getCollection(collectionConfig.type,{fetch:!0}).load({fetch:!0,callback:function(records,operation,success){callback(null,records)}})},createList:function(root,callback){var config={model:root.raw._type,fetch:!0,filters:[{property:"ObjectID",operator:"=",value:root.get("ObjectID")}]};async.map([config],wsapiQuery,function(err,results){var obj=results[0][0];app.list.push(obj);var childRef=null;if(app.defined(obj.get("Tasks"))?childRef="Tasks":app.defined(obj.get("Children"))?childRef="Children":app.defined(obj.get("UserStories"))&&(childRef="UserStories"),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)})})}else callback(null,obj)})},parentRef:function(obj){return _.isObject(obj.get("Parent"))?{type:"Parent",ref:obj.get("Parent")._ref}:_.isObject(obj.get("WorkProduct"))?{type:"WorkProduct",ref:obj.get("WorkProduct")._ref}:_.isObject(obj.get("PortfolioItem"))?{type:"PortfolioItem",ref:obj.get("PortfolioItem")._ref}:null},loadModel:function(type,callback){Rally.data.ModelFactory.getModel({type:type,success:function(model){callback(null,model)}})},isObject:function(obj){return!_.isUndefined(obj)&&!_.isNull(obj)},defined:function(obj){return app.isObject(obj)&&obj.Count>0},wsapiQuery:function(config,callback){Ext.create("Rally.data.WsapiDataStore",{autoLoad:!0,limit:"Infinity",model:config.model,fetch:config.fetch,filters:config.filters,listeners:{scope:this,load:function(store,data){callback(null,data)}}})},_getRequiredFields:function(){var deferred=Ext.create("Deft.Deferred");return Deft.Promise.all([this._getRequiredFieldsForModel("portfolioitem"),this._getRequiredFieldsForModel("hierarchicalrequirement"),this._getRequiredFieldsForModel("task")]).then({scope:this,success:function(results){deferred.resolve({portfolioitem:results[0],hierarchicalrequirement:results[1],task:results[2]})}}),deferred.promise},_getRequiredFieldsForModel:function(model_name){var deferred=Ext.create("Deft.Deferred");return Rally.data.ModelFactory.getModel({type:model_name,success:function(model){var fields=model.getFields(),required_fields=[];Ext.Array.each(fields,function(field){field.required&&!field.readOnly&&required_fields.push(field.name)}),deferred.resolve(required_fields)}}),deferred.promise},getSettingsFields:function(){return[{name:"portfolioitem",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["PortfolioItem/Feature"],margin:"10px 0 10px 0",fieldLabel:"Feature Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"},{name:"hierarchicalrequirement",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["HierarchicalRequirement"],margin:"10px 0 10px 0",fieldLabel:"Story Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"},{name:"task",xtype:"rallyfieldpicker",autoExpand:!0,alwaysExpanded:!1,modelTypes:["Task"],margin:"10px 0 200px 0",fieldLabel:"Task Fields",_shouldShowField:function(field){var attr=field.attributeDefinition;return attr&&!attr.ReadOnly&&"COLLECTION"!==attr.AttributeType},listeners:{ready:function(picker){picker.collapse()}},readyEvent:"ready"}]},isExternal:function(){return this.getAppId()===void 0},onSettingsUpdate:function(settings){console.log("onSettingsUpdate",settings),Ext.apply(this,settings),this.launch()}});
function getReleaseTimeBox(app){var timeboxScope=app.getContext().getTimeboxScope(),tbName=null;if(timeboxScope){var record=timeboxScope.getRecord();tbName=record.get("Name")}else tbName="";return tbName}function wsapiQuery(config,callback){Ext.create("Rally.data.WsapiDataStore",{autoLoad:!0,limit:"Infinity",model:config.model,fetch:config.fetch,filters:config.filters,listeners:{scope:this,load:function(store,data){callback(null,data)}}})}function snapshotQuery(config,callback){var storeConfig={find:config.find,fetch:config.fetch,hydrate:config.hydrate,autoLoad:!0,pageSize:1e4,limit:"Infinity",listeners:{scope:this,load:function(store,snapshots,success){console.log("snapshots:",snapshots.length),callback(null,snapshots)}}},snapshotStore=Ext.create("Rally.data.lookback.SnapshotStore",storeConfig)}function pointsUnitType(type){return"Points"==type}

Rally.launchApp('CustomApp', {
Expand Down

0 comments on commit dc89451

Please sign in to comment.