Rally:团队状态信息未获取所有必需信息

时间:2012-07-13 14:22:55

标签: javascript rally

我一直在尝试获取一些信息,例如用户名,显示名,角色和容量,具体取决于迭代。查询返回指定项目的一些结果,但不是所有迭代的结果。我不确定是什么原因造成的。你可以在下面找到我的作品。

function iterationSelected(dropdown, eventArgs) {

     console.log("Iteration Selected Callback");
     if(table != null){
        table.destroy();
     }


    var queryByUser = {
        key: "teamDataByUser", type: "User", 
        fetch: 'DisplayName,UserName',
        query: '(ObjectID > 0)'
    };
    rallyDataSource.findAll(queryByUser, queryTeamInformation);


}

function queryTeamInformation(results){
    console.log(results.teamDataByUser.length);
    for(var i=0;i<results.teamDataByUser.length;i++){
        console.log(results.teamDataByUser[i].UserName + " " + results.teamDataByUser[i].DisplayName);
    }


    console.log(iterationDropdown.getSelectedName());
    var queryByUserName = {
        key: "teamData", type: "UserIterationCapacity", 
        project: null,
        fetch: "Capacity,User,Role,EmailAddress,DisplayName,UserName",
        query: '((Iteration.Name = ' + '"' + iterationDropdown.getSelectedName() + '") AND (Project = /project/5564891653))'
    };
    rallyDataSource.findAll(queryByUserName, processResults);
    console.log("GH");

}

function processResults(results){
    rally.forEach(results.teamData, 
    function(teamData) {
        console.log(teamData._ref);

    });
    console.log(results.teamData.length);


        var tableDiv = document.getElementById('table');
        var config = { columns: 
             [{key: 'emailaddress', header: 'Team Member Email', width: 200}, 
             {key: 'displayname', header: 'Display name'},
             {key: 'username', header: 'User name'},
             {key: 'role', header: 'Role'},
             {key: 'cap', header: 'Capacity'}] };

        if(table != null){
            console.log("Got here");
            table.destroy();
        }
        table = new rally.sdk.ui.Table(config);
        for(var i=0;i<results.teamData.length;i++){

            var rowInfo = {'emailaddress': results.teamData[i].User.DisplayName, 'displayname': results.teamData[i].User.UserName, 'username': results.teamData[i].User.EmailAddress, 'role' : results.teamData[i].User.Role, 'cap' : results.teamData[i].Capacity}; 
            table.addRow(rowInfo);
        }



        table.display(tableDiv);


}



//========================================================================================================================
/*
 * Initializes all the page elements
 */
function initPage() {

    rallyDataSource = new rally.sdk.data.RallyDataSource('5410787910', '5948174836', 'false', 'true'); 

    var config = { label : "Select an iteration " };
    iterationDropdown = new rally.sdk.ui.IterationDropdown(config, rallyDataSource);
    iterationDropdown.display("aDiv", iterationSelected);
}
 rally.addOnLoad(initPage);

1 个答案:

答案 0 :(得分:1)

好的 - 我写了一个例子,我想这说明了你想要去的地方需要什么。它通过在queryConfig数组中执行两个查询来完成此操作:一个用于User,另一个用于UserIterationCapacity用于感兴趣的迭代。然后,在processResults函数中,代码构造三个哈希:

  • teamMembersByTeamName:每个项目的团队成员字符串,hashkey:团队/项目名称
  • myTeamList:包含来自Users(1st)查询的用户数据,为感兴趣的团队选择,hashkey:UserName
  • userIterationCapacityByUser:包含来自第二个查询的UserIterationCapacity数据,hashkey:UserName

最后,代码通过UserName进行交叉漫游,为所有TeamMembers重新构建容量数据,即使它们没有为感兴趣的Sprint定义容量。如果是这种情况,则容量显示为“N / A”。

您需要自定义workspaceOIDprojectOIDmyTeamSlashProjectName变量才能使其在您的环境中正常运行。您可能希望自定义和调整 - 它只是一个粗略的代码示例。但希望足以说明这个概念。

    <!-- Copyright (c) 2012 Rally Software Development Corp. All rights reserved -->
    <html>
    <head>
       <title>Team Capacity Summary Example</title>
       <meta name="Name" content="App Example: Team Capacity Summary" />
       <meta name="Version" content="1.31" />
       <meta name="Vendor" content="Rally Labs" />

       <script type="text/javascript" src="https://rally1.rallydev.com/apps/1.31/sdk.js"></script>
       <script type="text/javascript">

       var rallyDataSource = null;
       var iterationDropdown = null;
       var selectedIteration = "Iteration 1";
       var workspaceOID = "12345678910";
       var projectOID = "12345678911";
       var myTeamSlashProjectName = "My Project";
       var table;

        function iterationSelected(dropdown, eventArgs) {
              var selectedItem = eventArgs.item;
              selectedIteration = eventArgs.value;
              runMainQuery();
        }

        function runMainQuery() {

            var queryConfig = [];

            var capacityQueryString = '((Iteration.Name = ' + '"' + 
                    selectedIteration + 
                    '") AND (Project.ObjectID = "' + 
                    projectOID +
                     '"))';
            console.log(capacityQueryString);

            queryConfig[0] = {
                key: "usercapacities", 
                type: "UserIterationCapacity", 
                fetch: "Capacity,User,Role,EmailAddress,DisplayName,UserName",
                query: capacityQueryString
            };

            queryConfig[1] = {
                type: "users",
                key:  "userdata",
                fetch: "UserName,EmailAddress,DisplayName,UserName,UserPermissions,Project,Role,Name,TeamMemberships,Project,Name"
            };          

            rallyDataSource.findAll(queryConfig, processResults);

        }

        function processResults(results) {      

            // Populate a hash of team members by team name 
            var teamMembersByTeamName= new Array();

            for (i=0;i<results.userdata.length;i++){
                myUser = results.userdata[i];
                myUserName = myUser.UserName;
                myEmailAddress = myUser.EmailAddress;
                myDisplayName = myUser.DisplayName;
                myRole = "N/A";

                if (myUser.TeamMemberships) {

                    myTeamMemberships = myUser.TeamMemberships;

                    for (j=0;j<myTeamMemberships.length;j++) {
                        thisTeam = myTeamMemberships[j];
                        thisTeamName = thisTeam.Name;

                        if (!(thisTeamName in teamMembersByTeamName)) {
                            teamMembersByTeamName[thisTeamName] = [];
                        }

                        var dataToPush = new Array();
                        dataToPush["UserName"] = myUserName;
                        dataToPush["EmailAddress"] = myEmailAddress;
                        dataToPush["DisplayName"] = myDisplayName;
                        dataToPush["Role"] = myRole;
                        dataToPush["Capacity"] = "N/A";

                        teamMembersByTeamName[thisTeamName].push(dataToPush);
                    }
                }
            }

            // Now populate a hash of User Capacities

            var userIterationCapacityByUser = new Array();

            for (i=0;i<results.usercapacities.length;i++) {
                thisCapacityObject = results.usercapacities[i];
                thisUserName = thisCapacityObject.User.UserName;
                if (!(thisUserName in userIterationCapacityByUser)) {

                    thisUser = thisCapacityObject.User;
                    thisCapacity = thisCapacityObject.Capacity;

                    userIterationCapacityByUser[thisUserName] = [];

                    var dataToPush = new Array();
                    dataToPush["UserName"] = thisUser.UserName;
                    dataToPush["EmailAddress"] = thisUser.EmailAddress;
                    dataToPush["DisplayName"] = thisUser.DisplayName;
                    dataToPush["Role"] = thisUser.Role;
                    dataToPush["Capacity"] = thisCapacity;

                    userIterationCapacityByUser[thisUserName].push(dataToPush);             
                }
            }

            // Setup and configure the table
            var tableDiv = document.getElementById('tableDiv');
            var tableConfig = { columns: 
                 [{key: 'emailaddress', header: 'Team Member Email', width: 200}, 
                 {key: 'displayname', header: 'Display name'},
                 {key: 'username', header: 'User name'},
                 {key: 'role', header: 'Role'},
                 {key: 'cap', header: 'Capacity'}] };

            if(table != null){
                table.destroy();
            }

            table = new rally.sdk.ui.Table(tableConfig);        

            // Finally cross-walk team membership by correlating the data from the two hashes
            // Grab team list of interest
            myTeamList = teamMembersByTeamName[myTeamSlashProjectName];

            for(i=0;i<myTeamList.length;i++) {

                myTeamMemberData = myTeamList[i];
                myUserNameFromTeamList = myTeamMemberData["UserName"];

                // User has capacity information - populate data from that result set
                if (myUserNameFromTeamList in userIterationCapacityByUser) {                
                    myUserDataArray = userIterationCapacityByUser[myUserNameFromTeamList];
                    myUserData = myUserDataArray[0];            
                } // User doesn't have capacity information - populate data from user query
                else {
                    myUserData = myTeamMemberData;
                }

                var myUserName = myUserData["UserName"];
                var myEmailAddress = myUserData["EmailAddress"];
                var myDisplayName = myUserData["DisplayName"];
                var myRole = myUserData["Role"];
                var myCapacity = myUserData["Capacity"];

                if (myDisplayName) { 
                    thisDisplayName = myDisplayName;
                } else {
                    thisDisplayName = "N/A";
                }

                var rowInfo = {
                    'emailaddress': myEmailAddress, 
                    'displayname': thisDisplayName, 
                    'username': myUserName,
                    'role' : myRole, 
                    'cap' : myCapacity};
                table.addRow(rowInfo);
            }

            var tableDiv = document.getElementById("tableDiv");     
            table.display(tableDiv);
        }


        function onLoad() {
          rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
                                                       '__PROJECT_OID__',
                                                       '__PROJECT_SCOPING_UP__',
                                                       '__PROJECT_SCOPING_DOWN__');
          var config = {
                label : "Select an iteration ",
                defaultDisplayValue: selectedIteration
          };
          var iterationDropdown = new rally.sdk.ui.IterationDropdown(config, rallyDataSource);
          iterationDropdown.display("aDiv", iterationSelected);
        }

           rally.addOnLoad(onLoad);

        </script>
    </head>
      <body>
        <div id="aDiv"></div>
        <div id="tableDiv"></div>
    </body>
    </html>