cb07fc784666bd6adf16359fbd3ec0218d2f6ab5
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / onapSo / onapSo-module / src / main / resources / onapSo / onapSo.controller.js
1 /*
2  * Copyright (c) 2017 highstreet technologies GmbH and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(['app/onapSo/onapSo.module',
10   'app/onapSo/onapSo.services'],
11   function (onapSoApp) {
12
13     onapSoApp.register.controller('onapSoCtrl', ['uiGridConstants', '$uibModal', '$scope', '$rootScope', '$window', '$timeout', '$onapSo', '$mwtnLog',
14       function (uiGridConstants, $uibModal, $scope, $rootScope, $window, $timeout, $onapSo, $mwtnLog) {
15
16         var COMPONENT = 'onapSoCtrl';
17         $mwtnLog.info({ component: COMPONENT, message: 'onapSoCtrl started!' });
18
19         $rootScope.section_logo = 'src/app/onapSo/images/onapSo.png'; // Add your topbar logo location here such as 'assets/images/logo_topology.gif'
20
21         $scope.highlightFilteredHeader = $onapSo.highlightFilteredHeader;
22
23         $scope.pnf = {
24           pnfName: { id: 'pnfName', labelId: 'PNF_NAME', value: 'New-PNF' },
25           pnfId: { id: 'pnfId', labelId: 'PNF_IDENTIFIER', value: 'New-PNF network unique identifier' },
26           equipType: { id: 'equipType', labelId: 'PNF_EQUIPMENT_TYPE', value: 'Fancy equipment type' },
27           equipModel: { id: 'equipModel', labelId: 'PNF_EQUIPMENT_MODEL', value: 'Best in class' },
28           equipVendor: { id: 'equipVendor', labelId: 'PNF_EQUIPMENT_VENDOR', value: 'ONAP SDN-R Community' },
29           ipaddressV4Oam: { id: 'ipaddressV4Oam', labelId: 'PNF_IPv4ADDRESS', value: '10.10.10.10' },
30           inMaintenance: { id: 'inMaintenance', labelId: 'PNF_MAINTENANCE_MODE', value: false },
31           resourceVersion: { id: 'resourceVersion', labelId: 'PNF_RESOURCE_VERSION', value: '' }
32         }
33
34         $scope.createPnfInAai = function () {
35           
36           var data = {
37             "pnf-name": $scope.pnf.pnfName.value,
38             "pnf-id": $scope.pnf.pnfId.value,
39             "equip-type": $scope.pnf.equipType.value,
40             "equip-model": $scope.pnf.equipModel.value,
41             "equip-vendor": $scope.pnf.equipVendor.value,
42             "ipaddress-v4-oam": $scope.pnf.ipaddressV4Oam.value,
43             "in-maint": $scope.pnf.inMaintenance.value
44           }
45
46           $onapSo.createPnf(data).then(function (response) {
47             console.info('successfully created: ', data['pnf-name']);
48             $onapSo.getPnf(data).then(function (success) {
49               // console.info('success', JSON.stringify(success.data));
50               $scope.pnf.resourceVersion.value = success.data['resource-version'];
51             }, function (error) {
52               console.log('error1', JSON.stringify(error.data));
53               $scope.error = error;
54             });
55             }, function (error) {
56             console.log('error2', JSON.stringify(error.data));
57             $scope.error = error;
58           });
59         }
60
61         $scope.deletePnfInAai = function () {
62           var data = {
63             "pnf-name": $scope.pnf.pnfName.value,
64           }          
65           $onapSo.getPnf(data).then(function (success) {
66               console.info('success', JSON.stringify(success.data));
67               $scope.pnf.resourceVersion.value = success.data['resource-version'];
68             data['resource-version'] = success.data['resource-version'];
69             $onapSo.deletePnf(data).then(function (success) {
70               console.info('success', JSON.stringify(success));
71               $scope.pnf.resourceVersion.value = success.data['resource-version'];
72             }, function (error) {
73               console.log('error', JSON.stringify(error.data));
74               $scope.error = error;
75             });
76             }, function (error) {
77             console.log('error', JSON.stringify(error.data));
78             $scope.error = error;
79           });
80         }
81
82       }]);
83
84     });