From 6751c629ea2d4e0ea1d7c1bbd8cc34cb91cd5b49 Mon Sep 17 00:00:00 2001 From: bfcamara Date: Fri, 24 Oct 2014 15:21:21 +0100 Subject: [PATCH] allow https://.visualstudio.com as the account name optimized the base url calculations: calculate once in app loading --- app.js | 40 ++++++++++++++++++++++++++++------------ translations/en.json | 2 +- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index 4f79e68..cabcfcc 100644 --- a/app.js +++ b/app.js @@ -37,6 +37,7 @@ //Global view model shared by all instances vm: { + accountUrl: null, projects: [], fields: [], fieldSettings: {}, @@ -278,6 +279,9 @@ return this.switchTo('finish_setup'); } + //set account url + this.vm.accountUrl = this.buildAccountUrl(); + if (!this.store("auth_token_for_" + this.setting('vso_account'))) { return this.switchTo('login'); } @@ -864,17 +868,8 @@ }, vsoUrl: function (url, parameters) { - var setting = this.setting('vso_account'); - var baseUrl = helpers.fmt(VSO_URL_FORMAT, setting); - var loweredSetting = setting.toLowerCase(); - - if (loweredSetting.indexOf('http://') === 0 || loweredSetting.indexOf('https://') === 0) { - baseUrl = setting; - } - - baseUrl = (baseUrl[baseUrl.length - 1] === '/') ? baseUrl.slice(0, -1) : baseUrl; url = (url[0] === '/') ? url.slice(1) : url; - var full = [baseUrl, url].join('/'); + var full = [this.vm.accountUrl, url].join('/'); if (parameters) { full += '?' + _.map(parameters, function (value, key) { return [key, value].join('='); @@ -1073,8 +1068,29 @@ }.bind(this)); return attachments; + }, + + buildAccountUrl: function () { + var baseUrl; + var setting = this.setting('vso_account'); + var loweredSetting = setting.toLowerCase(); + + if (loweredSetting.indexOf('http://') === 0 || loweredSetting.indexOf('https://') === 0) { + baseUrl = setting; + } else { + baseUrl = helpers.fmt(VSO_URL_FORMAT, setting); + } + + baseUrl = (baseUrl[baseUrl.length - 1] === '/') ? baseUrl.slice(0, -1) : baseUrl; + + //check if collection defined + if (baseUrl.lastIndexOf('/') <= 'https://'.length) { + baseUrl = baseUrl + '/DefaultCollection'; + } + + return baseUrl; } - //#endregion - }; + //#endregion +}; }()); \ No newline at end of file diff --git a/translations/en.json b/translations/en.json index 1f87bb7..3475878 100644 --- a/translations/en.json +++ b/translations/en.json @@ -3,7 +3,7 @@ "parameters": { "vso_account": { "label": "Visual Studio Online account name", - "helpText": "Enter your Visual Studio Online account (https://.visualstudio.com). Learn more by visiting http://go.microsoft.com/fwlink/?LinkID=396756" + "helpText": "Enter your Visual Studio Online subdomain (part before visualstudio.com). Learn more by visiting http://go.microsoft.com/fwlink/?LinkID=396756" }, "vso_tag": { "label": "Visual Studio Online work item tag",