redoc/lib/components/Search/redoc-search.ts

44 lines
1.0 KiB
TypeScript
Raw Normal View History

2016-12-29 20:20:29 +03:00
'use strict';
import { Component, ChangeDetectionStrategy, OnInit, HostBinding } from '@angular/core';
2017-01-24 00:29:52 +03:00
import { Marker, SearchService, MenuService } from '../../services/';
2016-12-29 20:20:29 +03:00
@Component({
selector: 'redoc-search',
styleUrls: ['./redoc-search.css'],
templateUrl: './redoc-search.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RedocSearch implements OnInit {
logo:any = {};
2017-01-24 00:29:52 +03:00
items: any[] = [];
2016-12-29 20:20:29 +03:00
2017-01-24 00:29:52 +03:00
constructor(private marker: Marker, public search: SearchService, public menu: MenuService) {
2016-12-29 20:20:29 +03:00
}
init() {
2017-01-24 00:29:52 +03:00
this.search.indexAll();
2016-12-29 20:20:29 +03:00
}
update(val) {
2017-01-24 00:29:52 +03:00
let searchRes = this.search.search(val);
this.items = Object.keys(searchRes).map(id => ({
menuItem: this.menu.getItemById(id),
pointers: searchRes[id].map(el => el.pointer)
}));
2016-12-29 20:20:29 +03:00
this.marker.mark(val);
}
2017-01-24 00:29:52 +03:00
clickSearch(item) {
this.search.ensureSearchVisible(
item.pointers
);
this.marker.remark();
this.menu.activate(item.menuItem.flatIdx);
this.menu.scrollToActive();
}
2016-12-29 20:20:29 +03:00
ngOnInit() {
2017-01-24 00:29:52 +03:00
this.init();
2016-12-29 20:20:29 +03:00
}
}