1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 import { Injectable, OnInit } from '@angular/core';
\r
18 import { BehaviorSubject } from 'rxjs';
\r
23 export class ListService {
\r
25 listMap: {[uniqueKey: string]: {listSource: any, currentList: any} } = {};
\r
26 // private listSource = new BehaviorSubject(null);
\r
27 // currentList = this.listSource.asObservable();
\r
32 this.listMap[key] = {
\r
33 listSource: new BehaviorSubject(null),
\r
36 this.listMap[key].currentList = this.listMap[key].listSource.asObservable();
\r
37 this.listMap[key].listSource.next([]);
\r
40 changeMessage(key, message: any) {
\r
41 if(!this.listMap[key])
\r
42 this.createList(key);
\r
44 this.listMap[key].listSource.next(message)
\r
47 addElement(key, obj: any){
\r
48 this.listMap[key].currentList.subscribe(function(value){
\r
49 //console.log(value);
\r
54 removeElement(key, object_field_name, id: any){
\r
56 this.listMap[key].currentList.subscribe(function(value){
\r
57 value.forEach(function(elem, val) {
\r
58 if(elem[object_field_name] == id){
\r
59 value.splice(val, 1);
\r
66 updateElement(key, object_field_name, id: any, new_object){
\r
68 this.listMap[key].currentList.subscribe(function(value){
\r
69 value.forEach(function(elem, val) {
\r
70 if(elem[object_field_name] == id){
\r
71 value[val] = new_object;
\r