b7bc224eed41d01dc9f4e07b3323035f4f0c9f2c
[osm/LW-UI.git] / vimhandler / template / vim_list.html
1 <!--
2 Copyright 2019 ETSI
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 -->
16
17 {% extends "base.html" %}
18 {% load get %}
19 {% load staticfiles %}
20
21
22 {% block head_block %}
23 {{ block.super }}
24 <link rel="stylesheet" href="/static/node_modules/datatables.net-bs/css/dataTables.bootstrap.min.css">
25 {% endblock %}
26 {% block title_header_big %}
27 {{ block.super }}
28 {% endblock %}
29 {% block left_sidebar %}
30
31 {% include 'osm/osm_project_left_sidebar.html' %}
32
33 {% endblock %}
34
35
36 {% block breadcrumb_body %}
37 {{ block.super }}
38 <li><a href="{% url "vims:list" %}">VIMS</a></li>
39 {% endblock %}
40
41 {% block content_body %}
42 {{ block.super }}
43 {% include 'modal/vim_details.html' %}
44 {% csrf_token %}
45 <div class="row">
46 <div class="col-md-12">
47
48 <div class="box">
49 <div class="box-header with-border">
50 <h3 class="box-title">Registered VIM</h3>
51 <div class="box-tools">
52 <a href='{% url "vims:create" %}' class="btn btn-block btn-primary btn-sm"><i
53 class="fa fa-plus"></i><span> New VIM</span></a>
54 </div>
55 </div>
56 <div class="box-body">
57 <table id="vims_table" class="table table-bordered table-striped">
58 <thead>
59 <tr>
60 <th>Name</th>
61 <th>Identifier</th>
62 <th>Type</th>
63 <th>Operational State</th>
64 <th>Description</th>
65 <th>Actions</th>
66 </tr>
67 </thead>
68 <tbody>
69
70 </tbody>
71 </table>
72 </div>
73 </div>
74 </div>
75
76 </div>
77 {% endblock %}
78
79 {% block resource_block %}
80 {{ block.super }}
81 <script src="/static/node_modules/datatables.net/js/jquery.dataTables.min.js"></script>
82 <script src="/static/node_modules/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
83 <script>
84 $(document).ready( function () {
85 var table = $('#vims_table').DataTable({
86 responsive: true,
87 "ajax": {
88 "url": "/vims/list/",
89 "dataSrc": function (json) {
90 return json['datacenters'];
91 },
92 statusCode: {
93 401: function () {
94 console.log("no auth");
95 moveToLogin(window.location.pathname);
96 }
97 },
98 "error": function (hxr, error, thrown) {
99 console.log(hxr)
100 console.log(thrown)
101 console.log(error);
102 }
103
104 },
105 "columns": [
106 {
107 "render": function (data, type, row) {
108 return row["name"];
109 },
110 "targets": 0
111 },
112 {
113 "render": function (data, type, row) {
114 return row['_id'];
115 },
116 "targets": 1
117 },
118 {
119 "render": function (data, type, row) {
120 return row["vim_type"];
121 },
122 "targets": 2
123 },
124 {
125 "render": function (data, type, row) {
126 return row["_admin"]['operationalState'];
127 },
128 "targets": 3
129 },
130 {
131 "render": function (data, type, row) {
132 return row["_admin"]['description'] || '';
133 },
134 "targets": 4
135 },
136 {
137 "render": function (data, type, row) {
138 return '<div class="btn-group"><button type="button" class="btn btn-default" ' +
139 'onclick="location.href=\'/vims/'+row['_id']+'\'" data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info">' +
140 '<i class="fa fa-info"></i>' +
141 '</button> ' +
142 '<button type="button" class="btn btn-default"' +
143 'onclick="javascript:deleteVim(\''+row['_id']+'\', \''+ row["name"] +'\')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete">' +
144 '<i class="far fa-trash-alt" ></i></button></div>';
145 },
146 "targets": 5,
147 "orderable": false
148 }
149 ]
150 });
151
152 setInterval(function () {
153 table.ajax.reload();
154 }, 10000);
155 });
156 </script>
157 <script>
158
159 function deleteVim(vim_id, vim_name) {
160 var url = "/vims/"+vim_id+"/delete";
161 bootbox.confirm("Are you sure want to delete " + vim_name + "?", function (result) {
162 if (result) {
163 var dialog = bootbox.dialog({
164 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
165 closeButton: true
166 });
167 $.ajax({
168 url: url,
169 type: 'GET',
170 dataType: "json",
171 contentType: "application/json;charset=utf-8",
172 success: function (result) {
173 if (result['error'] == true) {
174 dialog.modal('hide');
175 bootbox.alert("An error occurred.");
176 }
177 else {
178 dialog.modal('hide');
179 location.reload();
180 }
181 },
182 error: function (error) {
183 dialog.modal('hide');
184 bootbox.alert("An error occurred.");
185 }
186 });
187 }
188 })
189 }
190 </script>
191
192 {% endblock %}