2015-10-09 23:19:35 +03:00
|
|
|
'use strict';
|
2016-08-22 12:12:13 +03:00
|
|
|
import { OnInit, OnDestroy } from '@angular/core';
|
2016-10-23 20:18:42 +03:00
|
|
|
import { SpecManager } from '../utils/spec-manager';
|
2017-01-19 00:48:55 +03:00
|
|
|
import { AppStateService } from '../services/app-state.service';
|
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
2015-10-09 23:19:35 +03:00
|
|
|
|
2016-08-22 12:12:13 +03:00
|
|
|
export { SpecManager };
|
2015-10-09 23:19:35 +03:00
|
|
|
|
2016-01-09 23:31:39 +03:00
|
|
|
function snapshot(obj) {
|
2016-06-13 20:54:24 +03:00
|
|
|
if(obj == undefined || typeof(obj) !== 'object') {
|
2016-01-09 23:31:39 +03:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
var temp = new obj.constructor();
|
|
|
|
|
|
|
|
for(var key in obj) {
|
|
|
|
if (obj.hasOwnProperty(key)) {
|
|
|
|
temp[key] = snapshot(obj[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:19:35 +03:00
|
|
|
/**
|
|
|
|
* Generic Component
|
|
|
|
* @class
|
|
|
|
*/
|
2016-06-15 21:48:04 +03:00
|
|
|
export class BaseComponent implements OnInit, OnDestroy {
|
2016-07-26 12:03:15 +03:00
|
|
|
pointer: string;
|
2016-08-22 12:12:13 +03:00
|
|
|
componentSchema: any = null;
|
2016-06-22 19:13:57 +03:00
|
|
|
dereferencedCache = {};
|
2016-06-13 20:54:24 +03:00
|
|
|
|
2016-06-23 17:36:38 +03:00
|
|
|
constructor(public specMgr: SpecManager) {
|
2015-10-09 23:19:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* onInit method is run by angular2 after all component inputs are resolved
|
|
|
|
*/
|
2015-12-14 18:20:40 +03:00
|
|
|
ngOnInit() {
|
2016-08-28 21:46:10 +03:00
|
|
|
this.preinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
preinit() {
|
2016-06-23 17:36:38 +03:00
|
|
|
this.componentSchema = this.specMgr.byPointer(this.pointer || '');
|
2015-10-17 21:12:46 +03:00
|
|
|
this.init();
|
2015-10-09 23:19:35 +03:00
|
|
|
}
|
|
|
|
|
2015-12-21 22:35:57 +03:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
|
2015-10-09 23:19:35 +03:00
|
|
|
/**
|
2016-07-20 11:07:08 +03:00
|
|
|
* Used to initialize component
|
2015-10-17 21:12:46 +03:00
|
|
|
* @abstract
|
|
|
|
*/
|
2016-06-13 20:54:24 +03:00
|
|
|
init() {
|
|
|
|
// empty
|
|
|
|
}
|
2015-12-21 22:35:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
+ Used to destroy component
|
|
|
|
* @abstract
|
|
|
|
*/
|
2016-06-13 20:54:24 +03:00
|
|
|
destroy() {
|
|
|
|
// emtpy
|
|
|
|
}
|
2015-10-09 23:19:35 +03:00
|
|
|
}
|
2017-01-19 00:48:55 +03:00
|
|
|
|
|
|
|
export class BaseSearchableComponent extends BaseComponent {
|
|
|
|
searchSubscription: Subscription;
|
|
|
|
constructor(public specMgr: SpecManager, public app: AppStateService) {
|
|
|
|
super(specMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribeForSearch() {
|
|
|
|
this.searchSubscription = this.app.searchContainingPointers.subscribe(ptrs => {
|
|
|
|
for (let i = 0; i < ptrs.length; ++i) {
|
|
|
|
this.ensureSearchIsShown(ptrs[i]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
preinit() {
|
|
|
|
super.preinit();
|
|
|
|
this.subscribeForSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.searchSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
+ Used to destroy component
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
ensureSearchIsShown(ptr: string) {
|
|
|
|
// empy
|
|
|
|
}
|
|
|
|
}
|