From 561cf7fdf3c6c3483d005e29daab9a1c8cda8348 Mon Sep 17 00:00:00 2001 From: "laura.panzariello" Date: Fri, 20 Sep 2019 17:37:28 -0300 Subject: [PATCH 1/2] create vlan static dir --- CadVlan/Vlan/static/css/new_vlan.css | 76 +++++++++++++++++ CadVlan/Vlan/static/js/new_vlan.js | 118 +++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 CadVlan/Vlan/static/css/new_vlan.css create mode 100644 CadVlan/Vlan/static/js/new_vlan.js diff --git a/CadVlan/Vlan/static/css/new_vlan.css b/CadVlan/Vlan/static/css/new_vlan.css new file mode 100644 index 00000000..87861d38 --- /dev/null +++ b/CadVlan/Vlan/static/css/new_vlan.css @@ -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%; +} \ No newline at end of file diff --git a/CadVlan/Vlan/static/js/new_vlan.js b/CadVlan/Vlan/static/js/new_vlan.js new file mode 100644 index 00000000..c190d21a --- /dev/null +++ b/CadVlan/Vlan/static/js/new_vlan.js @@ -0,0 +1,118 @@ +$(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(); + + $.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(); + } + }, + error: function(data) { + + console.log(data); + } + }); +} \ No newline at end of file From d0d4ddbc44ec8eebace6e1a331db237b409c8d54 Mon Sep 17 00:00:00 2001 From: "laura.panzariello" Date: Mon, 23 Sep 2019 20:28:26 -0300 Subject: [PATCH 2/2] set prefixv4 and prefixv6 with the default value --- CadVlan/Vlan/static/js/new_vlan.js | 12 +++++++++++- CadVlan/Vlan/templates/vlan/vlan-form.html | 2 +- CadVlan/Vlan/views.py | 15 +++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CadVlan/Vlan/static/js/new_vlan.js b/CadVlan/Vlan/static/js/new_vlan.js index c190d21a..a1e4a500 100644 --- a/CadVlan/Vlan/static/js/new_vlan.js +++ b/CadVlan/Vlan/static/js/new_vlan.js @@ -74,6 +74,9 @@ 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/", @@ -109,9 +112,16 @@ function get_environment_configuration_available() { $(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); } }); diff --git a/CadVlan/Vlan/templates/vlan/vlan-form.html b/CadVlan/Vlan/templates/vlan/vlan-form.html index e32a6fac..a31e863e 100755 --- a/CadVlan/Vlan/templates/vlan/vlan-form.html +++ b/CadVlan/Vlan/templates/vlan/vlan-form.html @@ -27,7 +27,7 @@ {% block content %}
-

Cadastrar Vlan

+

Cadastrar Vlan

diff --git a/CadVlan/Vlan/views.py b/CadVlan/Vlan/views.py index 240cc22e..0902a92b 100644 --- a/CadVlan/Vlan/views.py +++ b/CadVlan/Vlan/views.py @@ -1248,8 +1248,8 @@ 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, @@ -1257,10 +1257,7 @@ def get_environments(client): '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 @@ -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') @@ -1293,8 +1291,10 @@ 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) @@ -1302,8 +1302,6 @@ def ajax_get_available_ip_config_by_environment_id(request): 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) @@ -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))