Skip to content

Commit

Permalink
added toastr
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenwade committed Nov 19, 2017
1 parent 5cd4e0f commit b110ffe
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions .angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/ngx-toastr/toastr.css",
"styles.css"
],
"scripts": [
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"ngx-toastr": "^6.5.0",
"popper.js": "^1.12.6",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';


import { AppComponent } from './app.component';
import { routes } from './app.routes';
Expand All @@ -14,7 +17,9 @@ import { PagesModule } from './pages/pages.module';
AppComponent
],
imports: [
NgbModule.forRoot(),
NgbModule.forRoot(),
BrowserAnimationsModule,
ToastrModule.forRoot(),
BrowserModule,
SharedModule,
PagesModule,
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/blogAdmin/blogAdmin.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h6>{{post.title2}}</h6>
</div>
</div>
<div class="col-md-2">
<p>Published: {{post.publishedDate | date:'shortDate'}}</p><!--TODO:make date format pipe 10.2.2017-->
<p>Published: {{post.publishedDate | date:'shortDate'}}</p>
</div>
</div>
</div>
11 changes: 6 additions & 5 deletions src/app/pages/blogAdmin/blogAdmin.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { CrudService } from '../../shared/services/crud.service';
import { Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'blog-admin-page',
Expand All @@ -9,13 +10,13 @@ import { Router } from '@angular/router';

export class BlogAdminComponent implements OnInit {
posts:Blog[];
constructor(private crudService:CrudService, private router:Router) { }
constructor(private crudService:CrudService, private router:Router, private toastr:ToastrService) { }

ngOnInit() {
this.crudService.readAll('blogPosts').subscribe((resp)=>{
this.posts = resp;
},(error)=>{
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to retrieve blog posts!");
});
}
public createNewPost(){
Expand All @@ -26,14 +27,14 @@ export class BlogAdminComponent implements OnInit {
};
public deletePost(id:number){
this.crudService.delete('blogPosts',id).subscribe((resp)=>{
console.log("Toast popped!");//TODO:add toastr
this.toastr.success('Successfully deleted blog post.');
this.crudService.readAll('blogPosts').subscribe((resp)=>{
this.posts = resp;
},(error)=>{
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to retrieve blog posts!");
});
},(error)=>{
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to delete blog post!");
});
};
}
23 changes: 13 additions & 10 deletions src/app/pages/blogEdit/blogEdit.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { CrudService } from '../../shared/services/crud.service';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'blog-edit-page',
Expand All @@ -19,7 +20,8 @@ export class BlogEditComponent implements OnInit {
continueReadingLink:'',
publishedDate: undefined
};
constructor(private route: ActivatedRoute, private router:Router, private blogService: CrudService) { };
constructor(private route: ActivatedRoute, private router:Router,
private toastr:ToastrService,private blogService: CrudService) { };

ngOnInit() {
this.route.params.subscribe((params) => {
Expand All @@ -29,7 +31,7 @@ export class BlogEditComponent implements OnInit {
this.blogService.read('blogPosts', id).subscribe((resp) => {
this.post = <Blog>resp[0];
}, (error) => {
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to load blog post!");
});
}
});
Expand All @@ -38,28 +40,29 @@ export class BlogEditComponent implements OnInit {
if (this.isNewPost) {
this.post.publishedDate = new Date();
this.blogService.create('blogPosts', this.post).subscribe((resp) => {
console.error("Toast yum!");//TODO:add toastr
this.toastr.success("Successfully saved blog post.");
this.isNewPost = false;
this.post._id = resp._id;
//TODO:change the route
this.post._id = resp[0];
const newRoute = 'blogadmin/' + this.post._id;
this.router.navigate([newRoute]);
}, (error) => {
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to save blog post!");
});
}
else {
this.blogService.update('blogPosts', this.post._id, this.post).subscribe((resp) => {
console.error("Toast yum!");//TODO:add toastr
this.toastr.success("Successfully updated blog post.");
}, (error) => {
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to update blog post!");
});
}
}
public deletePost(){
this.blogService.delete('blogPosts', this.post._id).subscribe((resp) => {
console.error("Toast yum!");//TODO:add toastr
this.toastr.success("Successfully deleted blog post.");
this.router.navigateByUrl('/blogadmin');
}, (error) => {
console.error("Toast burnt!");//TODO:add toastr
this.toastr.error("Failed to delete blog post!");
});
}
}

0 comments on commit b110ffe

Please sign in to comment.