加载Rally用户故事模型,包括与其关联的任务的ObjectID

时间:2014-04-02 16:59:31

标签: rally appsdk2

这段代码用于工作,它加载一个用户故事模型,包括附加到它的所有任务的摘要(列表):

storyModel.load(story.id, {
    fetch: ['Name', 'PlanEstimate', ‘Tasks:summary[ObjectID]’],
    callback: function(result, operation) {
        // result.get('Summary').Tasks.ObjectID return an object like this {
        //    https://rally1.rallydev.com/slm/webservice/v2.0//7613899947: 1,
        //    https://rally1.rallydev.com/slm/webservice/v2.0//7626630531: 1,
        //    …
        // }
   },
    …
});

现在,result.get('摘要')。Tasks.ObjectID根本不返回任何对象。

是否有另一种方法可以将所有任务附加到给定的用户故事中?

1 个答案:

答案 0 :(得分:0)

github repo提供了获取与用户素材相关的所有任务的完整示例。此代码可能比您需要的更多:它在迭代中加载故事和缺陷的任务,并由任务的所有者进一步过滤。

 var taskCollection = story.getCollection('Tasks',{fetch: ['Name', 'FormattedID', 'State', 'Owner']});
      taskCollection.load({
    callback: function(records, operation, success){
      _.each(records, function(task){
        var owner = (task.get('Owner') && task.get('Owner')._refObjectName) || '-- No Entry --';
        if (owner===that._selectedUser) {
        //only show tasks owned by the selected user
        tasks.push(task);
        }
      });

该代码使用promises。对于仅构建回调的示例,该示例构建用户故事和相关任务的网格,请参阅代码in this repo。两个示例都使用AppSDK2rc2

Ext.define('CustomApp', {
    extend: 'Rally.app.TimeboxScopedApp',
    componentCls: 'app',
    scopeType: 'iteration',
    comboboxConfig: {
        fieldLabel: 'Select an Iteration:',
        labelWidth: 100,
        width: 300
    },
   onScopeChange: function() {
        Ext.create('Rally.data.WsapiDataStore', {
            model: 'UserStory',
            fetch: ['FormattedID','Name','Tasks'],
            pageSize: 100,
            autoLoad: true,
            filters: [this.getContext().getTimeboxScope().getQueryFilter()],
            listeners: {
                load: this._onDataLoaded,
                scope: this
            }
        }); 
    },

    _createGrid: function(stories) {
        var myStore = Ext.create('Rally.data.custom.Store', {
                data: stories,
                pageSize: 100,  
            });
        if (!this.grid) {
        this.grid = this.add({
            xtype: 'rallygrid',
            itemId: 'mygrid',
            store: myStore,
            columnCfgs: [
                {
                   text: 'Formatted ID', dataIndex: 'FormattedID', xtype: 'templatecolumn',
                    tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate')
                },
                {
                    text: 'Name', dataIndex: 'Name'
                },
                {
                    text: 'Task Count', dataIndex: 'TaskCount'
                },
                {
                    text: 'Tasks', dataIndex: 'Tasks', 
                    renderer: function(value) {
                        var html = [];
                        Ext.Array.each(value, function(task){
                            html.push('<a href="' + Rally.nav.Manager.getDetailUrl(task) + '">' + task.FormattedID + '</a>')
                        });
                        return html.join(', ');
                    }
                }
            ]
        });

         }else{
            this.grid.reconfigure(myStore);
         }
    },
    _onDataLoaded: function(store, data){
                var stories = [];
                var pendingTasks = data.length;

                Ext.Array.each(data, function(story) {
                            var s  = {
                                FormattedID: story.get('FormattedID'),
                                Name: story.get('Name'),
                                _ref: story.get("_ref"),
                                TaskCount: story.get('Tasks').Count,
                                Tasks: []
                            };

                            var tasks = story.getCollection('Tasks');
                            tasks.load({
                                fetch: ['FormattedID'],
                                callback: function(records, operation, success){
                                    Ext.Array.each(records, function(task){
                                        s.Tasks.push({_ref: task.get('_ref'),
                                                        FormattedID: task.get('FormattedID')
                                                    });
                                    }, this);

                                    --pendingTasks;
                                    if (pendingTasks === 0) {
                                        this._createGrid(stories);
                                    }
                                },
                                scope: this
                            });
                            stories.push(s);
                }, this);
    }             
});