-
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.
feature/#22_hide_credentials: display a form in order for the user to…
… identify. closes #22
- Loading branch information
1 parent
f270dc0
commit 4ada1d3
Showing
13 changed files
with
197 additions
and
20 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
Empty file.
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,17 @@ | ||
<div class="card-body"> | ||
<form (ngSubmit)="onSubmit()" [formGroup]="profileForm"> | ||
<div class="form-group"> | ||
<label for="login">login</label> | ||
<input class="form-control" id="login" | ||
formControlName="login" placeholder="{{cred.login}}"> | ||
|
||
<label for="password">password</label> | ||
<input class="form-control" id="password" | ||
formControlName="password" placeholder="{{cred.password}}"> | ||
|
||
<div class="form-row"> | ||
<button class="btn btn-outline-default btn-danger" type="submit">Save</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> |
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 { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { BasicFormComponent } from './basic-form.component'; | ||
|
||
describe('BasicFormComponent', () => { | ||
let component: BasicFormComponent; | ||
let fixture: ComponentFixture<BasicFormComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ BasicFormComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BasicFormComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,50 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {BasicAuth} from '../../models/BasicAuth.models'; | ||
import {FormControl, FormGroup} from '@angular/forms'; | ||
import {connexionRequest} from '../../actions/shelters.action'; | ||
import {select, Store} from '@ngrx/store'; | ||
import {Clone} from '../../utils/clone'; | ||
import {Observable} from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'app-basic-form', | ||
templateUrl: './basic-form.component.html', | ||
styleUrls: ['./basic-form.component.css'] | ||
}) | ||
export class BasicFormComponent implements OnInit { | ||
|
||
profileForm = new FormGroup({ | ||
login: new FormControl(''), | ||
password: new FormControl('') | ||
}); | ||
private cred$: Observable<BasicAuth> = this.store.pipe(select('cred')); | ||
private cred: BasicAuth; | ||
private edit: boolean = true; | ||
|
||
constructor(private clone: Clone, private store: Store<{ cred: BasicAuth }>) { | ||
this.cred$.subscribe((newCreds: BasicAuth) => { | ||
console.log('credentials used', newCreds); | ||
this.cred = newCreds; | ||
} | ||
); | ||
} | ||
|
||
ngOnInit(): void { | ||
this.profileForm.get('login').setValue(this.cred.login); | ||
this.profileForm.get('password').setValue(this.cred.password); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
onSubmit() { | ||
this.cred = this.clone.simpleClone(this.cred); | ||
this.cred.login = this.profileForm.value.login; | ||
this.cred.password = this.profileForm.value.password; | ||
|
||
this.store.dispatch(connexionRequest({cred: this.cred})); | ||
|
||
// TODO: change the edit status only after action is done (callback ?) | ||
this.edit = !this.edit; | ||
} | ||
} |
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,4 @@ | ||
export interface BasicAuth { | ||
login: string | ||
password: string | ||
} |
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
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,15 @@ | ||
import {TestBed} from '@angular/core/testing'; | ||
import {Clone} from './clone'; | ||
|
||
describe('Clone', () => { | ||
let clone: Clone; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
clone = TestBed.inject(Clone); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(clone).toBeTruthy(); | ||
}); | ||
}); |
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 {Injectable} from '@angular/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class Clone { | ||
|
||
constructor() { | ||
} | ||
|
||
/** | ||
* shallow clone of an object | ||
* @param obj | ||
*/ | ||
simpleClone(obj: any) { | ||
return Object.assign({}, obj); | ||
} | ||
} |