mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-01 23:10:47 +00:00
Replace ng2-toast with material snacbar, Fixes: #75
This commit is contained in:
parent
5f477a58ce
commit
301edb0bbb
@ -1,2 +1 @@
|
|||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
<ng2-toasty></ng2-toasty>
|
|
@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import {Http} from "@angular/http";
|
import {Http} from "@angular/http";
|
||||||
import {MatIconRegistry} from "@angular/material";
|
import {MatIconRegistry} from "@angular/material";
|
||||||
import {DomSanitizer} from "@angular/platform-browser";
|
import {DomSanitizer} from "@angular/platform-browser";
|
||||||
import {ToastyConfig} from "ng2-toasty";
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -12,9 +11,7 @@ import {ToastyConfig} from "ng2-toasty";
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
constructor(http: Http, iconReg: MatIconRegistry, sanitizer: DomSanitizer, toastyConfig: ToastyConfig) {
|
constructor(http: Http, iconReg: MatIconRegistry, sanitizer: DomSanitizer) {
|
||||||
toastyConfig.theme = 'material';
|
|
||||||
|
|
||||||
iconReg.addSvgIcon('gns3', sanitizer.bypassSecurityTrustResourceUrl('./assets/gns3_icon.svg'));
|
iconReg.addSvgIcon('gns3', sanitizer.bypassSecurityTrustResourceUrl('./assets/gns3_icon.svg'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ import {
|
|||||||
MatTableModule,
|
MatTableModule,
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
MatProgressSpinnerModule
|
MatProgressSpinnerModule,
|
||||||
|
MatSnackBarModule
|
||||||
} from '@angular/material';
|
} from '@angular/material';
|
||||||
|
|
||||||
import { D3Service } from 'd3-ng2-service';
|
import { D3Service } from 'd3-ng2-service';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { ToastyModule } from 'ng2-toasty';
|
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ import { ProjectsComponent } from './projects/projects.component';
|
|||||||
import { DefaultLayoutComponent } from './default-layout/default-layout.component';
|
import { DefaultLayoutComponent } from './default-layout/default-layout.component';
|
||||||
import { ProgressDialogComponent } from './shared/progress-dialog/progress-dialog.component';
|
import { ProgressDialogComponent } from './shared/progress-dialog/progress-dialog.component';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
//import { MapComponent } from './cartography/map/map.component';
|
|
||||||
import { CreateSnapshotDialogComponent, ProjectMapComponent } from './project-map/project-map.component';
|
import { CreateSnapshotDialogComponent, ProjectMapComponent } from './project-map/project-map.component';
|
||||||
import { ServersComponent, AddServerDialogComponent } from './servers/servers.component';
|
import { ServersComponent, AddServerDialogComponent } from './servers/servers.component';
|
||||||
import { NodeContextMenuComponent } from './shared/node-context-menu/node-context-menu.component';
|
import { NodeContextMenuComponent } from './shared/node-context-menu/node-context-menu.component';
|
||||||
@ -52,6 +52,7 @@ import { ApplianceComponent } from './appliance/appliance.component';
|
|||||||
import { ApplianceListDialogComponent } from './appliance/appliance-list-dialog/appliance-list-dialog.component';
|
import { ApplianceListDialogComponent } from './appliance/appliance-list-dialog/appliance-list-dialog.component';
|
||||||
import { NodeSelectInterfaceComponent } from './shared/node-select-interface/node-select-interface.component';
|
import { NodeSelectInterfaceComponent } from './shared/node-select-interface/node-select-interface.component';
|
||||||
import { CartographyModule } from './cartography/cartography.module';
|
import { CartographyModule } from './cartography/cartography.module';
|
||||||
|
import { ToasterService } from './shared/services/toaster.service';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -73,7 +74,6 @@ import { CartographyModule } from './cartography/cartography.module';
|
|||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
NgbModule.forRoot(),
|
NgbModule.forRoot(),
|
||||||
ToastyModule.forRoot(),
|
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
HttpModule,
|
HttpModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
@ -91,6 +91,7 @@ import { CartographyModule } from './cartography/cartography.module';
|
|||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatProgressBarModule,
|
MatProgressBarModule,
|
||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
|
MatSnackBarModule,
|
||||||
CdkTableModule,
|
CdkTableModule,
|
||||||
CartographyModule
|
CartographyModule
|
||||||
],
|
],
|
||||||
@ -106,7 +107,8 @@ import { CartographyModule } from './cartography/cartography.module';
|
|||||||
IndexedDbService,
|
IndexedDbService,
|
||||||
HttpServer,
|
HttpServer,
|
||||||
SnapshotService,
|
SnapshotService,
|
||||||
ProgressDialogService
|
ProgressDialogService,
|
||||||
|
ToasterService
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
AddServerDialogComponent,
|
AddServerDialogComponent,
|
||||||
|
@ -19,20 +19,20 @@ import { MapComponent } from "../cartography/map/map.component";
|
|||||||
import { ServerService } from "../shared/services/server.service";
|
import { ServerService } from "../shared/services/server.service";
|
||||||
import { ProjectService } from '../shared/services/project.service';
|
import { ProjectService } from '../shared/services/project.service';
|
||||||
import { Server } from "../shared/models/server";
|
import { Server } from "../shared/models/server";
|
||||||
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from "@angular/material";
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef, MatSnackBar } from "@angular/material";
|
||||||
import { SnapshotService } from "../shared/services/snapshot.service";
|
import { SnapshotService } from "../shared/services/snapshot.service";
|
||||||
import { Snapshot } from "../shared/models/snapshot";
|
import { Snapshot } from "../shared/models/snapshot";
|
||||||
import { ProgressDialogService } from "../shared/progress-dialog/progress-dialog.service";
|
import { ProgressDialogService } from "../shared/progress-dialog/progress-dialog.service";
|
||||||
import { ProgressDialogComponent } from "../shared/progress-dialog/progress-dialog.component";
|
import { ProgressDialogComponent } from "../shared/progress-dialog/progress-dialog.component";
|
||||||
import { ToastyService } from "ng2-toasty";
|
|
||||||
import { Drawing } from "../cartography/shared/models/drawing.model";
|
import { Drawing } from "../cartography/shared/models/drawing.model";
|
||||||
import { NodeContextMenuComponent } from "../shared/node-context-menu/node-context-menu.component";
|
import { NodeContextMenuComponent } from "../shared/node-context-menu/node-context-menu.component";
|
||||||
import {Appliance} from "../shared/models/appliance";
|
import { Appliance } from "../shared/models/appliance";
|
||||||
import {NodeService} from "../shared/services/node.service";
|
import { NodeService } from "../shared/services/node.service";
|
||||||
import {Symbol} from "../shared/models/symbol";
|
import { Symbol } from "../shared/models/symbol";
|
||||||
import {NodeSelectInterfaceComponent} from "../shared/node-select-interface/node-select-interface.component";
|
import { NodeSelectInterfaceComponent } from "../shared/node-select-interface/node-select-interface.component";
|
||||||
import {Port} from "../shared/models/port";
|
import { Port } from "../shared/models/port";
|
||||||
import {LinkService} from "../shared/services/link.service";
|
import { LinkService } from "../shared/services/link.service";
|
||||||
|
import { ToasterService } from '../shared/services/toaster.service';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -69,7 +69,7 @@ export class ProjectMapComponent implements OnInit {
|
|||||||
private linkService: LinkService,
|
private linkService: LinkService,
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
private progressDialogService: ProgressDialogService,
|
private progressDialogService: ProgressDialogService,
|
||||||
private toastyService: ToastyService) {
|
private toaster: ToasterService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -238,17 +238,11 @@ export class ProjectMapComponent implements OnInit {
|
|||||||
const progress = this.progressDialogService.open();
|
const progress = this.progressDialogService.open();
|
||||||
|
|
||||||
const subscription = creation.subscribe((created_snapshot: Snapshot) => {
|
const subscription = creation.subscribe((created_snapshot: Snapshot) => {
|
||||||
this.toastyService.success({
|
this.toaster.success(`Snapshot '${snapshot.name}' has been created.`);
|
||||||
'title': 'Snapshot created',
|
|
||||||
'msg': `Snapshot '${snapshot.name}' has been created.`
|
|
||||||
});
|
|
||||||
progress.close();
|
progress.close();
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
const error = response.json();
|
const error = response.json();
|
||||||
this.toastyService.error({
|
this.toaster.error(`Cannot create snapshot: ${error.message}`);
|
||||||
'title': 'Cannot create snapshot',
|
|
||||||
'msg': error.message
|
|
||||||
});
|
|
||||||
progress.close();
|
progress.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
32
src/app/shared/services/toaster.service.spec.ts
Normal file
32
src/app/shared/services/toaster.service.spec.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { TestBed, inject } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ToasterService } from './toaster.service';
|
||||||
|
import { MatSnackBar } from '@angular/material';
|
||||||
|
|
||||||
|
class MockedSnackBar {
|
||||||
|
public open(message: string, ignored: any, options: any) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ToasterService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [ToasterService, {provide: MatSnackBar, useClass: MockedSnackBar}]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([ToasterService], (service: ToasterService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should open when success', inject([ToasterService, MatSnackBar], (service: ToasterService, snackBar: MatSnackBar) => {
|
||||||
|
const spy = spyOn(snackBar, 'open');
|
||||||
|
service.success("message");
|
||||||
|
expect(snackBar.open).toHaveBeenCalledWith("message", null, { duration: 2000 });
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should open when error', inject([ToasterService, MatSnackBar], (service: ToasterService, snackBar: MatSnackBar) => {
|
||||||
|
const spy = spyOn(snackBar, 'open');
|
||||||
|
service.error("message");
|
||||||
|
expect(snackBar.open).toHaveBeenCalledWith("message", null, { duration: 2000 });
|
||||||
|
}));
|
||||||
|
});
|
15
src/app/shared/services/toaster.service.ts
Normal file
15
src/app/shared/services/toaster.service.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { MatSnackBar } from '@angular/material';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ToasterService {
|
||||||
|
constructor(private snackbar: MatSnackBar) { }
|
||||||
|
|
||||||
|
public error(message: string) {
|
||||||
|
this.snackbar.open(message, null, { duration: 2000 });
|
||||||
|
}
|
||||||
|
|
||||||
|
public success(message: string) {
|
||||||
|
this.snackbar.open(message, null, { duration: 2000 });
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user