diff options
author | 2017-05-09 14:24:20 -0400 | |
---|---|---|
committer | 2017-05-09 14:44:09 -0400 | |
commit | e2aefda183de4f1c1256d97f7ce09f8bee5477db (patch) | |
tree | 4b0eaf3f153df90591711daf081e63a8b20ace74 /dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess | |
parent | 472635713b7471b300a988db7e907bab0119eaee (diff) |
[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 <cl778h@att.com>
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'dcae_dmaapbc_webapp/dbca-overlay/src/main/webapp/app/dbcapp/dmaapaccess')
5 files changed, 603 insertions, 0 deletions
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 List. Controller is specified by route provider --> +<div id="page-content"> + + <h1 class="heading-page" id="dmaapAccess">DMaaP Access Profiles</h1> + + <!-- show progress indicator --> + <div ng-show="dbcapp.isDataLoading"> + <div class="span" style="margin-bottom:20px;"> + <i class="icon-primary-spinner small" role="img" aria-label="Please wait while the content loads"></i> + Please wait while the content loads. + </div> + </div> + + <div ng-hide="dbcapp.isDataLoading"> + + <div id="button-search-row"> + <!-- no button --> + <div style="float:right;"> + <div class="form-field form-field__small"> + <input + type="text" + placeholder="Search profiles" + ng-model="dbcapp.searchString"/> + <!-- <i class="icon-primary-questionmark"></i> --> + </div> + </div> + </div> + + <div ng-show="dbcapp.isRequestFailed"> + <span class="errorMessageText">{{dbcapp.errMsg}}</span> + </div> + + <div style="text-align: justify; text-align-last: auto;">Click on + a radio button to select that profile for use in this web application. + </div> + + <div ng-show="dbcapp.isRequestFailed"> + <span class="errorMessageText">{{dbcapp.errMsg}}</span> + </div> + + <div + b2b-table + id="dmaap-access-table" + class="b2b-table-div" + table-data="dbcapp.tableData" + search-string="dbcapp.searchString" + current-page="dbcapp.currentPageIgnored" + next-sort="dbcapp.nextSortIgnored"> + + <table> + + <thead b2b-table-row type="header"> + <tr id="th-header-row"> + <th b2b-table-header sortable="false">Selected</th> + <th b2b-table-header key="name">Name</th> + <th b2b-table-header key="dmaapUrl">URL</th> + <th b2b-table-header key="mechId">Mech ID</th> + </tr> + </thead> + + <tbody b2b-table-row type="body" row-repeat="rowData in dbcapp.tableData"> + <tr> + <td b2b-table-body> + <label class="radio"> + <input + type="radio" + name="dmaapSelGroup" + title="rowData.id" + ng-value="rowData.id" + ng-model="dbcapp.selectDmaapModel.id" + ng-change="dbcapp.selectDmaapAccess(rowData);"> + <i class="skin"></i> + <span></span> + </label> + </td> + <td b2b-table-body + ng-bind="rowData.name" + ng-click="dbcapp.editDmaapAccessModalPopup(rowData)"></td> + <td b2b-table-body + ng-bind="rowData.dmaapUrl" + ng-click="dbcapp.editDmaapAccessModalPopup(rowData)"></td> + <td b2b-table-body + ng-bind="rowData.mechId" + ng-click="dbcapp.editDmaapAccessModalPopup(rowData)"></td> + </tr> + </tbody> + </table> + </div> + + </div><!-- loading --> + +</div><!-- page content --> 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 @@ +<script type="text/ng-template" id="edit_dmaap_access_popup.html"> + + <div class="b2b-modal-header ng-scope"> + <h2 id="myModalLabel" modal-title="">{{dbcapp.label}}</h2> + <div class="corner-button in"> + <button type="button" class="close" aria-label="Close" + ng-click="$dismiss('cancel')"></button> + </div> + </div> + + <div class="b2b-modal-body ng-scope ng-isolate-scope" tabindex="0" + role="region" aria-label="Modal body content"> + + <div class="row-nowrap"> + <div class="span12"> + <div class="form-row"> + <label for="name">*Name</label> + <div class="field-group"> + <!--autofocus is HTML5 attribute; doesn't work in Firefox--> + <input id="name" class="span12" type="text" data-ng-model="dbcapp.editDmaapAccess.name" autofocus> + </div> + </div> + </div> + </div> + + <div class="row-nowrap"> + <div class="span12"> + <div class="form-row"> + <label for="url">*URL</label> + <!-- edit disabled for DE238329 --> + <div class="field-group"> + <input id="url" class="span12" type="text" disabled="disabled" data-ng-model="dbcapp.editDmaapAccess.dmaapUrl"> + </div> + </div> + </div> + <div class="span12"> + <div class="form-row"> + <label for="testButton"> </label> + <div class="field-group"> + <button + id="testButton" + class="btn btn-alt btn-small" + href="javascript:void(0)" + ng-click="dbcapp.testDmaapAccess(dbcapp.editDmaapAccess);"> + Test... + </button> + </div> + </div> + </div> + </div> + + <div class="row-nowrap"> + <div class="span12"> + <div class="form-row"> + <label for="mechid">Mech ID</label> + <div class="field-group"> + <input id="mechid" class="span12" type="text" data-ng-model="dbcapp.editDmaapAccess.mechId"> + </div> + </div> + </div> + </div> + + <div class="row-nowrap"> + <div class="span12"> + <div class="form-row"> + <label for="password">Password</label> + <div class="field-group"> + <input id="password" class="span12" type="password" data-ng-model="dbcapp.editDmaapAccess.password"> + </div> + </div> + </div> + </div> + + </div> + + <div class="b2b-modal-footer ng-scope ng-isolate-scope"> + <div class="cta-button-group in"> + <button class="btn btn-alt btn-small" type="button" + ng-click="dbcapp.saveDmaapAccess(dbcapp.editDmaapAccess);"> + Save + </button> + <button class="btn btn-small" type="button" + ng-click="$dismiss('cancel')"> + Cancel + </button> + </div> + </div> + +</script> |