-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ionic tabs after shell integration as component
Closes #106
- Loading branch information
1 parent
96dd32f
commit 9ddb56e
Showing
22 changed files
with
372 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
generators/app/templates/src/app/settings/__ionic-tabs._settings-routing.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
|
||
import { extract } from '@app/core'; | ||
import { SettingsComponent } from '@app/settings/settings.component'; | ||
import { Shell } from '@app/shell/shell.service'; | ||
|
||
const routes: Routes = [ | ||
Shell.childRoutes([ | ||
{ path: 'settings', component: SettingsComponent, data: { title: extract('Settings') } } | ||
]) | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
providers: [] | ||
}) | ||
export class SettingsRoutingModule { } |
40 changes: 40 additions & 0 deletions
40
generators/app/templates/src/app/settings/__ionic-tabs._settings.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<ion-header> | ||
<ion-navbar color="primary"> | ||
<ion-title><span translate>Settings</span></ion-title> | ||
</ion-navbar> | ||
</ion-header> | ||
<ion-content> | ||
<% if (props.auth) { -%> | ||
<div> | ||
<div class="profile" text-center padding> | ||
<ion-icon class="profile-icon" name="contact"></ion-icon> | ||
<div class="profile-title">{{username}}</div> | ||
</div> | ||
</div> | ||
<ion-list-header> | ||
<ion-label translate>Account</ion-label> | ||
</ion-list-header> | ||
<button ion-item> | ||
<ion-icon name="contact" item-start></ion-icon> | ||
<ion-label translate>Profile</ion-label> | ||
</button> | ||
<ion-item (click)="logout()"> | ||
<ion-icon name="md-log-out" item-start></ion-icon> | ||
<ion-label translate>Logout</ion-label> | ||
</ion-item> | ||
<% } -%> | ||
|
||
<ion-list-header> | ||
<ion-label translate>Preferences</ion-label> | ||
</ion-list-header> | ||
<button *ngIf="isWeb" ion-item (click)="changeLanguage()"> | ||
<ion-icon name="md-globe" item-start></ion-icon> | ||
<ion-label translate>Change language</ion-label> | ||
</button> | ||
<ion-item> | ||
<ion-icon name="notifications" item-start></ion-icon> | ||
<ion-label translate>Notifications</ion-label> | ||
<ion-toggle></ion-toggle> | ||
</ion-item> | ||
|
||
</ion-content> |
19 changes: 19 additions & 0 deletions
19
generators/app/templates/src/app/settings/__ionic-tabs._settings.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import "src/theme/theme-variables"; | ||
|
||
[ion-fixed] { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.profile { | ||
background: color($colors, primary); | ||
} | ||
|
||
.profile-icon { | ||
font-size: 6rem; | ||
color: color-contrast($colors, primary); | ||
} | ||
|
||
.profile-title { | ||
color: color-contrast($colors, primary); | ||
} |
37 changes: 37 additions & 0 deletions
37
generators/app/templates/src/app/settings/__ionic-tabs._settings.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { IonicModule } from 'ionic-angular'; | ||
|
||
import { SharedModule } from '@app/shared'; | ||
import { CoreModule } from '@app/core'; | ||
import { SettingsComponent } from './settings.component'; | ||
|
||
describe('SettingsComponent', () => { | ||
let component: SettingsComponent; | ||
let fixture: ComponentFixture<SettingsComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule, | ||
TranslateModule.forRoot(), | ||
IonicModule.forRoot(SettingsComponent), | ||
CoreModule, | ||
SharedModule | ||
], | ||
declarations: [ SettingsComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SettingsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
generators/app/templates/src/app/settings/__ionic-tabs._settings.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActionSheetController, AlertController, Platform } from 'ionic-angular'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { I18nService } from '@app/core/i18n.service'; | ||
<% if (props.auth) { -%> | ||
import { AuthenticationService } from '@app/core/authentication/authentication.service'; | ||
<% } -%> | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-settings', | ||
templateUrl: './settings.component.html', | ||
styleUrls: ['./settings.component.scss'] | ||
}) | ||
export class SettingsComponent implements OnInit { | ||
|
||
constructor(private router: Router, | ||
private activatedRoute: ActivatedRoute, | ||
private translateService: TranslateService, | ||
private platform: Platform, | ||
private alertController: AlertController, | ||
private actionSheetController: ActionSheetController, | ||
<% if (props.auth) { -%> | ||
private authenticationService: AuthenticationService, | ||
<% } -%> | ||
private i18nService: I18nService) { } | ||
|
||
ngOnInit() { } | ||
|
||
get isWeb(): boolean { | ||
return !this.platform.is('cordova'); | ||
} | ||
|
||
<% if (props.auth) { -%> | ||
get username(): string | null { | ||
const credentials = this.authenticationService.credentials; | ||
return credentials ? credentials.username : null; | ||
} | ||
|
||
logout() { | ||
this.authenticationService.logout() | ||
.subscribe(() => this.router.navigate(['/login'], { replaceUrl: true })); | ||
} | ||
<% } -%> | ||
|
||
changeLanguage() { | ||
this.alertController | ||
.create({ | ||
title: this.translateService.instant('Change language'), | ||
inputs: this.i18nService.supportedLanguages.map(language => ({ | ||
type: 'radio', | ||
label: language, | ||
value: language, | ||
checked: language === this.i18nService.language | ||
})), | ||
buttons: [ | ||
{ | ||
text: this.translateService.instant('Cancel'), | ||
role: 'cancel' | ||
}, | ||
{ | ||
text: this.translateService.instant('Ok'), | ||
handler: language => { | ||
this.i18nService.language = language; | ||
} | ||
} | ||
] | ||
}) | ||
.present(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
generators/app/templates/src/app/settings/__ionic-tabs._settings.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { IonicModule } from 'ionic-angular'; | ||
|
||
import { SettingsRoutingModule } from './settings-routing.module'; | ||
import { SettingsComponent } from './settings.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
TranslateModule, | ||
IonicModule, | ||
SettingsRoutingModule | ||
], | ||
entryComponents: [ | ||
SettingsComponent | ||
], | ||
declarations: [ | ||
SettingsComponent | ||
] | ||
}) | ||
export class SettingsModule { } |
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
generators/app/templates/src/app/shell/__ionic-tabs.shell.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<ion-tabs #navTabs *ngIf="tabs" [selectedIndex]="selectedTabIndex" (ionChange)="onTabChange($event)"> | ||
<ion-tab *ngFor="let t of tabs" [root]="t.component" [tabTitle]="t.title | translate" [tabIcon]="t.icon"></ion-tab> | ||
</ion-tabs> |
52 changes: 52 additions & 0 deletions
52
generators/app/templates/src/app/shell/__ionic-tabs.shell.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; | ||
import { Tab } from 'ionic-angular'; | ||
import { filter } from 'rxjs/operators'; | ||
import { findIndex } from 'lodash'; | ||
import { SettingsComponent } from '@app/settings/settings.component'; | ||
import { AboutComponent } from '@app/about/about.component'; | ||
import { HomeComponent } from '@app/home/home.component'; | ||
@Component({ | ||
selector: 'app-shell', | ||
templateUrl: './shell.component.html', | ||
styleUrls: ['./shell.component.scss'] | ||
}) | ||
export class ShellComponent implements OnInit { | ||
tabs = [ | ||
{ component: HomeComponent, route: 'home', title: 'Home', icon: 'home' }, | ||
{ component: AboutComponent, route: 'about', title: 'About', icon: 'logo-angular' }, | ||
{ component: SettingsComponent, route: 'settings', title: 'Settings', icon: 'cog' } | ||
]; | ||
selectedTabIndex: number; | ||
subscription: any; | ||
constructor(private router: Router, | ||
private activatedRoute: ActivatedRoute) { | ||
} | ||
ngOnInit() { | ||
this.updateTab(this.activatedRoute); | ||
// Bind Ionic navigation to Angular router events | ||
this.subscription = this.router.events | ||
.pipe(filter(event => event instanceof NavigationEnd)) | ||
.subscribe(() => this.updateTab(this.activatedRoute)); | ||
} | ||
onTabChange(selectedTab: Tab) { | ||
this.router.navigate([this.tabs[selectedTab.index].route]); | ||
} | ||
private updateTab(route: ActivatedRoute) { | ||
if (!route || !route.firstChild) { | ||
return; | ||
} | ||
// First component should always be IonicApp | ||
route = route.firstChild; | ||
if (route && route.component === ShellComponent && route.firstChild) { | ||
route = route.firstChild; | ||
// Fixed the bug#19420 : route.component is undefined if module is lazy | ||
// See: https://github.com/angular/angular/issues/19420 | ||
while (route.firstChild) { | ||
route = route.firstChild; | ||
} | ||
// Fixed #19420 end | ||
this.selectedTabIndex = findIndex(this.tabs, { route: route.routeConfig.path }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.