added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / shared / services / json2html.service.ts
diff --git a/otf-frontend/client/src/app/shared/services/json2html.service.ts b/otf-frontend/client/src/app/shared/services/json2html.service.ts
new file mode 100644 (file)
index 0000000..2943c05
--- /dev/null
@@ -0,0 +1,60 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+import { Injectable } from "@angular/core";\r
+import { toInteger } from "@ng-bootstrap/ng-bootstrap/util/util";\r
+\r
+@Injectable({\r
+    providedIn: 'root'\r
+})\r
+\r
+export class ToHtml {\r
+    constructor() {}\r
+\r
+    convert(json:any = [{name: 'Adam', age: 23}, {name: 'Raj', age: 22}, {name: 'Justin', age: 5}], tabs = 0){\r
+        var html = '';\r
+        var tabHtml = '';\r
+        if(typeof json === 'string'){\r
+          json = JSON.parse(json);\r
+        }\r
+        for(let i = 0; i < tabs; i++){\r
+          tabHtml += '&nbsp;&nbsp;&nbsp;&nbsp;';\r
+        }\r
+        for(let key in json){\r
+          if(json.hasOwnProperty(key)){\r
+            if(typeof json[key] === "object"){\r
+              html += tabHtml + '<b><u>' + key + ':</u></b><br/>';\r
+              if(json.constructor === Array && toInteger(key) > 0){\r
+                tabs--;\r
+              }\r
+              html += this.convert(json[key], ++tabs);\r
+            }else{\r
+              html += tabHtml + '<b><u>' + key + ':</u></b>' + '<br/>';\r
+              if(typeof json[key] === 'string'){\r
+                json[key] = json[key].replace(/\\n/g, '<br/>' + tabHtml);\r
+              }\r
+              html += tabHtml + json[key] + '<br/>';\r
+              html += '<br/>';\r
+            }\r
+          }\r
+        }\r
+        return html;\r
+      }\r
+    \r
+    convertString(str){\r
+        return str.replace(/\\n/g, '<br/>');\r
+    }\r
+}
\ No newline at end of file