-
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.
Merge branch 'feature/440243-nueva-politica' into 'develop'
Rehecho crear policy. See merge request upm-inesdata/inesdata-connector-interface!27
- Loading branch information
Showing
69 changed files
with
2,216 additions
and
85 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
52 changes: 23 additions & 29 deletions
52
src/app/pages/policies/new-policy-dialog/new-policy-dialog.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
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
79 changes: 31 additions & 48 deletions
79
src/app/pages/policies/new-policy-dialog/new-policy-dialog.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 |
---|---|---|
@@ -1,69 +1,52 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { PolicyInput } from "../../../shared/models/edc-connector-entities"; | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { MatDialogRef } from "@angular/material/dialog"; | ||
import { NotificationService } from 'src/app/shared/services/notification.service'; | ||
import { PolicyBuilder } from '@think-it-labs/edc-connector-client'; | ||
import { PolicyDefinitionCreatePageForm } from './policy-definition-create-page-form'; | ||
import { ExpressionFormHandler } from '../policy-editor/editor/expression-form-handler'; | ||
import { ValidationMessages } from 'src/app/shared/validators/validation-messages'; | ||
import { Subject } from 'rxjs'; | ||
import { PolicyDefinitionCreateDto } from '../policy-editor/model/policy-definition-create-dto'; | ||
|
||
@Component({ | ||
selector: 'app-new-policy-dialog', | ||
templateUrl: './new-policy-dialog.component.html', | ||
styleUrls: ['./new-policy-dialog.component.scss'] | ||
}) | ||
export class NewPolicyDialogComponent implements OnInit { | ||
editMode: boolean = false; | ||
policy: PolicyInput = { | ||
"@type": "Set" | ||
}; | ||
export class NewPolicyDialogComponent implements OnInit,OnDestroy { | ||
|
||
policyId: string = ''; | ||
permissionsJson: string = ''; | ||
prohibitionsJson: string = ''; | ||
obligationsJson: string = ''; | ||
|
||
constructor(private dialogRef: MatDialogRef<NewPolicyDialogComponent>, | ||
private notificationService: NotificationService) { | ||
} | ||
constructor( | ||
public form: PolicyDefinitionCreatePageForm, | ||
public expressionFormHandler: ExpressionFormHandler, | ||
public validationMessages: ValidationMessages, | ||
private dialogRef: MatDialogRef<NewPolicyDialogComponent>, | ||
private notificationService: NotificationService | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.editMode = true; | ||
|
||
this.expressionFormHandler.reset() | ||
this.form.reset() | ||
} | ||
|
||
onSave() { | ||
try { | ||
this.policy.permission = this.parseAndVerifyJson(this.permissionsJson); | ||
this.policy.prohibition = this.parseAndVerifyJson(this.prohibitionsJson); | ||
this.policy.obligation = this.parseAndVerifyJson(this.obligationsJson); | ||
|
||
this.dialogRef.close({ | ||
'@id': this.policyId, | ||
policy: new PolicyBuilder() | ||
.raw({ | ||
...this.policy | ||
}) | ||
.build() | ||
}); | ||
|
||
} catch (error) { | ||
if (error instanceof SyntaxError) { | ||
this.notificationService.showError("Error parsing JSON: " + error.message); | ||
console.error(error); | ||
} | ||
const createDto = this.buildPolicyDefinitionCreateDto(); | ||
if(this.form.group.valid){ | ||
this.dialogRef.close(createDto); | ||
} | ||
} | ||
|
||
/** | ||
* Parse and verify a JSON from the policy | ||
* | ||
* @param json JSON to parse and verify | ||
* @returns the parsed JSON or null if it is empty | ||
*/ | ||
private parseAndVerifyJson(json: string): any { | ||
if (json.trim() != '') { | ||
const parsedJson = JSON.parse(json); | ||
return parsedJson; | ||
} | ||
|
||
return null; | ||
buildPolicyDefinitionCreateDto(): PolicyDefinitionCreateDto { | ||
return { | ||
policyDefinitionId: this.form.group.controls.id.value, | ||
expression: this.expressionFormHandler.toUiPolicyExpression(), | ||
}; | ||
} | ||
|
||
ngOnDestroy$ = new Subject(); | ||
|
||
ngOnDestroy(): void { | ||
this.ngOnDestroy$.next(null); | ||
this.ngOnDestroy$.complete(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/app/pages/policies/new-policy-dialog/policy-definition-create-page-form-model.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,9 @@ | ||
import {FormControl, UntypedFormGroup, ɵFormGroupValue} from '@angular/forms'; | ||
|
||
export type PolicyDefinitionCreatePageFormValue = | ||
ɵFormGroupValue<PolicyDefinitionCreatePageFormModel>; | ||
|
||
export interface PolicyDefinitionCreatePageFormModel { | ||
id: FormControl<string>; | ||
treeControls: UntypedFormGroup; | ||
} |
40 changes: 40 additions & 0 deletions
40
src/app/pages/policies/new-policy-dialog/policy-definition-create-page-form.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,40 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; | ||
import { | ||
PolicyDefinitionCreatePageFormModel, | ||
PolicyDefinitionCreatePageFormValue, | ||
} from './policy-definition-create-page-form-model'; | ||
import { ExpressionFormControls } from '../policy-editor/editor/expression-form-controls'; | ||
import { noWhitespacesOrColonsValidator } from 'src/app/shared/validators/no-whitespaces-or-colons-validator'; | ||
|
||
/** | ||
* Handles AngularForms for NewPolicyDialog | ||
*/ | ||
@Injectable() | ||
export class PolicyDefinitionCreatePageForm { | ||
group = this.buildFormGroup(); | ||
|
||
/** | ||
* Quick access to full value | ||
*/ | ||
get value(): PolicyDefinitionCreatePageFormValue { | ||
return this.group.value; | ||
} | ||
|
||
constructor( | ||
private formBuilder: FormBuilder, | ||
private expressionFormControls: ExpressionFormControls, | ||
) {} | ||
|
||
buildFormGroup(): FormGroup<PolicyDefinitionCreatePageFormModel> { | ||
return this.formBuilder.nonNullable.group({ | ||
id: ['', [Validators.required, noWhitespacesOrColonsValidator]], | ||
treeControls: this.expressionFormControls.formGroup, | ||
}); | ||
} | ||
|
||
reset(){ | ||
this.expressionFormControls.reset() | ||
this.group = this.buildFormGroup() | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/app/pages/policies/policy-editor/editor/controls/participant-id-select/array-utils.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,21 @@ | ||
/** | ||
* Remove item once from list. | ||
* | ||
* Use this over .filter(...) to remove items on user interactions | ||
* to prevent one click from removing many items. | ||
* | ||
* Returns copy. | ||
*/ | ||
export function removeOnce<T>(list: T[], item: T): T[] { | ||
const index = list.indexOf(item); | ||
if (index >= 0) { | ||
const copy = [...list]; | ||
copy.splice(index, 1); | ||
return copy; | ||
} | ||
return list; | ||
} | ||
|
||
export function filterNonNull<T>(array: (T | null | undefined)[]): T[] { | ||
return array.filter((it) => it != null) as T[]; | ||
} |
24 changes: 24 additions & 0 deletions
24
.../policy-editor/editor/controls/participant-id-select/participant-id-select.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,24 @@ | ||
<mat-form-field class="grow" appearance="outline" color="accent"> | ||
<mat-label>Participant ID</mat-label> | ||
<mat-chip-grid | ||
#chipList | ||
[formControl]="control"> | ||
<mat-chip | ||
*ngFor="let participantId of control?.value ?? []" | ||
(removed)="remove(participantId)"> | ||
{{ participantId }} | ||
<button matChipRemove> | ||
<mat-icon>cancel</mat-icon> | ||
</button> | ||
</mat-chip> | ||
<input | ||
[matChipInputAddOnBlur]="true" | ||
[matChipInputFor]="chipList" | ||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" | ||
(matChipInputTokenEnd)="add($event)" /> | ||
</mat-chip-grid> | ||
<mat-hint> | ||
The Participant ID of your Connector can be | ||
found on the dashboard of your Connector. | ||
</mat-hint> | ||
</mat-form-field> |
Oops, something went wrong.