Skip to content

Fix "add new module" #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/app/new-module/new-module.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ <h1 mat-dialog-title>Load new Process Equipment Assembly</h1>
</mat-form-field>
<div [hidden]="formGroup.value.authentication!=='password'">
<mat-form-field>
<input matInput name="username" placeholder="OPC UA username" required
type="text" formControlName="username">
<input matInput name="username" placeholder="OPC UA username" type="text" formControlName="username">
</mat-form-field>
<mat-form-field>
<input matInput name="password" placeholder="OPC UA password" required
type="password" formControlName="password">
<input matInput name="password" placeholder="OPC UA password" type="password" formControlName="passsword">
</mat-form-field>
</div>
</form>
Expand Down
21 changes: 18 additions & 3 deletions src/app/new-module/new-module.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {MatSnackBar} from '@angular/material/snack-bar';
import {ModuleInterface, ModuleOptions} from '@p2olab/polaris-interface';
import {NGXLogger} from 'ngx-logger';
import {Subscription} from 'rxjs';
import {BackendService} from '../_services/backend.service';
import {ModuleService} from '../_services/module.service';

Expand All @@ -15,6 +16,7 @@ import {ModuleService} from '../_services/module.service';
export class NewModuleComponent implements OnInit {

public formGroup: FormGroup;
subscription: Subscription;

constructor(@Inject(MAT_DIALOG_DATA) public module: ModuleOptions,
private backend: BackendService,
Expand All @@ -31,9 +33,22 @@ export class NewModuleComponent implements OnInit {
opcua: new FormControl(this.module.opcua_server_url,
[Validators.required, Validators.pattern('opc.tcp://(.*)')]),
authentication: new FormControl(this.module.username ? 'password' : 'anonymous'),
username: new FormControl(this.module.username, Validators.minLength(3)),
password: new FormControl(this.module.password, Validators.minLength(3))
username: new FormControl(this.module.username),
password: new FormControl(this.module.password)
});

this.subscription = this.formGroup.get('authentication').valueChanges.subscribe(value => {
if(value==='password'){
this.formGroup.get('username').setValidators([Validators.required, Validators.minLength(3)]);
this.formGroup.get('password').setValidators([Validators.required, Validators.minLength(3)]);
}
else {
this.formGroup.get('username').setValidators(null);
this.formGroup.get('password').setValidators(null);
}
this.formGroup.get('username').updateValueAndValidity();
this.formGroup.get('password').updateValueAndValidity();
})
}

public addModule() {
Expand All @@ -50,4 +65,4 @@ export class NewModuleComponent implements OnInit {
});
this.dialogRef.close();
}
}
}