nsi list, show, create, delete

Change-Id: I0c7757cdb7a38712e8960806765a2508b0013ce6
Signed-off-by: lombardofr <lombardo@everyup.it>
diff --git a/instancehandler/template/instance_list.html b/instancehandler/template/instance_list.html
index 067dcb5..9fddbc0 100644
--- a/instancehandler/template/instance_list.html
+++ b/instancehandler/template/instance_list.html
@@ -42,6 +42,8 @@
                 {% include 'instance_list_vnf.html' %}
             {% elif type == 'pdu' %}
                 {% include 'instance_list_pdu.html' %}
+            {% elif type == 'nsi' %}
+                {% include 'instance_list_nsi.html' %}
             {% endif %}
 
         </div>
@@ -49,6 +51,7 @@
     </div>
     {% include 'modal/instance_create.html' %}
     {% include 'modal/instance_create_pdu.html' %}
+    {% include 'modal/instance_create_nsi.html' %}
     {% include 'modal/instance_show.html' %}
     {% include 'modal/instance_new_action.html' %}
     {% include 'modal/instance_new_alarm.html' %}
@@ -282,6 +285,105 @@
                     "targets": 5,
                     "orderable": false
                 }
+            ],
+            'nsi': [
+                {
+                    "render": function (data, type, row) {
+                        return row["name"];
+                    },
+                    "targets": 0
+                },
+                {
+                    "render": function (data, type, row) {
+                        return row["_id"];
+                    },
+                    "targets": 1
+                },
+                {
+                    "render": function (data, type, row) {
+                        return row["nst-ref"];
+                    },
+                    "targets": 2
+                },
+                {
+                 //   "width": "5%",
+                    "render": function (data, type, row) {
+                        if(row["operational-status"] === 'failed')
+                           return '<span class="label label-danger">'+ row["operational-status"] +'</span>';
+                        if(row["operational-status"] === 'init')
+                           return '<span class="label label-warning">'+ row["operational-status"] +'</span>';
+                        if(row["operational-status"] === 'running')
+                           return '<span class="label label-success">'+ row["operational-status"] +'</span>';
+                        return  ''+row["operational-status"]+'';
+                    },
+                    "targets": 3
+                },
+                {
+                //    "width": "5%",
+                    "render": function (data, type, row) {
+                         if(row["config-status"] === 'failed')
+                           return '<span class="label label-danger">'+ row["config-status"] +'</span>';
+                        if(row["config-status"] === 'init')
+                           return '<span class="label label-warning">'+ row["config-status"] +'</span>';
+                        if(row["config-status"] === 'running')
+                           return '<span class="label label-success">'+ row["config-status"] +'</span>';
+                        if(row["config-status"] === 'configured')
+                           return '<span class="label label-success">'+ row["config-status"] +'</span>';
+                        return  ''+row["operational-status"]+'';
+                    },
+                    "targets": 4
+                },
+                {
+                   // "className": "ellipsis",
+                    "render": function (data, type, row) {
+                        return row["detailed-status"];
+                    },
+                    "targets": 5
+                },{
+                     "width": "20%",
+                    "render": function (data, type, row) {
+                          var template = '<div class="btn-group">' +
+                            ' <button type="button" class="btn btn-default"' +
+                            '         onclick="javascript:showInstanceDetails(\''+instance_type+'\', \''+row["_id"]+'\')"' +
+                            '         data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info">' +
+                            '     <i class="fa fa-info"></i>';
+                            /* if (row["operational-status"] === "running") {
+                                template += ' <button type="button" class="btn btn-default"' +
+                                '         onclick="javascript:showTopology(\'' + instance_type + '\', \'' + row["_id"] + '\')"' +
+                                '         data-toggle="tooltip" data-placement="top" data-container="body" title="Show Graph">' +
+                                '     <i class="fa fa-sitemap"></i>' +
+                                ' </button>';
+                            }else{
+                                template += ' <button type="button" disabled class="btn btn-default"' +
+                                '         onclick="javascript:showTopology(\'' + instance_type + '\', \'' + row["_id"] + '\')"' +
+                                '         data-toggle="tooltip" data-placement="top" data-container="body" title="Show Graph">' +
+                                '     <i class="fa fa-sitemap"></i>' +
+                                ' </button>';
+                            } */
+                            template += ' <button type="button" class="btn btn-default"' +
+                            '         onclick="javascript:deleteNsi(\''+ row["name"] +'\', \''+row["_id"]+'\')"' +
+                            '         data-toggle="tooltip" data-placement="top" data-container="body" title="Delete"><i' +
+                            '         class="far fa-trash-alt"></i></button>' +
+                            ' <button type="button" class="btn btn-default dropdown-toggle"' +
+                            '         data-toggle="dropdown" aria-expanded="false">Actions' +
+                            '     <span class="fa fa-caret-down"></span></button>' +
+                            ' <ul class="dropdown-menu">' +
+                            '     <li>' +
+                            '         <a href="/instances/nsi/' +row["_id"] +'/operation">' +
+                            '             <i class="fa fa-list"></i> History of operations</a></li>' +
+                            '     <li class="divider"></li>' +
+
+                            '     <li>' +
+                            '         <a href="javascript:deleteNsi(\''+ row["name"] +'\', \''+row["_id"]+'\', true)">' +
+                            '             <i class="far fa-trash-alt" style="color:red" ></i> Force delete</a></li>' +
+                            ' </ul>' +
+                            '</div>';
+                          return template;
+                    },
+                    "targets": 5,
+                    "orderable": false
+                },
+
             ]
         };
         $(document).ready(function () {
diff --git a/instancehandler/template/instance_list_nsi.html b/instancehandler/template/instance_list_nsi.html
new file mode 100644
index 0000000..a90e04c
--- /dev/null
+++ b/instancehandler/template/instance_list_nsi.html
@@ -0,0 +1,41 @@
+{% load get %}
+<div class="box">
+    <div class="box-header with-border">
+        <h3 class="box-title">Network Slices Instances</h3>
+
+        <div class="box-tools">
+
+            <button type="button" class="btn btn-default" data-container="body"
+                    data-toggle="tooltip" data-placement="top" title="Instantiate NSI"
+                    onclick="javascript:openModalCreateNSI({ 'project_id':'{{ project_id }}','vim_list_url': '{% url "vims:list"  %}', 'nst_list_url': '{% url "netslices:list_templates" %}'})">
+                <i class="fa fa-paper-plane"></i> <span> Create NSI</span></button>
+
+        </div>
+
+    </div>
+    <div class="box-body">
+    {% if alert_error %}
+        <div class="alert alert-danger alert-dismissible fade in">
+            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
+            <h4><i class="icon fa fa-ban"></i> Error</h4>
+            {{alert_error}}
+        </div>
+    {% endif %}
+        <table id="instances_table" class="table table-bordered table-striped responsive" style="width:100%">
+            <thead>
+            <tr>
+                <th>Name</th>
+                <th>Identifier</th>
+                <th>Nst name</th>
+                <th style="width:5%">Operational Status</th>
+                <th style="width:5%">Config Status</th>
+                <th>Detailed Status</th>
+                <th>Actions</th>
+            </tr>
+            </thead>
+            <tbody>
+
+            </tbody>
+        </table>
+    </div>
+</div>
diff --git a/instancehandler/template/modal/instance_create_nsi.html b/instancehandler/template/modal/instance_create_nsi.html
new file mode 100644
index 0000000..bad979f
--- /dev/null
+++ b/instancehandler/template/modal/instance_create_nsi.html
@@ -0,0 +1,71 @@
+<div class="modal" id="modal_new_nsi" xmlns="http://www.w3.org/1999/html">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">×</span></button>
+                <h4 class="modal-title">New NSI</h4>
+            </div>
+            <form id="formCreateNS" action='{% url "instances:create" type='nsi' %}'
+                  class="form-horizontal"
+                  method="post" enctype="multipart/form-data">
+                {% csrf_token %}
+                <div class="modal-body" id="modal_new_instance_body">
+                    <div class="form-group">
+                        <label for="nsiName" class="col-sm-3 control-label">Name *</label>
+                        <div class="col-sm-6">
+                            <input class="form-control" id="nsiName" name="nsiName"
+                                   placeholder="Ns name" required>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="nsiDescription" class="col-sm-3 control-label">Description *</label>
+                        <div class="col-sm-6">
+                            <input class="form-control" id="nsiDescription" name="nsiDescription"
+                                   placeholder="Description" required>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="nstId" class="col-sm-3 control-label">Nst Id *</label>
+                        <div class="col-sm-6">
+                            <select required id="nstId" class="js-example-basic form-control" name="nstId">
+                            </select>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="vimAccountIdNSI" class="col-sm-3 control-label">Vim Account Id *</label>
+                        <div class="col-sm-6">
+                            <select required id="vimAccountIdNSI" class="js-example-basic form-control" name="vimAccountId">
+                            </select>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="ssh_key_nsi" class="col-sm-3 control-label">SSH Key </label>
+                        <div class="col-sm-6">
+                            <textarea class="form-control" id="ssh_key_nsi" name="ssh_key"
+                                      placeholder="Paste your key here..." rows="4"></textarea>
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label for="config_nsi" class="col-sm-3 control-label">Config </label>
+                        <div class="col-sm-6">
+                            <textarea class="form-control" id="config_nsi" name="config" placeholder="Yaml config"
+                                      rows="4"></textarea>
+                        </div>
+                    </div> 
+
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+                    <button class="btn btn-primary"
+                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Creating..."
+                            id="create_new_instance_nsi">Create
+                    </button>
+
+                </div>
+            </form>
+        </div>
+        <!-- /.modal-content -->
+    </div>
+    <!-- /.modal-dialog -->
+</div>
diff --git a/instancehandler/template/modal/instance_show.html b/instancehandler/template/modal/instance_show.html
index 6df8bc1..1263855 100644
--- a/instancehandler/template/modal/instance_show.html
+++ b/instancehandler/template/modal/instance_show.html
@@ -1,5 +1,5 @@
 <div class="modal" id="modal_show_instance" xmlns="http://www.w3.org/1999/html">
-    <div   class="modal-dialog">
+    <div   class="modal-dialog modal-lg">
         <div class="modal-content">
             <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">