Skip to content

Commit

Permalink
Fixed cape sdk angular standalone and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emastrosimone committed Nov 30, 2021
1 parent 04c0d6d commit ded9e13
Show file tree
Hide file tree
Showing 31 changed files with 115 additions and 62 deletions.
2 changes: 1 addition & 1 deletion cape-dashboard/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
build:
context: .
args:
BASE_HREF: /cape-dashboard
BASE_HREF: /cape-dashboard/
ports:
- '80:80'
volumes:
Expand Down
2 changes: 1 addition & 1 deletion cape-online-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"private": true,
"dependencies": {
"cape-sdk-angular": "1.0.36",
"cape-sdk-angular": "1.0.38",
"@akveo/ng2-completer": "^9.0.1",
"@angular/animations": "11.2.12",
"@angular/cdk": "11.2.11",
Expand Down
2 changes: 1 addition & 1 deletion cape-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"private": true,
"dependencies": {
"cape-sdk-angular": "1.0.36",
"cape-sdk-angular": "1.0.38",
"@akveo/ng2-completer": "^9.0.1",
"@angular/animations": "11.2.12",
"@angular/cdk": "11.2.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { Component, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
import { NgxConfigureService } from 'ngx-configure';
import { TranslateService } from '@ngx-translate/core';
import { CapeSdkAngularService, ServiceLinkEvent, ConsentRecordEvent, SlStatusEnum, ConsentStatusEnum } from 'cape-sdk-angular';
Expand Down Expand Up @@ -63,7 +63,7 @@ const sampleChartData: any[] = [
templateUrl: './cholesterol.component.html',
styleUrls: ['./cholesterol.component.scss'],
})
export class CholesterolComponent implements OnInit {
export class CholesterolComponent implements OnInit, OnDestroy {
private config: any;
public locale: string;
public sdkUrl: string;
Expand Down
2 changes: 1 addition & 1 deletion cape-sdk/cape-sdk-angular-standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"private": true,
"dependencies": {
"cape-sdk-angular": "1.0.36",
"cape-sdk-angular": "1.0.38",
"@akveo/ng2-completer": "^9.0.1",
"@angular/animations": "11.2.12",
"@angular/cdk": "11.2.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="header-container">
<div class="logo-container">
<a (click)="toggleSidebar()" href="#" class="sidebar-toggle">
<!-- <a (click)="toggleSidebar()" href="#" class="sidebar-toggle">
<nb-icon icon="menu-2-outline"></nb-icon>
</a>
</a> -->
<a class="logo" href="#" (click)="navigateHome()"
><img class="p-1" src="assets\images\cape-logo.png" style="height: 64px" />
<!-- <span class="ml-3">{{ 'general.services.no_name_welcome' | translate: { name: user?.name } }}</span> -->
Expand All @@ -21,7 +21,7 @@
<!--<nb-action class="control-item" icon="email-outline"></nb-action>-->
<!-- <nb-action class="control-item" icon="bell-outline"></nb-action>-->
<nb-action class="user-action">
<nb-user [nbContextMenu]="loggedUserMenu" [onlyPicture]="userPictureOnly" [name]="user?.name" [title]="" [picture]="'assets/images/app/default_user.png'">
<nb-user [nbContextMenu]="loggedUserMenu" [onlyPicture]="userPictureOnly" [name]="user.name" [title]="" [picture]="'assets/images/app/default_user.png'">
</nb-user>

<ng-template #elseBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Subject } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { OidcUserInformationService } from 'src/app/auth/services/oidc-user-information.service';
import { UserClaims } from 'src/app/auth/model/oidc';
import { NgxConfigureService } from 'ngx-configure';
import { AppConfig } from 'src/app/model/appConfig';

@Component({
selector: 'ngx-header',
Expand All @@ -15,6 +17,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
private destroy$: Subject<void> = new Subject<void>();
userPictureOnly: boolean = false;
user: UserClaims;
appConfig: AppConfig;

themes = [
{
Expand Down Expand Up @@ -47,10 +50,18 @@ export class HeaderComponent implements OnInit, OnDestroy {
private breakpointService: NbMediaBreakpointsService,
private translateService: TranslateService,
private userService: OidcUserInformationService,
private cdr: ChangeDetectorRef
) {}
private cdr: ChangeDetectorRef,
private configureService: NgxConfigureService
) {
this.appConfig = this.configureService.config;
}

ngOnInit() {
this.loggedUserMenu.push({
title: this.translateService.instant('general.go_to_dashboard') as string,
url: this.appConfig.system.dashboardUrl,
target: '_blank',
});
this.loggedUserMenu.push({ title: this.translateService.instant('login.logout_button') as string, link: '' });
this.currentTheme = this.themeService.currentTheme;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Auth {
export interface Services {
sdkUrl: string;
checkConsentAtOperator: boolean;
showAdditionalConsentFormOptions: boolean;
}

export interface I18n {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AfterViewInit, Component, OnInit } from '@angular/core';
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { Router, ActivatedRoute, NavigationExtras, Params } from '@angular/router';
import { NgxConfigureService } from 'ngx-configure';
import { NbDialogService } from '@nebular/theme';
Expand All @@ -12,16 +12,19 @@ import {
CapeSdkDialogService,
dialogType,
ConsentFormComponent,
ConsentRecordEvent,
} from 'cape-sdk-angular';
// import { NbAuthService } from '@nebular/auth';
import { AppConfig } from 'src/app/model/appConfig';
import { ErrorDialogService } from '../error-dialog/error-dialog.service';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
@Component({
selector: 'app-services',
templateUrl: './services.component.html',
styleUrls: ['./services.component.scss'],
})
export class ServicesComponent implements AfterViewInit {
export class ServicesComponent implements AfterViewInit, OnDestroy {
config: AppConfig;
private locale: string;

Expand All @@ -42,6 +45,7 @@ export class ServicesComponent implements AfterViewInit {
public checkConsentAtOperator: boolean;
public showConsentAdditionalOptions = false;
consentRecord: ConsentRecordSigned;
private unsubscribe: Subject<void> = new Subject();

constructor(
private configService: NgxConfigureService,
Expand Down Expand Up @@ -81,6 +85,11 @@ export class ServicesComponent implements AfterViewInit {

this.checkAndGo(this.serviceId, this.serviceName, this.serviceRole, queryParams.purposeId);
}

// this.capeService.consentRecordStatus$.pipe(takeUntil(this.unsubscribe)).subscribe(async (event) => {
// event = event as ConsentRecordEvent;
// if (event?.serviceId === this.serviceId) this.capeConsentStatus = event.status.consent_status;
// });
}

checkAndGo = async (serviceId: string, serviceName: string, serviceRole: RoleEnum, purposeId: string) => {
Expand Down Expand Up @@ -234,7 +243,7 @@ export class ServicesComponent implements AfterViewInit {
sdkUrl: this.sdkUrl,
consentForm: await this.capeService.fetchConsentForm(this.sdkUrl, this.serviceAccountId, serviceId, this.operatorId, purposeId, serviceRole),
locale: sessionStorage.getItem('currentLocale') as string,
showAdditionalOptions: true,
showAdditionalOptions: this.config.services.showAdditionalConsentFormOptions,
},
})
.onClose.subscribe((accepted) => {
Expand All @@ -244,4 +253,9 @@ export class ServicesComponent implements AfterViewInit {
this.errorDialogService.openErrorDialog(error);
}
}

ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"services": {
"sdkUrl": "https://www.cape-suite.eu/cape-service-sdk",
"checkConsentAtOperator": "true"
"checkConsentAtOperator": "true",
"showAdditionalConsentFormOptions": false
},
"i18n": {
"locale": "en"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"general": {
"logo_text": "CaPe",
"home": "Home",
"go_to_dashboard": "Go to Cape Dashboard",
"error": "Error",
"refresh": "Refresh",
"close": "Close",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"general": {
"logo_text": "CaPe",
"home": "Home",
"go_to_dashboard": "Vai a Cape Dashboard",
"error": "Errore",
"refresh": "Aggiorna",
"close": "Chiudi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"form": {
"header": "Data Consent",
"title": "Data collection and use",
"body": "The service requires consent to use data for specific purposes.\r\nCheck the ones you agree to grant consent for the declared purpose.",
"body": "The service requires consent to use data for specific purposes.",
"dataMapping": "\r\nCheck the ones you agree to grant consent for the declared purpose.",
"processing": {
"header": "Purposes and processes",
"purpose": "These data will be used for:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"form": {
"header": "Consenso Dati",
"title": "Collezione ed uso dei dati",
"body": "Il servizio richiede il consenso ad utilizzare alcuni dati per specifiche finalità.\r\nSeleziona quelle per cui acconsenti a dare il consenso per le finalità dichiarate.",
"body": "Il servizio richiede il consenso ad utilizzare alcuni dati per specifiche finalità.",
"dataMapping": "\r\nSeleziona quelli per cui acconsenti a dare il consenso per le finalità dichiarate.",
"processing": {
"header": "Finalità e processamenti",
"purpose": "Questi dati verranno usati per:",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cape-sdk-angular",
"version": "1.0.36",
"version": "1.0.38",
"peerDependencies": {
"@angular/common": "^11.2.12",
"@angular/core": "^11.2.12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form [formGroup]="userConsentForm" (ngSubmit)="giveConsent(); dialogRef.close(true)">
<form [formGroup]="userConsentForm" (ngSubmit)="giveConsent()">
<nb-card>
<nb-card-header class="d-flex justify-content-between">
<h5 class="h5 mr-3">{{ 'general.consent.form.header' | translate }}</h5>
Expand All @@ -8,15 +8,19 @@ <h5 class="h5 mr-3">{{ 'general.consent.form.header' | translate }}</h5>
</nb-card-header>
<nb-card-body class="m-3">
<h3>{{ 'general.consent.form.title' | translate }}</h3>
<div class="row">
<span class="col-md">{{ 'general.consent.form.body' | translate }}</span>
<span class="col-md">{{ 'general.consent.form.body' | translate }}</span>
<div *ngIf="consentForm.resource_set?.datasets[0] != undefined" class="row">
<span class="col-md">{{ 'general.consent.form.dataMapping' | translate }}</span>
</div>
<div class="m-2" formGroupName="dataMapping">
<div class="" *ngFor="let concept of consentForm.resource_set.datasets[0].dataMappings">
<div *ngIf="consentForm.resource_set.datasets[0] !== undefined" class="m-2" formGroupName="dataMapping">
<div class="" *ngFor="let concept of consentForm.resource_set?.datasets[0]?.dataMappings">
<nb-checkbox [formControlName]="concept.name">{{ concept.name }}</nb-checkbox>
</div>
</div>
<div class="row m-2 font-weight-bold">
<div
*ngIf="consentForm.usage_rules.policy.policyRef != undefined && consentForm.usage_rules.policy.policyRef != ''"
class="row m-2 font-weight-bold"
>
{{ 'general.consent.form.policyRef' | translate }}
<a href="{{ consentForm.usage_rules.policy.policyRef }}" class="ml-2">{{ consentForm.usage_rules.policy.policyRef }}</a>
</div>
Expand All @@ -36,7 +40,7 @@ <h3>{{ 'general.consent.form.title' | translate }}</h3>
</nb-accordion-item-body>
</nb-accordion-item>

<nb-accordion-item>
<nb-accordion-item *ngIf="consentForm.usage_rules.shareWith.length > 0">
<nb-accordion-item-header>{{ 'general.consent.form.shareWith.header' | translate }}</nb-accordion-item-header>
<nb-accordion-item-body>
<div class="row m-1">{{ 'general.consent.form.shareWith.body' | translate }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ export class ConsentFormComponent implements OnInit {

ngOnInit(): void {
this.userConsentForm = this.fb.group({
dataMapping: new FormGroup(
Object.fromEntries(
this.consentForm.resource_set.datasets[0].dataMappings.map((concept) => [
concept.name,
new FormControl({ value: concept.required, disabled: concept.required }),
])
)
),
shareWith: new FormGroup(
Object.fromEntries(
this.consentForm.usage_rules.shareWith.map((shareWith) => [
Expand All @@ -49,19 +41,35 @@ export class ConsentFormComponent implements OnInit {
collectionOperatorId: new FormControl(''),
});

if (this.consentForm.resource_set.datasets[0] !== undefined)
this.userConsentForm.addControl(
'dataMapping',
new FormGroup(
Object.fromEntries(
this.consentForm.resource_set.datasets[0].dataMappings.map((concept) => [
concept.name,
new FormControl({ value: concept.required, disabled: concept.required }),
])
)
)
);

this.translateService.use(this.locale);
this.cdr.detectChanges();
}

async giveConsent(): Promise<void> {
const dataMappingControls = new Map(
Object.entries((this.userConsentForm.controls.dataMapping as FormGroup).controls).map((obj) => [obj[0], obj[1]])
);
if (this.consentForm.resource_set.datasets[0] !== undefined) {
const dataMappingControls = new Map(
Object.entries((this.userConsentForm.controls.dataMapping as FormGroup).controls).map((obj) => [obj[0], obj[1]])
);
this.consentForm.resource_set.datasets[0].dataMappings = this.consentForm.resource_set.datasets[0].dataMappings.filter(
(concept) => dataMappingControls.get(concept.name)?.value
);
}

const shareWithControls = new Map(Object.entries((this.userConsentForm.controls.shareWith as FormGroup).controls).map((obj) => [obj[0], obj[1]]));

this.consentForm.resource_set.datasets[0].dataMappings = this.consentForm.resource_set.datasets[0].dataMappings.filter(
(concept) => dataMappingControls.get(concept.name)?.value
);
this.consentForm.usage_rules.shareWith = this.consentForm.usage_rules.shareWith.filter(
(shareWith) => shareWithControls.get(shareWith.orgName)?.value
);
Expand All @@ -70,6 +78,7 @@ export class ConsentFormComponent implements OnInit {
this.consentForm.collection_operator_id = (this.userConsentForm.controls.collectionOperatorId as FormControl).value as string;
try {
const newConsentRecordSigned = await this.capeService.giveConsent(this.sdkUrl, this.consentForm);
this.dialogRef.close(true);
this.toastrService.primary('', this.translateService.instant('general.consent.giveConsentSuccessful'), {
position: NbGlobalLogicalPosition.BOTTOM_END,
duration: 3500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
@ToString
public class Policy {

@NotBlank(message = "policyRef field is mandatory")
public @NotBlank(message = "policyRef field is mandatory") String policyRef;
// @NotBlank(message = "policyRef field is mandatory")
public String policyRef;
public String policyHash;
public String policyVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class UsageRules {
private Set<ProcessingCategory> processingCategories;

@Valid
@NotNull
// @NotNull
private Policy policy = new Policy();

private Storage storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
@ToString
public class Policy {

@NotBlank(message = "policyRef field is mandatory")
public @NotBlank(message = "policyRef field is mandatory") String policyRef;
// @NotBlank(message = "policyRef field is mandatory")
public String policyRef;
public String policyHash;
public String policyVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class UsageRules {
private Set<ProcessingCategory> processingCategories;

@Valid
@NotNull
// @NotNull
private Policy policy = new Policy();

private Storage storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
@ToString
public class Policy {

@NotBlank(message = "policyRef field is mandatory")
public @NotBlank(message = "policyRef field is mandatory") String policyRef;
// @NotBlank(message = "policyRef field is mandatory")
public String policyRef;
public String policyHash;
public String policyVersion;

Expand Down

0 comments on commit ded9e13

Please sign in to comment.