Added slices
Change-Id: I9dfaa9348fa82da844a04c0c2a58ce07e9fa3a28
diff --git a/src/app/services/stores/instance.store.ts b/src/app/services/stores/instance.store.ts
index a87630c..9a07095 100644
--- a/src/app/services/stores/instance.store.ts
+++ b/src/app/services/stores/instance.store.ts
@@ -2,11 +2,11 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs/Rx';
-import {IInstance} from '../../interfaces/instance.interface';
+import {IInstance} from '../../interfaces/models.interface';
import {InstanceService} from '../rest/instance.service';
-import * as _ from 'lodash';
import {IWSEvent} from '../../interfaces/ws.interface';
import {GlobalEvent} from '../websockets/websocket.global';
+import {ObservableCollectionHandler} from '../helpers/store.service';
@Injectable()
export class InstanceStore {
@@ -14,25 +14,10 @@
constructor(private instanceService: InstanceService, private globalEvent: GlobalEvent) {
this.loadInitialData();
this.globalEvent.list()
- .filter((e: IWSEvent) => {
- console.log('filter', e);
- return e.model === 'Instance';
- })
+ .filter((e: IWSEvent) => e.model === 'Instance')
.subscribe(
(event: IWSEvent) => {
-
- const collection = this._instances.value;
-
- const exist = _.find(collection, (i) => {
- return i.id === event.msg.object.id;
- });
-
- // remove in order to update
- if (exist) {
- _.remove(collection, {id: event.msg.object.id});
- }
- collection.push(event.msg.object);
- this._instances.next(collection);
+ ObservableCollectionHandler.update(event, this._instances);
}
);
}
diff --git a/src/app/services/stores/slice.store.ts b/src/app/services/stores/slice.store.ts
new file mode 100644
index 0000000..aeab9f3
--- /dev/null
+++ b/src/app/services/stores/slice.store.ts
@@ -0,0 +1,39 @@
+/// <reference path="../../../../typings/index.d.ts"/>
+
+import {Injectable} from '@angular/core';
+import {BehaviorSubject} from 'rxjs/Rx';
+import {ISlice} from '../../interfaces/models.interface';
+import {IWSEvent} from '../../interfaces/ws.interface';
+import {GlobalEvent} from '../websockets/websocket.global';
+import {SliceService} from '../rest/slices.service';
+import {ObservableCollectionHandler} from '../helpers/store.service';
+
+@Injectable()
+export class SliceStore {
+ private _slices: BehaviorSubject<ISlice[]> = new BehaviorSubject([]);
+ constructor(private sliceService: SliceService, private globalEvent: GlobalEvent) {
+ this.loadInitialData();
+ this.globalEvent.list()
+ .filter((e: IWSEvent) => e.model === 'Slice')
+ .subscribe(
+ (event: IWSEvent) => {
+ ObservableCollectionHandler.update(event, this._slices);
+ }
+ );
+ }
+
+ loadInitialData() {
+ this.sliceService.query()
+ .subscribe(
+ res => {
+ this._slices.next(res);
+ },
+ err => console.log('Error retrieving Instances', err)
+ );
+ }
+
+ query() {
+ return this._slices.asObservable();
+ }
+
+}