Skip to content

Commit

Permalink
Merge pull request #73 from laurapanzariello/develop
Browse files Browse the repository at this point in the history
prefixv4 and prefixv6
  • Loading branch information
Laura authored Sep 23, 2019
2 parents d8f6928 + d0d4ddb commit 8e0d640
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 9 deletions.
76 changes: 76 additions & 0 deletions CadVlan/Vlan/static/css/new_vlan.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
html body {
display: grid;
grid-template-columns: 1fr;
margin: 10%;
background-color: #f2fcff;
}

section.container-cadvlan {
display: flex;
flex-direction: column;
align-items: center;
flex-basis: 100%;

}

div.form-group-cadvlan {
display: flex;
flex-direction: column;
align-items: flex-start;
border-left: 2px solid #0D84A5;
margin: 20px;
}

div.form-row-cadvlan {
display: flex;
flex-direction: row;
align-content: space-between;
align-items: flex-start;
margin: 10px;
margin-top: 16px;
}

div.form-group {
display: flex;
flex-direction: row;
align-content: flex-start;
align-items: flex-end;
margin: 5px;
}

div.field-group {
vertical-align: bottom;
}

.form-control,
.input.form-control.bs-autocomplete {
background-color : #FFFFFF;
}

input:required,
select.form-control:required {
border-left-color: #c87392;
border-left-width: 1px;
}

button.btn.btn-social-add.btn-responsive.env {
margin-top: 35px;
}

button#more_range.btn.btn-social-add.btn-responsive.channel,
button#btn_add_router_env.btn.btn-social-add.btn-responsive.channel,
button#btn_add_logic_env.btn.btn-social-add.btn-responsive.channel,
button#btn_add_vrf.btn.btn-social-add.btn-responsive.channel,
button#btn_add_fisic_env.btn.btn-social-add.btn-responsive.channel {
margin-bottom: 0px;
}

select.form-control,
input.form-control.bs-autocomplete {
height: 36px;
font-size: 0.875rem;
border: 1px solid #e8e8e8;
border-radius: 3px;
padding: 0.5em 1.07em 0.5em;
width: 100%;
}
128 changes: 128 additions & 0 deletions CadVlan/Vlan/static/js/new_vlan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
$(document).ready(function() {

let id_prefixv4 = document.getElementById("id_prefixv4");
let id_prefixv6 = document.getElementById("id_prefixv6");
let btn_sav = document.getElementById("btn_sav");
let btn_can = document.getElementById("btn_can");
let id_name = document.getElementById("id_name");
let id_environment = document.getElementById("id_environment");
let id_network_ipv4 = document.getElementById("id_network_ipv4");
let id_network_ipv6 = document.getElementById("id_network_ipv6");
let id_vlan_number = document.getElementById("id_vlan_number");
let id_number = document.getElementById("id_number");

$(id_prefixv4).parent().hide();
$(id_prefixv6).parent().hide();

$(btn_sav).button({ icons: {primary: "ui-icon-disk"} });

$(btn_can).button({ icons: {primary: "ui-icon-cancel"} }).click(function(){
location.href = "vlan/list/";
});

$(id_name).keyup(function() {
var valor = $(this).val().replace(/[^0-9A-Za-z_-]+/g,'');
$(this).val(valor);
});

$(id_name).mouseover(function() {
$(this).attr("title","Somente letras maiúsculas e minúsculas, números, '-' e '_' são permitidos.");
});

get_environment_configuration_available();

$(id_environment).change(function() {
$(id_network_ipv4).val($('option:first', this).val());
$(id_network_ipv6).val($('option:first', this).val());

get_environment_configuration_available();
});

$(id_network_ipv4).change(function(){
var options = $(this).children("option:selected").text();

if (options == "Sim") {
$(id_prefixv4).parent().show();
} else {
$(id_prefixv4).parent().hide();
}
});

$(id_network_ipv6).change(function(){
var options = $(this).children("option:selected").text();

if (options == "Sim") {
$(id_prefixv6).parent().show();
} else {
$(id_prefixv6).parent().hide();
}
});

$(id_vlan_number).change(function(){
var options = $(this).children("option:selected").text();

if (options == "Sim") {
$(id_number).parent().show();
} else {
$(id_number).parent().hide();
}
});

})

function get_environment_configuration_available() {

var environment_id = $(id_environment).val();

var maskv4;
var maskv6;

$.ajax({
data: {environment_id: environment_id},
url: "/vlan/form/get/available/environment/configuration/by/environment/id/",
method: 'GET',
success: function(data) {

data = $.parseJSON(data);

var network_ipv4 = '';
var network_ipv6 = '';

if (data.available_environment_config_ipv4 == true) {
$(id_network_ipv4).parent().show();
} else {
$(id_network_ipv4).parent().hide();
}

if (data.available_environment_config_ipv6 == true) {
$(id_network_ipv6).parent().show();
} else {
$(id_network_ipv6).parent().hide();
}

if (data.vlan_range == true){
$(id_vlan_number).parent().show();
$(id_number).parent().hide();
} else {
$(id_vlan_number).parent().hide();
$(id_number).parent().show();
}

if (data.hide_vlan_range == true){
$(id_vlan_number).parent().hide();
$(id_number).parent().hide();
}

if (data.maskv4){
id_prefixv4.value = data.maskv4
}

if (data.maskv6){
id_prefixv6.value = data.maskv6
}
},
error: function(data) {
console.log(data);
}
});
}
2 changes: 1 addition & 1 deletion CadVlan/Vlan/templates/vlan/vlan-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% block content %}
<div id="page_tab" style="margin-left:10%; margin-right:10%;border:none">
<div style="font-size: 40px;margin: 20px;border:none;">
<p style="text-align: center;">Cadastrar Vlan</p>
<p style="text-align: center;color: #7C6767">Cadastrar Vlan</p>
</div>
<div id="tabs-1">
<form id="add_form" method="post" action="{% url vlan.form %}">
Expand Down
15 changes: 7 additions & 8 deletions CadVlan/Vlan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,19 +1248,16 @@ def apply_acl_for_network(request, client, equipments, vlan, environment, networ


def get_environments(client):

try:
# Get all environments from NetworkAPI
search_env = {
'extends_search': [],
'start_record': 0,
'custom_search': '',
'end_record': 99999999,
'asorting_cols': [],
'searchable_columns': []}
env_cli = client.create_api_environment()
# env_list = env_cli.search()
return client.create_api_environment().search(search=search_env, kind='basic')

except Exception as e:
raise e

Expand All @@ -1275,7 +1272,8 @@ def ajax_get_available_ip_config_by_environment_id(request):
available_environment_config_ipv6 = False
vlan_range = False
hide_vlan_range = True
mask = ""
maskv4 = ""
maskv6 = ""

if request.method == 'GET':
environment_id = request.GET.get('environment_id')
Expand All @@ -1293,17 +1291,17 @@ def ajax_get_available_ip_config_by_environment_id(request):
for config in lists_configuration:
if config.get('type', '').upper() == 'V4':
available_environment_config_ipv4 = True
maskv4 = config.get('new_prefix')
if config.get('type', '').upper() == 'V6':
available_environment_config_ipv6 = True
maskv6 = config.get('new_prefix')

# if range:
ambiente = client.create_ambiente().buscar_por_id(environment_id)
ambiente = ambiente.get("ambiente")
if ambiente.get('min_num_vlan_1'):
vlan_range = True

mask = ambiente.get('subnet').split('/')[2] if ambiente.get('subnet') else ""

except NetworkAPIClientError as e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
Expand All @@ -1315,6 +1313,7 @@ def ajax_get_available_ip_config_by_environment_id(request):
context['available_environment_config_ipv6'] = available_environment_config_ipv6
context['vlan_range'] = vlan_range
context['hide_vlan_range'] = hide_vlan_range
context['mask'] = mask
context['maskv4'] = maskv4
context['maskv6'] = maskv6

return render_json(json.dumps(context))

0 comments on commit 8e0d640

Please sign in to comment.