Added books component

pull/1574/head
Halil İbrahim Kalkan 6 years ago
parent b324cbd2cc
commit 7d683b82d1

@ -48,6 +48,7 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ngxs-schematic": "^1.1.5",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",

@ -16,6 +16,11 @@ const routes: Routes = [
} as ABP.Route,
},
},
{ path: 'books', loadChildren: () => import('./books/books.module').then(m => m.BooksModule), data: {
routes: {
name: 'Books',
} as ABP.Route,
}, },
{
path: 'account',
loadChildren: () => import('./lazy-libs/account-wrapper.module').then(m => m.AccountWrapperModule),
@ -33,6 +38,7 @@ const routes: Routes = [
data: { routes: TENANT_MANAGEMENT_ROUTES },
},
{ path: '**', redirectTo: '/' },
];
@NgModule({

@ -11,12 +11,15 @@ import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';
import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { BooksState } from './store/states/books.state';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
HttpClientModule,
AppRoutingModule,
SharedModule,
ThemeSharedModule.forRoot(),
@ -27,7 +30,7 @@ import { ThemeSharedModule } from '@abp/ng.theme.shared';
},
}),
OAuthModule.forRoot(),
NgxsModule.forRoot([]),
NgxsModule.forRoot([BooksState, ]),
NgxsReduxDevtoolsPluginModule.forRoot({ disabled: environment.production }),
],
providers: [],

@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { BooksComponent } from './books.component';
import { LayoutApplicationComponent } from '@abp/ng.theme.basic';
const routes: Routes = [
{
path: '',
component: LayoutApplicationComponent,
children: [{ path: '', component: BooksComponent }],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class BooksRoutingModule { }

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BooksComponent } from './books.component';
describe('BooksComponent', () => {
let component: BooksComponent;
let fixture: ComponentFixture<BooksComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BooksComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BooksComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,13 @@
import { Component, OnInit } from "@angular/core";
import { Store } from "@ngxs/store";
@Component({
selector: "app-books",
templateUrl: "./books.component.html",
styleUrls: ["./books.component.scss"]
})
export class BooksComponent implements OnInit {
constructor(private store: Store) {}
ngOnInit() {}
}

@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BooksRoutingModule } from './books-routing.module';
import { BooksComponent } from './books.component';
import { SharedModule } from '../shared/shared.module';
@NgModule({
declarations: [BooksComponent],
imports: [
CommonModule,
BooksRoutingModule,
SharedModule
]
})
export class BooksModule { }

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { BooksService } from './books.service';
describe('BooksService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: BooksService = TestBed.get(BooksService);
expect(service).toBeTruthy();
});
});

@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class BooksService {
constructor(private http: HttpClient) { }
get() {
return this.http.get(`${environment.apis.default.url}/app/book`)
}
}

@ -0,0 +1,4 @@
export class BooksGet {
static readonly type = '[Books] Get';
constructor(public readonly payload?: any) { }
}

@ -0,0 +1,5 @@
export namespace Books {
export interface State {
data: any;
}
}

@ -0,0 +1,27 @@
import { State, Action, StateContext } from "@ngxs/store";
import { BooksGet } from "../actions/books.actions";
import { Books } from "../models/books";
import { BooksService } from "src/app/shared/services/books.service";
import { tap } from "rxjs/operators";
@State<Books.State>({
name: "BooksState",
defaults: {} as Books.State
})
export class BooksState {
constructor(private booksService: BooksService) {}
@Action(BooksGet)
booksAction(
{ getState, patchState }: StateContext<Books.State>,
{ payload }: BooksGet
) {
return this.booksService.get().pipe(
tap(data => {
patchState({
data
});
})
);
}
}
Loading…
Cancel
Save