Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add angular-material UI choice #155

Merged
merged 4 commits into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions generators/app/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ module.exports = [
value: 'bootstrap',
name: 'Bootstrap (more website-oriented)'
},
{
value: 'material',
name: 'Angular Material (more website-oriented)'
},
{
value: 'ionic',
name: 'Ionic (more mobile-oriented)'
Expand Down
4 changes: 4 additions & 0 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5",
"bootstrap": "4.0.0-beta",
"font-awesome": "^4.7.0",
<% } else if (props.ui === 'material') { -%>
"@angular/cdk": "^2.0.0-beta.12",
"@angular/material": "^2.0.0-beta.12",
"font-awesome": "^4.7.0",
<% } -%>
"core-js": "^2.4.1",
"lodash": "^4.17.4",
Expand Down
2 changes: 2 additions & 0 deletions generators/app/templates/src/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@
<% } else if (props.ui === 'bootstrap') { -%>
@import "~bootstrap/scss/bootstrap";
@import "~font-awesome/scss/font-awesome.scss";
<% } else if (props.ui === 'material') { -%>
@import "~font-awesome/scss/font-awesome.scss";
<% } -%>

// Theme customization
Expand Down
70 changes: 70 additions & 0 deletions generators/app/templates/src/app/__material.material.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { NgModule } from '@angular/core';
import { CdkTableModule } from '@angular/cdk/table';
import { OverlayModule } from '@angular/cdk/overlay';
import {
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatNativeDateModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatSliderModule,
MatSlideToggleModule,
MatSnackBarModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
} from '@angular/material';

@NgModule({
exports: [
// CDk
CdkTableModule,
OverlayModule,

// Material
MatAutocompleteModule,
MatButtonModule,
MatButtonToggleModule,
MatCardModule,
MatCheckboxModule,
MatChipsModule,
MatDatepickerModule,
MatDialogModule,
MatExpansionModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatListModule,
MatMenuModule,
MatProgressBarModule,
MatProgressSpinnerModule,
MatRadioModule,
MatRippleModule,
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule,
MatSliderModule,
MatSnackBarModule,
MatTabsModule,
MatToolbarModule,
MatTooltipModule,
MatNativeDateModule,
]
})
export class MaterialModule { }
10 changes: 8 additions & 2 deletions generators/app/templates/src/app/_app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { TranslateModule } from '@ngx-translate/core';
<% if (props.ui === 'bootstrap') { -%>
<% if (props.ui === 'material') { -%>
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MaterialModule } from './material.module';
<% } else if (props.ui === 'bootstrap') { -%>
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
<% } else if (props.ui === 'ionic') { -%>
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
Expand Down Expand Up @@ -35,7 +38,10 @@ import { LoginModule } from './login/login.module';
FormsModule,
HttpModule,
TranslateModule.forRoot(),
<% if (props.ui === 'bootstrap') { -%>
<% if (props.ui === 'material') { -%>
BrowserAnimationsModule,
MaterialModule,
<% } else if (props.ui === 'bootstrap') { -%>
NgbModule.forRoot(),
<% } else if (props.ui === 'ionic') { -%>
IonicModule.forRoot(AppComponent, {locationStrategy: 'path'}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="app-content text-center">
<h1>
<span translate>APP_NAME</span>
</h1>
<p>
<i class="fa fa-bookmark-o"></i> <span translate>Version</span> {{version}}
</p>
</div>
8 changes: 6 additions & 2 deletions generators/app/templates/src/app/core/_core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { HttpModule, Http, XHRBackend, ConnectionBackend, RequestOptions } from
import { TranslateModule } from '@ngx-translate/core';
<% if (props.ui === 'bootstrap') { -%>
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
<% } else if (props.ui === 'material') { -%>
import { MaterialModule } from './../material.module';
<% } else if (props.ui === 'ionic') { -%>
import { IonicModule } from 'ionic-angular';
<% } -%>

import { ShellComponent } from './shell/shell.component';
<% if (props.ui === 'bootstrap') { -%>
<% if (props.ui === 'bootstrap' || props.ui === 'material') { -%>
import { HeaderComponent } from './shell/header/header.component';
<% } -%>
<% if (props.auth) { -%>
Expand All @@ -34,6 +36,8 @@ export function createHttpService(backend: ConnectionBackend,
TranslateModule,
<% if (props.ui === 'bootstrap') { -%>
NgbModule,
<% } else if (props.ui === 'material') { -%>
MaterialModule,
<% } else if (props.ui === 'ionic') { -%>
IonicModule,
<% } -%>
Expand All @@ -45,7 +49,7 @@ export function createHttpService(backend: ConnectionBackend,
],
<% } -%>
declarations: [
<% if (props.ui === 'bootstrap') { -%>
<% if (props.ui === 'bootstrap' || props.ui === 'material') { -%>
HeaderComponent,
<% } -%>
ShellComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<app-header></app-header>
<router-outlet></router-outlet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-shell',
templateUrl: './shell.component.html',
styleUrls: ['./shell.component.scss']
})
export class ShellComponent implements OnInit {

constructor() { }

ngOnInit() { }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<mat-toolbar class="mat-elevation-z6 navbar" color="primary">
<span><a class="toolbar-brand" href="https://github.com/ngx-rocket" translate>APP_NAME</a></span>
<span class="example-spacer"></span>
<button mat-button routerLink="/home" routerLinkActive="active">
<i class="fa fa-home"></i>
<span translate>Home</span>
</button>
<button mat-button routerLink="/about" routerLinkActive="active">
<i class="fa fa-question-circle"></i>
<span translate>About</span>
</button>
<button mat-button [matMenuTriggerFor]="langMenu">
{{currentLanguage}}
</button>
<mat-menu #langMenu="matMenu">
<button mat-menu-item *ngFor="let language of languages" (click)="setLanguage(language)">
{{language}}
</button>
</mat-menu>
<% if (props.auth) { -%>
<button mat-icon-button [matMenuTriggerFor]="userMenu">
<i class="fa fa-user-circle"></i>
</button>
<mat-menu #userMenu="matMenu">
<mat-list>
<mat-list-item><span translate>Logged in as</span>&nbsp;<b>{{username}}</b></mat-list-item>
</mat-list>
<button mat-menu-item (click)="logout()" translate>Logout</button>
</mat-menu>
<% } -%>
</mat-toolbar>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from './../../../material.module';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';

<% if (props.auth) { -%>
import { AuthenticationService } from '../../authentication/authentication.service';
import { MockAuthenticationService } from '../../authentication/authentication.service.mock';
<% } -%>
import { I18nService } from '../../i18n.service';
import { HeaderComponent } from './header.component';

describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule,
TranslateModule.forRoot()
],
declarations: [HeaderComponent],
providers: [
<% if (props.auth) { -%>
{ provide: AuthenticationService, useClass: MockAuthenticationService },
<% } -%>
I18nService
]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(HeaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Component, OnInit } from '@angular/core';
<% if (props.auth) { -%>
import { Router } from '@angular/router';

import { AuthenticationService } from '../../authentication/authentication.service';
<% } else { -%>

<% } -%>
import { I18nService } from '../../i18n.service';

@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {

menuHidden = true;
langMenu: Object;
userMenu: Object;

<% if (props.auth) { -%>
constructor(private router: Router,
private authenticationService: AuthenticationService,
private i18nService: I18nService) { }
<% } else { -%>
constructor(private i18nService: I18nService) { }
<% } -%>

ngOnInit() { }

toggleMenu() {
this.menuHidden = !this.menuHidden;
}

setLanguage(language: string) {
this.i18nService.language = language;
}

<% if (props.auth) { -%>
logout() {
this.authenticationService.logout()
.subscribe(() => this.router.navigate(['/login'], { replaceUrl: true }));
}

<% } -%>
get currentLanguage(): string {
return this.i18nService.language;
}

get languages(): string[] {
return this.i18nService.supportedLanguages;
}

<% if (props.auth) { -%>
get username(): string {
const credentials = this.authenticationService.credentials;
return credentials ? credentials.username : null;
}

<% } -%>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import "src/theme/theme-variables";

.navbar {
position: sticky;
}

.toolbar-brand {
color: #fff;
text-decoration: none;
}

.example-spacer {
flex: 1 1 auto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="app-content text-center">
<h1>
<img class="logo" src="assets/ngx-rocket-logo.png" alt="angular logo" />
<span translate>Hello world !</span>
</h1>
<app-loader [isLoading]="isLoading"></app-loader>
<q [hidden]="isLoading" class="text-center">{{quote}}</q>
</div>
8 changes: 6 additions & 2 deletions generators/app/templates/src/app/home/_home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Http, BaseRequestOptions } from '@angular/http';
import { MockBackend } from '@angular/http/testing';
<% if (props.ui === 'ionic') { -%>
<% if (props.ui === 'material') { -%>
import { MaterialModule } from './../material.module';
<% } else if (props.ui === 'ionic') { -%>
import { IonicModule } from 'ionic-angular';
<% } -%>

Expand All @@ -16,7 +18,9 @@ describe('HomeComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
<% if (props.ui === 'ionic') { -%>
<% if (props.ui === 'material') { -%>
MaterialModule,
<% } else if (props.ui === 'ionic') { -%>
IonicModule.forRoot(HomeComponent),
<% } -%>
SharedModule
Expand Down
8 changes: 6 additions & 2 deletions generators/app/templates/src/app/home/_home.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
<% if (props.ui === 'ionic') { -%>
<% if (props.ui === 'material') { -%>
import { MaterialModule } from './../material.module';
<% } else if (props.ui === 'ionic') { -%>
import { IonicModule } from 'ionic-angular';
<% } -%>

Expand All @@ -17,7 +19,9 @@ import { QuoteService } from './quote.service';
TranslateModule,
CoreModule,
SharedModule,
<% if (props.ui === 'ionic') { -%>
<% if (props.ui === 'material') { -%>
MaterialModule,
<% } else if (props.ui === 'ionic') { -%>
IonicModule,
<% } -%>
HomeRoutingModule
Expand Down
Loading