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

Fix url params getting changed erroneously #1726

Merged
merged 2 commits into from
Oct 4, 2024
Merged
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
50 changes: 50 additions & 0 deletions deploy-board/deploy_board/static/js/deploy-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,56 @@ function getUrlParameter(sParam) {
}
}
}
function setUrlParameter(url, name, val){
let searchString = url.search.substring(1);
let vars = searchString.split("&")
let modifiedString = "?"
let set= false;

for(let i=0; i < vars.length; i++){
if(i>0){
modifiedString+="&"
}
let currParam = vars[i].split('=');
if(currParam[0] === name){
modifiedString+=name
modifiedString+= "=" + encodeURIComponent(val)
set=true;
} else {
modifiedString+=vars[i]
}
}
if(!set){
if(modifiedString.length>1){
modifiedString+="&"
}
modifiedString+=name
modifiedString+="="+encodeURIComponent(val)
}
url.search=modifiedString;
return url
}

function deleteUrlParameter(url, name){
let searchString = url.search.substring(1);
let vars = searchString.split("&")
let modifiedString = "?"

for(let i=0; i < vars.length; i++){
let currParam = vars[i].split('=');
if(currParam[0]!==name){
if(modifiedString.length>1){
modifiedString+="&"
}
modifiedString+=vars[i]
}
}
url.search=modifiedString;
return url
}




function getRemainingCapacity(capacityInfo, placementList) {
if (!capacityInfo || !placementList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ <h4 class="panel-title pull-left">Capacity</h4>
<div id="clusterAlert">
<in-rolling-alert v-show="showReplaceAlert" actionlink="/env/{{ env.envName }}/{{ env.stageName }}/config/cluster/config/"></in-rolling-alert>
</div>
{% include "environs/env_tabs.tmpl" with envTabKind="config/capacity" %}


<div id="mainPanel" class="panel panel-default">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ <h4 class="panel-title pull-left">Capacity</h4>
</div>
{% endif %}

{% include "environs/env_tabs.tmpl" with envTabKind="config/capacity" %}
<script type="text/javascript" src="{% static "js/components/capacitycomponents.js"%}?changedate=2023.01.30"></script>
<script type="text/javascript" src="{% static "js/components/clusterconfigcomponents.js"%}?changedate=2023.08.22"></script>
<script type="text/javascript" src="{% static "js/base-image-utils.js"%}?changedate=2023.01.30"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ <h4 class="panel-title pull-left">Capacity</h4>
{% block new-pred-deploys-panel %}
{% endblock %}
{% block main%}
{% include "environs/env_tabs.tmpl" with envTabKind="config/capacity" %}
<script type="text/javascript" src="{% static "js/components/capacitycomponents.js"%}?changedate=2023.01.30"></script>
<script type="text/javascript" src="{% static "js/components/clusterconfigcomponents.js"%}?changedate=2023.08.22"></script>
<script type="text/javascript" src="{% static "js/base-image-utils.js"%}?changedate=2023.01.30"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ <h4 class="panel-title pull-left">Actions</h4>
{% endblock %}

{% block main %}
{% include "environs/env_tabs.tmpl" with envTabKind="config/schedule" %}
<div class="panel panel-default">
{% include "configs/schedule_config.tmpl" %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

jQuery(function(){
var maxCheckedAllowed = 2;
var checkboxes = $('input[type="checkbox"]');
var checkboxes = $("#deployHistoryTableId").find('input[type="checkbox"]');
checkboxes.change(function(){
var numChecked = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', numChecked >= maxCheckedAllowed);
Expand Down
36 changes: 17 additions & 19 deletions deploy-board/deploy_board/templates/environs/env_tabs.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@
{% endfor %}
</ul>
</div>
<ul id="stageTabs" class="nav nav-tabs" style="padding-right:40px;">
{% for stage in envs %}
<li data-stagetype="{{stage.stageType}}" {% if stage.stageName == env.stageName %}class="active"{% endif %}>
<a class="deployToolTip" data-container="body" data-toggle="tooltip" title="{{stage.description}}" data-placement="bottom"
onclick="callback(event, this)"
href="/env/{{ env.envName }}/{{ stage.stageName }}/{{ envTabKind }}">{{ stage.stageName }}</a>
</li>
{% endfor %}
</ul>
<div id="filterOpts" data-filter="{{stagetype_filter}}" />
<ul id="stageTabs" class="nav nav-tabs" style="padding-right:40px;">
{% for stage in envs %}
<li data-stagetype="{{stage.stageType}}" {% if stage.stageName == env.stageName %}class="active"{% endif %}>
<a class="deployToolTip" data-container="body" data-toggle="tooltip" title="{{stage.description}}" data-placement="bottom"
onclick="callback(event, this)"
href="/env/{{ env.envName }}/{{ stage.stageName }}/{{ envTabKind }}">{{ stage.stageName }}</a>
</li>
{% endfor %}
</ul>
</div>


Expand All @@ -56,8 +55,7 @@
let filterInactive = true;

try {
filter = Array.from(JSON.parse(decodeURIComponent($("#filterOpts").attr("data-filter"))));
console.log(filter);
filter = JSON.parse(getUrlParameter("stageFilter"))
if(!Array.isArray(filter)){
throw new Error("invalid url filter params");
}
Expand Down Expand Up @@ -85,7 +83,6 @@

update();
function update() {
console.log(filter)
if(filter.length < 1){
filterInactive = true;
} else {
Expand Down Expand Up @@ -161,22 +158,23 @@

//update filter param in url as it changes
function updateUrl(){
let url = new URL(window.location.href);
let url = new URL(window.location.href)
let newUrl;
if(filter.length < 1){
url.searchParams.delete("stageFilter");
newUrl = deleteUrlParameter(url, "stageFilter")
} else {
url.searchParams.set("stageFilter", JSON.stringify(filter));
newUrl = setUrlParameter(url, "stageFilter", JSON.stringify(filter))
}
window.history.replaceState(null,null,url);
window.history.replaceState(null,null,newUrl);
}

//intercept and add filter parameter to link
function callback(e, anchor){
if(!filterInactive){
e.preventDefault();
let url = new URL(anchor.href);
url.searchParams.set("stageFilter", JSON.stringify(filter));
window.location.href=url;
let newUrl = setUrlParameter(url,"stageFilter", JSON.stringify(filter));
window.location.href=newUrl;
}
}
</script>
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/alarm_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ def get(self, request, name, stage):
envs = environs_helper.get_all_env_stages(request, name)
stages, env = common.get_all_stages(envs, stage)
alarms = environs_helper.get_env_alarms_config(request, name, stage)

return render(request, 'configs/alarm_config.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"alarms": alarms,
})
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/capacity_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ def get(self, request, name, stage):
stages, env = get_all_stages(envs, stage)
hosts = environs_helper.get_env_capacity(request, name, stage, capacity_type="HOST")
groups = get_env_groups(request, name, stage)

if cluster_name in groups:
groups.remove(cluster_name)
data = {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"hosts": hosts,
"groups": groups,
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/config_map_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def get(self, request, name, stage):
# otherwise, return a page
envs = environs_helper.get_all_env_stages(request, name)
stages, env = get_all_stages(envs, stage)

return render(request, 'configs/config_map.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"configs": configs,
"customization": CUSTOMIZATION[flavor],
Expand Down
1 change: 1 addition & 0 deletions deploy-board/deploy_board/webapp/env_config_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def get(self, request, name, stage):
return render(request, 'configs/env_config.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"show_remove": show_remove,
"pinterest": IS_PINTEREST,
Expand Down
13 changes: 10 additions & 3 deletions deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def logging_status(request, name, stage):

html = render_to_string('deploys/deploy_logging_check_landing.tmpl', {
"envs": envs,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"csrf_token": get_token(request),
"panel_title": "Kafka logging for %s (%s)" % (name, stage),
"env": env,
Expand Down Expand Up @@ -444,7 +445,6 @@ def get(self, request, name, stage=None):

asg_suspended_processes = _get_asg_suspended_processes(request, env) or []

stagetype_filter = request.GET.get('stageFilter', [])

if not env['deployId']:
capacity_hosts = deploys_helper.get_missing_hosts(request, name, stage)
Expand All @@ -454,7 +454,6 @@ def get(self, request, name, stage=None):
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stagetype_filter": stagetype_filter,
"env_promote": env_promote,
"stages": stages,
"metrics": metrics,
Expand Down Expand Up @@ -551,7 +550,6 @@ def get(self, request, name, stage=None):
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stagetype_filter": stagetype_filter,
"env_promote": env_promote,
"stages": stages,
"report": report,
Expand Down Expand Up @@ -941,6 +939,7 @@ def get_env_deploys(request, name, stage):
return render(request, 'environs/env_history.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"deploy_summaries": [],
"filter_title": filter_title,
Expand Down Expand Up @@ -976,6 +975,7 @@ def get_env_deploys(request, name, stage):
return render(request, 'environs/env_history.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"deploy_summaries": deploy_summaries,
"filter_title": filter_title,
Expand Down Expand Up @@ -1466,6 +1466,7 @@ def get_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stage": stage,
"stages": stages,
"agents_wrapper": agents_wrapper,
Expand Down Expand Up @@ -1493,6 +1494,7 @@ def get_hosts_by_deploy(request, name, stage, deploy_id):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand Down Expand Up @@ -1577,6 +1579,7 @@ def get_unknown_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand All @@ -1595,6 +1598,7 @@ def get_provisioning_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand All @@ -1613,6 +1617,7 @@ def get_all_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand All @@ -1633,6 +1638,7 @@ def get_failed_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand Down Expand Up @@ -1668,6 +1674,7 @@ def get_sub_account_hosts(request, name, stage):
return render(request, 'environs/env_hosts.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"agents_wrapper": agents_wrapper,
"title": title,
Expand Down
1 change: 1 addition & 0 deletions deploy-board/deploy_board/webapp/metrics_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get(self, request, name, stage):
return render(request, 'configs/metrics_config.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"metrics": metrics,
})
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/promote_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def get(self, request, name, stage):
return HttpResponse(json.dumps({'html': html}), content_type="application/json")

# otherwise, return a page

return render(request, 'configs/promote_config.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"stage_names": stage_names,
"env_promote": env_promote,
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/webhook_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ def get(self, request, name, stage):
envs = environs_helper.get_all_env_stages(request, name)
stages, env = common.get_all_stages(envs, stage)
webhooks = environs_helper.get_env_hooks_config(request, name, stage)

return render(request, 'configs/webhooks_config.html', {
"envs": envs,
"env": env,
"all_stage_types": sorted(environs_helper.STAGE_TYPES),
"stages": stages,
"webhooks": webhooks,
})
Expand Down
Loading