Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
248 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { MultiTranslateHttpLoader } from 'ngx-translate-multi-http-loader'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
export function HttpLoaderFactory(http: HttpClient) { | ||
return new MultiTranslateHttpLoader(http, [ | ||
{ prefix: './assets/i18n/', suffix: '/core.json' } | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
ALERT_HORZ_POSITION, | ||
ALERT_VERT_POSITION, | ||
AlertService, | ||
ERROR_MESSAGE_DURATION, | ||
INFO_MESSAGE_DURATION | ||
} from './alert.service'; | ||
import { LoggerModule } from '@angular-ru/logger'; | ||
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
describe('AlertService', () => { | ||
const TEST_MESSAGE = 'This is the alert message'; | ||
|
||
let service: AlertService; | ||
let snackbar: MatSnackBar; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
LoggerModule.forRoot(), | ||
TranslateModule.forRoot(), | ||
MatSnackBarModule | ||
] | ||
}); | ||
|
||
service = TestBed.inject(AlertService); | ||
snackbar = TestBed.inject(MatSnackBar); | ||
spyOn(snackbar, 'open'); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
describe('showing an information alert', () => { | ||
beforeEach(() => { | ||
service.info(TEST_MESSAGE); | ||
}); | ||
|
||
it('opens the message popup', () => { | ||
expect(snackbar.open).toHaveBeenCalledWith( | ||
TEST_MESSAGE, | ||
jasmine.any(String), | ||
jasmine.objectContaining({ | ||
duration: INFO_MESSAGE_DURATION, | ||
horizontalPosition: ALERT_HORZ_POSITION, | ||
verticalPosition: ALERT_VERT_POSITION | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('showing an error alert', () => { | ||
beforeEach(() => { | ||
service.error(TEST_MESSAGE); | ||
}); | ||
|
||
it('opens the message popup', () => { | ||
expect(snackbar.open).toHaveBeenCalledWith( | ||
TEST_MESSAGE, | ||
jasmine.any(String), | ||
jasmine.objectContaining({ | ||
duration: ERROR_MESSAGE_DURATION, | ||
horizontalPosition: ALERT_HORZ_POSITION, | ||
verticalPosition: ALERT_VERT_POSITION | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2020, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
import { Injectable } from '@angular/core'; | ||
import { LoggerService } from '@angular-ru/logger'; | ||
import { MatSnackBar } from '@angular/material/snack-bar'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
export const INFO_MESSAGE_DURATION = 500; | ||
export const ERROR_MESSAGE_DURATION = 0; | ||
export const ALERT_HORZ_POSITION = 'end'; | ||
export const ALERT_VERT_POSITION = 'top'; | ||
|
||
/** | ||
* AlertService shows message toasters to the user. | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AlertService { | ||
constructor( | ||
private logger: LoggerService, | ||
private translateService: TranslateService, | ||
private snackbar: MatSnackBar | ||
) {} | ||
|
||
/** Shows an information alert. */ | ||
info(message: string): void { | ||
this.logger.trace('Showing info message:', message); | ||
this.snackbar.open( | ||
message, | ||
this.translateService.instant('alert.info-action'), | ||
{ | ||
duration: INFO_MESSAGE_DURATION, | ||
horizontalPosition: ALERT_HORZ_POSITION, | ||
verticalPosition: ALERT_VERT_POSITION | ||
} | ||
); | ||
} | ||
|
||
/** Shows an error alert. */ | ||
error(message: string): void { | ||
this.logger.trace('Showing error message:', message); | ||
this.snackbar.open( | ||
message, | ||
this.translateService.instant('alert.error-action'), | ||
{ | ||
duration: ERROR_MESSAGE_DURATION, | ||
horizontalPosition: ALERT_HORZ_POSITION, | ||
verticalPosition: ALERT_VERT_POSITION | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"alert": { | ||
"info-action": "INFO", | ||
"error-action": "ERROR" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"alert": { | ||
"info-action": "INFO", | ||
"error-action": "ERROR" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"alert": { | ||
"info-action": "INFO", | ||
"error-action": "ERROR" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"alert": { | ||
"info-action": "INFO", | ||
"error-action": "ERROR" | ||
} | ||
} |