Skip to content

Commit

Permalink
Merge pull request #229 from D10S0VSkY-OSS/hotfix/clone_deployments
Browse files Browse the repository at this point in the history
🐛fix: clone deployments when null
  • Loading branch information
D10S0VSkY-OSS authored Dec 31, 2023
2 parents aa5a367 + 9178054 commit d53fd0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
17 changes: 12 additions & 5 deletions sld-dashboard/app/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,27 +688,34 @@ def clone_deploy(deploy_id):
headers={"Authorization": f"Bearer {token}"},
)
aws_content = aws_response.get("json")
aws_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in aws_content]

# Get data from gcp accounts
gcp_response = request_url(
verb="GET",
uri="accounts/gcp/",
headers={"Authorization": f"Bearer {token}"},
)
gcp_content = gcp_response.get("json")
gcp_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in gcp_content]

# Get data from azure accounts
azure_response = request_url(
verb="GET",
uri="accounts/azure/",
headers={"Authorization": f"Bearer {token}"},
)
azure_content = azure_response.get("json")
azure_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in azure_content]

# Get data from custom providers accounts
custom_response = request_url(
verb="GET",
uri="accounts/custom_providers/",
headers={"Authorization": f"Bearer {token}"},
)
custom_content = custom_response.get("json")
custom_result = [{'squad': entry['squad'], 'environment': entry['environment']} for entry in custom_content]
# Get defaults vars by deploy
vars_json = request_url(
verb="GET",
Expand Down Expand Up @@ -788,10 +795,10 @@ def clone_deploy(deploy_id):
name="Edit Deploy",
form=form,
deploy=deploy,
aws_content=aws_content,
gcp_content=gcp_content,
azure_content=azure_content,
custom_content=custom_content,
aws_content=aws_result,
gcp_content=gcp_result,
azure_content=azure_result,
custom_content=custom_result,
data_json=vars_json["json"],
)
except TemplateNotFound:
Expand Down Expand Up @@ -833,7 +840,7 @@ def edit_schedule(deploy_id):
# Deploy
response = request_url(
verb="PATCH",
uri="{endpoint}",
uri=endpoint,
headers={"Authorization": f"Bearer {token}"},
json=data,
)
Expand Down
11 changes: 1 addition & 10 deletions sld-dashboard/app/home/templates/deploy-clone.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,10 @@ <h6><strong>{{key}}</strong></h6>
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Obtener el prefijo del deploy.stack_name
var stackName = "{{ deploy.stack_name | default('') }}";
var stackNamePrefix = stackName.split('_')[0];
console.log("Stack Name Prefix:", stackNamePrefix);

// Obtener el contenido correspondiente al prefijo
var contentList;
if (stackNamePrefix === "aws") {
contentList = {{ aws_content | safe }};
Expand All @@ -207,14 +205,12 @@ <h6><strong>{{key}}</strong></h6>
} else if (stackNamePrefix === "custom") {
contentList = {{ custom_content | safe }};
} else {
contentList = []; // Manejar otros casos según sea necesario
contentList = [];
}

// Filtrar la lista de squads y entornos según el tipo de contenido
var squads = Array.from(new Set(contentList.map(item => item.squad)));
var environments = Array.from(new Set(contentList.map(item => item.environment)));

// Actualizar los desplegables con los datos filtrados
var squadSelect = document.getElementById("squadSelect");
var environmentSelect = document.getElementById("environmentSelect");

Expand All @@ -232,17 +228,13 @@ <h6><strong>{{key}}</strong></h6>
environmentSelect.add(option);
});

// Función para actualizar las opciones del campo de entorno según el escuadrón seleccionado
function updateEnvironmentOptions(selectedSquad) {
// Filtrar la lista de entornos para el escuadrón seleccionado
var filteredEnvironments = contentList
.filter(item => item.squad === selectedSquad)
.map(item => item.environment);

// Limpiar las opciones actuales
environmentSelect.innerHTML = "";

// Agregar las nuevas opciones
filteredEnvironments.forEach(function (environment) {
var option = document.createElement("option");
option.value = environment;
Expand All @@ -251,7 +243,6 @@ <h6><strong>{{key}}</strong></h6>
});
}

// Agregar un evento de cambio al campo de escuadrón
squadSelect.addEventListener('change', function () {
var selectedSquad = squadSelect.value;
updateEnvironmentOptions(selectedSquad);
Expand Down

0 comments on commit d53fd0b

Please sign in to comment.