mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-01-06 01:28:50 +01:00
feat: upgrade to Angular 9 and Nebular 5 (#5628)
BREAKING CHANGE: Angular updated to version 9. Nebular updated to version 5. `@agm/core` replaced with `@angular/google-maps`. `ng2-completer` replaced with `@akveo/ng2-completer`, read details [here](https://github.com/akveo/ng2-smart-table/pull/1140#issue-392285957).
This commit is contained in:
parent
b48f502f37
commit
aa4ae169d9
21 changed files with 6191 additions and 3175 deletions
|
|
@ -159,8 +159,8 @@ export class CoreModule {
|
|||
throwIfAlreadyLoaded(parentModule, 'CoreModule');
|
||||
}
|
||||
|
||||
static forRoot(): ModuleWithProviders {
|
||||
return <ModuleWithProviders>{
|
||||
static forRoot(): ModuleWithProviders<CoreModule> {
|
||||
return {
|
||||
ngModule: CoreModule,
|
||||
providers: [
|
||||
...NB_CORE_PROVIDERS,
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ const SERVICES = [
|
|||
],
|
||||
})
|
||||
export class MockDataModule {
|
||||
static forRoot(): ModuleWithProviders {
|
||||
return <ModuleWithProviders>{
|
||||
static forRoot(): ModuleWithProviders<MockDataModule> {
|
||||
return {
|
||||
ngModule: MockDataModule,
|
||||
providers: [
|
||||
...SERVICES,
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ const PIPES = [
|
|||
declarations: [...COMPONENTS, ...PIPES],
|
||||
})
|
||||
export class ThemeModule {
|
||||
static forRoot(): ModuleWithProviders {
|
||||
return <ModuleWithProviders>{
|
||||
static forRoot(): ModuleWithProviders<ThemeModule> {
|
||||
return {
|
||||
ngModule: ThemeModule,
|
||||
providers: [
|
||||
...NbThemeModule.forRoot(
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import {
|
|||
NbResetPasswordComponent,
|
||||
} from '@nebular/auth';
|
||||
|
||||
const routes: Routes = [
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: 'pages',
|
||||
loadChildren: () => import('app/pages/pages.module')
|
||||
loadChildren: () => import('./pages/pages.module')
|
||||
.then(m => m.PagesModule),
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@ import {
|
|||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
AppRoutingModule,
|
||||
|
||||
ThemeModule.forRoot(),
|
||||
|
||||
NbSidebarModule.forRoot(),
|
||||
NbMenuModule.forRoot(),
|
||||
NbDatepickerModule.forRoot(),
|
||||
|
|
@ -41,6 +38,7 @@ import {
|
|||
messageGoogleMapKey: 'AIzaSyA_wNuCzia92MAmdLRzmqitRGvCF7wCZPY',
|
||||
}),
|
||||
CoreModule.forRoot(),
|
||||
ThemeModule.forRoot(),
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { NbMediaBreakpoint, NbMediaBreakpointsService, NbThemeService } from '@nebular/theme';
|
||||
import { takeWhile } from 'rxjs/operators';
|
||||
import { CountryOrderData } from '../../../@core/data/country-order';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-country-orders',
|
||||
styleUrls: ['./country-orders.component.scss'],
|
||||
template: `
|
||||
<nb-card [size]="breakpoint.width >= breakpoints.md ? 'medium' : 'giant'">
|
||||
<nb-card-header>Country Orders Statistics</nb-card-header>
|
||||
<nb-card-body>
|
||||
<ngx-country-orders-map (select)="selectCountryById($event)"
|
||||
countryId="USA">
|
||||
</ngx-country-orders-map>
|
||||
<ngx-country-orders-chart [countryName]="countryName"
|
||||
[data]="countryData"
|
||||
[labels]="countriesCategories"
|
||||
maxValue="20">
|
||||
</ngx-country-orders-chart>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
`,
|
||||
})
|
||||
export class CountryOrdersComponent implements OnInit, OnDestroy {
|
||||
|
||||
private alive = true;
|
||||
|
||||
countryName = '';
|
||||
countryData: number[] = [];
|
||||
countriesCategories: string[];
|
||||
breakpoint: NbMediaBreakpoint = { name: '', width: 0 };
|
||||
breakpoints: any;
|
||||
|
||||
constructor(private themeService: NbThemeService,
|
||||
private breakpointService: NbMediaBreakpointsService,
|
||||
private countryOrderService: CountryOrderData) {
|
||||
this.breakpoints = this.breakpointService.getBreakpointsMap();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.themeService.onMediaQueryChange()
|
||||
.pipe(takeWhile(() => this.alive))
|
||||
.subscribe(([oldValue, newValue]) => {
|
||||
this.breakpoint = newValue;
|
||||
});
|
||||
this.countryOrderService.getCountriesCategories()
|
||||
.pipe(takeWhile(() => this.alive))
|
||||
.subscribe((countriesCategories) => {
|
||||
this.countriesCategories = countriesCategories;
|
||||
});
|
||||
}
|
||||
|
||||
selectCountryById(countryName: string) {
|
||||
this.countryName = countryName;
|
||||
|
||||
this.countryOrderService.getCountriesCategoriesData(countryName)
|
||||
.pipe(takeWhile(() => this.alive))
|
||||
.subscribe((countryData) => {
|
||||
this.countryData = countryData;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.alive = false;
|
||||
}
|
||||
}
|
||||
8
src/app/pages/maps/gmaps/gmaps.component.html
Normal file
8
src/app/pages/maps/gmaps/gmaps.component.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<nb-card>
|
||||
<nb-card-header>Google Maps</nb-card-header>
|
||||
<nb-card-body>
|
||||
<google-map [center]="position" [zoom]="8" width="100%" height="36.5625rem">
|
||||
<map-marker [position]="position"></map-marker>
|
||||
</google-map>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
10
src/app/pages/maps/gmaps/gmaps.component.ts
Normal file
10
src/app/pages/maps/gmaps/gmaps.component.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-gmaps',
|
||||
styleUrls: ['./gmaps.component.scss'],
|
||||
templateUrl: './gmaps.component.html',
|
||||
})
|
||||
export class GmapsComponent {
|
||||
readonly position = { lat: 51.678418, lng: 7.809007 };
|
||||
}
|
||||
24
src/app/pages/maps/maps.module.ts
Normal file
24
src/app/pages/maps/maps.module.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { GoogleMapsModule } from '@angular/google-maps';
|
||||
import { LeafletModule } from '@asymmetrik/ngx-leaflet';
|
||||
import { NgxEchartsModule } from 'ngx-echarts';
|
||||
import { NbCardModule } from '@nebular/theme';
|
||||
|
||||
import { ThemeModule } from '../../@theme/theme.module';
|
||||
import { MapsRoutingModule, routedComponents } from './maps-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
ThemeModule,
|
||||
GoogleMapsModule,
|
||||
LeafletModule.forRoot(),
|
||||
MapsRoutingModule,
|
||||
NgxEchartsModule,
|
||||
NbCardModule,
|
||||
],
|
||||
exports: [],
|
||||
declarations: [
|
||||
...routedComponents,
|
||||
],
|
||||
})
|
||||
export class MapsModule { }
|
||||
6
src/app/pages/maps/search-map/entity/position.model.ts
Normal file
6
src/app/pages/maps/search-map/entity/position.model.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export class PositionModel {
|
||||
constructor(
|
||||
public lat = 53.9,
|
||||
public lng = 27.5667,
|
||||
) {}
|
||||
}
|
||||
3
src/app/pages/maps/search-map/map/map.component.html
Normal file
3
src/app/pages/maps/search-map/map/map.component.html
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<google-map [center]="position" [zoom]="zoom" width="100%" height="36.5625rem">
|
||||
<map-marker [position]="position"></map-marker>
|
||||
</google-map>
|
||||
32
src/app/pages/maps/search-map/map/map.component.ts
Normal file
32
src/app/pages/maps/search-map/map/map.component.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { PositionModel } from '../entity/position.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-map',
|
||||
templateUrl: './map.component.html',
|
||||
styleUrls: ['./map.component.scss'],
|
||||
})
|
||||
export class MapComponent implements OnInit {
|
||||
position: PositionModel = null;
|
||||
zoom: number = 1;
|
||||
|
||||
@Input()
|
||||
public set searchedPosition(position: PositionModel) {
|
||||
if (position) {
|
||||
this.position = position;
|
||||
this.zoom = 12;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// set up current location
|
||||
if ('geolocation' in navigator) {
|
||||
navigator.geolocation.getCurrentPosition((position) => {
|
||||
this.searchedPosition = new PositionModel(
|
||||
position.coords.latitude,
|
||||
position.coords.longitude,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/app/pages/maps/search-map/search-map.component.html
Normal file
7
src/app/pages/maps/search-map/search-map.component.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<nb-card>
|
||||
<nb-card-header>Google Maps with search</nb-card-header>
|
||||
<nb-card-body>
|
||||
<ngx-search (positionChanged)="setPosition($event)"></ngx-search>
|
||||
<ngx-map [searchedPosition]="searchedPosition"></ngx-map>
|
||||
</nb-card-body>
|
||||
</nb-card>
|
||||
14
src/app/pages/maps/search-map/search-map.component.ts
Normal file
14
src/app/pages/maps/search-map/search-map.component.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { PositionModel } from './entity/position.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-search-map',
|
||||
templateUrl: './search-map.component.html',
|
||||
})
|
||||
export class SearchMapComponent {
|
||||
searchedPosition: PositionModel = new PositionModel();
|
||||
|
||||
setPosition(position: PositionModel) {
|
||||
this.searchedPosition = position;
|
||||
}
|
||||
}
|
||||
40
src/app/pages/maps/search-map/search/search.component.ts
Normal file
40
src/app/pages/maps/search-map/search/search.component.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { Component, ElementRef, EventEmitter, NgZone, OnInit, Output, ViewChild } from '@angular/core';
|
||||
import { PositionModel } from '../entity/position.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-search',
|
||||
templateUrl: './search.component.html',
|
||||
})
|
||||
export class SearchComponent implements OnInit {
|
||||
|
||||
@Output()
|
||||
positionChanged: EventEmitter<PositionModel> = new EventEmitter<PositionModel>();
|
||||
|
||||
@ViewChild('search', { static: true })
|
||||
searchElementRef: ElementRef;
|
||||
|
||||
constructor(private ngZone: NgZone) {}
|
||||
|
||||
ngOnInit() {
|
||||
const autocomplete = new google.maps.places.Autocomplete(
|
||||
this.searchElementRef.nativeElement, { types: ['address'] },
|
||||
);
|
||||
|
||||
autocomplete.addListener('place_changed', () => {
|
||||
this.ngZone.run(() => {
|
||||
// get the place result
|
||||
const place: google.maps.places.PlaceResult = autocomplete.getPlace();
|
||||
|
||||
// verify result
|
||||
if (place.geometry === undefined || place.geometry === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.positionChanged.emit(new PositionModel(
|
||||
place.geometry.location.lat(),
|
||||
place.geometry.location.lng(),
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
86
src/app/pages/modal-overlays/toastr/toastr.component.ts
Normal file
86
src/app/pages/modal-overlays/toastr/toastr.component.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
import { Component } from '@angular/core';
|
||||
import {
|
||||
NbComponentStatus,
|
||||
NbGlobalLogicalPosition,
|
||||
NbGlobalPhysicalPosition,
|
||||
NbGlobalPosition,
|
||||
NbToastrService,
|
||||
NbToastrConfig,
|
||||
} from '@nebular/theme';
|
||||
|
||||
@Component({
|
||||
selector: 'ngx-toastr',
|
||||
styleUrls: ['./toastr.component.scss'],
|
||||
templateUrl: './toastr.component.html',
|
||||
})
|
||||
export class ToastrComponent {
|
||||
constructor(private toastrService: NbToastrService) {}
|
||||
|
||||
config: NbToastrConfig;
|
||||
|
||||
index = 1;
|
||||
destroyByClick = true;
|
||||
duration = 2000;
|
||||
hasIcon = true;
|
||||
position: NbGlobalPosition = NbGlobalPhysicalPosition.TOP_RIGHT;
|
||||
preventDuplicates = false;
|
||||
status: NbComponentStatus = 'primary';
|
||||
|
||||
title = 'HI there!';
|
||||
content = `I'm cool toaster!`;
|
||||
|
||||
types: NbComponentStatus[] = [
|
||||
'primary',
|
||||
'success',
|
||||
'info',
|
||||
'warning',
|
||||
'danger',
|
||||
];
|
||||
positions: string[] = [
|
||||
NbGlobalPhysicalPosition.TOP_RIGHT,
|
||||
NbGlobalPhysicalPosition.TOP_LEFT,
|
||||
NbGlobalPhysicalPosition.BOTTOM_LEFT,
|
||||
NbGlobalPhysicalPosition.BOTTOM_RIGHT,
|
||||
NbGlobalLogicalPosition.TOP_END,
|
||||
NbGlobalLogicalPosition.TOP_START,
|
||||
NbGlobalLogicalPosition.BOTTOM_END,
|
||||
NbGlobalLogicalPosition.BOTTOM_START,
|
||||
];
|
||||
|
||||
quotes = [
|
||||
{ title: null, body: 'We rock at Angular' },
|
||||
{ title: null, body: 'Titles are not always needed' },
|
||||
{ title: null, body: 'Toastr rock!' },
|
||||
];
|
||||
|
||||
makeToast() {
|
||||
this.showToast(this.status, this.title, this.content);
|
||||
}
|
||||
|
||||
openRandomToast () {
|
||||
const typeIndex = Math.floor(Math.random() * this.types.length);
|
||||
const quoteIndex = Math.floor(Math.random() * this.quotes.length);
|
||||
const type = this.types[typeIndex];
|
||||
const quote = this.quotes[quoteIndex];
|
||||
|
||||
this.showToast(type, quote.title, quote.body);
|
||||
}
|
||||
|
||||
private showToast(type: NbComponentStatus, title: string, body: string) {
|
||||
const config = {
|
||||
status: type,
|
||||
destroyByClick: this.destroyByClick,
|
||||
duration: this.duration,
|
||||
hasIcon: this.hasIcon,
|
||||
position: this.position,
|
||||
preventDuplicates: this.preventDuplicates,
|
||||
};
|
||||
const titleContent = title ? `. ${title}` : '';
|
||||
|
||||
this.index += 1;
|
||||
this.toastrService.show(
|
||||
body,
|
||||
`Toast ${this.index}${titleContent}`,
|
||||
config);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue