create ns instance from ns list; minor fix 33/6133/1
authorlombardof <flombardo@cnit.it>
Fri, 11 May 2018 11:47:10 +0000 (13:47 +0200)
committerlombardof <flombardo@cnit.it>
Fri, 11 May 2018 11:47:10 +0000 (13:47 +0200)
Change-Id: I31e3b349e86f67e776b85c2484f455c3594da0a6
Signed-off-by: lombardof <flombardo@cnit.it>
instancehandler/template/instance_list.html
instancehandler/template/modal/instance_create.html
projecthandler/template/project/osm/descriptor/descriptor_new.html
projecthandler/template/project/osm/descriptor/descriptorlist.html
projecthandler/template/project/osm/osm_project_details.html
projecthandler/template/project/osm/osm_project_left_sidebar.html
projecthandler/urls/project.py
projecthandler/views.py
static/src/instancehandler/instance_create.js

index b2485c2..52b3da4 100644 (file)
@@ -42,7 +42,7 @@
 
                         <button type="button" class="btn btn-default" data-container="body"
                                 data-toggle="tooltip" data-placement="top" title="Instantiate NS"
-                                onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}','vim_list_url': '{% url "vim:list" %}'})" disabled>
+                                onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}','vim_list_url': '{% url "vim:list" %}', 'nsd_list_url': '{% url "projects:list_descriptors" project_id=project_id descriptor_type='nsd'  %}'})" >
                             <i class="fa fa-paper-plane"></i> <span> New NS</span></button>
 
                     </div>
index ffbce47..f1c24d9 100644 (file)
                     <div class="form-group">
                         <label for="nsdId" class="col-sm-3 control-label">Nsd Id *</label>
                         <div class="col-sm-6">
-                            <input class="form-control" id="nsdId" name="nsdId"
-                                   placeholder="Nsd Id">
+                            <select required id="nsdId" class="js-example-basic form-control" name="nsdId">
+                            </select>
                         </div>
                     </div>
                     <div class="form-group">
                         <label for="vimAccountId" class="col-sm-3 control-label">Vim Account Id *</label>
                         <div class="col-sm-6">
-                            <select id="vimAccountId" class="js-example-basic form-control" name="vimAccountId">
+                            <select required id="vimAccountId" class="js-example-basic form-control" name="vimAccountId">
                             </select>
                         </div>
                     </div>
index d257d7f..eb1e127 100644 (file)
@@ -1,22 +1,7 @@
 {% extends "descriptor/descriptor_view_base.html" %}
 
 {% load staticfiles %}
-{% block head_base %}
-    {% with skin_css="AdminLTE/dist/css/skins/skin-purple.min.css"%}
-        {{ block.super }}
-    {% endwith %}
-{% endblock %}
 
-{% block body %}
-    {% with skin="purple"%}
-        {{ block.super }}
-    {% endwith %}
-{% endblock %}
-{% block logo_sidebar %}
-    {% with logo_mini="assets/img/osm_small_logo.png" logo="assets/img/OSM-logo.png"%}
-        {{ block.super }}
-    {% endwith %}
-{% endblock %}
 
 {% block title_header_big %}
 {{ block.super }}
@@ -65,6 +50,7 @@ Onboard new {{ descriptor_type }} package
 {{ block.super }}
 
 <script>
+    var descr_list_url = '{% url "projects:list_descriptors"  project_id=project_id descriptor_type=descriptor_type%}'
 
     var dropZone = document.getElementById('drop-zone');
     dropZone.ondrop = function(e) {
@@ -132,7 +118,7 @@ Onboard new {{ descriptor_type }} package
                     success: function(result) {
                         console.log(result)
 
-                        window.location.href="/projects/{{project_id}}/descriptors/{{descriptor_type}}"
+                        window.location.href=descr_list_url
 
                     },
                     error: function(result) {
@@ -142,7 +128,7 @@ Onboard new {{ descriptor_type }} package
         }
 
     function cancel(id){
-        window.location.href="/projects/{{project_id}}/descriptors/{{descriptor_type}}"
+        window.location.href= descr_list_url
     }
 
 
index 4e3e24b..f2f4c8d 100644 (file)
@@ -37,7 +37,7 @@
                     <td>
                         <div class="btn-group">
                             {% if descriptor_type == "nsd" %}
-                            <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Instantiate NS" onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}', 'descriptor_type': '{{descriptor_type}}', 'descriptor_id':'{{ k|get:"_id" }}','vim_list_url': '{% url "vim:list" %}'})"><i class="fa fa-paper-plane"></i></button>
+                            <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Instantiate NS" onclick="javascript:openModalCreateNS({ 'project_id':'{{project_id}}', 'descriptor_type': '{{descriptor_type}}', 'descriptor_name':'{{ k|get:"name" }}', 'descriptor_id':'{{ k|get:"_id" }}','vim_list_url': '{% url "vim:list" %}',  'nsd_list_url': '{% url "projects:list_descriptors" project_id=project_id descriptor_type=descriptor_type  %}' })"><i class="fa fa-paper-plane"></i></button>
                             {% endif %}
                             <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Edit" onclick="javascript:openDescriptorView('{{project_id}}', '{{descriptor_type}}', '{{ k|get:"_id" }}')"><i class="fa fa-edit"></i></button>
                             <button type="button" class="btn btn-default" data-container="body" data-toggle="tooltip" data-placement="top" title="Show content" onclick="javascript:openPackageContentList('{{project_id}}', '{{descriptor_type}}', '{{ k|get:"_id" }}')"><i class="fa fa-folder-open"></i></button>
index ab90385..8c5f8fc 100644 (file)
@@ -44,7 +44,7 @@
                     <div class="inner"><h3>{{ project_overview.nsd }}</h3>
                         <p>NS packages</p></div>
                     <div class="icon"><i class="fa fa-archive"></i></div>
-                    <a href="/projects/{{ project_id }}/descriptors/nsd" class="small-box-footer">Open list <i
+                    <a href='{% url "projects:list_descriptors"  project_id=project_id descriptor_type="nsd" %}' class="small-box-footer">Open list <i
                             class="fa fa-arrow-circle-right"></i></a></div>
             </div>
             <div class="col-md-6 ">
@@ -52,7 +52,7 @@
                     <div class="inner"><h3>{{ project_overview.vnfd }}</h3>
                         <p>VNF packages</p></div>
                     <div class="icon"><i class="fa fa-archive"></i></div>
-                    <a href="/projects/{{ project_id }}/descriptors/vnfd" class="small-box-footer">Open list <i
+                    <a href='{% url "projects:list_descriptors"  project_id=project_id descriptor_type="vnfd" %}' class="small-box-footer">Open list <i
                             class="fa fa-arrow-circle-right"></i></a></div>
             </div>
         </div>
index 029ae11..ec0b0f3 100644 (file)
@@ -13,9 +13,9 @@
                   <i class="fa fa-file-text fa-fw"></i><span>Overview</span>
               </a>
           </li>
-          {% url "projects:list_descriptors"  project_id=project_id descriptor_type="vnfd" as  nsd_list_url %}
+          {% url "projects:list_descriptors"  project_id=project_id descriptor_type="nsd" as  nsd_list_url %}
           {% url "projects:list_descriptors"  project_id=project_id descriptor_type='vnfd' as  vnfd_list_url %}
-        <li {% if request.get_full_path == nsd_list_url %} class="active treeview" {% else %} class="treeview" {% endif %} >
+        <li {% if request.get_full_path == nsd_list_url or  request.get_full_path == vnfd_list_url%} class="active treeview" {% else %} class="treeview" {% endif %} >
                 <a href="#">
                     <i class="fa fa-archive fa-fw"></i> <span>Packages {{nsd_list}}</span>
                     <span class="pull-right-container">
                 </a>
                 <ul class="treeview-menu">
                     <li {% if request.get_full_path == nsd_list_url %} class="active" {% endif %}>
-                        <a href="/projects/{{project_id}}/descriptors/nsd">
+                        <a href='{{ nsd_list_url }}'>
                             <i class="fa fa-archive fa-fw"></i>NS Packages
                         </a>
                     </li>
                     <li {% if request.get_full_path == vnfd_list_url %} class="active" {% endif %}>
-                        <a href="/projects/{{project_id}}/descriptors/vnfd">
+                        <a href='{{ vnfd_list_url }}'>
                             <i class="fa fa-archive fa-fw"></i>VNF Packages
                         </a>
                     </li>
index 61e4d4e..2b2f824 100644 (file)
@@ -35,7 +35,7 @@ urlpatterns = [
     url(r'^(?P<project_id>\d+)/graph/addlink$', views.add_link, name='addlink'),
     url(r'^(?P<project_id>\d+)/graph/removelink$', views.remove_link, name='removelink'),
     url(r'^(?P<project_id>\d+)/graph/availablenodes', views.get_available_nodes, name='get_available_nodes'),
-    url(r'^(?P<project_id>\d+)/descriptors/(?P<descriptor_type>\w+)(/$)', views.show_descriptors, name='list_descriptors'),
+    url(r'^(?P<project_id>\d+)/descriptors/(?P<descriptor_type>\w+)/list$', views.show_descriptors, name='list_descriptors'),
     url(r'^(?P<project_id>\d+)/descriptors/(?P<descriptor_type>\w+)/(?P<descriptor_id>[-\w]+)(/$)',
         views.edit_descriptor, name='edit_descriptor'),
     url(r'^(?P<project_id>\d+)/descriptors/(?P<descriptor_type>\w+)/(?P<descriptor_id>[-\w]+)/delete$',
index 8c553a4..cd10806 100644 (file)
@@ -166,7 +166,6 @@ def delete_project(request, project_id=None):
             return render(request, 'error.html', {'error_msg': 'Project not found.'})
 
 
-
 @login_required
 def show_descriptors(request, project_id=None, descriptor_type=None):
     csrf_token_value = get_token(request)
@@ -174,16 +173,15 @@ def show_descriptors(request, project_id=None, descriptor_type=None):
     project_overview = projects[0].get_overview_data()
     prj_token = project_overview['type']
 
-    page = prj_token + '/' + prj_token + '_project_descriptors.html'
-
-    return render(request, page, {
+    url = prj_token + '/' + prj_token + '_project_descriptors.html'
+    return __response_handler(request, {
         'descriptors': projects[0].get_descriptors(descriptor_type),
         'project_id': project_id,
         'project_type': prj_token,
         'project_overview_data': project_overview,
         "csrf_token_value": csrf_token_value,
         'descriptor_type': descriptor_type
-    })
+    },url)
 
 
 @login_required
index b09aa5b..0bf1dbc 100644 (file)
@@ -16,7 +16,6 @@
 
 
 function openModalCreateNS(args) {
-
     // load vim account list
     select2_groups = $('#vimAccountId').select2({
         placeholder: 'Select VIM',
@@ -39,18 +38,20 @@ function openModalCreateNS(args) {
             }
         }
     });
-    /*
+
     // load nsd list
     select2_groups = $('#nsdId').select2({
         placeholder: 'Select NSD',
+        width: '100%',
         ajax: {
             url: args.nsd_list_url,
             dataType: 'json',
             processResults: function (data) {
                 nsd_list = [];
-                if (data['nsd_list']) {
-                    for (d in data['nsd_list']) {
-                        var nsd = data['nsd_list'][d];
+
+                if (data['descriptors']) {
+                    for (d in data['descriptors']) {
+                        var nsd = data['descriptors'][d];
                         nsd_list.push({id: nsd['_id'], text: nsd['name']})
                     }
                 }
@@ -61,7 +62,18 @@ function openModalCreateNS(args) {
             }
         }
     });
-    */
-    $('#nsdId').val(args.descriptor_id);
+
+    if(args.descriptor_id){
+        // Set the value, creating a new option if necessary
+        if ($('#nsdId').find("option[value='" + args.descriptor_id + "']").length) {
+            $('#nsdId').val(args.descriptor_id).trigger('change');
+        } else {
+            // Create a DOM Option and pre-select by default
+            var newOption = new Option(args.descriptor_name, args.descriptor_id, true, true);
+            // Append it to the select
+            $('#nsdId').append(newOption).trigger('change');
+        }
+    }
+
     $('#modal_new_instance').modal('show');
 }
\ No newline at end of file