Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 408b3b6

Browse files
committed
refactor(modules): organize into core and material modules
1 parent f65c556 commit 408b3b6

18 files changed

+122
-65
lines changed

src/app/app.component.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { RouterTestingModule } from '@angular/router/testing';
33
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
44
import { AppComponent } from './app.component';
5-
import { ToolbarModule } from './toolbar/toolbar.module';
65
import { MatSidenavModule, MatListModule } from '@angular/material';
7-
import { SeoService } from './services/seo.service';
6+
import { CoreModule } from './core/core.module';
87

98
describe('AppComponent', () => {
109
let component: AppComponent;
@@ -16,12 +15,11 @@ describe('AppComponent', () => {
1615
imports: [
1716
RouterTestingModule,
1817
BrowserAnimationsModule,
19-
ToolbarModule,
18+
CoreModule,
2019
MatSidenavModule,
2120
MatListModule
2221
],
23-
declarations: [AppComponent],
24-
providers: [SeoService]
22+
declarations: [AppComponent]
2523
}).compileComponents();
2624
})
2725
);

src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
RouterEvent
77
} from '@angular/router';
88
import { filter, map, mergeMap } from 'rxjs/operators';
9-
import { SeoService, SeoData } from './services/seo.service';
9+
import { SeoService, SeoData } from './core/services/seo.service';
1010

1111
interface Menu {
1212
title: string;

src/app/app.module.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import { SeoService } from './services/seo.service';
1+
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
3+
import { MatSidenavModule, MatListModule } from '@angular/material';
34
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4-
import { NgModule } from '@angular/core';
5+
import { FlexLayoutModule } from '@angular/flex-layout';
56

6-
import { AppComponent } from './app.component';
7-
import { ToolbarModule } from './toolbar/toolbar.module';
8-
import { MatSidenavModule, MatListModule } from '@angular/material';
7+
import { CoreModule } from '../app/core/core.module';
8+
import { MaterialModule } from './material/material.module';
99
import { AppRoutingModule } from './app-routing.module';
1010

11+
import { AppComponent } from './app.component';
12+
1113
@NgModule({
1214
declarations: [AppComponent],
1315
imports: [
1416
BrowserModule,
1517
BrowserAnimationsModule,
16-
ToolbarModule,
17-
MatListModule,
18-
MatSidenavModule,
19-
AppRoutingModule
18+
FlexLayoutModule,
19+
MaterialModule,
20+
AppRoutingModule,
21+
CoreModule.forRoot()
2022
],
21-
providers: [SeoService],
2223
bootstrap: [AppComponent]
2324
})
2425
export class AppModule {}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { NgModule } from '@angular/core';
2-
32
import { CompaniesComponent } from './companies.component';
43
import { CompaniesRoutingModule } from './companies-routing.module';
5-
import { SharedModule } from '../shared.module';
6-
import { environment } from '../../environments/environment';
74

85
@NgModule({
9-
imports: [CompaniesRoutingModule, SharedModule],
6+
imports: [CompaniesRoutingModule],
107
declarations: [CompaniesComponent]
118
})
129
export class CompaniesModule {}

src/app/toolbar/toolbar.component.spec.ts renamed to src/app/core/components/toolbar/toolbar.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
2-
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
3-
import { RouterTestingModule } from "@angular/router/testing";
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { RouterTestingModule } from '@angular/router/testing';
44

5-
import { ToolbarComponent } from "./toolbar.component";
6-
import { SharedModule } from "../shared.module";
5+
import { ToolbarComponent } from './toolbar.component';
6+
import { SharedModule } from '../shared.module';
77

8-
describe("ToolbarComponent", () => {
8+
describe('ToolbarComponent', () => {
99
let component: ToolbarComponent;
1010
let fixture: ComponentFixture<ToolbarComponent>;
1111

@@ -24,7 +24,7 @@ describe("ToolbarComponent", () => {
2424
fixture.detectChanges();
2525
});
2626

27-
it("should create", () => {
27+
it('should create', () => {
2828
expect(component).toBeTruthy();
2929
});
3030
});

src/app/toolbar/toolbar.component.ts renamed to src/app/core/components/toolbar/toolbar.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component, OnInit, Output, EventEmitter } from "@angular/core";
1+
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
22

33
@Component({
4-
selector: "app-toolbar",
5-
templateUrl: "./toolbar.component.html",
6-
styleUrls: ["./toolbar.component.scss"]
4+
selector: 'app-toolbar',
5+
templateUrl: './toolbar.component.html',
6+
styleUrls: ['./toolbar.component.scss']
77
})
88
export class ToolbarComponent implements OnInit {
99
@Output() navToggle = new EventEmitter<boolean>();

src/app/core/core.module.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { RouterModule } from '@angular/router';
4+
import { FlexLayoutModule } from '@angular/flex-layout';
5+
6+
import { CopierService } from './services/copier.service';
7+
import { SeoService } from './services/seo.service';
8+
import { ToolbarComponent } from './components/toolbar/toolbar.component';
9+
import { MaterialModule } from '../material/material.module';
10+
11+
@NgModule({
12+
imports: [FlexLayoutModule, RouterModule, CommonModule, MaterialModule],
13+
declarations: [ToolbarComponent],
14+
exports: [ToolbarComponent]
15+
})
16+
export class CoreModule {
17+
static forRoot() {
18+
return {
19+
ngModule: CoreModule,
20+
providers: [CopierService, SeoService]
21+
};
22+
}
23+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Injectable } from '@angular/core';
2+
3+
/*
4+
* Based on:
5+
* https://github.com/angular/material.angular.io/blob/c812fadf8e18f57026c56ef3b4d7d3ebb8c441fe/src/app/shared/copier/copier.service.ts
6+
*/
7+
@Injectable()
8+
export class CopierService {
9+
private textarea: HTMLTextAreaElement;
10+
11+
/** Copy the text value to the clipboard. */
12+
copyText(text: string): boolean {
13+
this.createTextareaAndSelect(text);
14+
15+
const copySuccessful = document.execCommand('copy');
16+
this.removeFake();
17+
18+
return copySuccessful;
19+
}
20+
21+
/**
22+
* Creates a hidden textarea element, sets its value from `text` property,
23+
* and makes a selection on it.
24+
*/
25+
private createTextareaAndSelect(text: string) {
26+
// Create a fake element to hold the contents to copy
27+
this.textarea = document.createElement('textarea');
28+
29+
// Prevent zooming on iOS
30+
this.textarea.style.fontSize = '12pt';
31+
32+
// Hide the element
33+
this.textarea.classList.add('cdk-visually-hidden');
34+
35+
// Move element to the same position vertically
36+
const yPosition = window.pageYOffset || document.documentElement.scrollTop;
37+
this.textarea.style.top = yPosition + 'px';
38+
39+
this.textarea.setAttribute('readonly', '');
40+
this.textarea.value = text;
41+
42+
document.body.appendChild(this.textarea);
43+
44+
this.textarea.select();
45+
this.textarea.setSelectionRange(0, this.textarea.value.length);
46+
}
47+
48+
/** Remove the text area from the DOM. */
49+
private removeFake() {
50+
if (this.textarea) {
51+
document.body.removeChild(this.textarea);
52+
this.textarea = null;
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)