From e2aefda183de4f1c1256d97f7ce09f8bee5477db Mon Sep 17 00:00:00 2001 From: "Christopher Lott (cl778h)" Date: Tue, 9 May 2017 14:24:20 -0400 Subject: [ONAP-rebase] Rebase as 1.1.0-SNAPSHOT Consolidate into a single maven project; no more separate model and client jars. Change-Id: Ibbba982250b74c0dfd09ee1c65c0fb6c158dd632 Signed-off-by: Christopher Lott Signed-off-by: Christopher Lott (cl778h) --- .../dmaapaccess/dmaap-access-list-controller.js | 176 +++++++++++++++++++++ .../dmaapaccess/dmaap-access-popup-controller.js | 106 +++++++++++++ .../app/dbcapp/dmaapaccess/dmaap-access-service.js | 140 ++++++++++++++++ .../app/dbcapp/dmaapaccess/dmaap_access_list.html | 92 +++++++++++ .../dmaapaccess/dmaap_access_popup_template.html | 89 +++++++++++ 5 files changed, 603 insertions(+) create mode 100644 dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-list-controller.js create mode 100644 dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-popup-controller.js create mode 100644 dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-service.js create mode 100644 dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_list.html create mode 100644 dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_popup_template.html (limited to 'dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess') diff --git a/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-list-controller.js b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-list-controller.js new file mode 100644 index 0000000..5c93821 --- /dev/null +++ b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-list-controller.js @@ -0,0 +1,176 @@ +appDS2.controller('dmaapAccessListCtrl', function ($scope, $log, $modal, modalService, DmaapAccessService) { + 'use strict'; + + // this object holds all app data and functions + $scope.dbcapp = {}; + // Model for radio-button selection group. + // Uses database row ID as unique value. + $scope.dbcapp.selectDmaapModel = { id: null }; + $("#dialog").hide(); + $scope.dbcapp.isDataLoading=true; + + /** + * Loads the table of DMaaP access profiles. + * + * Interprets the remote controller's response and copies to scope + * variables. The response is either list to be assigned to tableData, + * or an error to be shown. + */ + $scope.dbcapp.loadTable = function() { + $scope.dbcapp.isDataLoading = true; + DmaapAccessService.getDmaapAccessList() + .then(function(jsonObj) { + if (jsonObj.error) { + $scope.dbcapp.isRequestFailed = true; + $scope.dbcapp.errMsg = jsonObj.error; + $scope.dbcapp.tableData = []; + } else { + $scope.dbcapp.isRequestFailed = false; + $scope.dbcapp.errMsg = null; + $scope.dbcapp.tableData = jsonObj.data; + $scope.dbcapp.updateDmaapAccessSelection(); + } + $scope.dbcapp.isDataLoading = false; + }, function(error) { + // Called with a string, not JSON obj. + $log.error("dmaapAccessListCtrl.getDmaapAccessList failed: " + error); + $scope.dbcapp.isRequestFailed = true; + $scope.dbcapp.errMsg = error; + $scope.dbcapp.tableData = []; + $scope.dbcapp.isDataLoading = false; + }); + }; + + /** + * Sets a value in the model for the radio-button selection group. + */ + $scope.dbcapp.updateDmaapAccessSelection = function() { + for (var i in $scope.dbcapp.tableData) { + var da = $scope.dbcapp.tableData[i]; + // Set radio button for the selected profile + // $log.info('dmaapAccessListCtrl: examining ' + JSON.stringify(da)); + if (da.selected) { + // $log.info('dmaapAccessListCtrl: selecting id ' + da.id); + $scope.dbcapp.selectDmaapModel.id = da.id; + } + } + }; + + /** + * Handles a click on radio button to select a profile. + */ + $scope.dbcapp.selectDmaapAccess = function(dmaapAccess) { + if (dmaapAccess == null || dmaapAccess.id == null) + $log.error('selectDmaapAccess invoked with null'); + else + DmaapAccessService.setSelectedDmaapAccess(dmaapAccess.id); + }; + + /** + * Shows a modal pop-up to add a DMaaP access profile. + * Passes data in via an object named "message". + * On successful completion, updates the profile list. + * + * After implementing DE238329, this is never called. + */ + $scope.dbcapp.addDmaapAccessModalPopup = function() { + $scope.dbcapp.editDmaapAccess = null; + var modalInstance = $modal.open({ + templateUrl: 'edit_dmaap_access_popup.html', + controller: 'dmaapAccessPopupCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-small', + resolve: { + message: function () { + var dataForPopup = { + dmaapAccess : $scope.dbcapp.editDmaapAccess, + dmaapAccessList : $scope.dbcapp.tableData + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (response == null) { + // $log.debug('addDmaapAccessModelPopup: user closed dialog'); + } + else { + if (response.error != null) + alert('Failed to add access profile:\n' + response.error); + else + // success, get the updated list. + $scope.dbcapp.loadTable(); + } + }); + }; + + /** + * Shows a modal pop-up to edit a DMaaP access profile. + * Passes data in via an object named "message". + * On successful completion, updates the profile list. + */ + $scope.dbcapp.editDmaapAccessModalPopup = function(dmaapAccess) { + // edit a copy, not the model for the table row. + $scope.dbcapp.editDmaapAccess = JSON.parse(JSON.stringify(dmaapAccess)); + var modalInstance = $modal.open({ + templateUrl: 'edit_dmaap_access_popup.html', + controller: 'dmaapAccessPopupCtrl', + windowClass: 'modal-docked', + sizeClass: 'modal-small', + resolve: { + message: function () { + var dataForPopup = { + dmaapAccess : $scope.dbcapp.editDmaapAccess, + dmaapAccessList : $scope.dbcapp.tableData + }; + return dataForPopup; + } + } + }); + modalInstance.result.then(function(response) { + if (response == null) { + // $log.debug('addDmaapAccessModelPopup: user closed dialog'); + } + else { + if (response.error != null) + alert('Failed to edit access profile:\n' + response.error); + else + // success, get the updated list. + $scope.dbcapp.loadTable(); + } + }); + }; + + /** + * Shows a modal pop-up to confirm deletion of a DMaaP access profile. + * On successful completion, updates the profile list. + * + * After implementing DE238329, this is never called. + */ + $scope.dbcapp.deleteDmaapAccess = function(dmaapAccess) { + modalService.popupConfirmWin("Confirm", "Delete the DMaaP access profile: " + + dmaapAccess.name + "\nContinue?", + function() { + // $log.debug('deleteDmaapAccess: deleting id ' + dmaapAccess.id); + DmaapAccessService.deleteDmaapAccess(dmaapAccess.id).then( + function(response) { + if (response.error != null) { + $log.error('deleteDmaapAccess: failed to delete: ' + response.error); + alert('Failed to delete access profile:\n' + response.error); + } + else { + // success, get the updated list. + $scope.dbcapp.loadTable() + } + }, + function(error) { + $log.error('deleteDmaapAccess failed: ' + error); + alert('dmaapAccessListCtrl failed to delete object'); + }); + }) + }; + + // Populate the table on load. + $scope.dbcapp.loadTable(); + +}); diff --git a/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-popup-controller.js b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-popup-controller.js new file mode 100644 index 0000000..4fe3805 --- /dev/null +++ b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-popup-controller.js @@ -0,0 +1,106 @@ +appDS2.controller('dmaapAccessPopupCtrl', function($scope, $log, $modalInstance, modalService, message, DmaapAccessService) { + 'use strict'; + + // this object holds all app data and functions + $scope.dbcapp = {}; + + // Set the label variable for the template + if (message.dmaapAccess == null) + $scope.dbcapp.label = 'Add Access Profile'; + else + $scope.dbcapp.label = 'Edit Access Profile'; + $scope.dbcapp.editDmaapAccess = message.dmaapAccess; + + /** + * Validates content of user-editable fields. + * Returns null if all is well, + * a descriptive error message otherwise. + */ + $scope.dbcapp.validateProfile = function(dmaapAccess) { + if (dmaapAccess == null) + return "No data found.\nPlease enter some values."; + if (dmaapAccess.name == null || dmaapAccess.name.trim() == '') + return "Name is required.\nPlease enter a value."; + // User cannot edit URL + //if (dmaapAccess.dmaapUrl == null || dmaapAccess.dmaapUrl.trim() == '') + // return "URL is required.\nPlease enter a value."; + //if (dmaapAccess.dmaapUrl.toLowerCase().indexOf('http') != 0) + // return "Unexpected URL prefix.\nPlease enter a URL starting with 'http'."; + for (var x in message.dmaapAccessList) { + // $log.debug('saveDmaapAccess: checking item >' + message.dmaapAccessList[x].name + '<'); + // Ignore the name in the one being edited. + if (message.dmaapAccessList[x].id == dmaapAccess.id) + continue; + if (message.dmaapAccessList[x].name == dmaapAccess.name) + return "Name " + dmaapAccess.name + " exists.\nPlease enter a different name."; + } + return null; + } + + /** + * Tests the URL for validity. Shows a modal dialog to display test result. + * Returns nothing. + */ + $scope.dbcapp.testDmaapAccess = function(dmaapAccess) { + if (dmaapAccess == null || dmaapAccess.dmaapUrl == null || dmaapAccess.dmaapUrl.trim() == '') { + alert('No URL found.\nPlease enter a URL.'); + return; + } + // result should have a data aggregate that's a serialized DMaaP object + DmaapAccessService.testDmaapAccess(dmaapAccess) + .then(function(response) { + if (response.error != null) + alert('Invalid Content:\n' + response.error); + else + alert('DMaaP name is ' + response.data.dmaapName) + }, + function (error) { + alert('Test failed:\n' + error); + } + ); + } + + /** + * Validates the content; on success, calls service to save it. + */ + $scope.dbcapp.saveDmaapAccess = function(dmaapAccess) { + var validateMsg = $scope.dbcapp.validateProfile(dmaapAccess); + if (validateMsg != null) { + alert('Invalid Content:\n' + validateMsg); + return; + } + + // Set the selected flag if this is the only access profile. + if (dmaapAccess.id == null && message.dmaapAccessList.length == 0) + dmaapAccess.selected = true; + + if (dmaapAccess.id == null) { + // No id, so create a new one + DmaapAccessService.addDmaapAccess(dmaapAccess) + .then(function(dmaapAccessList) { + + $modalInstance.close(dmaapAccessList); + }, + function (error) { + $log.error('dmaapAccessPopupCtrl: error while adding: ' + error); + } + ); + } + else { + // Has id, so update an existing one + DmaapAccessService.updateDmaapAccess(dmaapAccess) + .then(function(dmaapAccessList) { + $modalInstance.close(dmaapAccessList); + }, + function (error) { + $log.error('dmaapAccessPopupCtrl: error while updating: ' + error); + } + ); + } + + }; + + $scope.dbcapp.close = function() { + $modalInstance.close(); + }; +}); diff --git a/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-service.js b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-service.js new file mode 100644 index 0000000..b3df6e9 --- /dev/null +++ b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap-access-service.js @@ -0,0 +1,140 @@ +appDS2.factory('DmaapAccessService', function ($http, $q, $log) { + return { + /** + * Gets the list of DMaaP access profiles for the current user (not paginated). + * @return {JSON} Response object from remote side + */ + getDmaapAccessList: function() { + // cache control for IE + var cc = "?cc=" + new Date().getTime().toString(); + return $http({ + method: 'GET', + url: 'dmaap_access' + cc, + cache: false, + responseType: 'json'}) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.getDmaapAccessList: response.data null or not object'); + else + return response.data; + }, function(error) { + $log.error('DmaapAccessService.getDmaapAccessList failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Gets and returns the selected DMaaP access profile for the current user. + getSelectedDmaapAccess: function() { + // cache control for IE + var cc = "?cc=" + new Date().getTime().toString(); + return $http({ + method: 'GET', + url: 'select_dmaap_access' + cc, + cache: false, + responseType: 'json'}) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.getSelectedDmaapAccess: response.data null or not object'); + else + return response.data; + }, function(error) { + $log.error('DmaapAccessService.getSelectedDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Selects the specified DMaaP access profile for the current user. + // Returns nothing. + setSelectedDmaapAccess: function(dmaapId) { + return $http({ + method: 'PUT', + url: 'select_dmaap_access/' + dmaapId, + responseType: 'json' }) + .then(function(response) { + // successful response is status:200 + // $log.info('setSelectedDmaapAccess complete: ' + JSON.stringify(response)); + }, function(error) { + $log.error('DmaapAccessService.setSelectedDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Creates a new DMaaP access profile for the current user. + // Returns the current DMaaP access list. + addDmaapAccess: function(dmaapAccess) { + return $http({ + method: 'POST', + url: 'dmaap_access', + data: dmaapAccess, + responseType: 'json' }) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.addDmaapAccess: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('DmaapAccessService.addDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Updates an existing DMaaP access profile for the current user + // Returns the current DMaaP access list. + updateDmaapAccess: function(dmaapAccess) { + return $http({ + method: 'PUT', + url: 'dmaap_access/' + dmaapAccess.id, + data: dmaapAccess, + responseType: 'json' }) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.updateDmaapAccess: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('DmaapAccessService.updateDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Deletes the specified DMaaP access profile for the current user. + // Returns the current DMaaP access list. + deleteDmaapAccess: function(dmaapId) { + return $http({ + method: 'DELETE', + url: 'dmaap_access/' + dmaapId, + responseType: 'json' }) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.deleteDmaapAccess: response.data null or not object'); + else + return response.data; + }, + function(error) { + $log.error('DmaapAccessService.deleteDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + // Tests the URL in the access profile by fetching the DMaaP object from it. + testDmaapAccess: function(dmaapAccess) { + return $http({ + method: 'POST', + url: 'test_dmaap_access', + data: dmaapAccess, + responseType: 'json' }) + .then(function(response) { + if (response.data == null || typeof response.data != 'object') + return $q.reject('DmaapAccessService.testDmaapAccess: response.data null or not object'); + else + return response.data; + }, function(error) { + $log.error('DmaapAccessService.testDmaapAccess failed: ' + JSON.stringify(error)); + return $q.reject(error.statusText); + }); + }, + + }; +}); diff --git a/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_list.html b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_list.html new file mode 100644 index 0000000..36a52aa --- /dev/null +++ b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_list.html @@ -0,0 +1,92 @@ + +
+ +

DMaaP Access Profiles

+ + +
+
+ + Please wait while the content loads. +
+
+ +
+ +
+ +
+
+ + +
+
+
+ +
+ {{dbcapp.errMsg}} +
+ +
Click on + a radio button to select that profile for use in this web application. +
+ +
+ {{dbcapp.errMsg}} +
+ +
+ + + + + + + + + + + + + + + + + + + + +
SelectedNameURLMech ID
+ +
+
+ +
+ +
diff --git a/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_popup_template.html b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_popup_template.html new file mode 100644 index 0000000..a3653b3 --- /dev/null +++ b/dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess/dmaap_access_popup_template.html @@ -0,0 +1,89 @@ + -- cgit 1.2.3-korg