-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ramon Spahr
committed
Apr 27, 2021
1 parent
82b04a1
commit 46aea3a
Showing
27 changed files
with
8,719 additions
and
14,170 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -24,5 +24,6 @@ export class HomeComponent { | |
'evaluate-absences', | ||
'my-absences', | ||
'my-profile', | ||
'my-settings' | ||
]; | ||
} |
78 changes: 78 additions & 0 deletions
78
...my-settings/components/my-settings-notifications/my-settings-notifications.component.html
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,78 @@ | ||
<div | ||
class="erz-container erz-container-limited erz-container-padding-y erz-container-padding-x-responsive" | ||
*erzLet="{ | ||
notificationFormGroup: notificationFormGroup$ | async | ||
} as data" | ||
> | ||
<!-- setting-header --> | ||
<h5 class="m-0" class="setting-header"> | ||
{{ 'my-settings.notifications.title' | translate }} | ||
</h5> | ||
|
||
<form | ||
*ngIf="data.notificationFormGroup" | ||
[formGroup]="data.notificationFormGroup" | ||
(ngSubmit)="onSubmit()" | ||
> | ||
|
||
<!-- setting-entry --> | ||
<div class="checkbox-setting"> | ||
<input | ||
id="my-settings-notifications-gui" | ||
type="checkbox" | ||
class="checkbox-setting-input" | ||
formControlName="notificationsGui" | ||
/> | ||
<label class="checkbox-setting-label" id="my-settings-notifications-gui"> | ||
{{ 'my-settings.notifications.gui' | translate }} | ||
</label> | ||
</div> | ||
|
||
<!-- setting-entry --> | ||
<div class="checkbox-setting"> | ||
<input | ||
id="my-settings-notifications-mail" | ||
type="checkbox" | ||
class="checkbox-setting-input" | ||
formControlName="notificationsMail" | ||
/> | ||
<label class="checkbox-setting-label" id="my-settings-notifications-mail"> | ||
{{ 'my-settings.notifications.mail' | translate }} | ||
</label> | ||
</div> | ||
|
||
<!-- setting-entry --> | ||
<div class="checkbox-setting"> | ||
<input | ||
id="my-settings-notifications-phoneMobile" | ||
type="checkbox" | ||
class="checkbox-setting-input" | ||
formControlName="notificationsPhoneMobile" | ||
/> | ||
<label | ||
class="checkbox-setting-label" | ||
id="my-settings-notifications-phoneMobile" | ||
> | ||
{{ 'my-settings.notifications.phoneMobile' | translate }} | ||
</label> | ||
</div> | ||
<div class="d-flex justify-content-end"> | ||
<button | ||
type="submit" | ||
class="btn btn-primary ml-2" | ||
[disabled]="saving$ | async" | ||
> | ||
{{ 'my-settings.notifications.save' | translate }} | ||
<div | ||
*ngIf="saving$ | async" | ||
class="spinner-border spinner-border-sm align-middle" | ||
role="status" | ||
> | ||
<span class="sr-only">Loading...</span> | ||
</div> | ||
</button> | ||
</div> | ||
|
||
</form> | ||
|
||
</div> |
23 changes: 23 additions & 0 deletions
23
...my-settings/components/my-settings-notifications/my-settings-notifications.component.scss
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,23 @@ | ||
@import "../../../../bootstrap-variables"; | ||
|
||
.setting-header { | ||
padding-bottom: 1rem; | ||
} | ||
|
||
.checkbox-setting { | ||
margin: 0; | ||
padding: 0.6rem $spacer/2 0 0; | ||
} | ||
|
||
.checkbox-setting-label { | ||
margin: 0; | ||
padding: 0.6rem $spacer/2 0 0; | ||
padding-left: 1.2rem; | ||
} | ||
|
||
.checkbox-setting input.checkbox-setting-input { | ||
// Make the following statements !important since the are | ||
// overwritten in Evento as such | ||
position: static !important; | ||
margin: 0 !important; | ||
} |
76 changes: 76 additions & 0 deletions
76
...settings/components/my-settings-notifications/my-settings-notifications.component.spec.ts
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,76 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import { buildTestModuleMetadata } from 'src/spec-helpers'; | ||
import { MySettingsService } from '../../services/my-settings.service'; | ||
import { MySettingsNotificationsComponent } from './my-settings-notifications.component'; | ||
|
||
describe('MySettingsNotificationsComponent', () => { | ||
let fixture: ComponentFixture<MySettingsNotificationsComponent>; | ||
let element: HTMLElement; | ||
let settingsService: jasmine.SpyObj<MySettingsService>; | ||
|
||
settingsService = jasmine.createSpyObj('MySettingsService', ['getCurrentNotificationSettingsPropertyValue','updateCurrentNotificationSettingsPropertyValue']); | ||
settingsService.getCurrentNotificationSettingsPropertyValue.and.returnValue(of({ mail: true, gui: true, phoneMobile: false })); | ||
settingsService.updateCurrentNotificationSettingsPropertyValue.and.returnValue(of({})); | ||
|
||
beforeEach( | ||
waitForAsync(() => { | ||
TestBed.configureTestingModule( | ||
buildTestModuleMetadata({ | ||
declarations: [MySettingsNotificationsComponent], | ||
providers: [ | ||
{ | ||
provide: MySettingsService, | ||
useValue: settingsService, | ||
} | ||
], | ||
}) | ||
).compileComponents(); | ||
}) | ||
); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MySettingsNotificationsComponent); | ||
element = fixture.debugElement.nativeElement; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('renders form fields with current values', () => { | ||
expect(getInput('notificationsGui').checked).toBe(true); | ||
expect(getInput('notificationsMail').checked).toBe(true); | ||
expect(getInput('notificationsPhoneMobile').checked).toBe(false); | ||
}); | ||
|
||
it('updates settings on submit and reloads', () => { | ||
changeValue('notificationsGui', false); | ||
changeValue('notificationsMail', false); | ||
changeValue('notificationsPhoneMobile', true); | ||
clickSubmitButton(); | ||
|
||
expect(settingsService.updateCurrentNotificationSettingsPropertyValue | ||
).toHaveBeenCalled(); | ||
}); | ||
|
||
function getInput(name: string): HTMLInputElement { | ||
const field = element.querySelector(`input[formControlName="${name}"]`); | ||
expect(field).not.toBeNull(); | ||
return field as HTMLInputElement; | ||
} | ||
|
||
function changeValue(name: string, value: any): void { | ||
const input = getInput(name); | ||
input.value = value; | ||
input.dispatchEvent(new Event('input')); | ||
fixture.detectChanges(); | ||
} | ||
|
||
function clickSubmitButton(): void { | ||
const button = element.querySelector( | ||
'.btn-primary' | ||
) as Option<HTMLButtonElement>; | ||
if (button) { | ||
button.click(); | ||
fixture.detectChanges(); | ||
} | ||
} | ||
}); |
79 changes: 79 additions & 0 deletions
79
...p/my-settings/components/my-settings-notifications/my-settings-notifications.component.ts
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,79 @@ | ||
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; | ||
import { FormBuilder, FormGroup } from '@angular/forms'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { | ||
NotificationPropertyValueType, | ||
} from 'src/app/shared/models/user-setting.model'; | ||
import { MySettingsService } from '../../services/my-settings.service'; | ||
import { | ||
shareReplay, | ||
map, | ||
take, | ||
finalize, | ||
} from 'rxjs/operators'; | ||
import { ToastrService } from 'ngx-toastr'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
|
||
@Component({ | ||
selector: 'erz-my-settings-notifications', | ||
templateUrl: './my-settings-notifications.component.html', | ||
styleUrls: ['./my-settings-notifications.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MySettingsNotificationsComponent implements OnInit { | ||
|
||
notificationSettings$ = this.settingsService.getCurrentNotificationSettingsPropertyValue(); | ||
notificationFormGroup$ = this.notificationSettings$.pipe( | ||
map(this.createNotificationFormGroup.bind(this)), | ||
shareReplay(1) | ||
); | ||
|
||
saving$ = new BehaviorSubject(false); | ||
private submitted$ = new BehaviorSubject(false); | ||
|
||
constructor( | ||
private settingsService: MySettingsService, | ||
private formBuilder: FormBuilder, | ||
private toastr: ToastrService, | ||
private translate: TranslateService | ||
) {} | ||
|
||
ngOnInit(): void { } | ||
|
||
private createNotificationFormGroup(notifications: NotificationPropertyValueType): FormGroup { | ||
return this.formBuilder.group({ | ||
notificationsGui: [notifications.gui], | ||
notificationsMail: [notifications.mail], | ||
notificationsPhoneMobile: [notifications.phoneMobile], | ||
}); | ||
} | ||
|
||
onSubmit(): void { | ||
this.submitted$.next(true); | ||
this.notificationFormGroup$.pipe(take(1)).subscribe((formGroup) => { | ||
if (formGroup.valid) { | ||
const { notificationsGui, notificationsMail, notificationsPhoneMobile } = formGroup.value; | ||
this.save(notificationsGui, notificationsMail, notificationsPhoneMobile); | ||
} | ||
}); | ||
} | ||
|
||
private save( | ||
gui: boolean, | ||
mail: boolean, | ||
phoneMobile: boolean | ||
): void { | ||
this.saving$.next(true); | ||
this.settingsService.updateCurrentNotificationSettingsPropertyValue( | ||
gui, mail, phoneMobile | ||
).pipe( | ||
finalize(() => this.saving$.next(false)) | ||
) | ||
.subscribe(this.onSaveSuccess.bind(this)); | ||
} | ||
|
||
private onSaveSuccess(): void { | ||
this.toastr.success(this.translate.instant('my-settings.notifications.save-success')); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/app/my-settings/components/my-settings-show/my-settings-show.component.html
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 @@ | ||
<erz-my-settings-notifications></erz-my-settings-notifications> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/my-settings/components/my-settings-show/my-settings-show.component.spec.ts
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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { MySettingsShowComponent } from './my-settings-show.component'; | ||
|
||
describe('MySettingsShowComponent', () => { | ||
let component: MySettingsShowComponent; | ||
let fixture: ComponentFixture<MySettingsShowComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ MySettingsShowComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MySettingsShowComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
src/app/my-settings/components/my-settings-show/my-settings-show.component.ts
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,12 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'erz-my-settings-show', | ||
templateUrl: './my-settings-show.component.html', | ||
styleUrls: ['./my-settings-show.component.scss'] | ||
}) | ||
export class MySettingsShowComponent implements OnInit { | ||
|
||
ngOnInit(): void { } | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
src/app/my-settings/components/my-settings/my-settings.component.html
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 @@ | ||
<router-outlet></router-outlet> |
Empty file.
29 changes: 29 additions & 0 deletions
29
src/app/my-settings/components/my-settings/my-settings.component.spec.ts
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,29 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
|
||
import { MySettingsComponent } from './my-settings.component'; | ||
import { buildTestModuleMetadata } from '../../../../spec-helpers'; | ||
|
||
describe('MySettingsComponent', () => { | ||
let component: MySettingsComponent; | ||
let fixture: ComponentFixture<MySettingsComponent>; | ||
|
||
beforeEach( | ||
waitForAsync(() => { | ||
TestBed.configureTestingModule( | ||
buildTestModuleMetadata({ | ||
declarations: [MySettingsComponent], | ||
}) | ||
).compileComponents(); | ||
}) | ||
); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(MySettingsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
src/app/my-settings/components/my-settings/my-settings.component.ts
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,18 @@ | ||
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; | ||
import { MySettingsService } from '../../services/my-settings.service'; | ||
|
||
@Component({ | ||
selector: 'erz-my-setting', | ||
templateUrl: './my-settings.component.html', | ||
styleUrls: ['./my-settings.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
providers: [MySettingsService], | ||
}) | ||
export class MySettingsComponent implements OnInit { | ||
|
||
constructor() { } | ||
|
||
ngOnInit(): void { | ||
} | ||
|
||
} |
Oops, something went wrong.