Skip to content

Commit

Permalink
Merge pull request #12 from FurtunaDaniel/structure
Browse files Browse the repository at this point in the history
Get rid on Inject in constructor for momentjs
  • Loading branch information
FurtunaDaniel authored Sep 6, 2018
2 parents cef005e + bd30dba commit c962fda
Show file tree
Hide file tree
Showing 26 changed files with 140 additions and 130 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ before_script:
- npm install -g --silent firebase-tools # installs firebase to run firebase deploy
- npm install -g --silent @angular/cli

script:
install:
- travis_wait 30 npm install

script:
- npm run deploy

deploy:
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
"test": "ng test --source-map=false",
"lint": "ng lint",
"e2e": "ng e2e",
"deploy":
"ng build --prod && compodoc -p tsconfig.json -n \"Hr Assist Documentation\" && cp -r documentation/ dist",
"doc":
"./node_modules/.bin/compodoc -p tsconfig.json -s --port 8081 --theme postmark -o ",
"checkNode": "check-node-version --package "
"deploy": "ng build --prod && compodoc -p tsconfig.json -n \"Hr Assist Documentation\" && cp -r documentation/ dist",
"doc": "./node_modules/.bin/compodoc -p tsconfig.json -s --port 8081 --theme postmark -o ",
"checkNode": "check-node-version --package",
"fixLint": "ng lint hr-assist --fix"
},
"engines": {
"node": ">=8.0.0",
Expand Down Expand Up @@ -52,16 +51,17 @@
"zone.js": "~0.8.26"
},
"devDependencies": {
"check-node-version": "1.1.0",
"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "6.1.3",
"@angular/cli": "6.1.5",
"@angular/compiler-cli": "6.0.7",
"@angular/language-service": "6.0.7",
"@compodoc/compodoc": "^1.1.5",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~10.5.1",
"codelyzer": "~4.4.2",
"check-node-version": "1.1.0",
"codelyzer": "^4.4.4",
"i": "^0.3.6",
"jasmine-core": "~3.1.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.4",
Expand All @@ -74,6 +74,7 @@
"protractor": "~5.3.2",
"ts-node": "~4.1.0",
"tslint": "~5.10.0",
"tslint-angular": "^1.1.2",
"typescript": "2.7.2"
}
}
10 changes: 7 additions & 3 deletions src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { HttpTokenInterceptor } from './interceptors/http.token.interceptor';

import {
AuthentificatHelper,
UserLoginService,
AuthGuard,
AuthStatusService
AuthStatusService,
ApiService,
MomentService
} from './services';
import { ApiService } from './services/api.service';

@NgModule({
imports: [CommonModule],
imports: [CommonModule, FormsModule, ReactiveFormsModule],
providers: [
AuthentificatHelper,
UserLoginService,
AuthGuard,
ApiService,
AuthStatusService,
MomentService,
{
provide: HTTP_INTERCEPTORS,
useClass: HttpTokenInterceptor,
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './auth-guard.service';
export * from './user-login.service';
export * from './AuthentificationHelper.service';
export * from './auth-status.service';
export * from './api.service';
export * from './moment-service';
9 changes: 9 additions & 0 deletions src/app/core/services/moment-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
import * as m from 'moment';

// tslint:disable-next-line:max-line-length
/* better implementation of moment inspired by https://stackoverflow.com/questions/39780378/making-moment-injectable-in-angular2?answertab=active#tab-top */
@Injectable()
export class MomentService {
moment = m;
}
8 changes: 4 additions & 4 deletions src/app/holiday/holidays-list/holidays-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ng-container matColumnDef="index">
<mat-header-cell *matHeaderCellDef
[translate]="'TABLE.NO_HEADER'"> </mat-header-cell>
<mat-cell *matCellDef="let element; let i = index;">{{i+1}}.</mat-cell>
<mat-cell *matCellDef="let element; let i = index;">{{ i+1 }}.</mat-cell>
</ng-container>

<ng-container matColumnDef="employee">
Expand All @@ -30,7 +30,7 @@
mat-sort-header>
<span [translate]="'TABLE.SART_DATE_HEADER'"></span>
</mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element.start_date ? moment(element.start_date).format('LL') : '' }} </mat-cell>
<mat-cell *matCellDef="let element"> {{ element.start_date ? ms.moment(element.start_date).format('LL') : '' }} </mat-cell>
</ng-container>

<ng-container matColumnDef="end_date"
Expand All @@ -39,7 +39,7 @@
mat-sort-header>
<span [translate]="'TABLE.END_DATE_HEADER'"></span>
</mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element.end_date ? moment(element.end_date).format('LL') : '' }} </mat-cell>
<mat-cell *matCellDef="let element"> {{ element.end_date ? ms.moment(element.end_date).format('LL') : '' }} </mat-cell>
</ng-container>

<ng-container matColumnDef="days">
Expand All @@ -56,7 +56,7 @@
<mat-header-cell *matHeaderCellDef
[translate]="'TABLE.HOLIDAYS.SIGNING_DAY'"> </mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element.signing_day? moment(element.signing_day).format('LL'): '' }}
{{ element.signing_day? ms.moment(element.signing_day).format('LL'): '' }}
</mat-cell>
</ng-container>

Expand Down
16 changes: 8 additions & 8 deletions src/app/holiday/holidays-list/holidays-list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ describe('HolidaysListComponent', () => {
let fixture: ComponentFixture<HolidaysListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HolidaysListComponent ]
})
.compileComponents();
TestBed.configureTestingModule({
declarations: [ HolidaysListComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
expect(component).toBeTruthy();
});
});
9 changes: 4 additions & 5 deletions src/app/holiday/holidays-list/holidays-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HolidayService } from '../services/holiday.service';
import { UserService } from '../../user/services/user.service';
import { TranslateService } from '@ngx-translate/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
import { MomentService } from '../../core/services';

@Component({
selector: 'app-holidays-list',
Expand All @@ -22,15 +23,13 @@ export class HolidaysListComponent implements OnInit {
'action'
];
dataSource: MatTableDataSource<any>;
@ViewChild(MatPaginator)
paginator: MatPaginator;
@ViewChild(MatSort)
sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;

constructor(
private holidayService: HolidayService,
private userService: UserService,
@Inject('moment') private moment,
private ms: MomentService,
translate: TranslateService
) {
// this language will be used as a fallback when a translation isn't found in the current language
Expand Down
8 changes: 4 additions & 4 deletions src/app/holiday/services/holiday.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { HolidayService } from './holiday.service';

describe('HolidayService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [HolidayService]
});
TestBed.configureTestingModule({
providers: [HolidayService]
});
});

it('should be created', inject([HolidayService], (service: HolidayService) => {
expect(service).toBeTruthy();
expect(service).toBeTruthy();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ describe('ProjectDetailsComponent', () => {
let fixture: ComponentFixture<ProjectDetailsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ProjectDetailsComponent ]
})
.compileComponents();
TestBed.configureTestingModule({
declarations: [ ProjectDetailsComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
expect(component).toBeTruthy();
});
});
6 changes: 3 additions & 3 deletions src/app/project/projects-list/projects-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ng-container matColumnDef="index">
<mat-header-cell *matHeaderCellDef
[translate]="'TABLE.NO_HEADER'"> </mat-header-cell>
<mat-cell *matCellDef="let element; let i = index;">{{i+1}}.</mat-cell>
<mat-cell *matCellDef="let element; let i = index;">{{ i+1 }}.</mat-cell>
</ng-container>

<ng-container matColumnDef="name">
Expand All @@ -30,7 +30,7 @@
mat-sort-header>
<span [translate]="'TABLE.SART_DATE_HEADER'"></span>
</mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element.start_date ? moment(element.start_date).format('LL') : '' }} </mat-cell>
<mat-cell *matCellDef="let element"> {{ element.start_date ? ms.moment(element.start_date).format('LL') : '' }} </mat-cell>
</ng-container>

<ng-container matColumnDef="end_date"
Expand All @@ -39,7 +39,7 @@
mat-sort-header>
<span [translate]="'TABLE.END_DATE_HEADER'"></span>
</mat-header-cell>
<mat-cell *matCellDef="let element"> {{ element.end_date ? moment(element.end_date).format('LL') : '' }} </mat-cell>
<mat-cell *matCellDef="let element"> {{ element.end_date ? ms.moment(element.end_date).format('LL') : '' }} </mat-cell>
</ng-container>

<ng-container matColumnDef="customer">
Expand Down
16 changes: 8 additions & 8 deletions src/app/project/projects-list/projects-list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ describe('ProjectsListComponent', () => {
let fixture: ComponentFixture<ProjectsListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ProjectsListComponent ]
})
.compileComponents();
TestBed.configureTestingModule({
declarations: [ ProjectsListComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
expect(component).toBeTruthy();
});
});
11 changes: 5 additions & 6 deletions src/app/project/projects-list/projects-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, OnInit, ViewChild, Inject } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatSort, MatPaginator, MatTableDataSource } from '@angular/material';
import { ProjectService } from '../services/project.service';
import { TranslateService } from '@ngx-translate/core';
import { MomentService } from '../../core/services';

@Component({
selector: 'app-projects-list',
Expand All @@ -25,14 +26,12 @@ export class ProjectsListComponent implements OnInit {
dataSource: MatTableDataSource<any>;
isLoading: boolean;

@ViewChild(MatPaginator)
paginator: MatPaginator;
@ViewChild(MatSort)
sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;

constructor(
private projectService: ProjectService,
@Inject('moment') private moment,
private ms: MomentService,
translate: TranslateService
) {
this.isLoading = true;
Expand Down
7 changes: 0 additions & 7 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ import { SpinnerComponent } from './spinner/spinner.component';
imports: [
RouterModule,
HttpClientModule,
CommonModule,
FormsModule,
ReactiveFormsModule,
MatButtonModule,
MatMenuModule,
MatToolbarModule,
Expand Down Expand Up @@ -170,10 +167,6 @@ import { SpinnerComponent } from './spinner/spinner.component';
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE]
},
{
provide: 'moment',
useFactory: (): any => _moment
},

{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS }
]
Expand Down
16 changes: 8 additions & 8 deletions src/app/shared/spinner/spinner.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ describe('SpinnerComponent', () => {
let fixture: ComponentFixture<SpinnerComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SpinnerComponent ]
})
.compileComponents();
TestBed.configureTestingModule({
declarations: [ SpinnerComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit c962fda

Please sign in to comment.