From 0c7bb4d1f65b2b0255a686c4b38ff446f93fe53f Mon Sep 17 00:00:00 2001 From: Darren Nelsen Date: Fri, 4 Aug 2017 14:04:20 -0400 Subject: [PATCH] Added HeadNavComponent to use on all pages --- app/package.json | 2 +- app/src/components/head-nav/head-nav.html | 12 +++ .../components/head-nav/head-nav.module.ts | 16 +++ app/src/components/head-nav/head-nav.scss | 3 + app/src/components/head-nav/head-nav.ts | 101 ++++++++++++++++++ app/src/pages/address/address.html | 13 +-- app/src/pages/address/address.module.ts | 4 +- app/src/pages/block-detail/block-detail.html | 13 +-- .../pages/block-detail/block-detail.module.ts | 4 +- app/src/pages/blocksPage/blocksPage.html | 13 +-- app/src/pages/blocksPage/blocksPage.spec.ts | 2 + app/src/pages/blocksPage/blocksPage.ts | 81 +------------- app/src/pages/pages.module.ts | 3 +- app/src/pages/transaction/transaction.html | 13 +-- .../pages/transaction/transaction.module.ts | 4 +- app/src/test.ts | 4 +- 16 files changed, 154 insertions(+), 134 deletions(-) create mode 100644 app/src/components/head-nav/head-nav.html create mode 100644 app/src/components/head-nav/head-nav.module.ts create mode 100644 app/src/components/head-nav/head-nav.scss create mode 100644 app/src/components/head-nav/head-nav.ts diff --git a/app/package.json b/app/package.json index c00cda2..9b656f6 100644 --- a/app/package.json +++ b/app/package.json @@ -37,7 +37,7 @@ "devDependencies": { "@angular/cli": "1.1.2", "@ionic/app-scripts": "1.3.7", - "@ionic/cli-plugin-cordova": "1.6.1", + "@ionic/cli-plugin-cordova": "1.6.2", "@ionic/cli-plugin-ionic-angular": "1.4.1", "@types/jasmine": "2.5.41", "@types/node": "7.0.4", diff --git a/app/src/components/head-nav/head-nav.html b/app/src/components/head-nav/head-nav.html new file mode 100644 index 0000000..b441164 --- /dev/null +++ b/app/src/components/head-nav/head-nav.html @@ -0,0 +1,12 @@ + + + {{title}} + + + + + diff --git a/app/src/components/head-nav/head-nav.module.ts b/app/src/components/head-nav/head-nav.module.ts new file mode 100644 index 0000000..7fb2c00 --- /dev/null +++ b/app/src/components/head-nav/head-nav.module.ts @@ -0,0 +1,16 @@ +import { NgModule } from '@angular/core'; +import { IonicModule } from 'ionic-angular'; +import { HeadNavComponent } from './head-nav'; + +@NgModule({ + declarations: [ + HeadNavComponent, + ], + imports: [ + IonicModule, + ], + exports: [ + HeadNavComponent + ] +}) +export class HeadNavComponentModule {} diff --git a/app/src/components/head-nav/head-nav.scss b/app/src/components/head-nav/head-nav.scss new file mode 100644 index 0000000..b78439c --- /dev/null +++ b/app/src/components/head-nav/head-nav.scss @@ -0,0 +1,3 @@ +head-nav { + +} diff --git a/app/src/components/head-nav/head-nav.ts b/app/src/components/head-nav/head-nav.ts new file mode 100644 index 0000000..54fee4c --- /dev/null +++ b/app/src/components/head-nav/head-nav.ts @@ -0,0 +1,101 @@ +import { Component } from '@angular/core'; +import { Input } from '@angular/core'; +import { NavController } from 'ionic-angular'; +import { Http } from '@angular/http'; +import { ApiProvider } from '../../providers/api/api'; + +/** + * Generated class for the HeadNavComponent component. + * + * See https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html + * for more info on Angular Components. + */ +@Component({ + selector: 'head-nav', + templateUrl: 'head-nav.html' +}) +export class HeadNavComponent { + + public loading: boolean; + @Input() public title: string; + public q: string; + public badQuery: boolean = false; + + constructor(private navCtrl: NavController, private http: Http, private api: ApiProvider) { + } + + private resetSearch(): void { + this.q = ''; + this.loading = false; + } + + public search(): void { + let apiPrefix: string = this.api.apiPrefix; + + this.http.get(apiPrefix + 'block/' + this.q).subscribe( + function (data: any) { + this.resetSearch(); + console.log('block', data); + let parsedData: any = JSON.parse(data._body); + this.navCtrl.push('block-detail', { + 'blockHash': parsedData.hash + }); + }.bind(this), + () => { + this.http.get(apiPrefix + 'tx/' + this.q).subscribe( + function (data: any) { + this.resetSearch(); + console.log('tx', data); + let parsedData: any = JSON.parse(data._body); + this.navCtrl.push('transaction', { + 'txId': parsedData.txid + }); + }.bind(this), + () => { + this.http.get(apiPrefix + 'addr/' + this.q).subscribe( + function (data: any) { + this.resetSearch(); + console.log('addr', data); + let parsedData: any = JSON.parse(data._body); + this.navCtrl.push('address', { + 'addrStr': parsedData.addrStr + }); + }.bind(this), + () => { + this.http.get(apiPrefix + 'block-index/' + this.q).subscribe( + function (data: any): void { + this.resetSearch(); + let parsedData: any = JSON.parse(data._body); + this.navCtrl.push('block-detail', { + 'blockHash': parsedData.blockHash + }); + }.bind(this), + function (): void { + this.loading = false; + this.reportBadQuery(); + }.bind(this) + ); + } + ); + } + ); + } + ); + } + + /* tslint:disable:no-unused-variable */ + private reportBadQuery(): void { + this.badQuery = true; + console.log('badQuery', this.badQuery); + + setTimeout( + function (): void { + this.badQuery = false; + console.log('badQuery', this.badQuery); + }.bind(this), + 2000 + ); + }; + /* tslint:enable:no-unused-variable */ + +} diff --git a/app/src/pages/address/address.html b/app/src/pages/address/address.html index 7399a57..df423be 100644 --- a/app/src/pages/address/address.html +++ b/app/src/pages/address/address.html @@ -1,18 +1,7 @@ - - - - Address - - + - diff --git a/app/src/pages/address/address.module.ts b/app/src/pages/address/address.module.ts index 7db7464..e2a4bce 100644 --- a/app/src/pages/address/address.module.ts +++ b/app/src/pages/address/address.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { AddressPage } from './address'; import { TransactionListComponentModule } from '../../components/transaction-list/transaction-list.module'; +import { HeadNavComponentModule } from '../../components/head-nav/head-nav.module'; @NgModule({ declarations: [ @@ -9,7 +10,8 @@ import { TransactionListComponentModule } from '../../components/transaction-lis ], imports: [ IonicPageModule.forChild(AddressPage), - TransactionListComponentModule + TransactionListComponentModule, + HeadNavComponentModule ], exports: [ AddressPage diff --git a/app/src/pages/block-detail/block-detail.html b/app/src/pages/block-detail/block-detail.html index fd7735e..dda09f6 100644 --- a/app/src/pages/block-detail/block-detail.html +++ b/app/src/pages/block-detail/block-detail.html @@ -1,18 +1,7 @@ - - - - Block Detail - - + -

Block # {{ block.height }}

BlockHash {{ block.hash }}

diff --git a/app/src/pages/block-detail/block-detail.module.ts b/app/src/pages/block-detail/block-detail.module.ts index 0a3f8e6..1c835b5 100644 --- a/app/src/pages/block-detail/block-detail.module.ts +++ b/app/src/pages/block-detail/block-detail.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { BlockDetailPage } from './block-detail'; import { TransactionListComponentModule } from '../../components/transaction-list/transaction-list.module'; +import { HeadNavComponentModule } from '../../components/head-nav/head-nav.module'; @NgModule({ declarations: [ @@ -9,7 +10,8 @@ import { TransactionListComponentModule } from '../../components/transaction-lis ], imports: [ IonicPageModule.forChild(BlockDetailPage), - TransactionListComponentModule + TransactionListComponentModule, + HeadNavComponentModule ], exports: [ BlockDetailPage diff --git a/app/src/pages/blocksPage/blocksPage.html b/app/src/pages/blocksPage/blocksPage.html index 98e1422..6e7d491 100644 --- a/app/src/pages/blocksPage/blocksPage.html +++ b/app/src/pages/blocksPage/blocksPage.html @@ -1,16 +1,5 @@ - - - {{title}} - - - - - + diff --git a/app/src/pages/blocksPage/blocksPage.spec.ts b/app/src/pages/blocksPage/blocksPage.spec.ts index 27921e3..4e8ace9 100644 --- a/app/src/pages/blocksPage/blocksPage.spec.ts +++ b/app/src/pages/blocksPage/blocksPage.spec.ts @@ -21,9 +21,11 @@ describe('Blocks', () => { expect(instance).toBeTruthy(); }); + /* it('has a search method', () => { spyOn(instance, 'search'); instance.search(); expect(instance.search).toHaveBeenCalled(); }); + */ }); diff --git a/app/src/pages/blocksPage/blocksPage.ts b/app/src/pages/blocksPage/blocksPage.ts index 740a6ff..5f2eeaf 100644 --- a/app/src/pages/blocksPage/blocksPage.ts +++ b/app/src/pages/blocksPage/blocksPage.ts @@ -3,8 +3,6 @@ import { NavController } from 'ionic-angular'; import { Observable } from 'rxjs'; import { Block } from '../../models'; import { BlocksService } from '../../services'; -import { Http } from '@angular/http'; -import { ApiProvider } from '../../providers/api/api'; @Component({ templateUrl: './blocksPage.html' @@ -12,13 +10,10 @@ import { ApiProvider } from '../../providers/api/api'; export class BlocksPage { - public loading: boolean; public title: string; public blocks: Observable; - public q: string; - public badQuery: boolean = false; - constructor(private navCtrl: NavController, private http: Http, private blocksService: BlocksService, private api: ApiProvider) { + constructor(private navCtrl: NavController, private blocksService: BlocksService) { this.title = 'Blocks'; this.blocks = blocksService.latestBlocks; this.blocks.subscribe((blocks) => { @@ -27,80 +22,6 @@ export class BlocksPage { blocksService.getLatestBlocks(); } - public search(): void { - let apiPrefix: string = this.api.apiPrefix; - - this.http.get(apiPrefix + 'block/' + this.q).subscribe( - function (data: any) { - this.resetSearch(); - console.log('block', data); - let parsedData: any = JSON.parse(data._body); - this.navCtrl.push('block-detail', { - 'blockHash': parsedData.hash - }); - }.bind(this), - () => { - this.http.get(apiPrefix + 'tx/' + this.q).subscribe( - function (data: any) { - this.resetSearch(); - console.log('tx', data); - let parsedData: any = JSON.parse(data._body); - this.navCtrl.push('transaction', { - 'txId': parsedData.txid - }); - }.bind(this), - () => { - this.http.get(apiPrefix + 'addr/' + this.q).subscribe( - function (data: any) { - this.resetSearch(); - console.log('addr', data); - let parsedData: any = JSON.parse(data._body); - this.navCtrl.push('address', { - 'addrStr': parsedData.addrStr - }); - }.bind(this), - () => { - this.http.get(apiPrefix + 'block-index/' + this.q).subscribe( - function (data: any): void { - this.resetSearch(); - let parsedData: any = JSON.parse(data._body); - this.navCtrl.push('block-detail', { - 'blockHash': parsedData.blockHash - }); - }.bind(this), - function (): void { - this.loading = false; - this.reportBadQuery(); - }.bind(this) - ); - } - ); - } - ); - } - ); - } - - private resetSearch(): void { - this.q = ''; - this.loading = false; - } - - /* tslint:disable:no-unused-variable */ - private reportBadQuery(): void { - this.badQuery = true; - console.log('badQuery', this.badQuery); - - setTimeout( - function (): void { - this.badQuery = false; - console.log('badQuery', this.badQuery); - }.bind(this), - 2000 - ); - }; - /* tslint:enable:no-unused-variable */ - public goToBlock(blockHash: string): void { this.navCtrl.push('block-detail', { 'blockHash': blockHash diff --git a/app/src/pages/pages.module.ts b/app/src/pages/pages.module.ts index fe59ce6..2da0e6a 100644 --- a/app/src/pages/pages.module.ts +++ b/app/src/pages/pages.module.ts @@ -1,6 +1,7 @@ import { NgModule } from '@angular/core'; import { IonicModule } from 'ionic-angular'; import { ComponentsModule } from '../components'; +import { HeadNavComponentModule } from '../components/head-nav/head-nav.module'; import { BlocksPage, BroadcastTxPage, @@ -15,7 +16,7 @@ import { NodeStatusPage, VerifyMessagePage ], - imports: [ IonicModule, ComponentsModule ], + imports: [ IonicModule, ComponentsModule, HeadNavComponentModule ], exports: [ // CustomComponent, ], diff --git a/app/src/pages/transaction/transaction.html b/app/src/pages/transaction/transaction.html index 1d15e84..9bfe587 100644 --- a/app/src/pages/transaction/transaction.html +++ b/app/src/pages/transaction/transaction.html @@ -1,18 +1,7 @@ - - - - Transaction - - + - diff --git a/app/src/pages/transaction/transaction.module.ts b/app/src/pages/transaction/transaction.module.ts index 1fdea86..b24dc21 100644 --- a/app/src/pages/transaction/transaction.module.ts +++ b/app/src/pages/transaction/transaction.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { IonicPageModule } from 'ionic-angular'; import { TransactionPage } from './transaction'; import { TransactionComponentModule } from '../../components/transaction/transaction.module'; +import { HeadNavComponentModule } from '../../components/head-nav/head-nav.module'; @NgModule({ declarations: [ @@ -9,7 +10,8 @@ import { TransactionComponentModule } from '../../components/transaction/transac ], imports: [ IonicPageModule.forChild(TransactionPage), - TransactionComponentModule + TransactionComponentModule, + HeadNavComponentModule ], exports: [ TransactionPage diff --git a/app/src/test.ts b/app/src/test.ts index 77420ca..5a0cc78 100644 --- a/app/src/test.ts +++ b/app/src/test.ts @@ -17,6 +17,7 @@ import { ConfigMock, PlatformMock } from './mocks'; import { BlocksServiceMock } from './services/mocks'; import { BlocksService } from './services'; import { ApiProvider } from './providers/api/api'; +import { HeadNavComponentModule } from './components/head-nav/head-nav.module'; // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. declare var __karma__: any; @@ -68,7 +69,8 @@ export class TestUtils { FormsModule, IonicModule, ReactiveFormsModule, - HttpModule + HttpModule, + HeadNavComponentModule ] }); }