From bcde7a18119384ad99018a6bf7b76dad5a4a42fc Mon Sep 17 00:00:00 2001 From: c00149107 Date: Mon, 27 Feb 2017 14:56:20 +0800 Subject: Merge codes to the new client framework Merge codes to the new client framework Change-Id: Ie17f634790578bdfb6549d8cea4ffee5343532d9 Issue-ID:GSO-232 Signed-off-by: c00149107 --- .../src/main/webapp/lifecyclemgr/index.html | 2 +- .../src/main/webapp/lifecyclemgr/js/DataService.js | 698 +++++++++++++++++++-- .../src/main/webapp/lifecyclemgr/js/app.js | 118 ++-- .../main/webapp/lifecyclemgr/templates/home.html | 57 +- 4 files changed, 766 insertions(+), 109 deletions(-) diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/index.html b/lifecyclemgr/src/main/webapp/lifecyclemgr/index.html index d695eaca..ad6a359d 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/index.html +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/index.html @@ -11,7 +11,6 @@ - @@ -22,6 +21,7 @@ + diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js index fd3e3d9a..c31a7487 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js @@ -1,11 +1,19 @@ app.factory("DataService", function($http, $log){ var lcData = null; + var createParamJsonObj = { + templateId:'', + parameters: {} + }; + return { + getCreateParamJsonObj: function(){ + return createParamJsonObj; + }, loadGetServiceData : function() { //load main Table return $http({ - url: '/openoapi/inventory/v1/services', + url: '/openoapi/servicegateway/v1/services', //url: 'http://localhost:5000/api/getLCData', method: 'GET', headers: {'Content-Type': 'application/json'} @@ -20,8 +28,8 @@ app.factory("DataService", function($http, $log){ 'serviceId': ""})*/ }).then(function(response){ //$log.info(response); - lcData = response.data.lcData; - return response.data; + lcData = response; + return response; }); }, getSavedLCData : function(id){ @@ -71,44 +79,664 @@ app.factory("DataService", function($http, $log){ headers: {'Content-Type': 'application/json'} }).then(function(response){ //$log.info(response); - return response.data.templateData; + return response.data; }); }, - fetchCreateParameters : function(templateId) { - //For Template parameters tab in popup - return $http({ - url: '/openoapi/catalog/v1/servicetemplates/'+templateId, - // url: 'http://localhost:5000/api/getTemplateParameter', - method: 'GET', - headers: {'Content-Type': 'application/json'} - }).then(function(response){ - //$log.info(response); - return response.data; + generateCreateParameters : function(template) { + // For Template parameters tab in popup + return $.when(fetchCreateParameters(template.serviceTemplateId)) + .then(function(createParam) { + // set the create param object + createParamJsonObj = createParam; + // convert the create param to UI. + return convertCreateParamsToUI('create', createParam.parameters); + }); }, - createServiceInstance : function(lifecycleData, sengMsgObj) { - ///For submit of OK button - var parameter = { - 'service' : { - 'name' : lifecycleData.name, - 'description' : lifecycleData.desc, - 'serviceDefId' : '', //no need now, reserved - 'templateId' : lifecycleData.optSelect, - 'parameters' : sengMsgObj - } - }; - return $http({ - url: '/openoapi/servicegateway/v1/services', - //url: 'http://localhost:5000/api/getTemplateData', - method: 'POST', - headers: {'Content-Type': 'application/json'}, - data : JSON.stringify(parameter) - }).then(function(response){ - //$log.info(response); - return response.data.templateData; + createService : function(serviceBaseInfo) { + if (!checkInputs('create', createParamJsonObj.parameters)) { + return {status:'checkfailed'}; + } + var sengMsgObj = collectCreateParamfromUI('', 'create', createParamJsonObj.parameters); + var gatewayService = '/openoapi/servicegateway/v1/services'; + return createServiceInstance(serviceBaseInfo, sengMsgObj); + }, + + deleteService : function(serviceId) { + return deleteServiceInstance(serviceId); + } + } +}); + +/** + * init parameter tab + * @returns + */ +function initParameterTab() { + // Service template was not changed. Do not re-initiate the parameter tab. + if (!templateParameters.changed) { + return; + } + var templateId = $("#svcTempl").val(); + if ('select' === templateId) { + document.getElementById("templateParameterTab").innerHTML = ''; + return; + } + $.when(fetchCreateParameters(templateId)) + .then(function(createParam) { + // set the create param object + templateParameters.paramJsonObj = createParam.parameters; + // convert the create param to UI. + var components = convertCreateParamsToUI('create', createParam.parameters); + document.getElementById("templateParameterTab").innerHTML = components; + templateParameters.changed = false; + }); +} + +/** + * generate the template to create parameters object + * + * @param templateId + * the template id + * @returns + */ +function fetchCreateParameters(templateId) { + //return $.getJSON("./conf/queryCreateParams.json"); + var uri = '/openoapi/servicegateway/v1/createparameters/' + templateId; + return $.ajax({ + type : "GET", + url : uri, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Generate parameters failed.", xhr.responseText); + } + }); +} + +/** + * convert the template params obj to html UI string + * + * @param identify the object identify, it should be '' when called + * @return the html component string + */ +function convertCreateParamsToUI(identify, createParam) { + var components = ''; + // convert host to UI + if (undefined != createParam.domainHost && 'enum' === createParam.domainHost.type) { + components = components + + generateParamComponent(createParam.nodeType, identify, + createParam.domainHost, false); + } + // convert own locationConstraints to UI + if(undefined != createParam.nsParameters.locationConstraints){ + createParam.nsParameters.locationConstraints.forEach(function(param) { + components = components + + generateParamComponent(createParam.nodeType, + identify, param.locationConstraints.vimId, false); + }); + } + + // convert own param to UI + createParam.nsParameters.additionalParamForNs + .forEach(function(param) { + components = components + + generateParamComponent(createParam.nodeType, + identify, param, false); }); + // convert segments to UI + createParam.segments.forEach(function(segment) { + // each segment in a field set. + components = components + '
' + + segment.nodeTemplateName + ''; + // the identify for segment + var segmentIdentify = '' == identify ? segment.nodeTemplateName + : identify + '_' + segment.nodeTemplateName; + // convert segment to UI + components = components + + convertCreateParamsToUI(segmentIdentify, segment); + components = components + '
'; + }); + return components; +} + + +/** + * for each required parameter it could not be empty + * @param identify the identify of a segment + * @param createParam the create param object + * @returns the check result + */ +function checkInputs(identify, createParam) { + //check domain host + if (undefined != createParam.domainHost && 'enum' === createParam.domainHost.type) { + var value = collectParamValue(identify, createParam.domainHost); + if ('select' == value) { + var name = getParamLabel(createParam.nodeType, createParam.domainHost); + alert( name + ' is required.') + return false; + } + } + //check location constraints + if(undefined != createParam.nsParameters.locationConstraints){ + for(var i= 0; i < createParam.nsParameters.locationConstraints.length; i++){ + var param = createParam.nsParameters.locationConstraints[i].locationConstraints.vimId; + var value = collectParamValue(identify, param); + if('true' === param.required && ('' === value || ('enum' == param.type && 'select' == value))){ + // the param resource key is nodeType.paramName + var name = getParamLabel(createParam.nodeType, param); + alert(name + ' is required.') + return false; + } } } -}); \ No newline at end of file + + // check parameters + for(var i= 0; i < createParam.nsParameters.additionalParamForNs.length; i++){ + var param = createParam.nsParameters.additionalParamForNs[i]; + var value = collectParamValue(identify, param); + if('true' === param.required && ('' === value || ('enum' == param.type && 'select' == value))){ + // the param resource key is nodeType.paramName + var name = getParamLabel(createParam.nodeType, param); + alert(name + ' is required.') + return false; + } + } + // get segments param value from UI + var segmentcheckResult = true; + for(var i= 0; i < createParam.segments.length; i++){ + var segment = createParam.segments[i]; + // the identify for segment + var segmentIdentify = '' == identify ? segment.nodeTemplateName + : identify + '_' + segment.nodeTemplateName; + segmentcheckResult = checkInputs(segmentIdentify, segment); + if (!segmentcheckResult) { + break; + } + } + return segmentcheckResult; +} + + +/** + * convert the template params obj to html UI string + * + * @param identify the object identify, it should be different every time + * @return the html component string + */ +function collectCreateParamfromUI(parentHost,identify, createParam) { + // the create params used for create msg + var paramSentObj = { + domainHost:'', + nodeTemplateName:'', + nodeType:'', + segments:[], + nsParameters:{} + }; + // get the domain value + if (undefined != createParam.domainHost && 'enum' === createParam.domainHost.type) { + var domain = collectParamValue(identify, createParam.domainHost); + paramSentObj.domainHost = collectParamValue(identify, createParam.domainHost) + } + //if parent domainHost is not '' and local domain host is'', it should be setted as parent + if('' != parentHost && '' == paramSentObj.domainHost){ + paramSentObj.domainHost = parentHost; + } + paramSentObj.nodeTemplateName = createParam.nodeTemplateName; + paramSentObj.nodeType = createParam.nodeType; + + //get location constraints + if(undefined != createParam.nsParameters.locationConstraints){ + paramSentObj.nsParameters['locationConstraints'] = []; + createParam.nsParameters.locationConstraints.forEach(function(param) { + var locationConstraints = {}; + locationConstraints['vnfProfileId'] = param.vnfProfileId; + locationConstraints['locationConstraints'] = {}; + locationConstraints.locationConstraints['vimId'] = collectParamValue(identify, param.locationConstraints.vimId); + paramSentObj.nsParameters.locationConstraints.push(locationConstraints); + }); + } + + paramSentObj.nsParameters['additionalParamForNs'] = {}; + // get own param value from UI + createParam.nsParameters.additionalParamForNs.forEach(function(param) { + paramSentObj.nsParameters.additionalParamForNs[param.name] = collectParamValue(identify, param); + }); + // get segments param value from UI + createParam.segments.forEach(function(segment) { + // the identify for segment + var segmentIdentify = '' == identify ? segment.nodeTemplateName + : identify + '_' + segment.nodeTemplateName; + var segmentObj = collectCreateParamfromUI(paramSentObj.domainHost, segmentIdentify, segment); + paramSentObj.segments.push(segmentObj); + }); + return paramSentObj; +} + +/** + * get a param value + * @param identify the identify of a segment + * @param param the param object + * @returns the value of the param + */ +function collectParamValue(identify, param) { + var value = $('#' + getParamId(identify, param)).val(); + return value; +} + +/** + * get the param id in ui + * @param identify + * @param param + * @returns + */ +function getParamId(identify, param) { + return '' ===identify ? param.name : identify + '_' + param.name; +} + +/** + * get the resource string of a param. + * @param nodeType node type + * @param param param object + * @returns resource string + */ +function getParamLabel(nodeType, param) { + //var name = $.i18n.prop(nodeType + '.' + param.name); + var name = param.name; + if (name.length === 0 || name.slice(0, 1) === '[') { + name = param.name; + } + return name; +} +/** + * convert combox component + * + * @param inputPara + * @param items + * @param stringReadOnly + * @returns + */ +function generateParamComponent(nodeType, identify, param, strReadOnly) { + // the param resource key is nodeType.paramName + var name = getParamLabel(nodeType, param); + var id = getParamId(identify,param); + var component = ''; + if (param.type === 'string') { + component = '
' + + '' + + '
'+ '
'; + }else{ + component = component + '"/>'+ ''; + } + + } else if (param.type === 'enum') { + component = '
' + + '' + + '
' + + '
'; + } + return component; +} + +/** + * transfer the enum range to html body + * @param items the map of the range + * @returns the html string + */ +function transformToOptions(items) { + var options = ''; + var i; + for ( var key in items) { + var option = ''; + options = options + option; + } + return options; +} + +/** + * generate required identify to html string + * @param parameter the parameter object + * @returns the html string + */ +function generateRequiredLabel(parameter) { + var requiredLabel = ''; + if (parameter.required === 'true') { + requiredLabel = '*'; + } + return requiredLabel; +} + +/** + * create service + * @param sengMsgObj the parameters + * @returns + */ +function createServiceInstance(serviceBaseInfo, sengMsgObj) { + var defer = $.Deferred(); + var parameter = { + 'service' : { + 'name' : serviceBaseInfo.name, + 'description' : serviceBaseInfo.description, + 'serviceDefId' : '', //no need now, reserved + 'templateId' : serviceBaseInfo.templateId, + 'parameters' : sengMsgObj + } + }; + var serviceGatewayUri = '/openoapi/servicegateway/v1/services'; + $.when($.ajax({ + type : "POST", + url : serviceGatewayUri, + contentType : "application/json", + dataType : "json", + data : JSON.stringify(parameter), + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Create service failed.", xhr.responseText); + } + })) + .then(function(response) { + return queryProgress('create service', response.service.serviceId,response.service.operationId); + }).then(function(result){ + defer.resolve(result); + }); + return defer; +} + +/** + * sent delete instance msg + * @param serviceId the service id + * @returns + */ +function deleteServiceInstance(serviceId) { + var defer = $.Deferred(); + var deleteUrl = '/openoapi/servicegateway/v1/services/' + serviceId; + var parameter = {}; + $.when($.ajax({ + type : "DELETE", + url : deleteUrl, + contentType : "application/json", + dataType : "json", + data : JSON.stringify(parameter), + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Delete service failed.", xhr.responseText); + } + })) + .then(function(response) { + return queryProgress('delete service', serviceId,response.operationId); + }).then(function(result){ + defer.resolve(result); + }); + return defer; +} + +/** + * query progress of the operation + * @param operation the operation string + * @param serviceId the service id + * @param operationId the operation id + * @returns + */ +function queryProgress(operation, serviceId, operationId) { + //show the progress dialog + $( "#idProgressTitle" ).text(operation); + $( "#progressContent" ).text('status:'); + $( "#progressbar" ).attr("style","width: 0%"); + $( "#progressDialog" ).modal({backdrop:'static', keyboard:false}); + //set a timer for query operation + var defer = $.Deferred(); + var queryProgressUril = '/openoapi/servicegateway/v1/services/' + serviceId + '/operations/' + operationId; + var timerDefer = $.Deferred(); + var timeout = 3600000; + var fun = function() { + if (timeout === 0) { + timerDefer.resolve({ + status : 'error', + reason : operation + ' timeout!', + }); + return; + } + timeout = timeout - 1000; + $.when($.ajax({ + type : "GET", + url : queryProgressUril, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query progress failed.", xhr.responseText); + } + })) + .then(function(response) { + //update progress + $( "#progressbar" ).attr("style","width: " + response.operation.progress.toString() + "%"); + $( "#progressValue" ).text(response.operation.progress.toString() + '%'); + $( "#progressContent" ).text('status: ' + response.operation.operationContent); + if (response.operation.result == 'finished' || response.operation.result == 'error') { + timerDefer.resolve({ + status : response.operation.result , + reason : response.operation.reason + }); + } + }); + }; + var timerId = setInterval(fun, 1000); + $.when(timerDefer) + .then(function(responseDesc) { + clearInterval(timerId); + $('#progressDialog').modal('hide'); + defer.resolve({ + status : responseDesc.status, + reason : responseDesc.reason, + serviceId:serviceId + }); + + }); + return defer; +} + + +/** + * convert the input parameters to ui + * @param identify the identify of a segment + * @param createParam the create param object + * @returns the check result + */ +function convertInputsToUI(parentHost, identify, serviceParam) { + var components = ''; + // convert host to UI + if (undefined != serviceParam.domainHost && '' != serviceParam.domainHost && parentHost != serviceParam.domainHost) { + var param ={ + name:'domainHost', + type:'string', + defaultValue:getShowVal('domainHost', serviceParam.domainHost), + required:false + } + components = components + generateParamComponent(serviceParam.nodeType, identify, + param, true); + } + //convert location constraints to UI + if(undefined != serviceParam.nsParameters.locationConstraints){ + serviceParam.nsParameters.locationConstraints.forEach(function(param) { + var showValue = getShowVal('location', param.locationConstraints.vimId) + var param ={ + name: param.vnfProfileId + '_Location', + type:'string', + defaultValue:showValue, + required:false + } + components = components + generateParamComponent(serviceParam.nodeType, + identify, param, true); + }); + } + + // convert own param to UI + for(var key in serviceParam.nsParameters.additionalParamForNs ){ + var param ={ + name: key, + type:'string', + defaultValue:getShowVal(key, serviceParam.nsParameters.additionalParamForNs[key]), + required:false + } + components = components + generateParamComponent(serviceParam.nodeType, + identify, param, true); + } + // convert segments to UI + serviceParam.segments.forEach(function(segment) { + // each segment in a field set. + components = components + '
' + + segment.nodeTemplateName + ''; + // the identify for segment + var segmentIdentify = '' == identify ? segment.nodeTemplateName + : identify + '_' + segment.nodeTemplateName; + // convert segment to UI + components = components + + convertInputsToUI(serviceParam.domainHost, segmentIdentify, segment); + components = components + '
'; + }); + return components; +} + +function getShowVal(paramName, paramValue){ + if(paramName == 'domainHost'){ + return getHostNameByVal(paramValue); + } + else if(paramName == 'location'){ + return getVimNameById(paramValue); + } + else if(paramName == 'sdncontroller'){ + return getSdnControllerNameById(paramValue); + } + else{ + return paramValue; + } +} + +function getHostNameByVal(hostDomain){ + var requestUrl ="/openoapi/servicegateway/v1/domains"; + var returnObj = ''; + $.ajax({ + type : "GET", + async: false, + url : requestUrl, + contentType : "application/json", + success : function(jsonobj) { + jsonobj.forEach(function(host){ + if(host.host == hostDomain){ + returnObj = host.name; + } + }); + }, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query host failed.", xhr.responseText); + } + }); + return returnObj; +} + +//get the vim name by id. +function getVimNameById(vimId){ + var requestUrl ="/openoapi/extsys/v1/vims/" + vimId; + var returnObj; + $ + .ajax({ + type : "GET", + async: false, + url : requestUrl, + contentType : "application/json", + success : function(jsonobj) { + // TODO return according to the json data received. + returnObj = jsonobj.name; + }, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query vims failed.", xhr.responseText); + } + }); + return returnObj; +} + +//get the sdn controller name by id. +function getSdnControllerNameById(sdnControllerId){ + var requestUrl ="/openoapi/extsys/v1/sdncontrollers/" + sdnControllerId; + var returnObj; + $ + .ajax({ + type : "GET", + async: false, + url : requestUrl, + contentType : "application/json", + success : function(jsonobj) { + // TODO return according to the json data received. + returnObj = jsonobj.name; + }, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query sdn controllers failed.", xhr.responseText); + } + }); + return returnObj; +} + + + +/** + * show error dialog + * @param title the title + * @param result the result + * @returns + */ +function showErrorMessage(title, result) { + //show the error dialog + $( "#errorDialogTitle" ).text(title); + if(undefined != result.reason){ + $( "#errorDialogReason" ).text(result.reason); + } + else{ + $( "#errorDialogReason" ).text(result); + } + $( "#errorDialog" ).modal({backdrop:'static', keyboard:false}); +} + +/** + * generate the template to create parameters object + * + * @param templateId the template id + * @returns + */ +function queryService(serviceId) { + var uri = '/openoapi/servicegateway/v1/services/' + serviceId; + return $.ajax({ + type : "GET", + url : uri, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query service failed.", xhr.responseText); + } + }); +} + +function queryServiceData(){ + var returnVal = []; + var requestUrl = "/openoapi/servicegateway/v1/services"; + $ + .ajax({ + type : "GET", + url : requestUrl, + async: false, + contentType : "application/json", + success : function(jsonobj) { + // TODO return according to the json data received. + returnVal = jsonobj; + }, + error : function(xhr, ajaxOptions, thrownError) { + showErrorMessage("Query services fail",xhr.responseText); + } + }); + return returnVal; +} \ No newline at end of file diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js index 7293f0de..8a4d1e38 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js @@ -100,8 +100,8 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' DataService.loadGetServiceData() .then(function (data) { if (data) { - $scope.tableData = data.lcData; - var tableData = data.lcData; + $scope.tableData = data.data; + var tableData = data.data; loadTableData(); } else { @@ -191,11 +191,11 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' var number = $(modelTemplate).filter('#numeric').html(); var dropDown = $(modelTemplate).filter('#simpleDropdownTmpl').html(); - var dataText = {"ErrMsg" : {"textboxErr" : "Service name is required.", "modalVar":"lifecycleData.name", "placeholder":"Service Name"}}; + var dataText = {"ErrMsg" : {"textboxErr" : "Service name is required.", "modalVar":"lifecycleData.serviceName", "placeholder":"Service Name"}}; $('#myModal .serviceName').html($compile(Mustache.to_html(text, dataText.ErrMsg))($scope)); - var TempNameText = {"ErrMsg" : {"textboxErr" : "Template name is required.", "modalVar":"lifecycleData.template", "placeholder":"Template Name"}}; - $('#myModal .templateName').html($compile(Mustache.to_html(text, TempNameText.ErrMsg))($scope)); + var serviceDescriptionText = {"ErrMsg" : {"textboxErr" : "Description is required.", "modalVar":"lifecycleData.description", "placeholder":"Descritpion"}}; + $('#myModal .serviceDescription').html($compile(Mustache.to_html(text, serviceDescriptionText.ErrMsg))($scope)); //var creatorText = {"ErrMsg" : {"textboxErr" : "Creator is required.", "modalVar":"lifecycleData.creator", "placeholder":"Creator"}}; /*$scope.data = { @@ -275,15 +275,18 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' } $scope.templateParam = function() { - //$scope.lifecycleData.optSelect = 1.2; - //$log.info($scope.lifecycleData); - - DataService.fetchCreateParameters($scope.lifecycleData.optSelect) + + var template = $scope.lifecycleData.optSelect; + var lastSelTempCreateParam = DataService.getCreateParamJsonObj(); + //if the template not changed, no need to update the page. + if(lastSelTempCreateParam.templateId == template.serviceTemplateId){ + return; + } + $.when(DataService.generateCreateParameters(template)) .then(function (tmplatesParamResponse) { console.log("Data Param Template :: "); $log.info(tmplatesParamResponse); - $scope.paramJsonObj= tmplatesParamResponse.templateName; - + document.getElementById("templateParameters").innerHTML = tmplatesParamResponse; }, function (reason) { $scope.error = "Error ! " + reason; }); @@ -329,61 +332,58 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' } $scope.saveData = function() { - //TODO - var sengMsgObj = {};//collectCreateParamfromUI('', 'create', $scope.templateParameters.paramJsonObj); - //createServiceInstance(sengMsgObj) - DataService.createServiceInstance(lifecycleData, sengMsgObj) + //collect service base info + var serviceBaseInfo = { + 'name' : $scope.lifecycleData.serviceName, + 'description' : $scope.lifecycleData.description, + 'templateId' : $scope.lifecycleData.optSelect.serviceTemplateId, + }; + //send message + $.when(DataService.createService(serviceBaseInfo)) .then(function (response) { $log.info(response); - //TODO - }, function (reason) { - $scope.error = "Error ! " + reason; + if(response.sataus === 'checkfailed'){ + return; + }else if (response.status === 'finished') { + $.when(queryService(response.serviceId)).then(function(serviceInstance){ + $scope.tableData.push(serviceInstance); + $scope.$apply(); + $scope.tableParams.reload(); + $('#myModal').modal('hide'); + }); + } else{ + showErrorMessage('Create service failed',response); + } }); } - - /** - * convert the template params obj to html UI string - * - * @param identify the object identify, it should be different every time - * @return the html component string - */ - function collectCreateParamfromUI(parentHost,identify, createParam) { - // the create params used for create msg - var paramSentObj = { - domainHost:'', - nodeTemplateName:'', - nodeType:'', - segments:[], - additionalParamForNs:{} + $scope.deleteIndividualData = function(id){ + var deleteHandle = function(result) { + if (result) { + var remove = function() { + var pos = 0; + for(var i= 0; i < $scope.tableData.length; i++){ + if($scope.tableData[i].serviceId === id){ + pos = i; + break; + } + } + $scope.tableData.splice(pos, 1); + $scope.$apply(); + $scope.tableParams.reload(); + }; + $.when(DataService.deleteService(id)) + .then(function(response) { + if (response.status === 'finished') { + remove(); + } else { + showErrorMessage('Delete service failed',response); + } + }); + } }; - // get the domain value - if (undefined != createParam.domainHost && 'enum' === createParam.domainHost.type) { - var domain = collectParamValue(identify, createParam.domainHost); - paramSentObj.domainHost = collectParamValue(identify, createParam.domainHost) - } - //if parent domainHost is not '' and local domain host is'', it should be setted as parent - if('' != parentHost && '' == paramSentObj.domainHost){ - paramSentObj.domainHost = parentHost; - } - paramSentObj.nodeTemplateName = createParam.nodeTemplateName; - paramSentObj.nodeType = createParam.nodeType; - - // get own param value from UI - createParam.additionalParamForNs.forEach(function(param) { - paramSentObj.additionalParamForNs[param.name] = collectParamValue(identify, param); - }); - // get segments param value from UI - createParam.segments.forEach(function(segment) { - // the identify for segment - var segmentIdentify = '' == identify ? segment.nodeTemplateName - : identify + '_' + segment.nodeTemplateName; - var segmentObj = collectCreateParamfromUI(paramSentObj.domainHost, segmentIdentify, segment); - paramSentObj.segments.push(segmentObj); - }); - return paramSentObj; + bootbox.confirm("Do you confirm to delete service?", deleteHandle); } - }) .controller('lcTabsCtrl', function($scope, $state, $stateParams) { diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html b/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html index 64965614..f901ab6f 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html @@ -7,25 +7,25 @@
- + + {{lcData.templateName}} + {{lcData.createTime}}
- + - {{lcData.name}} + {{lcData.serviceName}} - {{lcData.template}} - {{lcData.createtime}} {{lcData.creator}} - - + +
@@ -66,8 +66,8 @@
- -
+ +
@@ -83,10 +83,6 @@
-
- -
{{paramJsonObj}}
-
@@ -94,4 +90,37 @@ - \ No newline at end of file + + + -- cgit 1.2.3-korg