2013-03-20 185 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