| lombardofr | 93770e2 | 2019-08-30 19:37:56 +0200 | [diff] [blame] | 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 | |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 17 | {% extends "base.html" %} |
| 18 | {% load get %} |
| 19 | {% load staticfiles %} |
| 20 | |
| 21 | |
| 22 | {% block head_block %} |
| 23 | {{ block.super }} |
| lombardofr | e5a130a | 2019-07-15 09:17:59 +0200 | [diff] [blame] | 24 | <link rel="stylesheet" href="/static/node_modules/datatables.net-bs/css/dataTables.bootstrap.min.css"> |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 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 "wims:list" %}">VIMS</a></li> |
| 39 | {% endblock %} |
| 40 | |
| 41 | {% block content_body %} |
| 42 | {{ block.super }} |
| 43 | {% include 'modal/wim_details.html' %} |
| 44 | {% include 'modal/wim_create.html' %} |
| 45 | {% csrf_token %} |
| 46 | <div class="row"> |
| 47 | <div class="col-md-12"> |
| 48 | |
| 49 | <div class="box"> |
| 50 | <div class="box-header with-border"> |
| 51 | <h3 class="box-title">Registered WIM</h3> |
| 52 | <div class="box-tools"> |
| 53 | <button type="button" class="btn btn-default" data-container="body" |
| 54 | data-toggle="tooltip" data-placement="top" title="New PDU" |
| 55 | onclick="javascript:openModalCreateWIM()"> |
| 56 | <i class="fa fa-plus"></i> <span> New WIM</span> |
| 57 | </button> |
| 58 | </div> |
| 59 | </div> |
| 60 | <div class="box-body"> |
| 61 | <table id="wims_table" class="table table-bordered table-striped"> |
| 62 | <thead> |
| 63 | <tr> |
| 64 | <th>Name</th> |
| 65 | <th>Identifier</th> |
| 66 | <th>Type</th> |
| 67 | <th>Operational State</th> |
| 68 | <th>Description</th> |
| 69 | <th>Actions</th> |
| 70 | </tr> |
| 71 | </thead> |
| 72 | <tbody> |
| 73 | |
| 74 | </tbody> |
| 75 | </table> |
| 76 | </div> |
| 77 | </div> |
| 78 | </div> |
| 79 | |
| 80 | </div> |
| 81 | {% endblock %} |
| 82 | |
| 83 | {% block resource_block %} |
| 84 | {{ block.super }} |
| lombardofr | e5a130a | 2019-07-15 09:17:59 +0200 | [diff] [blame] | 85 | <script src="/static/node_modules/datatables.net/js/jquery.dataTables.min.js"></script> |
| 86 | <script src="/static/node_modules/datatables.net-bs/js/dataTables.bootstrap.min.js"></script> |
| lombardofr | 3fcf21a | 2019-03-11 10:26:08 +0100 | [diff] [blame] | 87 | <script> |
| 88 | $(document).ready( function () { |
| 89 | var table = $('#wims_table').DataTable({ |
| 90 | responsive: true, |
| 91 | "ajax": { |
| 92 | "url": "/wims/list/", |
| 93 | "dataSrc": function (json) { |
| 94 | return json['datacenters']; |
| 95 | }, |
| 96 | statusCode: { |
| 97 | 401: function () { |
| 98 | console.log("no auth"); |
| 99 | moveToLogin(window.location.pathname); |
| 100 | } |
| 101 | }, |
| 102 | "error": function (hxr, error, thrown) { |
| 103 | console.log(hxr) |
| 104 | console.log(thrown) |
| 105 | console.log(error); |
| 106 | } |
| 107 | |
| 108 | }, |
| 109 | "columns": [ |
| 110 | { |
| 111 | "render": function (data, type, row) { |
| 112 | return row["name"]; |
| 113 | }, |
| 114 | "targets": 0 |
| 115 | }, |
| 116 | { |
| 117 | "render": function (data, type, row) { |
| 118 | return row['_id']; |
| 119 | }, |
| 120 | "targets": 1 |
| 121 | }, |
| 122 | { |
| 123 | "render": function (data, type, row) { |
| 124 | return row["wim_type"]; |
| 125 | }, |
| 126 | "targets": 2 |
| 127 | }, |
| 128 | { |
| 129 | "render": function (data, type, row) { |
| 130 | return row["_admin"]['operationalState']; |
| 131 | }, |
| 132 | "targets": 3 |
| 133 | }, |
| 134 | { |
| 135 | "render": function (data, type, row) { |
| 136 | return row['description'] || ''; |
| 137 | }, |
| 138 | "targets": 4 |
| 139 | }, |
| 140 | { |
| 141 | "render": function (data, type, row) { |
| 142 | return '<div class="btn-group"><button type="button" class="btn btn-default" ' + |
| 143 | 'onclick="javascript:showWIM( \''+row['_id'] + '\', \''+row['name'] +'\')" data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info">' + |
| 144 | '<i class="fa fa-info"></i>' + |
| 145 | '</button> ' + |
| 146 | '<button type="button" class="btn btn-default"' + |
| 147 | 'onclick="javascript:deleteWim(\''+row['_id']+'\', \''+ row["name"] +'\')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete">' + |
| 148 | '<i class="far fa-trash-alt" ></i></button></div>'; |
| 149 | }, |
| 150 | "targets": 5, |
| 151 | "orderable": false |
| 152 | } |
| 153 | ] |
| 154 | }); |
| 155 | |
| 156 | setInterval(function () { |
| 157 | table.ajax.reload(); |
| 158 | }, 10000); |
| 159 | }); |
| 160 | |
| 161 | function openModalCreateWIM(){ |
| 162 | $('#modal_new_wim').modal('show'); |
| 163 | } |
| 164 | function deleteWim(wim_id, wim_name) { |
| 165 | var url = "/wims/"+wim_id+"/delete"; |
| 166 | bootbox.confirm("Are you sure want to delete " + wim_name + "?", function (result) { |
| 167 | if (result) { |
| 168 | var dialog = bootbox.dialog({ |
| 169 | message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>', |
| 170 | closeButton: true |
| 171 | }); |
| 172 | $.ajax({ |
| 173 | url: url, |
| 174 | type: 'GET', |
| 175 | dataType: "json", |
| 176 | contentType: "application/json;charset=utf-8", |
| 177 | success: function (result) { |
| 178 | if (result['error'] == true) { |
| 179 | dialog.modal('hide'); |
| 180 | bootbox.alert("An error occurred."); |
| 181 | } |
| 182 | else { |
| 183 | dialog.modal('hide'); |
| 184 | location.reload(); |
| 185 | } |
| 186 | }, |
| 187 | error: function (error) { |
| 188 | dialog.modal('hide'); |
| 189 | bootbox.alert("An error occurred."); |
| 190 | } |
| 191 | }); |
| 192 | } |
| 193 | }) |
| 194 | } |
| 195 | |
| 196 | function showWIM(wim_uuid) { |
| 197 | var dialog = bootbox.dialog({ |
| 198 | message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>', |
| 199 | closeButton: true |
| 200 | }); |
| 201 | |
| 202 | $.ajax({ |
| 203 | url: '/wims/' + wim_uuid , |
| 204 | type: 'GET', |
| 205 | dataType: "json", |
| 206 | contentType: "application/json;charset=utf-8", |
| 207 | success: function (result) { |
| 208 | //$('#modal_show_vim_body').empty(); |
| 209 | var wim = result.wim; |
| 210 | |
| 211 | if (wim) { |
| 212 | $('#modal_show_wim_body').find('span').text('-'); |
| 213 | for (var k in wim) { |
| 214 | $('#' + k).text(wim[k]) |
| 215 | } |
| 216 | if (wim['_admin']) { |
| 217 | for (var i in wim['_admin']) { |
| 218 | if (i === 'modified' || i === 'created') { |
| 219 | //$('#' + i).text(new Date(wim['_admin'][i]* 1000).toUTCString()); |
| 220 | $('#' + i).text(moment(wim['_admin'][i] * 1000).format('DD/MM/YY hh:mm:ss')); |
| 221 | } |
| 222 | else if (i === 'deployed') { |
| 223 | $('#' + i).text(JSON.stringify(wim['_admin'][i])) |
| 224 | } |
| 225 | else |
| 226 | $('#' + i).text(wim['_admin'][i]) |
| 227 | } |
| 228 | } |
| 229 | dialog.modal('hide'); |
| 230 | $('#modal_show_wim').modal('show'); |
| 231 | } |
| 232 | else { |
| 233 | dialog.modal('hide'); |
| 234 | bootbox.alert("An error occurred while retrieving the WIM info."); |
| 235 | } |
| 236 | |
| 237 | }, |
| 238 | error: function (result) { |
| 239 | dialog.modal('hide'); |
| 240 | bootbox.alert("An error occurred while retrieving the WIM info."); |
| 241 | } |
| 242 | }); |
| 243 | |
| 244 | } |
| 245 | </script> |
| 246 | |
| 247 | {% endblock %} |