2013-03-20 93 views
0

我在GitHub上发现了一些代码(https://github.com/RallyCommunity/TagCloud),用于在拉力赛中显示TagCloud。从概念上看,它看起来不错,但我似乎无法完成它的工作,并想知道是否有任何可以快速查看的Rally JavaScript专家。拉力赛标签云

由于Google Analytics(分析)的网址不正确(根据文档),并且API被硬编码为折旧版本,所以我更新了这些内容,所以稍微修改了它。

我不是JavaScript专家。当我运行它时,它没有发现任何标签对故事。

当我在Chrome调试模式下运行这个功能时,我可以取得该URL并在我的浏览器中执行它,但它也不会返回任何标签。它回来了分析的完整结果响应,但没有标签,我知道在选定的项目中有对标签的故事。

任何人的想法?

<!DOCTYPE html> 
<html> 
<head> 
<title>TagCloud</title> 

<script type="text/javascript" src="/apps/2.0p/sdk.js"></script> 
<script type="text/javascript"> 
Rally.onReady(function() { 
    Ext.define('CustomApp', { 
     extend: 'Rally.app.App', 
     componentCls: 'app', 
     layout: 'border', 
     items: [ 
    { 
     title: 'Tag Cloud', 
     xtype: 'panel', 
     itemId: 'cloud', 
     region: 'west', 
     width: '30%', 
     collapsible: true, 
     bodyStyle: 'padding:15px', 
     listeners: { 'afterRender': function(el) { setTimeout(function() { el.setLoading(); }, 500);}} // needs a little delay 
    }, 
    { 
     title: '<<< Select a tag from the Tag Cloud', 
     xtype: 'panel', 
     itemId: 'grid', 
     region: 'center', 
     width: '70%', 
     collapsible: false 
    } 
     ], 

     tagMap : [], 
     maxFont : 24, // largest desired font size 
     minFont : 8, // and smallest 

     _renderTag : function renderHandler(tagLabel) { 
    tagLabel.getEl().on('click',this._tagSelected, this); 
     }, 

     // does the actual building of the cloud from 'tagMap' 
     _buildCloud: function(app, response) { 

     //title: '<<< Select a tag from the Tag Cloud - Building', 
     var i, tag; 
    for (i=0;i<response.Results.length;i++) { 
     tag = response.Results[i]; 

     if(typeof app.tagMap[tag.ObjectID] !== "undefined") { 
     app.tagMap[tag.ObjectID].Name = tag._refObjectName; 
     } 
    } 
    if(response.StartIndex+response.PageSize < response.TotalResultCount) { 
     app._queryForTagNames(response.StartIndex+response.PageSize, app, app._buildCloud); 
    } else { 
     if(app.tagMap.length === 0) { 
     tag = new Ext.form.Label({ 
      id: 'tagNone', 
      text: ' No tagged Stories found ' 
      }); 
      app.down('#cloud').add(tag); 
     } else { 
     var minFrequency = Number.MAX_VALUE; 
     var maxFrequency = Number.MIN_VALUE; 
     var tuples = []; 
     for (var x in app.tagMap) { 
      if (app.tagMap.hasOwnProperty(x)) { 
      tuples.push([x, app.tagMap[x]]); 
      if(app.tagMap[x].count > maxFrequency) { 
       maxFrequency = app.tagMap[x].count; 
      } 
      if(app.tagMap[x].count < minFrequency) { 
       minFrequency = app.tagMap[x].count; 
      } 
      } 
     } 

     tuples.sort(function(a,b) { a = a[1]; b = b[1]; return a.Name > b.Name ? 1 : a.Name < b.Name ? -1 : 0 ;}); 

     for (i = 0; i < tuples.length; i++) { 
      var ftsize = ((tuples[i][1].count-minFrequency)*(app.maxFont-app.minFont)/(maxFrequency-minFrequency)) + app.minFont; 
      tag = new Ext.form.Label({ 
      id: 'tag'+tuples[i][0], 
      text: ' ' + tuples[i][1].Name + ' ', 
      overCls: 'link', 
      style:"font-size: "+ftsize+"pt;", 
      listeners: { scope: app, render: app._renderTag } 
      }); 
      app.down('#cloud').add(tag); 
     } 
     } 
     app.getComponent('cloud').setLoading(false); 
    } 
     }, 

     // collects the _queryForTags responses and calls _queryForTagNames when it has them all 
     _buildTagMap: function(app, response) { 
    for (var i=0;i<response.Results.length;i++) { 
     var ent = response.Results[i]; 
     for (var j=0; j < ent.Tags.length; j++) { 
     var tag = ent.Tags[j]; 
     var mapent = app.tagMap[tag]; 
     if(typeof mapent === "undefined") { 
      mapent = { count: 1 }; 
     } else { 
      mapent.count++; 
     } 
     app.tagMap[tag] = mapent; 
     } 
    } 
    if(response.StartIndex+response.PageSize < response.TotalResultCount) { 
     app._queryForTags(response.StartIndex+response.PageSize, app, app._buildTagMap); 
    } else { 
     app._queryForTagNames(0, app, app._buildCloud); 
    } 
     }, 

     // get a list of the tags from the Lookback API, iterating if necessary (see _buildTagMap) 
     _queryForTags: function(start, app, callback) { 
    var params = { 
     find: "{'Tags':{'$exists':true}, '__At':'current', '_Type':'HierarchicalRequirement', '_ProjectHierarchy':"+ this.getContext().getProject().ObjectID +" }", 
     fields: "['Tags']", 
     pagesize: 20000, 
     start: start 
    }; 
    Ext.Ajax.request({ 
     url: 'https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/'+ this.context.getWorkspace().ObjectID + '/artifact/snapshot/query.js', 
     method: 'GET', 
     params: params, 
     withCredentials: true, 
     success: function(response){ 
     var text = response.responseText; 
     var json = Ext.JSON.decode(text); 
     callback(app, json); 
     } 
    }); 
     }, 

     // once all the tags have been collected, get a list of the tag names from the WSAPI, iterating if necessary (see _buildCloud) 
     _queryForTagNames: function(start, app, callback) { 
    Ext.Ajax.request({ 
     url: 'https://rally1.rallydev.com/slm/webservice/1.41/tag.js', 
     method: 'GET', 
     params: { fetch: "ObjectID", pagesize: 200, "start": start}, 
     withCredentials: true, 
     success: function(response){ 
     callback(app, Ext.JSON.decode(response.responseText).QueryResult); 
     } 
    }); 
     }, 

     _queryForStories: function(tagOid) { 
    Ext.create('Rally.data.WsapiDataStore', { 
     model: 'UserStory', 
     autoLoad: true, 
     fetch: ['Rank', 'FormattedID', 'Name', 'ScheduleState'], 
     filters: [{ 
     property:'Tags', 
     operator: '=', 
     value: "tag/" + tagOid 
     }], 
     sorters: [{ 
     property: 'Rank', 
     direction: 'ASC' 
     }], 
     listeners: { 
     load: this._onDataLoaded, 
     scope: this 
     } 
    }); 
     }, 

     _tagSelected: function(app, elem) { 
    this.getComponent('grid').setLoading(); 
    this._queryForStories(elem.id.substring(3)); // cheesy, id is "tag"+tagOid, we need the oid 
    this.tagName = elem.innerText; 
     }, 

     _onDataLoaded: function(store, data) { 
    var records = [], rankIndex = 1; 
    Ext.Array.each(data, function(record) { 
     records.push({ 
     Ranking: rankIndex, 
     FormattedID: record.get('FormattedID'), 
     Name: record.get('Name'), 
     State: record.get('ScheduleState') 
     }); 
     rankIndex++; 
    }); 

    var customStore = Ext.create('Rally.data.custom.Store', { 
     data: records, 
     pageSize: 25 
    }); 

    if(!this.grid) { 
     this.grid = this.down('#grid').add({ 
     xtype: 'rallygrid', 
     store: customStore, 
     columnCfgs: [ 
      { text: 'Ranking', dataIndex: 'Ranking' }, 
      { text: 'ID', dataIndex: 'FormattedID' }, 
      { text: 'Name', dataIndex: 'Name', flex: 1 }, 
      { text: 'State', dataIndex: 'State' } 
     ] 
     }); 
    } else { 
     this.grid.reconfigure(customStore); 
    } 
    this.getComponent('grid').setTitle('Stories tagged: ' + this.tagName); 
    this.getComponent('grid').setLoading(false); 
     }, 

     launch: function() { 
    this._queryForTags(0, this, this._buildTagMap); 
     } 
    }); 

Rally.launchApp('CustomApp', { 
name: 'TagCloud' 
}); 
}); 
</script> 

<style type="text/css"> 
    .app { 

    } 

    .link { 
    color: #066792; 
    cursor: pointer; 
    } </style> 
</head> 
<body></body> 
</html> 

回答

2

的代码是出于过期关于最近期的LBAPI变化 - 特别是使用_Type的VS _TypeHierarchy当然,网址,因为您已经发现了。请拿起更改,并给它一个旋转。

+0

谢谢乔尔,我上传了这些变化,但我仍然得到“没有找到标签”。我知道有标签,因为我在当前项目中有1,200个故事,所有这些标签都标有1个或更多标签。 – trevleyb 2013-03-20 20:03:34

+0

让我们确认LBAPI显示标记的故事。当你在浏览器中点击这个URL时,你会得到什么? (您必须首先登录到拉力赛):'https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/ /artifact/snapshot/query.js?find={'Tags' :{'$ exists':true},'__ At':'current','_ TypeHierarchy': - 51038,'_ ProjectHierarchy':}&fields = ['Tags']&pagesize = 20000&start = 0'替换您的工作区和项目 2013-03-21 17:03:41

+0

这样的作品。我找回了一个标签列表(其中1138个)。 “ “结果”:[{ “标签”:[11034443843,11013683178,11013754606,11013755361]},{ “标签”:[11013683178,11013755361,11034443843,11013754606]},{ “标签”:[11034443843,11013683178,11013754606, 11013755361]},{“Tags”:[11013754606,11013755361,11034443843,11013683178]},' – trevleyb 2013-03-21 18:26:47