frontend/src/app/components/option-picker/option-picker.component.ts
garrettmills f788654ff7
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Add ability to prefetch and auto-prefetch offline data
2020-10-28 23:48:46 -05:00

48 lines
1.5 KiB
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {ApiService} from '../../service/api.service';
import {PopoverController} from '@ionic/angular';
import {DatabaseService} from '../../service/db/database.service';
@Component({
selector: 'app-option-picker',
templateUrl: './option-picker.component.html',
styleUrls: ['./option-picker.component.scss'],
})
export class OptionPickerComponent implements OnInit {
@Input() toggleDark: () => void;
@Input() isDark: () => boolean;
@Input() showSearch: () => void | Promise<void>;
@Input() isPrefetch: () => boolean;
@Input() togglePrefetch: () => void;
@Input() doPrefetch: () => any;
constructor(
protected api: ApiService,
protected router: Router,
protected popover: PopoverController,
protected db: DatabaseService,
) { }
ngOnInit() {}
async onSelect(key) {
if ( key === 'html_export' ) {
window.open(this.api._build_url('/data/export/html'), '_blank');
} else if ( key === 'logout' ) {
await this.db.purge();
window.location.href = '/auth/logout';
} else if ( key === 'toggle_darkmode' ) {
this.toggleDark();
} else if ( key === 'search_everywhere' ) {
this.showSearch();
this.popover.dismiss();
} else if ( key === 'toggle_auto_prefetch' ) {
this.togglePrefetch();
} else if ( key === 'prefetch_data' ) {
this.popover.dismiss();
this.doPrefetch();
}
}
}