Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill param values from query #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Slingshot.Api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<!-- JS -->
<!-- load angular, nganimate, and ui-router -->
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
Expand Down
43 changes: 34 additions & 9 deletions Slingshot.Api/ng/Scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ function IsSiteLocationParam(paramName) {

function initialize() {
$scope.formData.repositoryUrl = getQueryVariable("repository");
var extraParams = getQueryVariable("extras");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a single param for all the data rather than promote each to its own query string param? The JSON param makes it a be tricky to hand write in the address bar (e.g. for testing).

Is it to avoid potential conflicts with other existing query params?

if (extraParams) {
sessionStorage.extraParams = extraParams;
} else {
extraParams = sessionStorage.extraParams;
}
if (extraParams) {
$scope.formData.queryParams = JSON.parse(extraParams);
}

if (!$scope.formData.repositoryUrl || $scope.formData.repositoryUrl.length === 0) {
if (sessionStorage.repositoryUrl) {
Expand All @@ -225,15 +234,21 @@ function IsSiteLocationParam(paramName) {
}

function getQueryVariable(variable) {
var query = window.location.search,
token = variable + "=",
startIndex = query.indexOf(token);

if (startIndex >= 0) {
return query.substring(startIndex + token.length);
}
return parseQuery()[variable] || null;
}

return null;
function parseQuery() {
var query = window.location.search;
if (query && query.length > 1) {
var pairs = query.substr(1).split('&');
return _.object(_.map(pairs, function (pair) {
return _.map(pair.split('='), function (v, i) {
return i == 0 ? v : decodeURIComponent(v);
});
}));
} else {
return {};
}
}

initialize();
Expand Down Expand Up @@ -262,7 +277,7 @@ function IsSiteLocationParam(paramName) {
$http({
method: "get",
url: "api/template",
params: {
params: {
"repositoryUrl": $scope.formData.repositoryUrl
}
})
Expand Down Expand Up @@ -346,6 +361,12 @@ function IsSiteLocationParam(paramName) {
param.defaultValue = parameter.defaultValue;
param.defaultValueComeFirst = parameter.defaultValueComeFirst;

if ($scope.formData.queryParams[name]) {
param.value = $scope.formData.queryParams[name];
param.defaultValue = param.value;
param.defaultValueComeFirst = true;
}

$scope.formData.params.push(param);

var paramName = param.name.toLowerCase();
Expand Down Expand Up @@ -476,6 +497,10 @@ function IsSiteLocationParam(paramName) {

$scope.showParam = function (param) {
var name = param.name.toLowerCase();
if ($scope.formData.queryParams[name]) {
param.value = $scope.formData.queryParams[name];
return false;
}
if (name === 'repourl' && $scope.formData.repositoryUrl) {
param.value = $scope.formData.repositoryUrl;
return false;
Expand Down