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

Commit

Permalink
Support for filtering on branch #8
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobehn committed Oct 31, 2018
1 parent cbffd4c commit f4a24fd
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 1,368 deletions.
16 changes: 0 additions & 16 deletions extension/src/BuildDetails.js

This file was deleted.

2 changes: 2 additions & 0 deletions extension/src/IDetailSettings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@

interface IDetailSettings {
definitionId: number;
branch: string;
showBranch: boolean;
}
149 changes: 0 additions & 149 deletions extension/src/build-details-configuration.js

This file was deleted.

86 changes: 72 additions & 14 deletions extension/src/build-details-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import TFS_Build_Contracts = require("TFS/Build/Contracts");
import TFS_Build_Client = require("TFS/Build/RestClient");
import TFS_Git_Client = require("TFS/VersionControl/GitRestClient");

VSS.require(["TFS/Dashboards/WidgetHelpers"], (WidgetHelpers) => {
WidgetHelpers.IncludeWidgetConfigurationStyles();
Expand All @@ -31,19 +32,33 @@ class DetailsConfiguration {
private definitionDropDown = $("#definitionDropDown");
private errordropdown = $("#definitionDropDown .validation-error > .validation-error-text");

private reposDropDown = $("#reposDropDown");
private showBranchCheckBox = $("#showBranchCheckBox");

private detailsSettings: IDetailSettings;
private showBranch: boolean = false;

constructor(public WidgetHelpers) { }

public async load(widgetSettings, widgetConfigurationContext) {
this.widgetConfigurationContext = widgetConfigurationContext;
const settings: IDetailSettings = JSON.parse(widgetSettings.customSettings.data);
if (!settings || !settings.definitionId) {
this.detailsSettings = JSON.parse(widgetSettings.customSettings.data);

if (!this.detailsSettings || !this.detailsSettings.definitionId) {
const options = this.definitionDropDown;
const text = "Select a build definition";
options.append($("<option style=\"font-style:italic\" />").val(-1).text(text));
}
await this.loadBuildDefinitions(settings);

await this.loadBuildDefinitions(this.detailsSettings);
this.showBranch = this.detailsSettings.showBranch;
if (this.showBranch) {
this.showBranchCheckBox.prop("checked", true);
} else {
this.showBranchCheckBox.prop("checked", false);
}
this.notifyOnChange(this.definitionDropDown);
this.notifyOnReposDropDownChange(this.reposDropDown);
this.notifyOnShowBranchChange(this.showBranchCheckBox);

return this.WidgetHelpers.WidgetStatusHelper.Success();
}
Expand All @@ -68,10 +83,40 @@ class DetailsConfiguration {
options.append($("<option />").val(defRef.id).text(defRef.name));
}
}

this.loadBranches();
}

private loadBranches() {
if (this.validateQueryDropdown(this.definitionDropDown, this.errordropdown)) {
const context = VSS.getWebContext();
const buildClient = TFS_Build_Client.getClient();
buildClient.getDefinition(this.definitionDropDown.val() as number, context.project.id)
.then((def) => {
const buildRepo = def.repository;

const gitClient = TFS_Git_Client.getClient();
gitClient.getBranches(buildRepo.id)
.then( (branches) => {
const options = this.reposDropDown;
options.empty();
options.append($("<option style=\"font-style:italic\" />").val(-1).text("Any"));

for (const b of branches) {

if (this.detailsSettings && this.detailsSettings.branch && b.name === this.detailsSettings.branch) {
options.append($("<option selected/>").val(b.name).text(b.name));
} else {
options.append($("<option />").val(b.name).text(b.name));
}
}
});
});
}
}

private validateQueryDropdown($queryDropdown, $errordropdown): boolean {
if (this.definitionDropDown.val() === "-1") {
if ($queryDropdown.val() === "-1") {
const text = "Please select a build definition";
$errordropdown.text(text);
$errordropdown.parent().css("visibility", "visible");
Expand All @@ -85,23 +130,36 @@ class DetailsConfiguration {
control.change(() => {
if (this.validateQueryDropdown(this.definitionDropDown, this.errordropdown)) {
$("#definitionDropDown option[value='-1']").remove();
this.widgetConfigurationContext.notify(this.WidgetHelpers.WidgetEvent.ConfigurationChange,
this.WidgetHelpers.WidgetEvent.Args(this.getCustomSettings()));
this.notifyConfigurationChanged();
this.loadBranches();
}
});
}

private notifyOnShowBranchChange(control) {
control.change(() => {
this.showBranch = !this.showBranch;
this.notifyConfigurationChanged();
});
}

private notifyOnReposDropDownChange(control) {
control.change(() => {
this.notifyConfigurationChanged();
});
}

private notifyConfigurationChanged() {
this.widgetConfigurationContext.notify(this.WidgetHelpers.WidgetEvent.ConfigurationChange,
this.WidgetHelpers.WidgetEvent.Args(this.getCustomSettings()));
}

private getCustomSettings() {
const data: IDetailSettings = {
branch: this.reposDropDown.val() as string,
definitionId: this.definitionDropDown.val() as number,
showBranch: this.showBranch,
};
return { data: JSON.stringify(data) };
}

private onSave() {
if (this.definitionDropDown.val() === "-1") {
return this.WidgetHelpers.WidgetConfigurationSave.Invalid();
}
return this.WidgetHelpers.WidgetConfigurationSave.Valid(this.getCustomSettings());
}
}
Loading

0 comments on commit f4a24fd

Please sign in to comment.