--- /dev/null
+/* 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, OnInit } from '@angular/core';\r
+import { BehaviorSubject } from 'rxjs';\r
+\r
+@Injectable({\r
+ providedIn: 'root'\r
+})\r
+export class ListService {\r
+\r
+ listMap: {[uniqueKey: string]: {listSource: any, currentList: any} } = {};\r
+ // private listSource = new BehaviorSubject(null);\r
+ // currentList = this.listSource.asObservable();\r
+\r
+ constructor() { }\r
+\r
+ createList(key){\r
+ this.listMap[key] = {\r
+ listSource: new BehaviorSubject(null),\r
+ currentList: null\r
+ }\r
+ this.listMap[key].currentList = this.listMap[key].listSource.asObservable();\r
+ this.listMap[key].listSource.next([]);\r
+ }\r
+\r
+ changeMessage(key, message: any) {\r
+ if(!this.listMap[key])\r
+ this.createList(key);\r
+\r
+ this.listMap[key].listSource.next(message)\r
+ }\r
+\r
+ addElement(key, obj: any){\r
+ this.listMap[key].currentList.subscribe(function(value){\r
+ //console.log(value);\r
+ value.push(obj);\r
+ });\r
+ }\r
+\r
+ removeElement(key, object_field_name, id: any){\r
+ let val = 0;\r
+ this.listMap[key].currentList.subscribe(function(value){\r
+ value.forEach(function(elem, val) {\r
+ if(elem[object_field_name] == id){\r
+ value.splice(val, 1);\r
+ }\r
+ });\r
+ });\r
+ \r
+ }\r
+\r
+ updateElement(key, object_field_name, id: any, new_object){\r
+ let val = 0;\r
+ this.listMap[key].currentList.subscribe(function(value){\r
+ value.forEach(function(elem, val) {\r
+ if(elem[object_field_name] == id){\r
+ value[val] = new_object;\r
+ }\r
+ })\r
+ });\r
+ }\r
+\r
+}\r