Skip to content

Commit

Permalink
ExtensionDataService keys can be max 50 characters, temporary impleme…
Browse files Browse the repository at this point in the history
…ntation / fix.
  • Loading branch information
Kees Schollaart committed Mar 15, 2018
1 parent c3ea271 commit af102b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
60 changes: 43 additions & 17 deletions src/sprint-goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import StatusIndicator = require("VSS/Controls/StatusIndicator");
import sg = require("./SprintGoalApplicationInsightsWrapper");

export class SprintGoal {
private iterationId: number;
private iterationId: string;
private teamId: string;
private storageUri: string;
private waitControl: StatusIndicator.WaitControl;
Expand Down Expand Up @@ -134,15 +134,21 @@ export class SprintGoal {
}

public getSprintGoalFromCookie = (): SprintGoalDto => {
var goal = this.getCookie(this.iterationId + this.teamId + "goalText");
var goal = this.getCookie(this.getConfigKey(this.iterationId, this.teamId) + "goalText");

var sprintGoalInTabLabel = false;
if (!goal) {
goal = this.getCookie(this.iterationId + "goalText");
sprintGoalInTabLabel = (this.getCookie(this.iterationId + "sprintGoalInTabLabel") == "true");
}
else {
// team specific setting
sprintGoalInTabLabel = (this.getCookie(this.iterationId + this.teamId + "sprintGoalInTabLabel") == "true");
if (goal) {
sprintGoalInTabLabel = (this.getCookie(this.getConfigKey(this.iterationId, this.teamId) + "sprintGoalInTabLabel") == "true");

} else {
var goal = this.getCookie(this.iterationId + this.teamId + "goalText");
if (goal) {
sprintGoalInTabLabel = (this.getCookie(this.iterationId + this.teamId + "sprintGoalInTabLabel") == "true");
}
else {
goal = this.getCookie(this.iterationId + "goalText");
sprintGoalInTabLabel = (this.getCookie(this.iterationId + "sprintGoalInTabLabel") == "true");
}
}

if (!goal) return undefined;
Expand All @@ -168,7 +174,7 @@ export class SprintGoal {
if (this.ai) this.ai.trackEvent("SaveSettings", sprintConfig);

var configIdentifier: string = this.iterationId.toString();
var configIdentifierWithTeam: string = this.iterationId.toString() + this.teamId;
var configIdentifierWithTeam: string = this.getConfigKey(this.iterationId, this.teamId);

this.updateSprintGoalCookie(configIdentifier, sprintConfig);
this.updateSprintGoalCookie(configIdentifierWithTeam, sprintConfig);
Expand Down Expand Up @@ -196,7 +202,8 @@ export class SprintGoal {

if (forceReload || !currentGoalInCookie || !cookieSupport) {
var configIdentifier = this.iterationId.toString();
var configIdentifierWithTeam = this.iterationId.toString() + this.teamId;
var oldConfigIdentifierWithTeam = this.iterationId.toString() + this.teamId;
var configIdentifierWithTeam = this.getConfigKey(this.iterationId, this.teamId);

return this.fetchSettingsFromExtensionDataService(configIdentifierWithTeam).then((teamGoal: SprintGoalDto): IPromise<SprintGoalDto> => {
if (teamGoal) {
Expand All @@ -209,13 +216,27 @@ export class SprintGoal {
});
}
else {
// fallback, also for backward compatibility: project/iteration level settings
return this.fetchSettingsFromExtensionDataService(configIdentifier).then((iterationGoal) => {
if (iterationGoal) {
this.updateSprintGoalCookie(configIdentifier, iterationGoal);
return this.fetchSettingsFromExtensionDataService(oldConfigIdentifierWithTeam).then((oldTeamGoal) => {
if (oldTeamGoal) {
this.updateSprintGoalCookie(configIdentifier, oldTeamGoal);
this.updateSprintGoalCookie(configIdentifierWithTeam, oldTeamGoal);
return oldTeamGoal;
}
return iterationGoal;
else return null;
}).then((goal) => {
if (goal) {
return Q.fcall((): SprintGoalDto => {
return goal;
});
}
return this.fetchSettingsFromExtensionDataService(configIdentifier).then((iterationGoal) => {
if (iterationGoal) {
this.updateSprintGoalCookie(configIdentifier, iterationGoal);
}
return iterationGoal;
})
});

}
});
}
Expand Down Expand Up @@ -246,6 +267,11 @@ export class SprintGoal {
});
}

private getConfigKey = (iterationId: string, teamId: string) => {
// https://github.com/Microsoft/vss-web-extension-sdk/issues/75
return iterationId.toString().substring(0, 15) + teamId.toString().substring(0, 15)
}

private updateSprintGoalCookie = (key: string, sprintGoal: SprintGoalDto) => {
this.setCookie(key + "goalText", sprintGoal.goal);
this.setCookie(key + "sprintGoalInTabLabel", sprintGoal.sprintGoalInTabLabel);
Expand All @@ -256,7 +282,7 @@ export class SprintGoal {
$("#cookieWarning").show();
}
if (!sprintGoal) {
$("#sprintGoalInTabLabel").prop("checked", false);
$("#sprintGoalInTabLabel").prop("checked", true);
$("#goal").val("")
}
else {
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "sprint-goal",
"name": "Sprint Goal",
"version": "3.0.45",
"version": "3.1.0",
"publisher": "keesschollaart",
"public": true,
"helpMarkDown": "[More Information](https://github.com/keesschollaart81/vsts-sprint-goal)",
Expand Down

0 comments on commit af102b4

Please sign in to comment.