2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 angular.module('abs').controller('dcaeMicroServiceController', ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
24 $scope.policyNavigator;
25 $scope.isCheck = false;
26 $scope.savebutton = true;
27 $scope.refreshCheck = false;
31 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
32 $scope.temp.policy = {
33 policyType : "Config",
34 configPolicyType : "Micro Service"
38 $scope.refresh = function(){
39 if($scope.refreshCheck){
40 $scope.policyNavigator.refresh();
42 $scope.modal('createNewPolicy', true);
43 $scope.temp.policy = "";
46 $scope.modal = function(id, hide) {
47 return $('#' + id).modal(hide ? 'hide' : 'show');
50 $('#ttlDate').datepicker({
51 dateFormat: 'dd/mm/yy',
54 onSelect: function(date) {
55 angular.element($('#ttlDate')).triggerHandler('input');
59 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
60 if ($scope.temp.policy.configName == undefined){
61 $scope.isCheck = false;
63 $scope.isCheck = true;
66 $scope.isCheck = false;
69 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
74 console.log($scope.onapNameDictionaryDatas);
76 console.log("failed");
79 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
84 console.log($scope.priorityDatas);
86 console.log("failed");
89 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
94 console.log($scope.groupPolicyScopeListDatas);
96 console.log("failed");
99 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
101 $scope.data = JSON.parse(j.data);
102 console.log($scope.data);
103 console.log("$scope.data.microServiceConfigNameDictionaryDatas : " + $scope.data.microServiceConfigNameDictionaryDatas);
104 if($scope.data.microServiceConfigNameDictionaryDatas){
105 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceConfigNameDictionaryDatas);
107 console.log($scope.microServiceCongigNameDictionaryDatas);
108 }, function (error) {
109 console.log("failed");
112 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
114 $scope.data = JSON.parse(j.data);
115 console.log($scope.data);
116 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
117 console.log($scope.microServiceLocationDictionaryDatas);
118 }, function (error) {
119 console.log("failed");
122 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
124 $scope.data = JSON.parse(j.data);
125 console.log($scope.data);
126 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
129 for(var i = 0; i < inputModelList.length; i++){
130 if(typeof unique[inputModelList[i]] == "undefined"){
131 unique[inputModelList[i]] = "";
132 uniqueList.push(inputModelList[i]);
135 $scope.microServiceModelsDictionaryDatas = uniqueList;
136 console.log($scope.microServiceModelsDictionaryDatas);
137 }, function (error) {
138 console.log("failed");
141 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
143 $scope.data = JSON.parse(j.data);
144 console.log($scope.data);
145 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
146 console.log($scope.dcaeUUIDDictionaryDatas);
147 }, function (error) {
148 console.log("failed");
151 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
153 $scope.data = JSON.parse(j.data);
154 console.log($scope.data);
155 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
156 console.log($scope.riskTypeDictionaryDatas);
157 }, function (error) {
158 console.log("failed");
161 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
163 $scope.data = JSON.parse(j.data);
164 console.log($scope.data);
165 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
166 console.log($scope.microServiceAttributeDictionaryDatas);
167 }, function (error) {
168 console.log("failed");
173 $scope.attributeDatas = [{"attributes" : $scope.choices}];
174 addNewChoice = function(value) {
175 console.log("input key : " + value);
176 var isFoundInRuleData = false;
177 if(value != undefined){
178 if (value.startsWith('div.')){
179 value = value.replace('div.','');
182 console.log(" document.getElementById : div."+value);
183 var parentElement = document.getElementById("div."+value);
184 console.log("parentElement : " + parentElement);
185 var div = document.getElementById(value+"@0");
187 var clone = div.cloneNode(true);
188 var addElement = parentElement.childElementCount;
189 clone.id = ''+value+'@'+addElement;
191 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ //if it's view or edit
192 if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){ // Only append child if its value found in ruleData or edit mode
193 if($scope.temp.policy.ruleData[clone.id]){
194 clone.value = $scope.temp.policy.ruleData[clone.id];
195 isFoundInRuleData = true;
197 console.log(" clone.value :" + clone.value);
198 console.log(" clone.id :" + clone.id);
199 if(!isFoundInRuleData && isInitViewEdit){
202 if(!clone.className.includes("child_single")){
203 clone.className += ' child_single'; //here cloned is single element
205 document.getElementById("div."+value).appendChild(clone);
206 plainAttributeKeys.push(''+value+'@'+addElement);
208 }else{ //not view or edit
209 if(!clone.className.includes("child_single")){
210 clone.className += ' child_single'; //here cloned is single element
212 document.getElementById("div."+value).appendChild(clone);
213 plainAttributeKeys.push(''+value+'@'+addElement);
217 if(parentElement == null){
220 div = document.getElementById("div."+value+"@0");
223 if(!div.className.includes('children_group border')){
228 div.className += ' children_group border' + layer; //here is div with a group of children.
231 var childElement = parentElement.firstElementChild;
232 var countParent = parentElement.childElementCount;
233 var childElementString = childElement.innerHTML;
234 var find = value+"@0";
235 var re = new RegExp(find, 'g');
236 childElementString = childElementString.replace(re,value+'@' + countParent);
237 var clone = childElement.cloneNode(true);
238 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
239 var childId = parentElement.childNodes[ii].id;
240 if(ii = parentElement.childNodes.length){
241 var childnewId = childId.slice(0, -1);
242 var count = childId.slice(-1);
245 var countvalue = parseInt(count) + 1;
246 clone.id = childnewId+countvalue;
248 clone.innerHTML=childElementString;
249 document.getElementById("div."+value).appendChild(clone);
250 var selects = clone.getElementsByTagName("select");
251 var inputs = clone.getElementsByTagName("input");
252 var removeValues = [];
253 for(var i=0; i<inputs.length; i++){
254 if ($scope.temp.policy.ruleData!=undefined){
255 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
256 console.log(" checkValue.value :" + checkValue);
257 console.log(" inputs["+i+"].id :" + inputs[i].id);
258 if (checkValue!=undefined && checkValue != "undefined"){
259 document.getElementById(inputs[i].id).value = checkValue;
260 plainAttributeKeys.push(inputs[i].id);
262 plainAttributeKeys.push(inputs[i].id);
265 plainAttributeKeys.push(inputs[i].id);
269 for(var i=0; i<selects.length; i++){
270 if ($scope.temp.policy.ruleData!=undefined){
271 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
272 if (checkValue!=undefined && checkValue!="undefined"){
273 if($scope.temp.policy.ruleData != null){
274 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
275 var option = document.createElement('option');
276 option.setAttribute('value', checkValue);
277 option.appendChild(document.createTextNode(checkValue));
278 document.getElementById(selects[i].id).appendChild(option);
279 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
280 plainAttributeKeys.push(selects[i].id);
283 plainAttributeKeys.push(selects[i].id);
286 plainAttributeKeys.push(selects[i].id);
290 for (var k=0; k<removeValues.length; k++){
291 var elem = document.getElementById(removeValues[k]);
292 elem.parentNode.removeChild(elem);
294 var ele = angular.element(document.getElementById("div."+value));
295 $compile(ele.contents())($scope)
301 removeChoice = function(value) {
303 if(value != undefined){
304 var c = document.getElementById("div."+value).childElementCount;
307 Notification.error("The original one is not removable.");
310 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
314 function findVal(object, key) {
316 Object.keys(object).some(function(k) {
321 if (object[k] && typeof object[k] === 'object') {
322 value = findVal(object[k], key);
323 return value !== undefined;
329 $scope.pullVersion = function(serviceName) {
330 console.log(serviceName);
331 if(serviceName != undefined){
332 var uuu = "policyController/getModelServiceVersioneData.htm";
333 var postData={policyData: serviceName};
338 contentType: 'application/json',
339 data: JSON.stringify(postData),
340 success : function(data){
341 $scope.$apply(function(){
342 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
345 error : function(data){
346 alert("Error While Retriving the Template Layout Pattren.");
353 var splitEqual = '=';
354 var splitComma = ',';
355 var splitcolon = ':';
356 var splitsemicolon = ";";
357 var splitEnum = "],";
358 var plainAttributeKeys = [];
360 var enumKeyList = [];
361 var dictionaryList = [];
362 var dictionaryNameList = [];
363 var isInitViewEdit = false;
364 $scope.addDataToFields = function(serviceName, version){
365 if(serviceName != null && version !=null){
366 var service=serviceName+"-v"+version;
367 var myNode = document.getElementById("DynamicTemplate");
368 myNode.innerHTML = '';
369 var uuu = "policyController/getDCAEMSTemplateData.htm";
370 var postData={policyData: service};
372 console.log("service: " +service);
374 var dataOrderInfo = "";
376 booleanTrueElements = [];
378 document.getElementById("msPolicyloader").style.visibility = "visible";
384 contentType: 'application/json',
385 data: JSON.stringify(postData),
386 success : function(data){
388 document.getElementById("msPolicyloader").style.visibility = "hidden";
390 $scope.$apply(function(){
391 var plainAttributeKeys = [];
392 $scope.dcaeModelData = data[0].dcaeModelData;
393 $scope.dcaeJsonDate = data[0].jsonValue;
394 $scope.dataOrderInfo = null;
395 $scope.dataOrderInfo = data[0].dataOrderInfo;
396 console.log("data[0].dataOrderInfo: " + data[0].dataOrderInfo);
397 console.log("$scope.dataOrderInfo: " + $scope.dataOrderInfo);
399 if(data[0].allManyTrueKeys){
400 console.log("$scope.allManyTrueKeys: " + $scope.allManyTrueKeys);
402 console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
403 var attributes = $scope.dcaeModelData.attributes;
404 console.log("attributes: " +attributes);
405 var refAttributes = $scope.dcaeModelData.ref_attributes;
406 var subAttributes = $scope.dcaeModelData.sub_attributes;
407 console.log("subAttributes: " + subAttributes);
408 console.log("refAttributes: " + refAttributes);
409 var headDefautlsData = data[0].headDefautlsData;
410 if(headDefautlsData != null){
411 $scope.temp.policy.onapName = headDefautlsData.onapName;
412 $scope.temp.policy.guard = headDefautlsData.guard;
413 $scope.temp.policy.riskType = headDefautlsData.riskType;
414 $scope.temp.policy.riskLevel = headDefautlsData.riskLevel;
415 $scope.temp.policy.priority = headDefautlsData.priority;
418 var enumAttributes = $scope.dcaeModelData.enumValues;
419 var annotation = $scope.dcaeModelData.annotation;
420 var dictionary = $scope.microServiceAttributeDictionaryDatas;
422 if (annotation == null || annotation.length<1){
423 $scope.isCheck = true;
425 $scope.isCheck = false;
426 var annoationList = annotation.split(splitComma);
427 for (k = 0; k < annoationList.length; k++){
428 var splitAnnotation = annoationList[k].split(splitEqual);
429 if (splitAnnotation[1].includes("matching-true")){
430 matching.push(splitAnnotation[0].trim());
436 if (dictionary!= null && dictionary.length>1){
437 for (m=0; m < dictionary.length; m += 1){
438 var keyCompare = dictionary[m].name;
439 var valueCompare = dictionary[m].value;
440 var valueModel = dictionary[m].modelName;
441 var conpairService = serviceName;
442 if (valueModel.includes('-v')){
443 conpairService = service;
445 if(valueModel.localeCompare(conpairService) == 0){
446 console.log(valueCompare);
447 dictionaryList.push(dictionary[m]);
448 if (!dictionaryNameList.includes(dictionary[m].name)){
449 dictionaryNameList.push(dictionary[m].name)
455 $scope.temp.policy.ruleGridData = [];
457 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
458 dataOrderInfo = $scope.dataOrderInfo;
461 $scope.jsonLayout($scope.dcaeJsonDate);
465 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ // If it's veiw or edit
466 isInitViewEdit = true;
469 // If ruleData contains extra elements created by clicked add button
470 console.log("$scope.temp.policy.ruleData:" + $scope.temp.policy.ruleData);
471 if($scope.temp.policy.ruleData != null){
472 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
473 propNames.forEach(function(name) {
477 var extraElements = data;
479 if(plainAttributeKeys != null){
480 for(var b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array
481 var newValue = plainAttributeKeys[b].split("*");
482 for(var a = 0; a < data.length; a++){
483 if(data[a] === newValue[0] || data[a] === (newValue[0]+"@0")){
484 extraElements.splice(a, 1);
489 //--- Populate these extra elements created by clicked add button
490 for(var a = 0; a < extraElements.length; a++){
491 if(extraElements[a].includes("@")){
492 var index = extraElements[a].lastIndexOf("@");
494 // Get the number after @
495 var n = getNumOfDigits(extraElements[a], index+1);
497 var key = extraElements[a].substring(0, index+n+1); //include @x in key also by n+2 since x can be 1,12, etc
498 console.log("key: " + key);
503 var unique = checkData.filter(onlyUnique);
504 var parentLevelElements = [];
506 //--- get all root level exta elments first (only contains one "@")
507 for(var i =0; i < unique.length; i++){
508 var firstIndex = unique[i].indexOf("@");
509 var lastIndex = unique[i].lastIndexOf("@");
510 if(firstIndex == lastIndex){
511 var newKey = unique[i].substring(0, firstIndex);
512 console.log("root element: " + newKey);
513 parentLevelElements.push(newKey);
514 unique[i] = "*processed*";
520 for (var i = 0; i < $scope.labelManyKeys.length; i++) {
521 var label = $scope.labelManyKeys[i];
522 if(parentLevelElements){
523 for (var k = 0; k < parentLevelElements.length; k++){
524 if(label == parentLevelElements[k]){
531 //if no layout order info, keep the process as before
533 for(var i =0; i < unique.length; i++){
534 if(unique[i] != "*processed*"){
535 var index = unique[i].lastIndexOf("@");
536 var newKey = unique[i].substring(0, index);
537 console.log("newKey: " + newKey);
539 var newElement = document.getElementById("div."+unique[j]);
540 //check weather it has been created already
541 if(newElement != null){
544 newElement = document.getElementById(unique[j]);
545 if(newElement != null){
551 addNewChoice(newKey);
556 //---reset to default
558 $scope.labelManyKeys = [];
560 //---process none labels
561 for (var j = 0; j < unique.length; j++){
562 if(unique[j] != "*processed*"){
563 // if not created yet
564 if(!document.getElementById(unique[j])){
565 var index = unique[j].lastIndexOf("@");
566 var newKey = unique[j].substring(0, index);
568 var newElement = document.getElementById("div."+unique[j]);
570 //check weather it has been created already
571 if(newElement != null){
574 newElement = document.getElementById(unique[j]);
575 if(newElement != null){
579 //if not created yet, then create it.
580 addNewChoice(newKey);
590 var ele = angular.element(document.getElementById("DynamicTemplate"));
591 $compile(ele.contents())($scope);
593 isInitViewEdit = false;
596 error : function(data){
597 alert("Error While Retriving the Template Layout Pattren.");
604 function getNumOfDigits(str_value, index){
605 // Get the number after @
606 var str = str_value.substring(index, str_value.length);
609 for (var x = 0; x < str.length; x++){
620 function getDictionary(attribute){
621 var dicName = attribute;
623 if(attribute.includes(":")){
624 dicName = attribute.split(":")[0];
627 var dictionaryRegExp = new RegExp(dicName);
628 listemunerateValues = [];
629 if (dictionaryRegExp.test(dictionaryNameList)) {
630 for (p=0; p < dictionaryList.length; p += 1) {
631 if (dicName == dictionaryList[p].name) {
632 listemunerateValues.push(dictionaryList[p].value);
636 return listemunerateValues;
639 function getList(attribute) {
640 var enumName = attribute;
641 console.log("In getList: attribute => " + attribute);
643 if(attribute.includes(":")){
644 enumName = attribute.split(":")[0];
647 var baseEnum = $scope.dcaeModelData.enumValues;
649 if(baseEnum != null){
650 enumList = baseEnum.split(splitEnum);
653 var patternTest = new RegExp(enumName);
654 for (k=0; k < enumList.length; k += 1){
655 if(patternTest.test(enumList[k]) == true){
656 enumAttributes = enumList[k].trim();
661 enumAttributes = enumAttributes.replace("[", "");
662 enumAttributes = enumAttributes.replace("]", "");
663 enumAttributes = enumAttributes.replace(/ /g, '');
664 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
665 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
666 //enumKeyList.push(attribute);
667 return listemunerateValues;
673 function getBooleanList(){
674 var booleanList = [];
675 booleanList.push(true);
676 booleanList.push(false);
681 function isArray(arrayTest) {
682 return Object.prototype.toString.call(arrayTest) === '[object Array]';
686 $scope.layOutElementList = [];
687 $scope.layOutOnlyLableList = [];
689 var elementOrderNum = 0;
691 function deconstructJSON(layOutData, level , name) {
695 var stringValue = "java.lang.String";
696 var string = "string";
697 var intValue = "int";
698 var integerValue = "integer";
699 var double = "double";
700 var boolean = "boolean";
701 var baseLevel = level;
703 var String = "String";
705 var attributekey = "";
707 if (name.length > 1){
708 label = label + name + '.';
711 for (key in layOutData) {
712 array = isArray(layOutData[key]);
713 console.log("key: " + key , "value: " + layOutData[key]);
715 if (!!layOutData[key] && typeof(layOutData[key])=="object") {
717 if (array==false && key!=="0"){
719 if($scope.dataOrderInfo){
720 var labelObject = {"label" : key, "level" : label, "array" : array};
721 //save it to the list
722 $scope.layOutOnlyLableList.push(labelObject);
726 $scope.labelLayout(label, key, array );
731 if (array == true && key!=0){
735 if (lableList.length > 0){
739 var newKey = lableList.pop();
741 if($scope.dataOrderInfo){
743 var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array};
744 //save it to the list
745 $scope.layOutOnlyLableList.push(labelObject);
749 $scope.labelLayout(baseLevel, newKey, array );
753 label = baseLevel + newKey + '@0.';
755 label = baseLevel + newKey + '.';
758 deconstructJSON(layOutData[key] , label, key);
760 var attirbuteLabel = label;
763 var isRequired = false;
764 if (layOutData[key].includes('defaultValue-')){
765 defaultValue = layOutData[key].split('defaultValue-')[1];
768 if (layOutData[key].includes('description-')){
769 description = layOutData[key].split('description-')[1];
775 attributekey = lableList.pop();
776 attirbuteLabel = baseLevel;
778 attributekey = key.split();
781 if (layOutData[key].includes('required-true')){
785 var subAttributes = $scope.dcaeModelData.sub_attributes;
788 var jsonObject = JSON.parse(subAttributes);
790 var lablInfo = findVal(jsonObject, attributekey);
791 console.log("deconstructJSON:findValue : " + attributekey +": "+ lablInfo);
793 if(lablInfo.includes('required-true')){
796 if(lablInfo.includes('defaultValue-')){
797 defaultValue = lablInfo.split('defaultValue-')[1];
800 if(lablInfo.includes('description-')){
801 description = lablInfo.split('description-')[1];
805 var allkeys = Object.keys(jsonObject);
807 for (var k = 0; k < allkeys.length; k++) {
808 var keyValue = allkeys[k];
809 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
810 if(jsonObject[keyValue]){
811 var tempObject = jsonObject[keyValue];
812 if(tempObject && tempObject[key]){
813 if (tempObject[key].includes('required-true')){
817 if(tempObject[key].includes('defaultValue-')){
818 defaultValue = tempObject[key].split('defaultValue-')[1];
821 if(tempObject[key].includes('description-')){
822 description = tempObject[key].split('description-')[1];
832 var elementObject = {};
833 switch (layOutData[key].split(splitcolon)[0]){
837 if($scope.dataOrderInfo){
839 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"text", "description":description};
840 $scope.layOutElementList.push(elementObject);
842 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
847 if($scope.dataOrderInfo){
849 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"number" , "description":description};
850 $scope.layOutElementList.push(elementObject);
852 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "number");
856 if($scope.dataOrderInfo){
858 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"double", "description":description};
859 $scope.layOutElementList.push(elementObject);
861 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "double");
865 if($scope.dataOrderInfo){
867 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue, "isRequired": isRequired, "type":"boolean", "description":description};
868 $scope.layOutElementList.push(elementObject);
870 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], getBooleanList());
874 if (layOutData[key].includes('dictionary-')){
875 var list = getDictionary(layOutData[key].split('dictionary-')[1]);
877 //--- get dropdown values from enumValues
878 var list = getList(layOutData[key]);
880 if (list.length===0){ //not dropdown element
881 if($scope.dataOrderInfo){
883 elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description};
884 $scope.layOutElementList.push(elementObject);
887 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired, "text");
890 if($scope.dataOrderInfo){
892 elementObject = {"id": elementOrderNum, "attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "list":list, "type":"dropBox", "description":description};
893 $scope.layOutElementList.push(elementObject);
895 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, layOutData[key], list, isRequired);
905 $scope.validContionalRequired = function(parentId) {
906 console.log("ng-blur event: parentId : " + parentId);
907 var c = document.getElementById(parentId).children;
909 var hasValue = false;
910 for (i = 0; i < c.length; i++) {
911 if(c[i].getAttribute("data-conditional")){
912 console.log(c[i].getAttribute("data-conditional"));
913 console.log(c[i].value);
914 if(c[i].value != null && c[i].value.trim() != ""){
920 for (i = 0; i < c.length; i++) {
921 if(c[i].getAttribute("data-conditional")){
923 c[i].setAttribute("required", true);
925 c[i].removeAttribute("required");
931 $scope.jsonLayout = function(layOutData){
933 deconstructJSON(layOutData , "", "");
935 var orderValue = $scope.dataOrderInfo;
936 var layOutElementList = $scope.layOutElementList;
937 var labelList = $scope.layOutOnlyLableList;
941 $scope.layOutElementList = [];
942 $scope.layOutOnlyLableList = [];
944 // Only layout in order if order info provided
947 if(orderValue.includes("[")){
948 orderValue = orderValue.replace("[", "") ;
949 orderValue = orderValue.replace("]", "") ;
952 orderValue = orderValue.split(',') ;
954 for (var i = 0; i < orderValue.length; i++) {
955 console.log("orderValue["+i+"]"+ orderValue[i]);
956 var key = orderValue[i].trim();
958 //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array};
960 for (var k = 0; k < labelList.length; k++){
962 var label = labelList[k].label.toString().trim();
963 var level = labelList[k].level.toString().trim();
964 var array = labelList[k].array;
967 $scope.labelLayout(level, label, array);
968 //in case to have duplicate label names
969 labelList[k].label = "*processed*";
974 //--- then layout each element based on its order defined in YAML file
975 for (var j = 0; j < layOutElementList.length; j++) {
977 var attributekey = layOutElementList[j].attributekey.toString().trim();
979 if(key == attributekey){
981 var attirbuteLabel = layOutElementList[j].attirbuteLabel.toString().trim();
982 var defaultValue = layOutElementList[j].defaultValue.toString().trim();
983 var description = layOutElementList[j].description;
984 var isRequired = layOutElementList[j].isRequired;
986 console.log("layOutElementList[" +j+ "]: id:" + layOutElementList[j].id + ", attributekey:"+ layOutElementList[j].attributekey + ", attirbuteLabel:" + layOutElementList[j].attirbuteLabel);
987 console.log("layOutElementList[" +j+ "]: type:" + layOutElementList[j].type);
988 if (layOutElementList[j].type == "dropBox"){
989 $scope.dropBoxLayout(attirbuteLabel, attributekey, layOutElementList[j].array, defaultValue, layOutElementList[j].list, isRequired, description);
992 $scope.attributeBox(attributekey, layOutElementList[j].array, attirbuteLabel, defaultValue, isRequired, layOutElementList[j].type, description);
996 //in case to have duplicate attribute names
997 layOutElementList[j].attributekey = "*processed*";
1006 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired, dataType, description){
1007 $scope.temp.policy.ruleGridData.push(attibuteKey);
1008 var br = document.createElement("BR");
1010 var label = document.createElement("Label");
1011 var labeltext = null;
1012 var requiredLabName = "";
1013 if (matching.includes(attibuteKey)){
1014 labeltext = document.createTextNode(attibuteKey + "*!");
1015 isRequired = true; //set required as true for matching element
1018 requiredLabName = attibuteKey + " * ";
1019 labeltext = document.createTextNode(requiredLabName);
1021 labeltext = document.createTextNode(attibuteKey);
1026 var divID = labelValue;
1028 if (labelValue.length < 1){
1029 divID = "DynamicTemplate";
1030 }else if (labelValue.endsWith('.')){
1031 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1034 label.appendChild(labeltext);
1036 var textField = document.createElement("INPUT");
1038 textField.setAttribute("class" , "form-control");
1040 if(dataType == "double"){
1041 textField.setAttribute("type" , "number");
1042 textField.setAttribute("step" , "any");
1044 }else if(dataType == "boolean"){ //gw1218 testing boolean
1045 var booleanDiv = document.createElement("div");
1047 booleanDiv.setAttribute("class" , "onoffswitch");
1049 //var checkField = document.createElement("INPUT");
1050 textField.setAttribute("type" , "checkbox");
1051 textField.setAttribute("name" , "onoffswitch");
1052 textField.setAttribute("class" , "onoffswitch-checkbox");
1053 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1054 if(defaultValue.substring(0,defaultValue.indexOf(":")) == "true") {
1055 textField.setAttribute("checked" , true);
1057 textField.removeAttribute("checked");
1060 var booleanlabel = document.createElement("Label");
1061 booleanlabel.setAttribute("class" , "onoffswitch-label");
1062 booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+'');
1064 var span1 = document.createElement("span");
1065 span1.setAttribute("class" , "onoffswitch-inner");
1067 var span2 = document.createElement("span");
1068 span2.setAttribute("class" , "onoffswitch-switch");
1071 booleanlabel.appendChild(span1);
1072 booleanlabel.appendChild(span2);
1073 booleanDiv.appendChild(textField);
1074 booleanDiv.appendChild(booleanlabel);
1076 document.getElementById(divID).appendChild(label);
1077 document.getElementById(divID).appendChild(booleanDiv);
1081 textField.setAttribute("type" , dataType);
1088 if(dataType != "boolean"){
1089 textField.setAttribute("style" , "width:300px;");
1090 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1091 if(description && description != "null"){
1092 textField.setAttribute("title", description);
1098 if(attributeManyKey){
1099 checkKey = labelValue + attibuteKey+'@0';
1100 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
1101 var divTag = document.createElement("div");
1102 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
1103 var addButton = document.createElement("BUTTON");
1104 var buttonaddLabel = document.createTextNode("+");
1105 addButton.appendChild(buttonaddLabel);
1106 addButton.setAttribute("id", labelValue + attibuteKey);
1107 addButton.setAttribute("class", "btn btn-add-remove");
1108 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + attibuteKey+'");');
1109 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1110 var removeButton = document.createElement("BUTTON");
1111 var buttonremoveLabel = document.createTextNode("-");
1112 removeButton.appendChild(buttonremoveLabel);
1113 removeButton.setAttribute("class", "btn btn-add-remove");
1114 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue + attibuteKey+'");');
1115 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1116 document.getElementById(divID).appendChild(addButton);
1117 document.getElementById(divID).appendChild(removeButton);
1118 document.getElementById(divID).appendChild(label);
1119 id = "div."+labelValue+attibuteKey;
1120 //var divTag = document.createElement("div");
1121 divTag.setAttribute("id", id);
1122 document.getElementById(divID).appendChild(divTag);
1123 textField.className += ' first_child';
1125 textField.setAttribute("required", "true");
1128 divTag.appendChild(textField);
1129 document.getElementById(divID).appendChild(divTag);
1131 }else if (dataType != "boolean"){
1132 checkKey = labelValue + attibuteKey;
1133 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
1134 if(document.getElementById(divID).hasAttribute('required') || !document.getElementById(divID).hasAttribute('data-conditional')){
1135 if(requiredLabName.includes("*") || isRequired){
1136 textField.setAttribute("required", "true");
1138 }else if (document.getElementById(divID).hasAttribute('data-conditional')){
1139 if(requiredLabName.includes("*")){
1140 var requiredNode = document.createElement('span');
1141 requiredNode.setAttribute("class", "mstooltip");
1142 requiredNode.textContent = "?";
1143 label.appendChild(requiredNode);
1145 var requiredNodeToolTip = document.createElement('span');
1146 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1147 requiredNodeToolTip.textContent = "Conditional Required";
1148 requiredNode.appendChild(requiredNodeToolTip);
1150 textField.setAttribute("data-conditional", divID);
1151 textField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1155 document.getElementById(divID).appendChild(label);
1156 document.getElementById(divID).appendChild(textField);
1157 document.getElementById(divID).appendChild(br);
1161 if(dataType != "boolean" && divID.includes("@0") && divID.includes("div.")){
1162 var firstChild_Id = divID.split("@0")[0];
1163 var firstChild_element = document.getElementById(firstChild_Id);
1164 if(firstChild_element){
1166 if(!firstChild_element.className.includes('children_group border')){
1171 firstChild_element.className += ' children_group border' + layer; //here is div with a group of children.
1175 console.log('firstChild_Id: ' + firstChild_Id);
1176 console.log('divID: ' + divID);
1178 if(dataType != "boolean" && defaultValue.length > 0){
1179 if(defaultValue.includes(":")){
1180 defaultValue = defaultValue.split(":")[0];
1181 if(defaultValue === "NA") {
1185 if(defaultValue != "undefined" && defaultValue != undefined && defaultValue != "null"){
1186 document.getElementById(checkKey).value = defaultValue;
1190 if($scope.temp.policy.ruleData != null){
1191 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1192 if (attributeManyKey){
1193 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
1194 if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){
1195 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
1198 if($scope.temp.policy.ruleData[checkKey] != undefined && $scope.temp.policy.ruleData[checkKey] != "undefined"){
1199 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
1204 if (dataType != "boolean"){
1205 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
1207 plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean");
1211 $scope.labelManyKeys = [];
1212 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
1213 var label = document.createElement("Label")
1214 var divID = labelValue;
1215 if (labelValue.endsWith('.')){
1216 var workingLabel = labelValue.substring(0, labelValue.length-1);
1218 var workingLabel = labelValue;
1221 if (labelValue.length < 1){
1222 divID = "DynamicTemplate";
1223 } else if (labelValue.endsWith('.')){
1224 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
1227 var subAttributes = $scope.dcaeModelData.sub_attributes;
1228 var jsonObject = JSON.parse(subAttributes);
1229 var lablInfo = findVal(jsonObject, lableName);
1230 console.log("findValue : " + lableName +": "+ lablInfo);
1232 var required = null;
1234 if(typeof lablInfo === 'string' ){
1235 if(lablInfo.includes("required-true")){
1238 }else if (lablInfo.includes("required-false")){
1244 var labeltext = document.createTextNode(lableName + star);
1246 label.appendChild(labeltext);
1250 var addButton = document.createElement("BUTTON");
1251 var buttonLabel = document.createTextNode("+");
1252 addButton.appendChild(buttonLabel);
1253 addButton.setAttribute("class", "btn btn-add-remove");
1254 addButton.setAttribute("onclick" , 'addNewChoice("'+labelValue + lableName+'");');
1255 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1256 var removeButton = document.createElement("BUTTON");
1257 var buttonremoveLabel = document.createTextNode("-");
1258 removeButton.appendChild(buttonremoveLabel);
1259 removeButton.setAttribute("class", "btn btn-add-remove");
1260 removeButton.setAttribute("onclick" , 'removeChoice("'+labelValue +lableName+'");');
1261 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1262 document.getElementById(divID).appendChild(addButton);
1263 document.getElementById(divID).appendChild(removeButton);
1264 document.getElementById(divID).appendChild(label);
1265 var id = "div."+labelValue+lableName;
1266 var divTag = document.createElement("div");
1267 divTag.setAttribute("id", id);
1268 document.getElementById(divID).appendChild(divTag);
1270 var divTag = document.createElement("div");
1271 divTag.setAttribute("id", id +'@0');
1273 if(!divTag.className.includes('children_group border')){
1278 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1281 divTag.setAttribute("required", required);
1282 }else if(required == false){
1283 divTag.setAttribute("data-conditional", "yes");
1286 document.getElementById(id).appendChild(divTag);
1288 $scope.labelManyKeys.push(lableName);
1291 var divTag = document.createElement("div");
1292 divTag.setAttribute("id", "div."+labelValue+lableName);
1294 if(!divTag.className.includes('children_group border')){
1299 divTag.className += ' children_group border' + layer; //here is div with a group of children.
1302 divTag.setAttribute("required", required);
1303 }else if(required == false){
1304 divTag.setAttribute("data-conditional", "yes");
1306 document.getElementById(divID).appendChild(label);
1307 document.getElementById(divID).appendChild(divTag);
1311 $scope.dropBoxLayout = function(labelLevel, attributeName, many , defaultValue, listemunerateValues, isRequired, description){
1312 var br = document.createElement("BR");
1314 if (labelLevel.length < 1){
1315 var divID = "DynamicTemplate";
1316 } else if (labelLevel.endsWith('.')){
1317 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
1321 var label = document.createElement("Label")
1323 var refAttributes = $scope.dcaeModelData.ref_attributes;
1324 if(isRequired != true && refAttributes){ //check refAttributes also
1325 var refAttributesList = refAttributes.split(splitComma);
1326 for (k = 0; k < refAttributesList.length; k++){
1327 var refAttribute = refAttributesList[k].split(splitEqual);
1328 if (attributeName == refAttribute[0].trim() && refAttribute[1].includes("required-true")){
1334 if (matching.includes(attributeName)){
1335 var labeltext = document.createTextNode(attributeName + "*!");
1336 label.appendChild(labeltext);
1337 isRequired = true; //set required as true for matching element
1339 var labeltext = document.createTextNode(attributeName);
1341 var requiredLabName = attributeName+ " * ";
1342 labeltext = document.createTextNode(requiredLabName);
1344 labeltext = document.createTextNode(attributeName);
1347 label.appendChild(labeltext);
1349 label.appendChild(labeltext);
1350 // if this field is required, but its parent is not required
1351 if(isRequired && document.getElementById(divID).hasAttribute('data-conditional')){
1352 var requiredNode = document.createElement('span');
1353 requiredNode.setAttribute("class", "mstooltip");
1354 requiredNode.textContent = "?";
1355 label.appendChild(requiredNode);
1357 var requiredNodeToolTip = document.createElement('span');
1358 requiredNodeToolTip.setAttribute("class", "tooltiptext");
1359 requiredNodeToolTip.textContent = "Conditional Required";
1360 requiredNode.appendChild(requiredNodeToolTip);
1364 var listField = document.createElement("SELECT");
1365 listField.setAttribute("class" , "form-control");
1366 listField.setAttribute("style" , "width:300px;");
1367 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
1369 if(description && description != "null"){
1370 listField.setAttribute("title", description);
1374 if(document.getElementById(divID).hasAttribute('data-conditional')){
1375 listField.setAttribute("data-conditional", divID);
1376 listField.setAttribute("ng-blur", "validContionalRequired('"+divID+"')");
1378 listField.setAttribute("required", true);
1381 if( many != true || isRequired != true){ // add an empty option for not required or not multiple select element
1382 var optionFirst = document.createElement('option');
1383 var optionValue = "";
1384 if($scope.temp.policy.ruleData != null){
1385 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1386 optionValue = $scope.temp.policy.ruleData[labelLevel + attributeName];
1389 optionFirst.setAttribute('value', optionValue);
1390 optionFirst.appendChild(document.createTextNode(optionValue));
1391 listField.appendChild(optionFirst);
1393 var ruleFormationCheck = false;
1394 if(listemunerateValues.length !== 0 && typeof listemunerateValues[0] == "string" && listemunerateValues[0].includes("dictionary:")) {
1395 var ruleCheck = listemunerateValues[0].split("&");
1396 var dictParams = ruleCheck[0].split(":");
1397 var dictParamsSplit = dictParams[1].split("@");
1398 if (ruleCheck[1] != undefined && ruleCheck[1] == 'Rule') {
1399 ruleFormationCheck = true;
1401 PolicyAppService.getData(dictParamsSplit[0]).then(function (data) {
1403 $scope.data = JSON.parse(j.data);
1404 console.log($scope.data);
1405 $scope.listDictionarys = JSON.parse($scope.data[dictParamsSplit[1]]);
1406 for (i=0; i < $scope.listDictionarys.length; i += 1) {
1407 option = document.createElement('option');
1408 option.setAttribute('value', $scope.listDictionarys[i]);
1409 option.appendChild(document.createTextNode($scope.listDictionarys[i]));
1410 listField.appendChild(option);
1412 }, function (error) {
1413 console.log("failed");
1418 for (i=0; i < listemunerateValues.length; i += 1) {
1419 if(typeof listemunerateValues[i] == "string" && listemunerateValues[i].includes("equal-sign")){
1420 listemunerateValues[i] = listemunerateValues[i].replace('equal-sign','=');
1423 option = document.createElement('option');
1424 option.setAttribute('value', listemunerateValues[i]);
1425 option.appendChild(document.createTextNode(listemunerateValues[i]));
1426 option.setAttribute('value', listemunerateValues[i]);
1427 listField.appendChild(option);
1430 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
1432 enumKeyList.push(attributeName);
1434 document.getElementById(divID).appendChild(label);
1435 document.getElementById(divID).appendChild(br);
1438 document.getElementById(divID).appendChild(listField).multiple = true;
1439 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
1441 document.getElementById(divID).appendChild(listField).multiple = false;
1442 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
1445 if(defaultValue.includes(':')){
1446 defaultValue = defaultValue.split(':')[0];
1448 var location = listemunerateValues.indexOf(defaultValue);
1449 document.getElementById(labelLevel +attributeName).options[location+1].selected = true;
1453 if (ruleFormationCheck) {
1454 var optionInput = document.createElement("INPUT");
1455 optionInput.setAttribute("type" , "text");
1456 optionInput.setAttribute("id" , ''+ labelLevel + attributeName + '.input');
1457 optionInput.setAttribute("name" , "ruleName");
1458 optionInput.setAttribute("value" , " ");
1459 optionInput.setAttribute("style" , "width:300px;");
1460 optionInput.setAttribute("ng-disabled" , "temp.policy.readOnly");
1461 optionInput.removeAttribute("required");
1463 document.getElementById(divID).appendChild(optionInput);
1465 var optionButton = document.createElement("BUTTON");
1466 optionButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
1467 var buttonLabel = document.createTextNode("+");
1468 optionButton.appendChild(buttonLabel);
1469 optionButton.setAttribute("class", "btn btn-add-remove");
1470 optionButton.setAttribute("onclick" , 'addDynamicOptions("'+ labelLevel + attributeName + '");');
1471 optionButton.removeAttribute("required");
1474 document.getElementById(divID).appendChild(optionButton);
1475 document.getElementById(divID).appendChild(br);
1478 if($scope.temp.policy.ruleData != null){
1480 document.getElementById(labelLevel +attributeName).options[0].selected = false;
1481 for (i=0; i < listemunerateValues.length; i += 1) {
1482 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
1483 if (testValue === undefined){
1484 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
1486 var location = listemunerateValues.indexOf(testValue);
1488 document.getElementById(labelLevel +attributeName).options[location].selected = true;
1492 if($scope.temp.policy.ruleData[labelLevel + attributeName] != undefined && $scope.temp.policy.ruleData[labelLevel + attributeName] != "undefined"){
1493 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
1499 addDynamicOptions = function(id) {
1500 var option = document.createElement("option");
1501 var value = document.getElementById(id+".input").value;
1502 option.setAttribute('value', value);
1503 option.appendChild(document.createTextNode(value));
1504 document.getElementById(id).options.add(option);
1505 document.getElementById(id+".input").value = "";
1508 function onlyUnique(value, index, self) {
1509 return self.indexOf(value) === index;
1513 function checkDictionary(value){
1514 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
1515 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
1521 $scope.savePolicy = function(policy){
1522 if(policy.itemContent != undefined){
1523 $scope.refreshCheck = true;
1524 $scope.policyNavigator = policy.itemContent;
1525 policy.itemContent = "";
1527 $scope.savebutton = false;
1530 var jsonPolicy = {};
1531 if(plainAttributeKeys != null){
1532 for(a = 0; a < plainAttributeKeys.length; a++){
1533 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1534 console.log("splitPlainAttributeKey: " + splitPlainAttributeKey);
1535 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1536 var key = splitPlainAttributeKey[0];
1537 if(searchElement == null){
1538 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1539 key = splitPlainAttributeKey[0]+'@0';
1540 }else if (searchElement.nodeName == 'BUTTON'){
1541 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1542 key = splitPlainAttributeKey[0]+'@0';
1544 if(searchElement != null){
1545 var keySplit = key.split(dot);
1546 var elumentLocation = keySplit.length;
1548 if (elumentLocation > 1){
1549 enumKey = keySplit[keySplit.length - 1];
1551 //check it is undefined or not
1552 if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){
1553 if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){
1554 var multiSlect = [];
1555 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1556 multiSlect.push(searchElement.selectedOptions[i].value);
1558 jsonPolicy[key]= multiSlect;
1560 console.log(" searchElement.value = > " + searchElement.value);
1561 if(splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1] == "boolean"){
1562 jsonPolicy[key]= false;
1563 for(var i=0; i<booleanTrueElements.length; i++){
1564 if(booleanTrueElements[i] == key){
1565 jsonPolicy[key]= true;
1570 jsonPolicy[key]= searchElement.value;
1574 if(searchElement.value != null){
1575 jsonPolicy[key]= searchElement.value;
1576 console.log(" searchElement.value = > " + searchElement.value);
1577 if(splitPlainAttributeKey[1] == "boolean"){
1578 jsonPolicy[key]= false;
1579 for(var i=0; i<booleanTrueElements.length; i++){
1580 if(booleanTrueElements[i] == key){
1581 jsonPolicy[key]= true;
1590 var uuu = "policycreation/save_policy";
1591 var postData={policyData: policy, policyJSON : jsonPolicy};
1596 contentType: 'application/json',
1597 data: JSON.stringify(postData),
1598 success : function(data){
1599 $scope.$apply(function(){
1600 $scope.data=data.policyData;
1601 if($scope.data == 'success'){
1602 $scope.temp.policy.readOnly = 'true';
1603 $scope.safetyChecker = data.policyData.split("#")[2];
1604 if ($scope.safetyChecker!=undefined) {
1605 Notification.success($scope.safetyChecker);
1607 $scope.pushStatus=data.policyData.split("&")[1];
1608 if($scope.pushStatus=="successPush"){
1609 Notification.success("Policy pushed successfully");
1611 Notification.success("Policy Saved Successfully.");
1612 }else if ($scope.data == 'PolicyExists'){
1613 $scope.savebutton = true;
1614 Notification.error("Policy Already Exists with Same Name in Scope.");
1617 console.log($scope.data);
1619 error : function(data){
1620 Notification.error("Error Occured while saving Policy.");
1625 var booleanTrueElements = [];
1626 $scope.validatePolicy = function(policy){
1627 document.getElementById("validate").innerHTML = "";
1630 var jsonPolicy = {};
1631 if(plainAttributeKeys != null){
1632 for(a = 0; a < plainAttributeKeys.length; a++){
1633 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
1634 console.log(splitPlainAttributeKey[1]);
1635 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
1636 var key = splitPlainAttributeKey[0];
1637 if(searchElement == null){
1638 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1639 key = splitPlainAttributeKey[0]+'@0';
1640 }else if (searchElement.nodeName == 'BUTTON'){
1641 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
1642 key = splitPlainAttributeKey[0]+'@0';
1644 if(searchElement != null){
1645 if (enumKeyList.indexOf(key) != -1){
1646 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
1647 var multiSlect = [];
1648 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
1649 multiSlect.push(searchElement.selectedOptions[i].value);
1651 jsonPolicy[key]= multiSlect;
1653 jsonPolicy[key]= searchElement.value;
1655 if(searchElement.getAttribute("required")){
1656 if(!searchElement.value){
1661 if(searchElement.value != null){
1662 jsonPolicy[key]= searchElement.value;
1663 if(searchElement.getAttribute("required")){
1664 if(!searchElement.value){
1674 var checkedValue = $('.onoffswitch-checkbox:checked').val();
1676 var x = document.getElementsByClassName("onoffswitch-checkbox");
1680 console.log("checkedValue:" + checkedValue);
1681 for(var i=0; i<x.length; x++){
1682 console.log("checkbox id: " + x[i].id);
1683 booleanTrueElements.push(x[i].id)
1687 var uuu = "policyController/validate_policy.htm";
1689 console.log("$scope.isCheck:" + $scope.isCheck);
1691 if($scope.isCheck == true){
1692 if(("configName" in policy) == false){
1693 Notification.error("Validation Failed: configName is required");
1694 $scope.savebutton = true;
1697 if(("location" in policy) == false){
1698 Notification.error("Validation Failed: location is required");
1699 $scope.savebutton = true;
1702 if(("uuid" in policy) == false){
1703 Notification.error("Validation Failed: uuid is required");
1704 $scope.savebutton = true;
1707 if(("policyScope" in policy) == false){
1708 Notification.error("Validation Failed: policyScope is required");
1709 $scope.savebutton = true;
1714 var postData={policyData: policy, policyJSON : jsonPolicy};
1719 contentType: 'application/json',
1720 data: JSON.stringify(postData),
1721 success : function(data){
1722 $scope.$apply(function(){
1723 $scope.validateData = data.data.replace(/\"/g, "");
1724 $scope.data=data.data.substring(1,8);
1725 var size = data.data.length;
1726 if($scope.data == 'success'){
1727 Notification.success("Validation Success.");
1728 $scope.savebutton = false;
1730 var displayWarning = data.data.substring(19,size - 1);
1731 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
1732 document.getElementById("validate").style.color = "white";
1733 document.getElementById("validate").style.backgroundColor = "skyblue";
1736 Notification.error("Validation Failed.");
1737 document.getElementById("validate").innerHTML = $scope.validateData;
1738 document.getElementById("validate").style.color = "white";
1739 document.getElementById("validate").style.backgroundColor = "red";
1740 $scope.savebutton = true;
1744 console.log($scope.data);
1746 error : function(data){
1747 Notification.error("Validation Failed.");
1748 $scope.savebutton = true;
1753 function extend(obj, src) {
1754 for (var key in src) {
1755 if (src.hasOwnProperty(key)) obj[key] = src[key];
1761 $('.Switch').click(function() {
1762 // Check If Enabled (Has 'On' Class)
1763 if ($(this).hasClass('On')){
1764 // Try To Find Checkbox Within Parent Div, And Check It
1765 $(this).parent().find('input:checkbox').attr('checked', true);
1766 // Change Button Style - Remove On Class, Add Off Class
1767 $(this).removeClass('On').addClass('Off');
1768 } else { // If Button Is Disabled (Has 'Off' Class)
1769 // Try To Find Checkbox Within Parent Div, And Uncheck It
1770 $(this).parent().find('input:checkbox').attr('checked', false);
1771 // Change Button Style - Remove Off Class, Add On Class
1772 $(this).removeClass('Off').addClass('On');
1775 // Loops Through Each Toggle Switch On Page
1776 $('.Switch').each(function() {
1777 // Search of a checkbox within the parent
1778 if ($(this).parent().find('input:checkbox').length){
1780 // If checkbox doesnt have the show class then hide it
1781 if (!$(this).parent().find('input:checkbox').hasClass("show")){
1782 $(this).parent().find('input:checkbox').hide(); }
1784 // Look at the checkbox's checkked state
1785 if ($(this).parent().find('input:checkbox').is(':checked')){
1786 // Checkbox is not checked, Remove the On Class and Add the Off Class
1787 $(this).removeClass('On').addClass('Off');
1789 // Checkbox Is Checked Remove Off Class, and Add the On Class
1790 $(this).removeClass('Off').addClass('On');