69f02e59fa7e909618ac68b071e467b8f847f572
[sdnc/oam.git] / admportal / views / mobility / vnfPreloadData.ejs
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4   <meta charset="UTF-8" />
5   <meta http-equiv="X-UA-Compatible" content="IE=edge">
6   <% include ../partials/head %>
7   <% include ../partials/header %>
8   <script type="text/javascript" src="/javascripts/admportal.js" async></script>
9   <title>SDN-C AdminPortal</title>
10 <script class="init">
11     $(document).ready(function() {
12     $('#vnf_data').DataTable( {
13         "order": [[ 0, "asc" ]]
14     } );
15 } );
16 </script>
17
18
19 </head>
20 <body>
21
22 <div class="well well-sm">
23 <h3>Pre-load VNF Data</h3>
24 </div>
25
26 <% if ( typeof result != 'undefined' ) {
27                 if (result.code.length > 0) { 
28                         if ( result.code == 'success' ) { %>
29                                 <div class='alert alert-success' role='alert'>
30                                 <%
31                                 for ( x in result.msg ){ %>
32                                         <div><%= result.msg[x] %></div>
33                                 <% } %>
34                                 </div>
35                         <% } else { %> 
36                                 <div class='alert alert-danger' role='danger'>
37                                 <%
38                                 for ( x in result.msg ){ %>
39                                         <div><%= result.msg[x] %></div>
40                                 <% } %>
41                                 </div>
42                         <% } %>
43                 <% } %>
44 <% } %>
45
46 <% if( typeof privilege != 'undefined'){
47     var priv = privilege.privilege;
48 } else {
49     var priv = 'A';
50 } %>
51
52
53 <div class="container-fluid">
54
55         <table id="vnf_data" class="table table-hover table-condensed">
56       <thead>
57         <tr>
58                   <th>ID</th>
59                   <th>SVC_REQUEST_ID</th>
60                   <th>VNF_NAME</th>
61                   <th>VNF_TYPE</th>
62                   <th>SVC_ACTION</th>
63                   <th>UPLOAD STATUS</th>
64           <th>FILENAME</th>
65           <th>IMPORT/UPLOAD TIMESTAMP</th>
66                   <% if(priv == 'A'){ %>
67           <th>Action</th>
68           <% } %>
69         </tr>
70       </thead>
71       <tbody>
72                 <% var i=0; retData.forEach( function(rowObj) { %>
73         <tr>
74             <td><%= rowObj.row.id %></td>
75             <td><a href="javascript:getVnfData('<%= rowObj.vnf_name %>','<%= rowObj.vnf_type %>');"><%= rowObj.row.svc_request_id %></a></td>
76                         <td><%= rowObj.vnf_name %></td>
77                         <td><%= rowObj.vnf_type %></td>
78             <td><%= rowObj.row.svc_action %></td>
79             <td><%= rowObj.row.status %></td>
80                         <td>
81                 <a data-toggle="collapse"
82                     href="#collapseExample<%= i %>" aria-expanded="false"
83                     aria-controls="collapseExample"><%= rowObj.row.filename %>
84                 </a>
85                 <div class="collapse" id="collapseExample<%= i %>">
86                     <div class="well">
87                         <pre><%= JSON.stringify(rowObj.filecontent,null,4) %></pre>
88                     </div>
89                 </div>
90            </td>
91
92             <td><%= rowObj.row.ts %></td>
93                         <% if(priv == 'A' ) { %>
94             <td>
95                                 <button type="button" class="btn btn-default btn-xs"
96                 onclick="deleteVnfData('<%= rowObj.row.id %>','<%= rowObj.row.svc_request_id %>','<%= rowObj.row.filename %>','<%= rowObj.row.status %>','<%= rowObj.vnf_name %>','<%= rowObj.vnf_type %>');">Delete</button>
97             <% if (typeof rowObj.vnf_name != 'undefined' || typeof rowObj.vnf_type != 'undefined'){ %>
98                                 <button type="button" class="btn btn-default btn-xs"
99                 onclick="loadVnfData('<%= rowObj.row.id %>','<%= rowObj.row.svc_request_id %>','<%= rowObj.row.svc_action %>','<%= rowObj.row.status %>','<%= rowObj.row.filename %>','<%= rowObj.row.ts %>');">Load Data</button>
100             <% } %>
101             </td>
102             <% } %>
103         </tr>
104                 <% i++; }); %>
105       </tbody>
106     </table>
107
108         <% if(priv == 'A'){ %>
109         <div class="row">
110     <div class="col-md-8  col-md-push-4">
111         <form method="POST" action="/mobility/uploadVnfData" enctype="multipart/form-data">
112                 <div class="form-group">
113                 <label for="dest">Upload pre processed JSON file.</label>
114                 <input name="filename" type="file" id="dest">
115                 <p class="help-block">Choose a JSON file to upload.</p>
116             <button type="button" class="btn btn-default"
117                                 data-toggle="tooltip" data-placement="bottom"
118                                 title="Upload a JSON file that has already been pre processed."
119                 onclick="uploadFile(this.form);">Upload JSON File</button>
120                 </div>
121         </form>
122     </div>
123         <div class="col-md-4 col-md-pull-8">
124         <form method="POST" action="/preload/uploadVnfCsv" enctype="multipart/form-data">
125                 <div class="form-group">
126                 <label for="dest">Upload Worksheet CSV files from the <%= preloadImportDirectory %> directory.</label>
127                 <input name="filename" type="file" id="dest" multiple>
128                 <p class="help-block">Choose Worksheet CSV files to upload.</p>
129                         <button type="button" class="btn btn-default" 
130                                 data-toggle="tooltip" data-placement="bottom" 
131                                 title="Must upload all the VNF CSV files from <%= preloadImportDirectory %>"
132                                 onclick="importWorksheet(this.form);">Upload VNF Worksheet CSV files
133                         </button>
134                 </div>
135         </form>
136         </div>
137         </div>
138         <% } %>
139 </div>
140
141 <% include ../partials/add_service_homing %>
142 <% include ../partials/update_service_homing %>
143 <footer>
144     <% include ../partials/footer %>
145 </footer>
146
147 <script type="text/javascript">
148
149 function importWorksheet(form)
150 {
151     if ( form.filename.value.length == 0)
152     {
153         bootbox.alert('Must select a file.');
154         return false;
155     }
156     else { 
157
158                 bootbox.confirm({
159                 message: "Are you sure you want to import VNF WORKSHEET .csv files from <%= preloadImportDirectory %>",
160                 callback: function(result) {
161                 if ( result )
162                 {
163                                         form.submit();
164                 }
165                 return;
166                 },
167                 buttons: {
168                 cancel: {
169                         label: "Cancel"
170                 },
171                 confirm: {
172                         label: "Yes"
173                 }
174                 }
175         });
176         }
177 }
178
179
180 function getVnfData(vnf_name,vnf_type,svc_request_id)
181 {
182         location.assign("/mobility/viewVnfData?vnf_name=" + vnf_name + "&vnf_type=" + vnf_type );
183         return;
184 }
185 function loadVnfData(id,svc_request_id,svc_action,status,filename,ts)
186 {
187         if ( status != 'pending' )
188         {
189                 bootbox.alert("Upload Status must be in 'pending' state.");
190                 return;
191         }
192         bootbox.confirm({
193         message: "Are you sure you want to load file [" + filename + "]? ",
194         callback: function(result) {
195             if ( result )
196             {
197                                 location.assign("/mobility/loadVnfData?id=" + id + "&svc_request_id=" + svc_request_id + "&filename=" + filename + "&status=" + status);
198             }
199             return;
200         },
201         buttons: {
202             cancel: {
203                 label: "Cancel"
204             },
205             confirm: {
206                 label: "Yes"
207             }
208         }
209     });
210 }
211
212 function deleteVnfData(id,svc_request_id,filename,status,vnf_name,vnf_type) {
213
214     bootbox.confirm({
215         message: "Are you sure you want to delete uploaded file [" + filename + "]? ",
216         callback: function(result) {
217             if ( result )
218             {
219                                 location.assign("/mobility/deleteVnfData?id=" 
220                                         + id 
221                                         + "&svc_request_id=" + svc_request_id 
222                                         + "&filename=" + filename 
223                                         + "&status=" + status
224                                         + "&vnf_name=" + vnf_name
225                                         + "&vnf_type=" + vnf_type);
226             }
227             return;
228         },
229         buttons: {
230             cancel: {
231                 label: "Cancel"
232             },
233             confirm: {
234                 label: "Yes"
235             }
236         }
237     });
238 }
239
240 </script>
241
242 </body>
243 </html>
244