import { Component , OnInit , NgZone , ViewChild , ElementRef } from '@angular/core' ; import { RouterExtensions } from '@nativescript/angular' ; import { openUrl } from '@nativescript/core/utils/utils' ; import { Page } from '@nativescript/core/ui/page' ; import { Color } from '@nativescript/core/color' ; import { BeancountFileService } from '../shared/beancount-file.service' ; import { openFilePicker } from '../shared/beancount-file-picker' ; import { SideDrawerService } from '../shared/sidedrawer.service' ; const BEANCOUNT_WEBSITE = 'http://furius.ca/beancount/' ; @ Component ( { selector : 'bc-welcome' , templateUrl : './welcome.component.html' , styleUrls : [ './welcome.component.scss' ] , } ) export class WelcomeComponent implements OnInit { welcomeText = 'Beancount is a plain-text accounting system. ' + 'You can read more about it at the ' + `<a href="${ BEANCOUNT_WEBSITE }">Beancount website</a>.` ; filePath : string ; @ ViewChild ( 'welcomeTextView' , { static : false } ) welcomeTextView : ElementRef ; constructor ( private ngZone , private page , private routerExtensions , private sideDrawer , private beancountFile ) { page . actionBarHidden = true ; } ngOnInit ( ) { this . sideDrawer . lock ( ) ; this . filePath = this . beancountFile . path ; } onWelcomeTextLoaded ( ) { const element = this . welcomeTextView . nativeElement . android ; element . setTextSize ( 16 ) ; element . setLetterSpacing ( 0.04 ) ; const textColor = new Color ( 255 * 0.6 , 255 , 255 , 255 ) . android ; element . setTextColor ( textColor ) ; element . setLinkTextColor ( textColor ) ; } openBeancountWebsite ( ) { openUrl ( BEANCOUNT_WEBSITE ) ; } openFilePicker ( ) { openFilePicker ( ) . then ( ( filePath ) => { if ( filePath ) { this . filePath = filePath ; } } ) . catch ( ( error ) => { console . warn ( error ) ; } ) ; } isValidPath ( ) { return BeancountFileService . isValidPath ( this . filePath ) ; } onContinueTap ( ) { this . beancountFile . setPath ( this . filePath ) ; this . beancountFile . load ( ) . then ( ( ) => { this . sideDrawer . unlock ( ) ; this . routerExtensions . navigate ( [ '/plaintext' ] , { clearHistory : true , } ) ; } ) . catch ( ( error ) => { this . beancountFile . reset ( ) ; console . warn ( error ) ; } ) ; } }