Skip to content

Commit

Permalink
feat(core): notification are now based on ngx-toastr
Browse files Browse the repository at this point in the history
* chore(*): change lib to make notifications (to ngx-toastr)

* chore(igo-message-center): delete the igo-message-center omponent

* feat(core): notification are now based on ngx-toastr

* refactor(context-service): moving to ngx-toastr lib

* fix(messageService): allow the message a the layer level to use a translation

* fix(messageService): allow the message a the layer level to use a translation

* wip

* wip

* wip

* fix(demo): inject language service before the app initialization.
  • Loading branch information
pelord authored Dec 8, 2021
1 parent 94f999f commit 82544c0
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 301 deletions.
18 changes: 17 additions & 1 deletion demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BrowserModule, DomSanitizer } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { HammerModule } from '@angular/platform-browser';
import { MatButtonModule } from '@angular/material/button';
import { MatIconRegistry, MatIconModule } from '@angular/material/icon';
Expand Down Expand Up @@ -50,6 +50,7 @@ import { AppContextModule } from './context/context/context.module';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { LanguageService } from '@igo2/core';

@NgModule({
declarations: [AppComponent],
Expand Down Expand Up @@ -107,6 +108,9 @@ import { AppComponent } from './app.component';

HammerModule
],
providers: [
{provide: APP_INITIALIZER, useFactory: appInitializerFactory, deps: [LanguageService], multi: true},
],
bootstrap: [AppComponent]
})
export class AppModule {
Expand All @@ -118,3 +122,15 @@ export class AppModule {
);
}
}

export function appInitializerFactory(languageService: LanguageService) {
return () => new Promise<any>((resolve: any) => {
languageService.translate.getTranslation(languageService.getLanguage()).subscribe(() => {
console.info(`Successfully initialized '${languageService.getLanguage()}' language.'`);
}, err => {
console.error(`Problem with '${languageService.getLanguage()}' language initialization.'`);
}, () => {
resolve(null);
});
});
}
1 change: 0 additions & 1 deletion demo/src/app/core/message/message.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
</mat-card-actions>
</mat-card>

<igo-message-center></igo-message-center>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@

</mat-card>

<igo-message-center></igo-message-center>
1 change: 0 additions & 1 deletion demo/src/app/geo/print/print.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@

</mat-card>

<igo-message-center></igo-message-center>
1 change: 0 additions & 1 deletion demo/src/app/geo/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@
</igo-actionbar>
</ng-template>

<igo-message-center></igo-message-center>
2 changes: 0 additions & 2 deletions demo/src/app/geo/spatial-filter/spatial-filter.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,4 @@
</ng-container>
</igo-panel>

<igo-message-center></igo-message-center>

</mat-card>
16 changes: 8 additions & 8 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"@angular/router": "^12.2.9",
"@azure/msal-angular": "^2.0.1",
"@azure/msal-browser": "^2.15.0",
"@igo2/angular2-notifications": "12.0.1",
"@ionic-native/core": "^5.10.0",
"@ionic-native/file": "^5.6.0",
"@ionic-native/file-opener": "^5.6.0",
Expand All @@ -113,6 +112,7 @@
"jwt-decode": "^2.2.0",
"moment": "^2.24.0",
"ngx-color-picker": "^10.1.0",
"ngx-toastr": "^14.1.3",
"ol": "^6.8.1",
"ol-mapbox-style": "^6.5.1",
"proj4": "^2.7.5",
Expand Down
24 changes: 11 additions & 13 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
RouteService,
Message,
MessageService,
Notification,
LanguageService
} from '@igo2/core';

Expand Down Expand Up @@ -55,7 +54,6 @@ export class ContextService {
private mapViewFromRoute: ContextMapView = {};
private options: ContextServiceOptions;
private baseUrl: string;
private contextMessage: Notification;

// Until the ContextService is completely refactored, this is needed
// to track the current tools
Expand Down Expand Up @@ -126,7 +124,8 @@ export class ContextService {
const url = `${this.baseUrl}/contexts/${id}/details`;
return this.http.get<DetailedContext>(url).pipe(
catchError((res) => {
return this.handleError(res, id);
this.handleError(res, id);
throw res;
})
);
}
Expand Down Expand Up @@ -240,7 +239,7 @@ export class ContextService {
contextId: string,
profil: string,
type: TypePermission
): Observable<ContextPermission[] | Message[]> {
): Observable<ContextPermission[]> {
const url = `${this.baseUrl}/contexts/${contextId}/permissions`;
const association = {
profil,
Expand All @@ -249,7 +248,8 @@ export class ContextService {

return this.http.post<ContextPermission[]>(url, association).pipe(
catchError((res) => {
return [this.handleError(res, undefined, true)];
this.handleError(res, undefined, true);
throw [res]; // TODO Not sure about this.
})
);
}
Expand Down Expand Up @@ -305,12 +305,14 @@ export class ContextService {
return resMerge;
}),
catchError((err) => {
return this.handleError(err, uri);
this.handleError(err, uri);
throw err;
})
);
}),
catchError((err2) => {
return this.handleError(err2, uri);
this.handleError(err2, uri);
throw err2;
})
);
}
Expand Down Expand Up @@ -600,9 +602,6 @@ export class ContextService {
}

private handleContextMessage(context: DetailedContext) {
if (this.contextMessage) {
this.messageService.remove(this.contextMessage.id);
}
if (this.context$.value && context.uri && this.context$.value.uri !== context.uri) {
this.messageService.removeAllAreNotError();
}
Expand Down Expand Up @@ -702,7 +701,7 @@ export class ContextService {
error: HttpErrorResponse,
uri: string,
permissionError?: boolean
): Message[] {
) {
const context = this.contexts$.value.ours.find((obj) => obj.uri === uri);
const titleContext = context ? context.title : uri;
error.error.title = this.languageService.translate.instant(
Expand All @@ -724,8 +723,7 @@ export class ContextService {
'igo.context.contextManager.errors.addPermission'
);
}

throw error;
this.messageService.error(error.error.message, error.error.title);
}

private handleContextsChange(
Expand Down
6 changes: 3 additions & 3 deletions packages/core/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"entryFile": "src/public_api.ts",
"umdModuleIds": {
"@igo2/utils" : "utils",
"@igo2/angular2-notifications" : "ng2notify",
"@ngx-translate/core" : "ngxt-core"
"@ngx-translate/core" : "ngxt-core",
"ngx-toastr": "ngxToastr"
}
},
"allowedNonPeerDependencies": ["@ngx-translate", "@igo2/angular2-notifications"]
"allowedNonPeerDependencies": ["@ngx-translate"]
}
6 changes: 3 additions & 3 deletions packages/core/ng-package.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"entryFile": "src/public_api.ts",
"umdModuleIds": {
"@igo2/utils" : "utils",
"@igo2/angular2-notifications" : "ng2notify",
"@ngx-translate/core" : "ngxt-core"
"@ngx-translate/core" : "ngxt-core",
"ngx-toastr": "ngxToastr"
}
},
"allowedNonPeerDependencies": ["@ngx-translate", "@igo2/angular2-notifications"]
"allowedNonPeerDependencies": ["@ngx-translate"]
}
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
},
"dependencies": {
"@ngx-translate/core": "^13.0.0",
"@igo2/angular2-notifications": "^12.0.1",
"tslib": "^2.0.0"
},
"peerDependencies": {
"@angular/cdk": "^12.2.9",
"@angular/common": "^12.2.9",
"@angular/core": "^12.2.9",
"@igo2/utils": "^1.9.4",
"rxjs": "^6.6.7"
"rxjs": "^6.6.7",
"ngx-toastr": "^14.1.3"
}
}
1 change: 0 additions & 1 deletion packages/core/src/lib/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './message-center';
export * from './shared';
1 change: 0 additions & 1 deletion packages/core/src/lib/message/message-center/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 82544c0

Please sign in to comment.