如何从Rally Web Services API中的用户故事参考中获取User对象?

时间:2013-08-13 21:53:25

标签: rally

我查询了PortfolioItem / Feature的WSAPI DataStore。对于每个Feature对象,我调用getCollection('UserStories')来获取Feature的用户故事数组。对于每个用户故事,我想获取所有者信息。

如何从我对User Story对象上可用的Owner字段的引用中获取实际的User对象?

1 个答案:

答案 0 :(得分:0)

除了WsapiDataStore之外,还需要一个Rally.data.custom.Store,其中所有者的访问方式如下:

 Ext.Array.each(records, function(story){
               f.UserStories.push({_ref: story.get('_ref'),
               FormattedID: story.get('FormattedID'),
               Owner:  (story.get('Owner') && story.get('Owner')._refObjectName) || 'None' 
               });

}

这是一个代码,用于构建功能网格及其子故事,以及故事的所有者。

Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',

    launch: function() {
        Ext.create('Rally.data.WsapiDataStore', {
            model: 'PortfolioItem/Feature',
            fetch: ['FormattedID','Name','UserStories'],
            pageSize: 100,
            autoLoad: true,
            listeners: {
                load: this._onDataLoaded,
                scope: this
            }
        });
    },

    _createGrid: function(features) {
         this.add({
            xtype: 'rallygrid',
            store: Ext.create('Rally.data.custom.Store', {
                data: features,
                pageSize: 100
            }),

            columnCfgs: [
                {
                   text: 'Formatted ID', dataIndex: 'FormattedID', xtype: 'templatecolumn',
                    tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate')
                },
                {
                    text: 'Name', dataIndex: 'Name'
                },
                {
                    text: 'Story Count', dataIndex: 'StoryCount'
                },
                {
                    text: 'User Stories', dataIndex: 'UserStories', 
                    renderer: function(value) {
                        var html = [];
                        Ext.Array.each(value, function(userstory){
                            html.push('<a href="' + Rally.nav.Manager.getDetailUrl(userstory) + '">' + userstory.FormattedID + '</a>')
                        });
                        return html.join(', ');
                    }
                },
                 {
                    text: 'Owner', dataIndex: 'UserStories', 
                    renderer: function(value) {
                        var html = [];
                        Ext.Array.each(value, function(userstory){
                            html.push(userstory.Owner);
                        });
                        return html.join(', ');
                    }
                }
            ]

        });
    },
    _onDataLoaded: function(store, data){
                var features = [];
                var pendingstories = data.length;
                var owner;
                Ext.Array.each(data, function(feature) {
                            var f  = {
                                FormattedID: feature.get('FormattedID'),
                                Name: feature.get('Name'),
                                _ref: feature.get("_ref"),
                                StoryCount: feature.get('UserStories').Count,
                                UserStories: []
                            };

                            var stories = feature.getCollection('UserStories');
                            stories.load({
                                fetch: ['FormattedID','Owner'],
                                callback: function(records, operation, success){

                                    Ext.Array.each(records, function(story){
                                            f.UserStories.push({_ref: story.get('_ref'),
                                            FormattedID: story.get('FormattedID'),
                                            Owner:  (story.get('Owner') && story.get('Owner')._refObjectName) || 'None' 
                                                    });
                                    }, this);
                                    --pendingstories;
                                    if (pendingstories === 0) {
                                        this._createGrid(features);
                                    }
                                },
                                scope: this
                            });
                            features.push(f);
                }, this);
    }             
});