diff --git a/src/main/java/org/project/openbaton/nfvo/gui/WebConfig.java b/src/main/java/org/openbaton/nfvo/gui/WebConfig.java similarity index 68% rename from src/main/java/org/project/openbaton/nfvo/gui/WebConfig.java rename to src/main/java/org/openbaton/nfvo/gui/WebConfig.java index 2e9a945..9182038 100644 --- a/src/main/java/org/project/openbaton/nfvo/gui/WebConfig.java +++ b/src/main/java/org/openbaton/nfvo/gui/WebConfig.java @@ -1,4 +1,4 @@ -package org.project.openbaton.nfvo.gui; +package org.openbaton.nfvo.gui; import org.springframework.stereotype.Controller; diff --git a/src/main/resources/static/descriptors/vnfd/vnfd.json b/src/main/resources/static/descriptors/vnfd/vnfd.json index d8b4791..efe2425 100644 --- a/src/main/resources/static/descriptors/vnfd/vnfd.json +++ b/src/main/resources/static/descriptors/vnfd/vnfd.json @@ -3,32 +3,27 @@ "version":"0.1", "name":"dummy1", "type":"server", - "endpoint":"dummy", + "endpoint":"generic", "vdu":[ { "vm_image":[ "ubuntu-14.04-server-cloudimg-amd64-disk1" ], - "computation_requirement":"", - "virtual_memory_resource_element":"1024", - "virtual_network_bandwidth_resource":"1000000", + "scale_in_out":2, "lifecycle_event":[ ], - "vimInstanceName":"vim-instance", - "vdu_constraint":"", - "high_availability":"ACTIVE_PASSIVE", - "scale_in_out":3, "vnfc":[ { "connection_point":[ { + "floatingIp":"random", "virtual_link_reference":"private" } ] } ], - "monitoring_parameter":[ - "cpu_utilization" + "vimInstanceName":[ + "vim-instance" ] } ], @@ -49,32 +44,9 @@ ], "deployment_flavour":[ { - "df_constraint":[ - "constraint1", - "constraint2" - ], - "costituent_vdu":[], "flavour_key":"m1.small" - },{ - "df_constraint":[ - "constraint3", - "constraint4" - ], - "costituent_vdu":[], - "flavour_key":"m1.nano" - } ], "auto_scale_policy":[ - ], - "manifest_file":"", - "requires":[ - "nfvo:ip-en5", - "database:ipB", - "database:ipC", - "database:ipD" - ], - "provides":[ - "ip" ] } \ No newline at end of file diff --git a/src/main/resources/static/dist/css/openbaton.css b/src/main/resources/static/dist/css/openbaton.css index 40c7bd0..b90afc4 100644 --- a/src/main/resources/static/dist/css/openbaton.css +++ b/src/main/resources/static/dist/css/openbaton.css @@ -799,4 +799,11 @@ h4 > a, h4 > a:hover { .upload-drop-zone.drop { color: #222; border-color: #222; +} + +.dl-table dd{ + margin-left: 60px; +} +.dl-table dt{ + margin-left: -60px; } \ No newline at end of file diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index 22675ee..7190ba0 100644 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -1,5 +1,5 @@ -angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies']) - .config(function ($routeProvider) { +angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies', 'angular-clipboard']) + .config(function ($routeProvider, $locationProvider) { $routeProvider. when('/login', { @@ -10,6 +10,18 @@ angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies']) templateUrl: 'pages/contents.html', controller: 'IndexCtrl' }). + when('/projects', { + templateUrl: 'pages/projects.html', + controller: 'ProjectCtrl' + }). + when('/users', { + templateUrl: 'pages/users/users.html', + controller: 'UserCtrl' + }). + when('/users/:userId', { + templateUrl: 'pages/users/userinfo.html', + controller: 'UserCtrl' + }). when('/packages', { templateUrl: 'pages/packages/packages.html', controller: 'PackageCtrl' @@ -18,6 +30,14 @@ angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies']) templateUrl: 'pages/packages/packageinfo.html', controller: 'PackageCtrl' }). + when('/events/:eventId', { + templateUrl: 'pages/events/eventinfo.html', + controller: 'EventCtrl' + }). + when('/events', { + templateUrl: 'pages/events/events.html', + controller: 'EventCtrl' + }). when('/nsdescriptors', { templateUrl: 'pages/nsdescriptors/nsdescriptors.html', controller: 'NsdCtrl' @@ -53,6 +73,10 @@ angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies']) .when('/nsrecords/:nsrecordId/vnfrecords/:vnfrecordId/vdus/:vduId', { templateUrl: 'pages/nsrecords/vdu.html', controller: 'NsrCtrl' + }) + .when('/nsrecords/:nsrecordId/vnfrecords/:vnfrecordId/vdus/:vduId/vnfci/:vnfciId', { + templateUrl: 'pages/nsrecords/vnfci.html', + controller: 'NsrCtrl' }). when('/nsdescriptors/:nsdescriptorId/vnfdependencies/:vnfdependencyId', { templateUrl: 'pages/nsdescriptors/vnfdependency.html', @@ -117,7 +141,7 @@ angular.module('app', ['ngRoute', 'ngSanitize', 'ui.bootstrap', 'ngCookies']) otherwise({ // redirectTo: '/' }); - + $locationProvider.html5Mode(false); }); /** diff --git a/src/main/resources/static/js/controllers/eventController.js b/src/main/resources/static/js/controllers/eventController.js new file mode 100644 index 0000000..041f60e --- /dev/null +++ b/src/main/resources/static/js/controllers/eventController.js @@ -0,0 +1,160 @@ +var app = angular.module('app'); +app.controller('EventCtrl', function ($scope, serviceAPI, $routeParams, http, $cookieStore, AuthService) { + + var url = $cookieStore.get('URL') + "/api/v1/events/"; + + $scope.alerts = []; + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + loadTable(); + + $scope.eventObj = { + 'name': 'event_name', + 'networkServiceId': '', + 'virtualNetworkFunctionId': '', + 'type': 'REST', + 'endpoint': 'localhost:8081/events', + 'event': 'INSTANTIATE_FINISH' + }; + + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function(){ + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + //console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('Event: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + ////console.log(newValue.checkbox); + ////console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + //console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + //console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ + + + $scope.types = ['REST', 'RABBIT', 'JMS']; + $scope.deleteEvent = function (data) { + http.delete(url + data.id) + .success(function (response) { + showOk('Event: ' + data.name + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + + $scope.save = function () { + //console.log($scope.eventObj); + http.post(url, $scope.eventObj) + .success(function (response) { + showOk('Event: ' + $scope.eventObj.name + ' saved.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + function loadTable() { + if (!angular.isUndefined($routeParams.eventId)) + http.get(url + $routeParams.eventId) + .success(function (response, status) { + //console.log(response); + $scope.event = response; + $scope.eventJSON = JSON.stringify(response, undefined, 4); + + }).error(function (data, status) { + showError(data, status); + }); + else { + http.get(url) + .success(function (response) { + $scope.events = response; + //console.log(response); + }) + .error(function (data, status) { + showError(data, status); + }); + + http.get(url + '/actions') + .success(function (response) { + $scope.actions = response; + }) + .error(function (data, status) { + showError(data, status); + }); + } + + } + + function showError(data, status) { + $scope.alerts.push({ + type: 'danger', + msg: 'ERROR: HTTP status: ' + status + ' response data : ' + JSON.stringify(data) + }); + $('.modal').modal('hide'); + if (status === 401) { + //console.log(status + ' Status unauthorized') + AuthService.logout(); + } + } + + function showOk(msg) { + $scope.alerts.push({type: 'success', msg: msg}); + loadTable(); + $('.modal').modal('hide'); + } + +}); + + + diff --git a/src/main/resources/static/js/controllers/indexController.js b/src/main/resources/static/js/controllers/indexController.js index 704c07a..06a228c 100644 --- a/src/main/resources/static/js/controllers/indexController.js +++ b/src/main/resources/static/js/controllers/indexController.js @@ -6,16 +6,32 @@ var app = angular.module('app'); * */ -app.controller('LoginController', function ($scope, AuthService, Session, $rootScope, $location, $cookieStore, $http) { +app.controller('LoginController', function ($scope, AuthService, Session, $rootScope, $location, $cookieStore, $http, $window) { $scope.currentUser = null; - //$scope.URL = 'http://localhost:8080'; + //$scope.URL = 'http://lore:8080'; + //$scope.URL = 'http://192.168.161.6:8080'; $scope.URL = ''; $scope.credential = { "username": '', "password": '', "grant_type": "password" }; + $scope.new = { + "username": '', + "password": '', + "password2": '', + "firstName": '', + "lastName": '', + "admin": true + }; + $scope.checkIfEqual = function () { + if ($scope.new.password2 !== $scope.new.password) + $scope.notEqual = true; + else + $scope.notEqual = false; + + }; if (angular.isUndefined($cookieStore.get('logged'))) { $scope.logged = false; $rootScope.logged = false; @@ -26,18 +42,18 @@ app.controller('LoginController', function ($scope, AuthService, Session, $rootS $rootScope.logged = $cookieStore.get('logged'); } $location.replace(); - console.log($scope.logged); + //console.log($scope.logged); $scope.loggedF = function () { return $scope.logged; }; $scope.checkSecurity = function () { - console.log($scope.URL + "/api/v1/security"); + //console.log($scope.URL + "/api/v1/security"); AuthService.removeSession(); $http.get($scope.URL + "/api/v1/security") .success(function (data) { - console.log(data); + //console.log(data); if (data === "false") { AuthService.loginGuest($scope.URL); } @@ -63,29 +79,40 @@ app.controller('LoginController', function ($scope, AuthService, Session, $rootS setTimeout(showLoginError, 2000); }; + + $scope.register = function (newUser) { + delete newUser.password2; + //console.log(newUser); + $http.post($scope.URL + '/register', newUser) + .success(function (data, status) { + $window.location.reload(); + }) + .error(function (status, data) { + }); + }; function showLoginError() { $scope.$apply(function () { $scope.loginError = angular.isUndefined($cookieStore.get('logged')); - console.log($scope.loginError); + //console.log($scope.loginError); }); } }); -app.controller('IndexCtrl', function ($scope, $cookieStore, $location, AuthService, http) { + +app.controller('IndexCtrl', function ($scope, $compile, $routeParams, serviceAPI, $interval, $cookieStore, $location, AuthService, http, $rootScope, $window) { $('#side-menu').metisMenu(); var url = $cookieStore.get('URL') + "/api/v1"; $scope.config = {}; - getConfig(); function getConfig() { http.get(url + '/configurations/') .success(function (data, status) { - console.log(data); + //console.log(data); $.each(data, function (i, conf) { if (conf.name === "system") { $scope.config = conf; @@ -101,7 +128,7 @@ app.controller('IndexCtrl', function ($scope, $cookieStore, $location, AuthServi }; $scope.logged = $cookieStore.get('logged'); - console.log($scope.logged); + //console.log($scope.logged); $location.replace(); @@ -109,33 +136,76 @@ app.controller('IndexCtrl', function ($scope, $cookieStore, $location, AuthServi $scope.numberNSD = 0; $scope.numberVNF = 0; $scope.numberUnits = 0; - http.syncGet(url + '/ns-descriptors/').then(function (data) { - $scope.numberNSD = data.length; - var vnf = 0; - $.each(data, function (i, nsd) { - //console.log(nsd.vnfd.length); - if (!angular.isUndefined(nsd.vnfd.length)) - vnf = vnf + nsd.vnfd.length; + + function loadNumbers() { + http.syncGet(url + '/ns-descriptors/').then(function (data) { + $scope.numberNSD = data.length; + var vnf = 0; + $.each(data, function (i, nsd) { + //console.log(nsd.vnfd.length); + if (!angular.isUndefined(nsd.vnfd.length)) + vnf = vnf + nsd.vnfd.length; + }); + $scope.numberVNF = vnf; }); - $scope.numberVNF = vnf; - }); - http.syncGet(url + '/ns-records/').then(function (data) { - $scope.numberNSR = data.length; - var units = 0; - $.each(data, function (i, nsr) { - $.each(nsr.vnfr, function (i, vnfr) { - $.each(vnfr.vdu, function (i, vdu) { - if (!angular.isUndefined(vdu.vnfc_instance.length)) - units = units + vdu.vnfc_instance.length; + http.syncGet(url + '/ns-records/').then(function (data) { + $scope.numberNSR = data.length; + var units = 0; + $.each(data, function (i, nsr) { + $.each(nsr.vnfr, function (i, vnfr) { + $.each(vnfr.vdu, function (i, vdu) { + if (!angular.isUndefined(vdu.vnfc_instance.length)) + units = units + vdu.vnfc_instance.length; + }); }); }); + $scope.numberUnits = units; }); - $scope.numberUnits = units; + } + + + $scope.$watch('projectSelected', function (newValue, oldValue) { + console.log(newValue); + if (!angular.isUndefined(newValue) && !angular.isUndefined(oldValue)) { + $cookieStore.put('project', newValue); + } + if (!angular.isUndefined(newValue) && angular.isUndefined(oldValue)) { + $cookieStore.put('project', newValue); + loadNumbers(); + getConfig(); + } }); + console.log($rootScope.projects); + console.log($rootScope.projectSelected); + + $scope.changeProject = function (project) { + if (arguments.length === 0) { + http.syncGet(url + '/projects/') + .then(function (response) { + if (angular.isUndefined($cookieStore.get('project')) || $cookieStore.get('project').id == '') { + $rootScope.projectSelected = response[0]; + $cookieStore.put('project', response[0]) + } else { + $rootScope.projectSelected = $cookieStore.get('project'); + } + $rootScope.projects = response; + }); + } + else { + $rootScope.projectSelected = project; + console.log(project); + $cookieStore.put('project', project); + $window.location.reload(); + } + + + }; + + $scope.saveSetting = function (config) { - console.log(config); + //console.log(config); $('.modal').modal('hide'); $('#modalSend').modal('show'); @@ -160,11 +230,11 @@ app.controller('IndexCtrl', function ($scope, $cookieStore, $location, AuthServi }; if ($scope.logged) - console.log('Ok Logged'); - $location.replace(); + //console.log('Ok Logged'); + $location.replace(); $scope.username = $cookieStore.get('userName'); - console.log($scope.username); + //console.log($scope.username); /** @@ -175,7 +245,33 @@ app.controller('IndexCtrl', function ($scope, $cookieStore, $location, AuthServi AuthService.logout(); }; + $scope.changePassword = function () { + $scope.oldPassword = ''; + $scope.newPassword = ''; + $scope.newPassword1 = ''; -}); + $('#modalChangePassword').modal('show'); + }; + + $scope.postNew = function() { + if ($scope.newPassword.localeCompare($scope.newPassword1) == 0) { + $scope.passwordData = {}; + $scope.passwordData.old_pwd = $scope.oldPassword; + $scope.passwordData.new_pwd = $scope.newPassword; + http.put(url + '/users/changepwd', JSON.stringify($scope.passwordData)) + .success(function (response) { + alert("The password has been successfully changed") + AuthService.logout()}) + .error(function (data, status) { + console.error('STATUS: ' + status + ' DATA: ' + JSON.stringify(data)); + alert('STATUS: ' + status + ' DATA: ' + JSON.stringify(data)) + ? "" : location.reload(); + }); + } else { + alert("The new passwords are not the same"); + } + + }; +}); diff --git a/src/main/resources/static/js/controllers/nsdController.js b/src/main/resources/static/js/controllers/nsdController.js index 05c2065..33eda26 100644 --- a/src/main/resources/static/js/controllers/nsdController.js +++ b/src/main/resources/static/js/controllers/nsdController.js @@ -1,10 +1,11 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile, $cookieStore, $routeParams, http, serviceAPI, $window, $route, $interval, $http, topologiesAPI, AuthService) { - var baseURL= $cookieStore.get('URL')+"/api/v1"; + var baseURL = $cookieStore.get('URL') + "/api/v1"; - var url = baseURL+ '/ns-descriptors'; - var urlRecord = baseURL+ '/ns-records'; - var urlVim = baseURL+'/datacenters'; + var url = baseURL + '/ns-descriptors/'; + var urlRecord = baseURL + '/ns-records/'; + var urlVim = baseURL + '/datacenters/'; + var urlVNFD = baseURL + '/vnf-descriptors/'; loadTable(); @@ -15,13 +16,14 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile $('#set-flavor').on('switchChange.bootstrapSwitch', function (event, state) { $scope.showSetting = state; - console.log($scope.showSetting); + //console.log($scope.showSetting); $scope.$apply(function () { $scope.showSetting; }); }); + $scope.nsdToSend = {}; $scope.textTopologyJson = ''; $scope.file = ''; @@ -30,7 +32,7 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile http.get(urlVim) .success(function (response, status) { $scope.vimInstances = response; - console.log(response); + //console.log(response); }) .error(function (data, status) { showError(status, data); @@ -46,105 +48,135 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile $scope.selection = []; - $scope.toggleSelection = function toggleSelection(image) { - var idx = $scope.selection.indexOf(image); - if (idx > -1) { - $scope.selection.splice(idx, 1); - } - else { - $scope.selection.push(image); - } - console.log($scope.selection); - $scope.vduCreate.vm_image = $scope.selection; + $scope.addTONSD = function () { + $scope.nsdCreateTmp.vnfd.push(angular.copy($scope.selectedVNFD)); + delete $scope.selectedVNFD; }; - $scope.addVDU = function () { - $http.get('descriptors/vnfd/vdu.json') - .then(function (res) { - console.log(res.data); - $scope.vduCreate = angular.copy(res.data); - }); - $('#addEditVDU').modal('show'); + + $scope.saveDependency = function () { + $scope.nsdCreateTmp.vnf_dependency.push(angular.copy($scope.dependency)); + //console.log($scope.nsdCreateTmp.vnf_dependency); + //console.log($scope.dependency); + + $('#modalDependency').modal('hide'); }; - $scope.editVDU = function (vnfd, index) { - $scope.vduCreate = vnfd; - $scope.vduEditIndex = index; - $('#addEditVDU').modal('show'); + $scope.selectedVNFD; + $scope.vnfdList = []; + + $scope.dependency = {}; + $scope.dependency.parameters = []; + + $scope.addParam = function (par) { + $scope.dependency.parameters.push(par); }; - $scope.addVDUtoVND = function () { - $('#addEditVDU').modal('hide'); - if (!angular.isUndefined($scope.vduEditIndex)) { - $scope.vnfdCreate.vdu.splice($scope.vduEditIndex, 1); - delete $scope.vduEditIndex; - } - $scope.vnfdCreate.vdu.push(angular.copy($scope.vduCreate)); + $scope.removeParam = function (index) { + $scope.dependency.parameters.splice(index, 1); }; - $scope.deleteVDU = function (index) { - $scope.vnfdCreate.vdu.splice(index, 1); + $scope.addVld = function (vld) { + $scope.nsdCreateTmp.vld.push({'name': vld}); }; - $scope.addVNFD = function () { - $http.get('descriptors/vnfd/vnfd.json') - .then(function (res) { - console.log(res.data); - $scope.vnfdCreate = angular.copy(res.data); - }); - $('#addEditVNDF').modal('show'); + $scope.removeVld = function (index) { + $scope.nsdCreateTmp.vld.splice(index, 1); }; - $scope.editVNFD = function (vnfd, index) { - $scope.vnfdCreate = vnfd; - $scope.vnfdEditIndex = index; - $('#addEditVNDF').modal('show'); + $scope.deleteDependency = function (index) { + $scope.nsdCreateTmp.vnf_dependency.splice(index, 1); }; - $scope.editDF = function (df, index) { - $scope.depFlavor = df; - $scope.dfEditIndex = index; - $('#modaladdDepFlavour').modal('show'); + $scope.isArray = function (obj) { + if (angular.isArray(obj) || angular.isObject(obj)) + return false; + else + return true; + }; + $scope.edit = function (obj) { + $scope.editObj = obj; }; - $scope.editLEfromVNFD = function (le, index) { - $scope.lifecycle_event = le; - $scope.leEditIndex = index; - $('#modaladdLifecycleEvent').modal('show'); + $scope.updateObj = function () { + http.put(url + $scope.editObj.id, $scope.editObj) + .success(function (response) { + showOk('Network Service Descriptor updated!'); + loadTable(); + }) + .error(function (data, status) { + console.error('STATUS: ' + status + ' DATA: ' + JSON.stringify(data)); + showError(status, JSON.stringify(data)); + }); }; + $scope.updateVNFD = function () { + http.put(url + $routeParams.nsdescriptorId + '/vnfdescriptors/' + $scope.editObj.id, $scope.editObj) + .success(function (response) { + showOk('VNF Descriptor updated!'); + loadTable(); + }) + .error(function (data, status) { + console.error('STATUS: ' + status + ' DATA: ' + JSON.stringify(data)); + showError(status, JSON.stringify(data)); + }); + }; - function paintBackdropModal() { - var height = parseInt($(window).height()) + 150 * $scope.nsdCreate.vnfd.length; - console.log('heigh: ' + height + 'px'); - $(".modal-backdrop").height(height) - } + $scope.addNewConfig = function () { + if (angular.isUndefined($scope.editObj.configurations)) { + $scope.editObj.configurations = {}; + $scope.editObj.configurations.configurationParameters = []; + } + $scope.editObj.configurations.configurationParameters.push({'confKey': '', 'value': ''}) + }; + $scope.removeConfig = function (index) { + $scope.editObj.configurations.configurationParameters.splice(index, 1); + }; - $scope.saveVirtualLink = function (vl) { -//console.log(vl); - var obj = {}; - obj[vl.key] = vl.value; - $scope.nsdCreate.vld.push(obj); + $scope.addLifecycleEvent = function (vdu) { + vdu.lifecycle_event.push({'event': "CONFIGURE", 'lifecycle_events': []}) }; - $scope.deleteVirtualLink = function (index) { - $scope.nsdCreate.vld.splice(index, 1); + + $scope.loadVNFD = function () { + $scope.nsdCreateTmp = {}; + $scope.nsdCreateTmp.name = ''; + $scope.nsdCreateTmp.vendor = ''; + $scope.nsdCreateTmp.version = ''; + $scope.nsdCreateTmp.vnfd = []; + $scope.nsdCreateTmp.vnf_dependency = []; + $scope.nsdCreateTmp.vld = []; + + http.get(urlVNFD) + .success(function (response, status) { + $scope.vnfdList = response; + //console.log(response); + $('#modalCreateNSD').modal('show'); + }) + .error(function (data, status) { + showError(status, data); + }); }; - $scope.addVNDtoNSD = function () { - $('#addEditVNDF').modal('hide'); - if (!angular.isUndefined($scope.vnfdEditIndex)) { - $scope.nsdCreate.vnfd.splice($scope.vnfdEditIndex, 1); - delete $scope.vnfdEditIndex; + + $scope.toggleSelection = function toggleSelection(image) { + var idx = $scope.selection.indexOf(image); + if (idx > -1) { + $scope.selection.splice(idx, 1); + } + else { + $scope.selection.push(image); } - $scope.nsdCreate.vnfd.push(angular.copy($scope.vnfdCreate)); - paintBackdropModal(); + //console.log($scope.selection); + $scope.vduCreate.vm_image = $scope.selection; }; - $scope.deleteVNFDForm = function (index) { - $scope.nsdCreate.vnfd.splice(index, 1); + + $scope.deleteVDU = function (index) { + $scope.vnfdCreate.vdu.splice(index, 1); }; + $scope.deleteVNFDependency = function (vnfd) { - http.delete(url + '/' + $scope.nsdinfo.id + '/vnfdependencies/' + vnfd.id) + http.delete(url + $scope.nsdinfo.id + '/vnfdependencies/' + vnfd.id) .success(function (response) { showOk('Deleted VNF Dependecy with id: ' + vnfd.id); loadTable(); @@ -156,8 +188,9 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile }; + $scope.deleteVNFD = function (vnfd) { - http.delete(url + '/' + $scope.nsdinfo.id + '/vnfdescriptors/' + vnfd.id) + http.delete(url + $scope.nsdinfo.id + '/vnfdescriptors/' + vnfd.id) .success(function (response) { showOk('Deleted VNF Descriptors with id: ' + vnfd.id); loadTable(); @@ -178,14 +211,14 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile if (!angular.isUndefined($routeParams.vduId)) { $scope.vduId = $routeParams.vduId; - console.log($scope.vduId); + //console.log($scope.vduId); } - $scope.storeNSDF = function (nsdCreate) { - $('#modalForm').modal('hide'); - console.log(nsdCreate); - http.post(url, nsdCreate) + $scope.sendNSDCreate = function (nsdCreate) { + $('.modal').modal('hide'); + //console.log($scope.nsdCreateTmp); + http.post(url, $scope.nsdCreateTmp) .success(function (response) { showOk('Network Service Descriptor stored!'); loadTable(); @@ -196,134 +229,6 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile }); }; - $scope.saveValueVMI = function (newValue) { - console.log(newValue); - $scope.vduCreate.vm_image.push(newValue); - }; - - $scope.deleteVMI = function (index) { - $scope.vduCreate.vm_image.splice(index, 1); - }; - - $scope.saveValueMP = function (newValue) { - console.log(newValue); - $scope.vduCreate.monitoring_parameter.push(newValue); - }; - - $scope.deleteMP = function (index) { - $scope.vduCreate.monitoring_parameter.splice(index, 1); - }; - $scope.saveValueMPfromVNFD = function (newValue) { - console.log(newValue); - $scope.vnfdCreate.monitoring_parameter.push(newValue); - }; - - $scope.deleteMPfromVNFD = function (index) { - $scope.vnfdCreate.monitoring_parameter.splice(index, 1); - }; - - $scope.saveValueMPfromNSD = function (newValue) { - console.log(newValue); - $scope.nsdCreate.monitoring_parameter.push(newValue); - }; - - $scope.deleteMPfromNSD = function (index) { - $scope.nsdCreate.monitoring_parameter.splice(index, 1); - }; - - $scope.saveValueCVDU = function (newValue) { - console.log(newValue); - $scope.depFlavor.costituent_vdu.push(newValue); - }; - - $scope.deleteCVDU = function (index) { - $scope.depFlavor.costituent_vdu.splice(index, 1); - }; - - $scope.saveValueDFC = function (newValue) { - console.log(newValue); - $scope.depFlavor.df_constraint.push(newValue); - }; - - - $scope.deleteDFC = function (index) { - $scope.depFlavor.df_constraint.splice(index, 1); - }; - - $scope.saveValueLifeCE = function (newValue) { - console.log(newValue); - $scope.lifecycle_event.lifecycle_events.push(newValue); - }; - - $scope.deleteLEfromVNFD = function (index) { - $scope.vnfdCreate.lifecycle_event.splice(index, 1); - }; - - $scope.addLifecycle = function () { - $scope.vnfdCreate.lifecycle_event.push(angular.copy($scope.lifecycle_event)); - }; - - $scope.deleteLifeCE = function (index) { - $scope.lifecycle_event.lifecycle_events.splice(index, 1); - }; - - $scope.deleteVNFDep = function (index) { - $scope.nsdCreate.vnf_dependency.splice(index, 1); - }; - - $scope.deleteDF = function (index) { - $scope.vnfdCreate.deployment_flavour.splice(index, 1); - }; - - $scope.addDepFlavour = function () { - $http.get('descriptors/vnfd/deployment_flavour.json') - .then(function (res) { - console.log(res.data); - $scope.depFlavor = angular.copy(res.data); - }); - $('#modaladdDepFlavour').modal('show'); - }; - - $scope.addLifecycleEvent = function () { - $http.get('descriptors/vnfd/lifecycle_event.json') - .then(function (res) { - console.log(res.data); - $scope.lifecycle_event = angular.copy(res.data); - }); - $('#modaladdLifecycleEvent').modal('show'); - }; - $scope.addVNFDependencies = function () { - $('#modalVNFDependencies').modal('show'); - }; - - $scope.source_target = {'source': {'name': ''}, 'target': {'name': ''}}; - $scope.addVNFDep = function () { - $scope.nsdCreate.vnf_dependency.push(angular.copy($scope.source_target)); - $('#modalVNFDependencies').modal('hide'); - }; - $scope.addLifecycle = function () { - if (!angular.isUndefined($scope.leEditIndex)) { - $scope.vnfdCreate.lifecycle_event.splice($scope.leEditIndex, 1); - delete $scope.leEditIndex; - } - $scope.vnfdCreate.lifecycle_event.push(angular.copy($scope.lifecycle_event)); - $('#modaladdLifecycleEvent').modal('hide'); - }; - - $scope.storeDepFlavour = function () { - $('#modaladdDepFlavour').modal('hide'); - if (!angular.isUndefined($scope.dfEditIndex)) { - $scope.vnfdCreate.deployment_flavour.splice($scope.dfEditIndex, 1); - delete $scope.dfEditIndex; - } - $scope.vnfdCreate.deployment_flavour.push(angular.copy($scope.depFlavor)); - }; - - $http.get('descriptors/network_service_descriptors/NetworkServiceDescriptor.json') - .then(function (res) { - //console.log(res.data); - $scope.nsdCreate = angular.copy(res.data); - }); $scope.setFile = function (element) { $scope.$apply(function ($scope) { @@ -379,8 +284,8 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile } - console.log(postNSD); - console.log(type); + //console.log(postNSD); + //console.log(type); if (sendOk) { if (type === 'topology') { @@ -424,7 +329,7 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile }; $scope.deleteNSD = function (data) { - http.delete(url + '/' + data.id) + http.delete(url + data.id) .success(function (response) { showOk('Deleted Network Service Descriptor with id: ' + data.id); loadTable(); @@ -436,12 +341,13 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile $scope.launchOption = function (data) { $scope.nsdToSend = data; - $('#madalLaunch').modal('show'); + //$('#madalLaunch').modal('show'); + $scope.launch(); }; $scope.launch = function () { - console.log($scope.nsdToSend); - http.post(urlRecord + '/' + $scope.nsdToSend.id) + //console.log($scope.nsdToSend); + http.post(urlRecord + $scope.nsdToSend.id) .success(function (response) { showOk("Created Network Service Record from Descriptor with id: \" + $scope.nsdToSend.id + "<\/a>"); }) @@ -451,14 +357,14 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile }; $scope.Jsplumb = function () { - http.get(url + '/' + $routeParams.nsdescriptorId) + http.get(url + $routeParams.nsdescriptorId) .success(function (response, status) { topologiesAPI.Jsplumb(response, 'descriptor'); - console.log(response); + //console.log(response); }).error(function (data, status) { - showError(status, data); - }); + showError(status, data); + }); }; @@ -477,6 +383,61 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile $scope.alerts.splice(index, 1); }; + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function () { + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + //console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('Items with id: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + ////console.log(newValue.checkbox); + ////console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + //console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + //console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ function showError(status, data) { if (status === 400) @@ -493,7 +454,7 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile $('.modal').modal('hide'); if (status === 401) { - console.log(status + ' Status unauthorized') + //console.log(status + ' Status unauthorized') AuthService.logout(); } } @@ -509,18 +470,18 @@ var app = angular.module('app').controller('NsdCtrl', function ($scope, $compile http.get(url) .success(function (response, status) { $scope.nsdescriptors = response; - console.log(response); + //console.log(response); }) .error(function (data, status) { showError(status, data); }); else - http.get(url + '/' + $routeParams.nsdescriptorId) + http.get(url + $routeParams.nsdescriptorId) .success(function (response, status) { $scope.nsdinfo = response; $scope.nsdJSON = JSON.stringify(response, undefined, 4); - console.log(response); + //console.log(response); }) .error(function (data, status) { showError(status, data); diff --git a/src/main/resources/static/js/controllers/nsrController.js b/src/main/resources/static/js/controllers/nsrController.js index ac3afe5..8bb35a3 100644 --- a/src/main/resources/static/js/controllers/nsrController.js +++ b/src/main/resources/static/js/controllers/nsrController.js @@ -1,6 +1,10 @@ -var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $compile, $cookieStore, $routeParams, http, serviceAPI, topologiesAPI, AuthService) { +var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $compile, $cookieStore, $routeParams, http, serviceAPI, topologiesAPI, AuthService, $location) { + + var baseUrl = $cookieStore.get('URL') + "/api/v1/"; + var url = baseUrl + 'ns-records/'; + var urlVNFD = baseUrl + 'vnf-descriptors/'; + var urlLog = baseUrl + 'logs/'; - var url = $cookieStore.get('URL') + "/api/v1/ns-records/"; loadTable(); @@ -16,8 +20,13 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ {active: false} ]; - $scope.addVNFCI = function (data) { - http.post(url + $routeParams.nsrecordId + '/vnfrecords/' + data.id + '/vdunits/vnfcinstances') + $scope.addVNFCIModal = function (data) { + $scope.vnfrSelected = angular.copy(data); + $('#addVNFCItoVDU').modal('show'); + }; + $scope.addVNFCI = function () { + //console.log($scope.connection_points) + http.post(url + $routeParams.nsrecordId + '/vnfrecords/' + $scope.vnfrSelected.id + '/vdunits/vnfcinstances', {"connection_point": $scope.connection_points}) .success(function (response) { showOk('Added a Virtual Network Function Component Instance.'); loadTable(); @@ -40,17 +49,47 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ $scope.removeVNFCItoVDU = function (vdu) { http.delete(url + $routeParams.nsrecordId + '/vnfrecords/' + $routeParams.vnfrecordId + '/vdunits/' + vdu.id + '/vnfcinstances') .success(function (response) { - showOk('Removed the Virtual Network Function Component Instance to Vdu with id: '+vdu.id+'.'); + showOk('Removed the Virtual Network Function Component Instance to Vdu with id: ' + vdu.id + '.'); loadTable(); }) .error(function (data, status) { showError(status, data); }); }; - $scope.addVNFCItoVDU = function (vdu) { - console.log(url + $routeParams.nsrecordId + '/vnfrecords/' + $routeParams.vnfrecordId + '/vdunits/' + vdu.id + '/vnfcinstances') + + $scope.addCPtoVNFCI = function () { + $scope.connection_points.push(angular.copy($scope.connection_point)); + }; + $scope.removeCPtoVNFCI = function (index) { + $scope.connection_points.splice(index, 1); + }; + + $scope.connection_points = []; + $scope.connection_point = { + "floatingIp": "", + "virtual_link_reference": "private" + }; + $scope.addVNFCItoVDU = function (vnfr, vdu) { + + $scope.vduSelected = angular.copy(vdu); + $scope.vnfrSelected = angular.copy(vnfr); + $('#addVNFCItoVDU').modal('show'); + /*$scope.connectionPoints = {"connection_point": angular.copy(vdu.vnfc[0].connection_point)}; + angular.forEach($scope.connectionPoints.connection_point, function (cp, index) { + if (!angular.isUndefined(cp.id)) { + delete cp.id; + delete cp.version; + } + }); + //console.log($scope.connectionPoints);*/ + + }; + + $scope.addCPtoVDU = function () { + //console.log($scope.connection_points); + http.post(url + $routeParams.nsrecordId + '/vnfrecords/' + $routeParams.vnfrecordId + '/vdunits/' + $scope.vduSelected.id + '/vnfcinstances', {"connection_point": $scope.connection_points}) .success(function (response) { - showOk('Added a Virtual Network Function Component Instance to Vdu with id: '+vdu.id+'.'); + showOk('Added a Virtual Network Function Component Instance to Vdu with id: ' + $scope.vduSelected.id + '.'); loadTable(); }) .error(function (data, status) { @@ -108,8 +147,8 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ } - console.log(postNSD); - console.log(type); + //console.log(postNSD); + //console.log(type); if (sendOk) { if (type === 'topology') { @@ -164,10 +203,68 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ if (!angular.isUndefined($routeParams.vduId)) { $scope.vduId = $routeParams.vduId; - console.log($scope.vduId); + //console.log($scope.vduId); } + if (!angular.isUndefined($routeParams.vnfciId)) { + $scope.vnfciId = $routeParams.vnfciId; + //console.log($scope.vnfciId); + } + + $scope.$watch('logReq', function (newValue, oldValue) { + console.log(newValue); + console.log(oldValue); + }); + $scope.vnfrName = ''; + $scope.setVNFRName = function (vduId, hostanme) { + console.log(vduId); + console.log(hostanme); + $cookieStore.put('vnfrName', hostanme); + $scope.vnfrName = hostanme; + $location.path('nsrecords/' + $routeParams.nsrecordId + '/vnfrecords/' + $routeParams.vnfrecordId + '/vdus/' + vduId); + $location.replace(); + }; + + + $scope.loadFullLog = function (hostname) { + console.log($scope.logReq); + console.log(hostname); + http.postLog(urlLog + $routeParams.nsrecordId + '/vnfrecord/' + $cookieStore.get('vnfrName') + '/hostname/' + hostname) + .success(function (response, status) { + $('.modal').modal('hide'); + var html = ""; + angular.forEach(response, function (val, i) { + html = html + val + '
'; + }); + $scope.log = html; + $scope.$apply(); + }).error(function (data, status) { + showError(data, status); + }); + }; + + $scope.logReq = {}; + $scope.loadLog = function (hostname) { + console.log($scope.logReq); + console.log(hostname); + //"{nsrId}/vnfrecord/{vnfrName}/hostname/{hostname}" + var lines; + if (!angular.isUndefined($scope.logReq.lines)) { + http.post(urlLog + $routeParams.nsrecordId + '/vnfrecord/' + $cookieStore.get('vnfrName') + '/hostname/' + hostname, {'lines': $scope.logReq.lines}) + .success(function (response, status) { + $('.modal').modal('hide'); + var html = ""; + angular.forEach(response, function (val, i) { + html = html + val + '
'; + }); + $scope.log = html; + + }).error(function (data, status) { + showError(data, status); + }); + } + }; $scope.returnUptime = function (longUptime) { var string = serviceAPI.returnStringUptime(longUptime); return string; @@ -217,6 +314,60 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ }); }; + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function () { + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + //console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('NSR with id: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + ////console.log(newValue.checkbox); + ////console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + //console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + //console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ function showError(status, data) { $scope.alerts.push({ @@ -226,11 +377,12 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ $('.modal').modal('hide'); if (status === 401) { - console.log(status + ' Status unauthorized') + //console.log(status + ' Status unauthorized') AuthService.logout(); } } + function showOk(msg) { $scope.alerts.push({type: 'success', msg: msg}); $('.modal').modal('hide'); @@ -241,11 +393,11 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ http.get(url + $routeParams.nsrecordId) .success(function (response, status) { topologiesAPI.Jsplumb(response, 'record'); - console.log(response); + //console.log(response); }).error(function (data, status) { - showError(data, status); - }); + showError(data, status); + }); }; @@ -254,19 +406,18 @@ var app = angular.module('app').controller('NsrCtrl', function ($scope, $http, $ http.get(url) .success(function (response, status) { $scope.nsrecords = response; - console.log(response); + //console.log(response); }) .error(function (data, status) { showError(status, data); - //var destinationUrl = '#'; - //$window.location.href = destinationUrl; + }); else http.get(url + $routeParams.nsrecordId) .success(function (response, status) { $scope.nsrinfo = response; $scope.nsrJSON = JSON.stringify(response, undefined, 4); - console.log(response); + //console.log(response); //topologiesAPI.Jsplumb(response); }) .error(function (data, status) { diff --git a/src/main/resources/static/js/controllers/packageController.js b/src/main/resources/static/js/controllers/packageController.js index 60495b5..0f7dd1f 100644 --- a/src/main/resources/static/js/controllers/packageController.js +++ b/src/main/resources/static/js/controllers/packageController.js @@ -22,11 +22,99 @@ app.controller('PackageCtrl', function ($scope, serviceAPI, $routeParams, http, }); }; + $scope.deleteScript = function (data) { + http.delete(url +$routeParams.packageid+'/scripts/'+ data.id) + .success(function (response) { + showOk('Script deleted.'); + + }) + .error(function (response, status) { + showError(response,status); + }); + }; + $scope.editScript = function (data) { + http.get(url +$routeParams.packageid+'/scripts/'+ data.id) + .success(function (response) { + $scope.scriptToEdit = response; + $scope.editingScript = data; + $("#modalEditScript").modal("show"); + }) + .error(function (response, status) { + showError(response,status); + }); + }; + $scope.sendScript = function (scriptToEdit) { + http.put(url +$routeParams.packageid+'/scripts/'+ $scope.editingScript.id, scriptToEdit) + .success(function (response) { + showOk('Script updated!'); + }) + .error(function (response, status) { + showError(response,status); + }); + }; $scope.closeAlert = function (index) { $scope.alerts.splice(index, 1); }; + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function(){ + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('Event: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + $scope.$watch('mainCheckbox', function (newValue, oldValue) { + console.log(newValue); + console.log($scope.selection.ids); + + + angular.forEach($scope.selection.ids, function (value, k) { + /* console.log(k); + console.log(value);*/ + + $scope.selection.ids[k] = newValue; + }); + console.log($scope.selection.ids); + + }); + $scope.$watch('selection', function (newValue, oldValue) { + console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ function loadTable() { if (!angular.isUndefined($routeParams.packageid)) @@ -82,6 +170,7 @@ app.controller('PackageCtrl', function ($scope, serviceAPI, $routeParams, http, if ($cookieStore.get('token') !== '') header = {'Authorization': 'Bearer ' + $cookieStore.get('token')}; + header['project-id'] = $cookieStore.get('project').id; var myDropzone = new Dropzone('#my-dropzone', { url: url, // Set the url method: "POST", diff --git a/src/main/resources/static/js/controllers/projectController.js b/src/main/resources/static/js/controllers/projectController.js new file mode 100644 index 0000000..ff4a980 --- /dev/null +++ b/src/main/resources/static/js/controllers/projectController.js @@ -0,0 +1,133 @@ +var app = angular.module('app'); +app.controller('ProjectCtrl', function ($scope, serviceAPI, $routeParams, http, $cookieStore, AuthService, $window) { + + var url = $cookieStore.get('URL') + "/api/v1/projects/"; + + $scope.alerts = []; + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + loadTable(); + + $scope.projectObj = { + 'name': 'projectName' + }; + + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function(){ + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + //console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('Event: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + ////console.log(newValue.checkbox); + ////console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + //console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + //console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ + + + $scope.types = ['REST', 'RABBIT', 'JMS']; + $scope.deleteEvent = function (data) { + http.delete(url + data.id) + .success(function (response) { + showOk('Event: ' + data.name + ' deleted.'); + loadTable(); + location.reload(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + + $scope.save = function () { + //console.log($scope.projectObj); + http.post(url, $scope.projectObj) + .success(function (response) { + showOk('Project: ' + $scope.projectObj.name + ' saved.'); + loadTable(); + location.reload(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + function loadTable() { + http.get(url) + .success(function (response) { + $scope.projects = response; + //console.log(response); + }) + .error(function (data, status) { + showError(data, status); + }); + } + + function showError(data, status) { + $scope.alerts.push({ + type: 'danger', + msg: 'ERROR: HTTP status: ' + status + ' response data : ' + JSON.stringify(data) + }); + $('.modal').modal('hide'); + if (status === 401) { + console.error(status + ' Status unauthorized') + AuthService.logout(); + } + } + + function showOk(msg) { + $scope.alerts.push({type: 'success', msg: msg}); + loadTable(); + $('.modal').modal('hide'); + } + +}); diff --git a/src/main/resources/static/js/controllers/userController.js b/src/main/resources/static/js/controllers/userController.js new file mode 100644 index 0000000..5abfbe9 --- /dev/null +++ b/src/main/resources/static/js/controllers/userController.js @@ -0,0 +1,197 @@ +var app = angular.module('app'); +app.controller('UserCtrl', function ($scope, serviceAPI, $routeParams, http, $cookieStore, AuthService, $window) { + + var url = $cookieStore.get('URL') + "/api/v1/users/"; + var urlprojects = $cookieStore.get('URL') + "/api/v1/projects/"; + //$scope.URL = 'http://lore:8080'; + //var url = "http://lore:8080/api/v1/users/"; + //var urlprojects = "http://lore:8080/api/v1/projects/"; + $scope.alerts = []; + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + $scope.roles = [ + 'GUEST', + 'ADMIN', + 'OB_ADMIN' + ]; + + loadTable(); + + $scope.roleAdd = { + "role": "GUEST", + "project": "*" + }; + $scope.addRole = function() { + var newRole = { + "role": "GUEST", + "project": "*" + }; + $scope.userObj.roles.push(newRole); + }; + + $scope.loadCurrentUser = function(){ + http.get(url +'current') + .success(function (response) { + console.log(response); + $scope.currentUser= response + }) + .error(function (response, status) { + showError(status, response); + }); + }; + + http.get(urlprojects) + .success(function (response) { + //console.log(response); + $scope.projects = response; + $scope.projects.push({name: '*'}); + }) + .error(function (response, status) { + showError(response, status); + }); + + + $scope.userObj = { + "username": "guest", + "password": "", + "enabled": true, + "roles": [ + { + "role": "GUEST", + "project": "*" + } + ] + }; + + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function () { + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + //console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('user: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + ////console.log(newValue.checkbox); + ////console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + //console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + //console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ + + + $scope.deleteUser = function (data) { + http.delete(url + data.id) + .success(function (response) { + showOk('User: ' + data.name + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; + + + $scope.save = function () { + //console.log($scope.userObj); + http.post(url, $scope.userObj) + .success(function (response) { + showOk('Project: ' + $scope.userObj.name + ' saved.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + }; + function loadTable() { + //console.log($routeParams.userId); + if (!angular.isUndefined($routeParams.userId)) + http.get(url + $routeParams.userId) + .success(function (response, status) { + //console.log(response); + $scope.user = response; + $scope.userJSON = JSON.stringify(response, undefined, 4); + + }).error(function (data, status) { + showError(data, status); + }); + else { + http.get(url) + .success(function (response) { + $scope.users = response; + //console.log(response); + }) + .error(function (data, status) { + showError(data, status); + }); + + + } + + } + + function showError(data, status) { + $scope.alerts.push({ + type: 'danger', + msg: 'ERROR: HTTP status: ' + status + ' response data : ' + JSON.stringify(data) + }); + $('.modal').modal('hide'); + if (status === 401) { + //console.log(status + ' Status unauthorized') + AuthService.logout(); + } + } + + function showOk(msg) { + $scope.alerts.push({type: 'success', msg: msg}); + loadTable(); + $('.modal').modal('hide'); + } + +}); diff --git a/src/main/resources/static/js/controllers/vimInstanceController.js b/src/main/resources/static/js/controllers/vimInstanceController.js index 4809672..f288ee8 100644 --- a/src/main/resources/static/js/controllers/vimInstanceController.js +++ b/src/main/resources/static/js/controllers/vimInstanceController.js @@ -1,196 +1,236 @@ -angular.module('app'). - controller('vimInstanceCtrl', function ($scope, $routeParams, http, $location, AuthService, $cookieStore) { +angular.module('app').controller('vimInstanceCtrl', function ($scope, $routeParams, http, $location, AuthService, $cookieStore) { + + var url = $cookieStore.get('URL') + "/api/v1/datacenters/"; + + $scope.alerts = []; + $scope.datacenter = {}; + $scope.file = ''; + $scope.showPass = false; + + loadVIM(); + + + $scope.textTopologyJson = ''; + $scope.changeText = function (text) { + $scope.textTopologyJson = text; + }; + + $scope.edit = function (obj) { + $scope.editObj = obj; + }; + $scope.isArray = function (obj) { + if (angular.isArray(obj) || angular.isObject(obj)) + return false; + else + return true; + }; + $scope.updateObj = function () { + if(!angular.isUndefined($routeParams.vimInstanceId)) + updateObject($routeParams.vimInstanceId); + else + updateObject($scope.editObj.id); + }; + + function updateObject(id){ + console.log($scope.editObj); + http.put(url + '/' + id, $scope.editObj) + .success(function (response) { + showOk('VIM Instance updated!'); + loadVIM(); + }) + .error(function (data, status) { + console.error('STATUS: ' + status + ' DATA: ' + JSON.stringify(data)); + showError(status, JSON.stringify(data)); + }); + } + + $scope.editField = function () { + this.editValue = true; + }; + $scope.hoverIn = function(){ + this.hoverEdit = true; + }; + + $scope.hoverOut = function(){ + this.hoverEdit = false; + }; + + $scope.setFile = function (element) { + $scope.$apply(function ($scope) { + + var f = element.files[0]; + if (f) { + var r = new FileReader(); + r.onload = function (element) { + var contents = element.target.result; + $scope.file = contents; + }; + r.readAsText(f); + } else { + alert("Failed to load file"); + } + }); + }; + $scope.sendInfrastructure = function () { + if ($scope.file !== '' && !angular.isUndefined($scope.file)) { + console.log($scope.file); + http.post(url, $scope.file) + .success(function (response) { + showOk('Vim Instance created.'); + loadVIM(); + }) + .error(function (data, status) { + if (status === 400) + showError(status, "Bad request: your json is not well formatted"); + else + showError(status, data); - var url = $cookieStore.get('URL')+"/api/v1/datacenters/"; + }); + } else if ($scope.textTopologyJson !== '') { + console.log($scope.textTopologyJson); + http.post(url, $scope.textTopologyJson) + .success(function (response) { + showOk('VIM Instance created.'); + $scope.file = ''; + }) + .error(function (data, status) { + if (status === 400) + showError(status, "Bad request: your json is not well formatted"); + else + showError(status, data); - $scope.alerts = []; - $scope.datacenter = {}; - $scope.file = ''; + }); + } + else { + showError('Problem with the VIM Instance'); + } + }; - loadVIM(); + $scope.nameFilter = null; - $scope.textTopologyJson = ''; - $scope.changeText = function (text) { - $scope.textTopologyJson = text; - }; - $scope.setFile = function (element) { - $scope.$apply(function ($scope) { - var f = element.files[0]; - if (f) { - var r = new FileReader(); - r.onload = function (element) { - var contents = element.target.result; - $scope.file = contents; - }; - r.readAsText(f); - } else { - alert("Failed to load file"); - } - }); - }; - $scope.sendInfrastructure = function () { - if ($scope.file !== '' && !angular.isUndefined($scope.file)) { - console.log($scope.file); - http.post(url, $scope.file) - .success(function (response) { - showOk('Vim Instance created.'); - loadVIM(); - }) - .error(function (data, status) { - if (status === 400) - showError(status, "Bad request: your json is not well formatted"); - else - showError(status, data); - - }); - } else if ($scope.textTopologyJson !== '') { - console.log($scope.textTopologyJson); - http.post(url, $scope.textTopologyJson) - .success(function (response) { - showOk('VIM Instance created.'); - $scope.file = ''; - }) - .error(function (data, status) { - if (status === 400) - showError(status, "Bad request: your json is not well formatted"); - else - showError(status, data); - - }); - } - else { - showError('Problem with the VIM Instance'); + $scope.changeSelection = function (selection) { + $scope.vimInstanceJson = {}; + $scope.vimInstanceJson = dataCenterJ[selection]; + }; + $scope.changeLocation = function (location) { + $scope.locationRadio = location; + }; - } - }; + $scope.saveDataCenter = function (vimInstanceJson) { + if ($scope.file !== '') { + vimInstanceJson = $scope.file; - $scope.nameFilter = null; + } + $('.modal').modal('hide'); + console.log(vimInstanceJson); + http.post(url, vimInstanceJson) + .success(function (response) { + showOk('Data Center created!'); + console.log(response); + $scope.selection = $scope.dataSelect[0]; + $scope.vimInstanceJson = {}; + }) + .error(function (data, status) { + showError(status, data); + }); - $scope.changeSelection = function (selection) { - $scope.vimInstanceJson = {}; - $scope.vimInstanceJson = dataCenterJ[selection]; - }; - $scope.changeLocation = function (location) { - $scope.locationRadio = location; - }; + }; + + $scope.setFile = function (element) { + $scope.$apply(function ($scope) { + + var f = element.files[0]; + if (f) { + var r = new FileReader(); + r.onload = function (element) { + var contents = element.target.result; + $scope.file = contents; + }; + r.readAsText(f); + } else { + alert("Failed to load file"); + } + }); + }; + + $scope.refreshDc = function () { + + $('#refreshIco').addClass('fa-spin'); + http.get(url + $routeParams.vimInstanceId + '/refresh') + .success(function (data) { + $('#refreshIco').removeClass('fa-spin'); + $scope.datacenter = data; + $scope.datacenterJSON = JSON.stringify(data, undefined, 4); + $scope.upDatacenter = data; + }) + .error(function (data, status) { + showError(status, data); + }); + }; + $scope.closeAlert = function (index) { + $scope.alerts.splice(index, 1); + }; - $scope.saveDataCenter = function (vimInstanceJson) { - if ($scope.file !== '') { - vimInstanceJson = $scope.file; + $scope.deleteData = function (id) { + http.delete(url + id) + .success(function (response) { + showOk('Vim Instance deleted with id ' + id + '.'); + loadVIM(); - } + }) + .error(function (data, status) { + showError(status, data); + }); + }; - $('.modal').modal('hide'); - console.log(vimInstanceJson); - http.post(url, vimInstanceJson) - .success(function (response) { - showOk('Data Center created!'); + function loadVIM() { + if (!angular.isUndefined($routeParams.vimInstanceId)) + http.get(url + $routeParams.vimInstanceId) + .success(function (response, status) { console.log(response); - $scope.selection = $scope.dataSelect[0]; - $scope.vimInstanceJson = {}; - }) - .error(function (data, status) { - showError(status, data); - }); + $scope.vimInstance = response; + $scope.vimInstanceJSON = JSON.stringify(response, undefined, 4); - }; - - $scope.setFile = function (element) { - $scope.$apply(function ($scope) { - - var f = element.files[0]; - if (f) { - var r = new FileReader(); - r.onload = function (element) { - var contents = element.target.result; - $scope.file = contents; - }; - r.readAsText(f); - } else { - alert("Failed to load file"); - } + }).error(function (data, status) { + showError(status, data); }); - }; - - $scope.refreshDc = function () { - - $('#refreshIco').addClass('fa-spin'); - http.get(url + $routeParams.vimInstanceId + '/refresh') - .success(function (data) { - $('#refreshIco').removeClass('fa-spin'); - $scope.datacenter = data; - $scope.datacenterJSON = JSON.stringify(data, undefined, 4); - $scope.upDatacenter = data; - }) - .error(function (data, status) { - showError(status, data); - }); - }; - $scope.closeAlert = function (index) { - $scope.alerts.splice(index, 1); - }; - - - $scope.deleteData = function (id) { - http.delete(url + id) + else { + http.get(url) .success(function (response) { - showOk('Vim Instance deleted with id ' + id + '.'); - loadVIM(); - + $scope.vimInstances = response; }) .error(function (data, status) { showError(status, data); }); - }; - - function loadVIM() { - if (!angular.isUndefined($routeParams.vimInstanceId)) - http.get(url + $routeParams.vimInstanceId) - .success(function (response, status) { - console.log(response); - $scope.vimInstance = response; - $scope.vimInstanceJSON = JSON.stringify(response, undefined, 4); - - }).error(function (data, status) { - showError(status, data); - }); - else { - http.get(url) - .success(function (response) { - $scope.vimInstances = response; - }) - .error(function (data, status) { - showError(status, data); - }); - } } + } - function showError(status,data) { - console.log('Status: ' + status + ' Data: ' + JSON.stringify(data)); - $scope.alerts.push({ - type: 'danger', - msg: 'ERROR: HTTP status: ' + status + ' response data : ' + JSON.stringify(data) - }); + function showError(status, data) { + console.log('Status: ' + status + ' Data: ' + JSON.stringify(data)); + $scope.alerts.push({ + type: 'danger', + msg: 'ERROR: HTTP status: ' + status + ' response data : ' + JSON.stringify(data) + }); - $('.modal').modal('hide'); - if (status === 401) { - console.log(status + ' Status unauthorized') - AuthService.logout(); - } + $('.modal').modal('hide'); + if (status === 401) { + console.log(status + ' Status unauthorized') + AuthService.logout(); } + } - function showOk(msg) { - $scope.alerts.push({type: 'success', msg: msg}); + function showOk(msg) { + $scope.alerts.push({type: 'success', msg: msg}); - $('.modal').modal('hide'); - } + $('.modal').modal('hide'); + } - }); +}); diff --git a/src/main/resources/static/js/controllers/vnfdController.js b/src/main/resources/static/js/controllers/vnfdController.js index 0e1501a..34d35ad 100644 --- a/src/main/resources/static/js/controllers/vnfdController.js +++ b/src/main/resources/static/js/controllers/vnfdController.js @@ -1,4 +1,4 @@ -var app = angular.module('app').controller('VnfdCtrl', function ($scope, $compile, $cookieStore, $routeParams, http, $http, $window, AuthService) { +var app = angular.module('app').controller('VnfdCtrl', function ($scope, $compile, $cookieStore, $routeParams, http, $http, $window, AuthService, clipboard) { var baseUrl = $cookieStore.get('URL')+"/api/v1/"; var url = baseUrl + '/vnf-descriptors/'; @@ -20,6 +20,18 @@ var app = angular.module('app').controller('VnfdCtrl', function ($scope, $compil }); + $scope.copyToClipboard = function () { + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push({'id': k}); + } + }); + //console.log(ids); + clipboard.copyText(JSON.stringify(ids)); + }; + + if (!angular.isUndefined($routeParams.vduId)) { $scope.vduId = $routeParams.vduId; console.log($scope.vduId); @@ -138,6 +150,10 @@ var app = angular.module('app').controller('VnfdCtrl', function ($scope, $compil $('#addEditVDU').modal('show'); }; + $scope.showTab = function (value) { + return (value > 0); + }; + $scope.addVNFD = function () { $http.get('descriptors/vnfd/vnfd.json') .then(function (res) { @@ -159,6 +175,62 @@ var app = angular.module('app').controller('VnfdCtrl', function ($scope, $compil }); }; + /* -- multiple delete functions Start -- */ + + $scope.multipleDeleteReq = function(){ + var ids = []; + angular.forEach($scope.selection.ids, function (value, k) { + if (value) { + ids.push(k); + } + }); + console.log(ids); + http.post(url + 'multipledelete', ids) + .success(function (response) { + showOk('Virtual Network Function Descriptor with id: ' + ids.toString() + ' deleted.'); + loadTable(); + }) + .error(function (response, status) { + showError(response, status); + }); + + }; + + $scope.main = {checkbox: false}; + $scope.$watch('main', function (newValue, oldValue) { + //console.log(newValue.checkbox); + //console.log($scope.selection.ids); + angular.forEach($scope.selection.ids, function (value, k) { + $scope.selection.ids[k] = newValue.checkbox; + }); + console.log($scope.selection.ids); + }, true); + + $scope.$watch('selection', function (newValue, oldValue) { + console.log(newValue); + var keepGoing = true; + angular.forEach($scope.selection.ids, function (value, k) { + if (keepGoing) { + if ($scope.selection.ids[k]) { + $scope.multipleDelete = false; + keepGoing = false; + } + else { + $scope.multipleDelete = true; + } + } + + }); + if (keepGoing) + $scope.mainCheckbox = false; + }, true); + + $scope.multipleDelete = true; + + $scope.selection = {}; + $scope.selection.ids = {}; + /* -- multiple delete functions END -- */ + function loadTable() { if (angular.isUndefined($routeParams.vnfdescriptorId)) http.get(url) diff --git a/src/main/resources/static/js/libs/angular/angular-clipboard.js b/src/main/resources/static/js/libs/angular/angular-clipboard.js new file mode 100644 index 0000000..16b3c53 --- /dev/null +++ b/src/main/resources/static/js/libs/angular/angular-clipboard.js @@ -0,0 +1,84 @@ +(function (root, factory) { + /* istanbul ignore next */ + if (typeof define === 'function' && define.amd) { + define(['angular'], factory); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(require('angular')); + } else { + root.angularClipboard = factory(root.angular); + } +}(this, function (angular) { + +return angular.module('angular-clipboard', []) + .factory('clipboard', ['$document', function ($document) { + function createNode(text, context) { + var node = $document[0].createElement('textarea'); + node.style.position = 'absolute'; + node.textContent = text; + node.style.left = '-10000px'; + if (context instanceof HTMLElement) { + node.style.top = context.getBoundingClientRect().top + 'px'; + } + return node; + } + + function copyNode(node) { + try { + // Set inline style to override css styles + $document[0].body.style.webkitUserSelect = 'initial'; + + var selection = $document[0].getSelection(); + selection.removeAllRanges(); + node.select(); + + if(!$document[0].execCommand('copy')) { + throw('failure copy'); + } + selection.removeAllRanges(); + } finally { + // Reset inline style + $document[0].body.style.webkitUserSelect = ''; + } + } + + function copyText(text, context) { + var node = createNode(text, context); + $document[0].body.appendChild(node); + copyNode(node); + $document[0].body.removeChild(node); + } + + return { + copyText: copyText, + supported: 'queryCommandSupported' in document && document.queryCommandSupported('copy') + }; + }]) + .directive('clipboard', ['clipboard', function (clipboard) { + return { + restrict: 'A', + scope: { + onCopied: '&', + onError: '&', + text: '=', + supported: '=?' + }, + link: function (scope, element) { + scope.supported = clipboard.supported; + + element.on('click', function (event) { + try { + clipboard.copyText(scope.text, element[0]); + if (angular.isFunction(scope.onCopied)) { + scope.$evalAsync(scope.onCopied()); + } + } catch (err) { + if (angular.isFunction(scope.onError)) { + scope.$evalAsync(scope.onError({err: err})); + } + } + }); + } + }; + }]); + +})); \ No newline at end of file diff --git a/src/main/resources/static/js/main.js b/src/main/resources/static/js/main.js index ed3f048..629c852 100644 --- a/src/main/resources/static/js/main.js +++ b/src/main/resources/static/js/main.js @@ -13,6 +13,7 @@ require({ jQueryRotate: "libs/jquery/jQueryRotate", angular_route: "libs/angular/angular-route.min", angular_cookies: "libs/angular/angular-cookies.min", + angular_clipboard: "libs/angular/angular-clipboard", d3: "libs/d3.min", ui_bootstrap: "libs/angular/ui-bootstrap-tpls-0.10.0.min", app: "app", @@ -25,6 +26,9 @@ require({ servicesServices: "services/servicesServices", topologyServices: "services/topologyServices", packageController: "controllers/packageController", + eventController: "controllers/eventController", + projectController: "controllers/projectController", + userController: "controllers/userController", vimInstanceController: "controllers/vimInstanceController", nsdController: "controllers/nsdController", nsrController: "controllers/nsrController", @@ -84,7 +88,7 @@ require({ deps: ['jquery', 'raphael'] }, app: { - deps: ['angular', 'angular_route', 'angular_sanitize', 'ui_bootstrap'] + deps: ['angular', 'angular_route', 'angular_sanitize', 'ui_bootstrap', 'angular_clipboard'] }, angular_route: { deps: ['angular'] @@ -125,6 +129,15 @@ require({ packageController: { deps: ['app', 'servicesServices', 'httpService', 'angular_cookies','authService','dropzone'] }, + eventController: { + deps: ['app', 'servicesServices', 'httpService', 'angular_cookies','authService'] + }, + projectController: { + deps: ['app', 'servicesServices', 'httpService', 'angular_cookies','authService'] + }, + userController: { + deps: ['app', 'servicesServices', 'httpService', 'angular_cookies','authService'] + }, indexController: { deps: ['app', 'httpService', 'servicesServices', 'morris', 'authService', 'angular_cookies'] }, @@ -155,6 +168,9 @@ require({ 'vnfcomponentController', 'vnfmanagerController', 'packageController', + 'eventController', + 'projectController', + 'userController', 'nsrController', 'vimInstanceController' ], function (require) { diff --git a/src/main/resources/static/js/services/authService.js b/src/main/resources/static/js/services/authService.js index 826b0a3..af4669b 100644 --- a/src/main/resources/static/js/services/authService.js +++ b/src/main/resources/static/js/services/authService.js @@ -2,56 +2,56 @@ * Angular Service for managing the login of the user */ -angular.module('app').factory('AuthService', function($http, Session, $location, http, $cookieStore, $window, $q) { +angular.module('app').factory('AuthService', function ($http, Session, $location, http, $cookieStore, $window, $q) { var authService = {}; var clientId = "openbatonOSClient"; var clientPass = "secret"; - authService.login = function(credentials, URL) { + authService.login = function (credentials, URL) { console.log(credentials); - var basic ="Basic " + btoa(clientId + ":" + clientPass); + var basic = "Basic " + btoa(clientId + ":" + clientPass); return $http({ method: 'POST', - url:URL + '/oauth/token', + url: URL + '/oauth/token', headers: { "Authorization": basic, 'Content-Type': 'application/x-www-form-urlencoded' }, - data: "username="+credentials.username+"&password="+credentials.password+"&grant_type="+credentials.grant_type}) - .then(function(res) { + data: "username=" + credentials.username + "&password=" + credentials.password + "&grant_type=" + credentials.grant_type + }) + .then(function (res) { console.log(res); Session.create(URL, res.data.value, credentials.username, true); $location.path("/"); $window.location.reload(); return; }); + }; - authService.loginGuest = function(URL) { - Session.create(URL,'', 'guest', true); + authService.loginGuest = function (URL) { + Session.create(URL, '', 'guest', true); $location.path("/"); $window.location.reload(); - return ; + return; }; - - - authService.isAuthenticated = function() { + authService.isAuthenticated = function () { return !!Session.userName; }; - authService.removeSession = function() { + authService.removeSession = function () { Session.destroy(); }; - authService.logout = function() { + authService.logout = function () { Session.destroy(); $window.location.reload(); }; - authService.isAuthorized = function(authorizedRoles) { + authService.isAuthorized = function (authorizedRoles) { if (!angular.isArray(authorizedRoles)) { authorizedRoles = [authorizedRoles]; } @@ -66,10 +66,9 @@ angular.module('app').factory('AuthService', function($http, Session, $location, * Angular Service for managing the session and cookies of the user */ -}).service('Session', function($cookieStore) { - +}).service('Session', function ($cookieStore) { - this.create = function(URL, token, userName, logged) { + this.create = function (URL, token, userName, logged) { this.URL = URL; this.token = token; this.userName = userName; @@ -78,10 +77,13 @@ angular.module('app').factory('AuthService', function($http, Session, $location, $cookieStore.put('userName', userName); $cookieStore.put('token', token); $cookieStore.put('URL', URL); + $cookieStore.put('project', {name: 'default', id: ''}); + + // console.log($cookieStore.get('token')); }; - this.destroy = function() { + this.destroy = function () { this.URL = null; this.token = null; this.userName = null; @@ -90,7 +92,7 @@ angular.module('app').factory('AuthService', function($http, Session, $location, $cookieStore.remove('userName'); $cookieStore.remove('token'); $cookieStore.remove('URL'); - + $cookieStore.remove('project'); }; return this; }); \ No newline at end of file diff --git a/src/main/resources/static/js/services/httpService.js b/src/main/resources/static/js/services/httpService.js index 7704e57..3d79e5a 100644 --- a/src/main/resources/static/js/services/httpService.js +++ b/src/main/resources/static/js/services/httpService.js @@ -1,14 +1,15 @@ angular.module('app') - .factory('http', function ($http, $q, $cookieStore) { + .factory('http', function ($http, $q, $cookieStore, $rootScope) { var customHeaders = {}; - if ($cookieStore.get('token') === '') + var http = {}; + + if ($cookieStore.get('token') === '' || angular.isUndefined($cookieStore.get('token'))) customHeaders = { 'Accept': 'application/json', 'Content-type': 'application/json' }; else { - customHeaders = { 'Accept': 'application/json', 'Content-type': 'application/json', @@ -16,8 +17,24 @@ angular.module('app') }; } - var http = {}; + http.get = function (url) { + console.log(customHeaders); + + if (url.indexOf("/scripts/") > -1) { + customHeaders['Accept'] = 'text/plain'; + customHeaders['Content-type'] = 'text/plain'; + + } else { + customHeaders['Accept'] = 'application/json'; + customHeaders['Content-type'] = 'application/json'; + + } + + customHeaders['project-id'] = $cookieStore.get('project').id; + //console.log(customHeaders); + //console.log($cookieStore.get('project')); + return $http({ url: url, method: 'GET', @@ -27,7 +44,8 @@ angular.module('app') http.post = function (url, data) { - console.log(data); + customHeaders['project-id'] = $cookieStore.get('project').id; + //console.log(data); $('#modalSend').modal('show'); return $http({ url: url, @@ -36,6 +54,18 @@ angular.module('app') headers: customHeaders }); + }; + http.postLog = function (url) { + customHeaders['project-id'] = $cookieStore.get('project').id; + $('#modalSend').modal('show'); + //console.log(url); + return $.ajax({ + url: url, + type: 'post', + headers: customHeaders, + dataType: 'json' + }); + }; http.postXML = function (url, data) { $('#modalSend').modal('show'); @@ -51,7 +81,16 @@ angular.module('app') }); }; http.put = function (url, data) { + customHeaders['project-id'] = $cookieStore.get('project').id; $('#modalSend').modal('show'); + if (url.indexOf("/scripts/") > -1) { + customHeaders['Content-type'] = 'text/plain'; + customHeaders['Accept'] = 'text/plain'; + } else { + customHeaders['Accept'] = 'application/json'; + customHeaders['Content-type'] = 'application/json'; + } + return $http({ url: url, method: 'PUT', @@ -61,6 +100,8 @@ angular.module('app') }; http.delete = function (url) { + customHeaders['project-id'] = $cookieStore.get('project').id; + //console.log(customHeaders); $('#modalSend').modal('show'); return $http({ url: url, @@ -77,6 +118,7 @@ angular.module('app') return deferred.promise; }; + return http; }) ; diff --git a/src/main/resources/static/js/services/servicesServices.js b/src/main/resources/static/js/services/servicesServices.js index 30d5f95..75c9c0e 100644 --- a/src/main/resources/static/js/services/servicesServices.js +++ b/src/main/resources/static/js/services/servicesServices.js @@ -1,42 +1,19 @@ -angular.module('app').factory('serviceAPI', function(http, $q) { +angular.module('app').factory('serviceAPI', function (http, $q) { var services = {}; - var serviceToLaunch; - /* - * - * @returns {Array} Array of locations - */ - services.getLocations = function() { - var locations = []; - http.get('/api/rest/admin/v2/vim-instances').success(function(response) { - for (var i = 0; i < response.length; i++) - locations.push(response[i].location.name); - }); - return locations; - }; - /* - * - * @returns {List} List of Services - */ - services.getServices = function() { - var deferred = $q.defer(); - http.get('/api/rest/orchestrator/v2/packages').success(function(data, status) { - deferred.resolve(data); - }); - return deferred.promise; - }; + /* From uptime to string * * @param {type} long * @returns {unresolved} Return a string like N weeks, M days */ - services.returnStringUptime = function(long) { + services.returnStringUptime = function (long) { var upTime = new Date(long); var now = new Date($.now()); - Date.dateDiff = function(datepart, fromdate, todate) { + Date.dateDiff = function (datepart, fromdate, todate) { datepart = datepart.toLowerCase(); var diff = todate - fromdate; var divideBy = { @@ -67,14 +44,14 @@ angular.module('app').factory('serviceAPI', function(http, $q) { 'minutes': 60, 'seconds': 60 }; - $.each(time, function(i, k) { + $.each(time, function (i, k) { var diff = Date.dateDiff(i, upTime, now); if (!_.isNaN(diff) && diff !== 0) result[k] = diff; }); var uptimeString = ''; var i = 0; - $.each(result, function(key, value) { + $.each(result, function (key, value) { if (i <= 1) { if (value > timeN[key]) { time = value % timeN[key]; @@ -93,50 +70,10 @@ angular.module('app').factory('serviceAPI', function(http, $q) { * * @returns {Number} */ - services.getRandom = function() { + services.getRandom = function () { return Math.floor((Math.random() * 100) + 1); }; - /**Clean a service Json - * - * @param {type} service - * @returns {unresolved} - */ - services.cleanService = function(service) { - delete service.id; - delete service.version; - for (var i = 0; i < service.configuration.parameters.length; i++) { - delete service.configuration.parameters[i].id; - } - delete service.configuration.configurationId; - delete service.configuration.configurationName; - return service; - }; - - services.cleanDC = function(dc) { - delete dc.id; - delete dc.version; - delete dc.configuration.id; - delete dc.configuration.version; - for (var i = 0; i < dc.configuration.parameters.length; i++) { - delete dc.configuration.parameters[i].id; - delete dc.configuration.parameters[i].version; - } - delete dc.switch.configurationId; - for (var i = 0; i < dc.switch.ports.length; i++) { - delete dc.switch.ports[i].id; - delete dc.switch.ports[i].version; - } - for (var i = 0; i < dc.subnets.length; i++) { - delete dc.subnets[i].id; - delete dc.subnets[i].version; - } - delete dc.switch.id; - delete dc.switch.version; - delete dc.location.id; - delete dc.location.version; - return dc; - }; /** return an array of keys by value * * @param {type} obj @@ -145,7 +82,7 @@ angular.module('app').factory('serviceAPI', function(http, $q) { */ services.returnKeys = function returnKeys(obj, value) { var keys = []; - _.each(obj, function(val, key) { + _.each(obj, function (val, key) { if (val === value) { keys.push(key); } @@ -160,36 +97,27 @@ angular.module('app').factory('serviceAPI', function(http, $q) { */ services.returnKeysString = function returnKeysString(obj, value) { var keys = ''; - _.each(obj, function(val, key) { + _.each(obj, function (val, key) { if (val === value) { keys += key + ','; } }); return keys.substring(0, keys.length - 1); }; - /** the list of relations - * - * @returns {Array} - */ - //packages.getRelations = function() { - // var relations = []; - // http.get('/api/rest/orchestrator/v2/relations').success(function(data, status) { - // relations = data; - // }); - // return relations; - //}; + + /** Set lat and lon in the dataJson by city * * @param {type} city * @param {type} dataJson * @returns {unresolved} */ - services.setCoordinates = function(city, dataJson) { + services.setCoordinates = function (city, dataJson) { var url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + city + '&sensor=false'; // for synchronizing the call with the controller var deferred = $q.defer(); - http.get(url).success(function(data, status) { + http.get(url).success(function (data, status) { dataJson.location.name = city; dataJson.location.latitude = data.results[0].geometry.location.lat; dataJson.location.longitude = data.results[0].geometry.location.lng; diff --git a/src/main/resources/static/login.html b/src/main/resources/static/login.html index bba389b..793e74c 100644 --- a/src/main/resources/static/login.html +++ b/src/main/resources/static/login.html @@ -1,35 +1,28 @@ -
-
-
- -
-
+
+
+ +
+
diff --git a/src/main/resources/static/menu.html b/src/main/resources/static/menu.html index de50aec..51f55f5 100644 --- a/src/main/resources/static/menu.html +++ b/src/main/resources/static/menu.html @@ -1,170 +1,245 @@
- -
- - +
+
- +
- - - -
- - -
- - -
- - -
- - - - - - - - @@ -182,4 +194,34 @@

VIM Instances

{{data.id}} - {{data.name}} - {{data.type}} + + {{data.name}} + + +
+
  • + +
  • +
    +
    + + + {{data.type}} + + +
    +
  • + +
  • +
    +
    +
    - \ No newline at end of file + + + \ No newline at end of file diff --git a/src/main/resources/static/pages/vnfmanagers/vnfmanagers.html b/src/main/resources/static/pages/vnfmanagers/vnfmanagers.html index 9aa57cd..f4fc8d9 100644 --- a/src/main/resources/static/pages/vnfmanagers/vnfmanagers.html +++ b/src/main/resources/static/pages/vnfmanagers/vnfmanagers.html @@ -2,7 +2,7 @@

    VNF Managers - List of VFN Managers + List of VNF Managers