Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from Microsoft/jeyou/max-work-items
Browse files Browse the repository at this point in the history
Return a maximum of 200 work items with an option to open browser for…
  • Loading branch information
Jeff Young committed Mar 31, 2016
2 parents f83b142 + 9374963 commit db5f55a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
29 changes: 23 additions & 6 deletions src/clients/witclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ export class WitClient extends BaseClient {
window.showQuickPick(self.getMyWorkItems(self._serverContext.TeamProject, query.wiql), { matchOnDescription: true, placeHolder: Strings.ChooseWorkItem }).then(
function (workItem) {
if (workItem) {
let editUrl: string = WorkItemTrackingService.GetEditWorkItemUrl(self._serverContext.TeamProjectUrl, workItem.id);
Logger.LogInfo("Edit Work Item Url: " + editUrl);
Utils.OpenUrl(editUrl);
let url: string = undefined;
if (workItem.id === undefined) {
url = WorkItemTrackingService.GetMyQueryResultsUrl(self._serverContext.TeamProjectUrl, query.label);
} else {
url = WorkItemTrackingService.GetEditWorkItemUrl(self._serverContext.TeamProjectUrl, workItem.id);
}
Logger.LogInfo("Work Item Url: " + url);
Utils.OpenUrl(url);
}
},
function (err) {
Expand All @@ -101,9 +106,14 @@ export class WitClient extends BaseClient {
window.showQuickPick(self.getMyWorkItems(this._serverContext.TeamProject, WitQueries.MyWorkItems), { matchOnDescription: true, placeHolder: Strings.ChooseWorkItem }).then(
function (workItem) {
if (workItem) {
let editUrl: string = WorkItemTrackingService.GetEditWorkItemUrl(self._serverContext.TeamProjectUrl, workItem.id);
Logger.LogInfo("Work Item Url: " + editUrl);
Utils.OpenUrl(editUrl);
let url: string = undefined;
if (workItem.id === undefined) {
url = WorkItemTrackingService.GetWorkItemsBaseUrl(self._serverContext.TeamProjectUrl);
} else {
url = WorkItemTrackingService.GetEditWorkItemUrl(self._serverContext.TeamProjectUrl, workItem.id);
}
Logger.LogInfo("Work Item Url: " + url);
Utils.OpenUrl(url);
}
},
function (err) {
Expand Down Expand Up @@ -160,6 +170,13 @@ export class WitClient extends BaseClient {
simpleWorkItems.forEach(wi => {
workItems.push({ label: wi.label, description: wi.description, id: wi.id});
});
if (simpleWorkItems.length === WorkItemTrackingService.MaxResults) {
workItems.push({
id: undefined,
label: Strings.BrowseAdditionalWorkItems,
description: Strings.BrowseAdditionalWorkItemsDescription
});
}

deferred.resolve(workItems);
}).catch((reason) => {
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/* tslint:disable:variable-name */
export class Strings {
static BrowseYourPullRequests: string = "Browse your Team Services pull requests.";
static BrowseAdditionalWorkItems: string = "Browse additional work items...";
static BrowseAdditionalWorkItemsDescription: string = "Choose this item to see all query results in your web browser";
static NavigateToBuildSummary: string = "Click to view build";
static NavigateToTeamServicesWebSite: string = "Click to view your team project website.";
static NoAccessTokenFound: string = "A personal access token for this Team Services repository was not found in your local user settings.";
Expand Down
20 changes: 17 additions & 3 deletions src/services/workitemtracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IQWorkItemTrackingApi } from "vso-node-api/WorkItemTrackingApi";
import { QueryExpand, QueryHierarchyItem, QueryResultType, Wiql, WorkItem,
WorkItemExpand, WorkItemType, WorkItemTypeReference } from "vso-node-api/interfaces/WorkItemTrackingInterfaces";
import { TeamServerContext } from "../contexts/servercontext";
import { WitQueries } from "../helpers/constants";

import Q = require("q");

Expand Down Expand Up @@ -127,6 +128,10 @@ export class WorkItemTrackingService {
deferred.resolve(results);
return promiseToReturn;
}
//Only request the maximum number of work items the API documents that we should
if (workItemIds.length >= WorkItemTrackingService.MaxResults) {
workItemIds = workItemIds.slice(0, WorkItemTrackingService.MaxResults);
}

this._witApi.getWorkItems(workItemIds,
[WorkItemFields.Id, WorkItemFields.Title, WorkItemFields.WorkItemType],
Expand Down Expand Up @@ -156,13 +161,13 @@ export class WorkItemTrackingService {

//Construct the url to the individual work item edit page
public static GetEditWorkItemUrl(teamProjectUrl: string, workItemId: string) : string {
return this.getWorkItemsBaseUrl(teamProjectUrl) + "/edit/" + workItemId;
return this.GetWorkItemsBaseUrl(teamProjectUrl) + "/edit/" + workItemId;
}

//Construct the url to the creation page for new work item type
public static GetNewWorkItemUrl(teamProjectUrl: string, issueType: string, title?: string, assignedTo?: string) : string {
//This form will redirect to the form below so let's use this one
let url:string = this.getWorkItemsBaseUrl(teamProjectUrl) + "/create/" + issueType;
let url:string = this.GetWorkItemsBaseUrl(teamProjectUrl) + "/create/" + issueType;
let separator: string = "?";
if (title !== undefined) {
url += separator + "[" + WorkItemFields.Title + "]=" + encodeURIComponent(title);
Expand All @@ -175,10 +180,19 @@ export class WorkItemTrackingService {
return url;
}

//Construct the url to the particular query results page
public static GetMyQueryResultsUrl(teamProjectUrl: string, queryName: string) : string {
return this.GetWorkItemsBaseUrl(teamProjectUrl) + "?path=" + encodeURIComponent(WitQueries.MyQueriesFolder + "/" + queryName) + "&_a=query";
}

//Returns the base url for work items
private static getWorkItemsBaseUrl(teamProjectUrl: string) {
public static GetWorkItemsBaseUrl(teamProjectUrl: string) {
return teamProjectUrl + "/_workitems";
}

/* tslint:disable:variable-name */
public static MaxResults: number = 200;
/* tslint:enable:variable-name */
}

export class SimpleWorkItem {
Expand Down
12 changes: 12 additions & 0 deletions test/services/workitemtracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,16 @@ describe("WorkItemTrackingService", function() {
assert.equal(WorkItemTrackingService.GetNewWorkItemUrl(url, issueType, title, assignedTo), url + "/_workitems" + "/create/" + issueType + "?[" + WorkItemFields.Title + "]=" + encodeURIComponent(title) + "&" + "[" + WorkItemFields.AssignedTo + "]=" + assignedTo);
});

it("should verify GetMyQueryResultsUrl with url and queryName", function() {
let url: string = "https://account.visualstudio.com/DefaultCollection/project";
let queryName: string = "My Favorite Query";

assert.equal(WorkItemTrackingService.GetMyQueryResultsUrl(url, queryName), url + "/_workitems" + "?path=" + encodeURIComponent("My Queries/") + encodeURIComponent(queryName) + "&_a=query");
});

it("should verify GetWorkItemsBaseUrl with url", function() {
let url: string = "https://account.visualstudio.com/DefaultCollection/project";

assert.equal(WorkItemTrackingService.GetWorkItemsBaseUrl(url), url + "/_workitems");
});
});

0 comments on commit db5f55a

Please sign in to comment.