|
|
|
@ -4,13 +4,16 @@ import {ApiService} from '../../service/api.service';
|
|
|
|
|
import {BehaviorSubject} from 'rxjs';
|
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
|
import {NodeTypeIcons} from '../../structures/node-types';
|
|
|
|
|
import {debounce} from "../../utility";
|
|
|
|
|
import {debounce} from '../../utility';
|
|
|
|
|
import {DatabasePageComponent} from '../editor/database/database-page.component';
|
|
|
|
|
import {FileBoxPageComponent} from '../nodes/file-box/file-box-page.component';
|
|
|
|
|
|
|
|
|
|
export interface SearchResult {
|
|
|
|
|
title: string;
|
|
|
|
|
short_title: string;
|
|
|
|
|
type: 'page' | 'node' | 'code';
|
|
|
|
|
type: string;
|
|
|
|
|
id: string;
|
|
|
|
|
boxId?: string;
|
|
|
|
|
associated?: {
|
|
|
|
|
title: string,
|
|
|
|
|
type: 'page',
|
|
|
|
@ -38,13 +41,13 @@ export class SearchComponent implements OnInit {
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
protected modal: ModalController,
|
|
|
|
|
protected ionModalController: ModalController,
|
|
|
|
|
protected api: ApiService,
|
|
|
|
|
protected router: Router,
|
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
async dismiss() {
|
|
|
|
|
await this.modal.dismiss();
|
|
|
|
|
await this.ionModalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
@ -68,7 +71,7 @@ export class SearchComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
async openResult(result: SearchResult) {
|
|
|
|
|
const nodeTypes = [
|
|
|
|
|
'node', 'code', 'db', 'files', 'markdown',
|
|
|
|
|
'node', 'code', 'files', 'markdown',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ( result.type === 'page' ) {
|
|
|
|
@ -77,6 +80,10 @@ export class SearchComponent implements OnInit {
|
|
|
|
|
} else if ( nodeTypes.includes(result.type) ) {
|
|
|
|
|
await this.router.navigate(['/editor', { id: result.associated.id, node_id: result.id }]);
|
|
|
|
|
await this.dismiss();
|
|
|
|
|
} else if ( result.type === 'db' ) {
|
|
|
|
|
await this.openDatabase(result.associated.id, result.id);
|
|
|
|
|
} else if ( result.type.startsWith('file_box') ) {
|
|
|
|
|
await this.openFileBox(result.associated.id, result.id, result.boxId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -91,4 +98,45 @@ export class SearchComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async openDatabase(pageId: string, nodeId: string) {
|
|
|
|
|
const modal = await this.ionModalController.create({
|
|
|
|
|
component: DatabasePageComponent,
|
|
|
|
|
componentProps: {
|
|
|
|
|
nodeId,
|
|
|
|
|
pageId,
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'modal-big',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const modalState = {
|
|
|
|
|
modal : true,
|
|
|
|
|
desc : 'Open Database'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
history.pushState(modalState, null);
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async openFileBox(pageId: string, nodeId: string, boxId?: string) {
|
|
|
|
|
const modal = await this.ionModalController.create({
|
|
|
|
|
component: FileBoxPageComponent,
|
|
|
|
|
componentProps: {
|
|
|
|
|
nodeId,
|
|
|
|
|
pageId,
|
|
|
|
|
boxId,
|
|
|
|
|
},
|
|
|
|
|
cssClass: 'modal-big',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const modalState = {
|
|
|
|
|
modal : true,
|
|
|
|
|
desc : 'Open File Box'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
history.pushState(modalState, null);
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|