Add warning if manadatory information is not filled in the existed services.

This commit is contained in:
Konstantinos Triantafyllou 2023-07-14 18:28:02 +03:00
parent 7c5e7ca2a9
commit ce3b2789f8
9 changed files with 86 additions and 27 deletions

View File

@ -1,16 +1,12 @@
import {ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild} from "@angular/core";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {FormArray, FormBuilder, FormGroup, Validators} from "@angular/forms";
import {Subscription} from "rxjs";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import {User} from "../openaireLibrary/login/utils/helper.class";
import {PersonalInfo, PersonalService} from "../services/personal.service";
import {NotificationHandler} from "../openaireLibrary/utils/notification-handler";
import {API, ApisService} from "../services/apis.service";
import {AlertModal} from "../openaireLibrary/utils/modal/alert";
import {StringUtils} from "../openaireLibrary/utils/string-utils.class";
import {properties} from "../../environments/environment";
import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder";
import {CommunityInfo} from "../openaireLibrary/connect/community/communityInfo";
import {UtilitiesService} from "../openaireLibrary/services/utilities.service";
declare var copy;
@ -60,8 +56,12 @@ declare var copy;
(click)="openEditModal(i)"></icon>
<icon name="delete" class="clickable uk-margin-xsmall-left"
customClass="uk-text-danger" (click)="openDeleteModal(i)"></icon>
<icon name="info" class="clickable uk-margin-xsmall-left"
<icon *ngIf="!api.invalid" name="info" class="clickable uk-margin-xsmall-left"
customClass="uk-text-secondary" (click)="openInfoModal(i)"></icon>
<icon *ngIf="api.invalid" name="warning" class="clickable uk-margin-xsmall-left"
customClass="uk-text-warning"
uk-tooltip="You have to fill missing information regarding your service in order to preview your details.
Click edit to fill the missing information"></icon>
</span>
</td>
</tr>
@ -77,9 +77,20 @@ declare var copy;
[formInput]="form.get('name')"></div>
<div class="uk-width-1-2@m uk-width-1-1" input type="logoURL" placeholder="Service URL"
[formInput]="form.get('url')"></div>
<div class="uk-width-1-1" input type="logoURL" placeholder="Logo URL"
<div class="uk-width-1-2@m uk-width-1-1" input type="logoURL" placeholder="Logo URL"
[formInput]="form.get('logoURL')">
</div>
<div class="uk-width-1-2@m uk-width-1-1" input type="select" placeholder="Service Frequency of use"
[formInput]="form.get('frequency')" [options]="frequency">
</div>
<div class="uk-width-1-1" input type="textarea" placeholder="Service Description"
[formInput]="form.get('description')">
</div>
<div class="uk-width-1-1" input type="chips" placeholder="Target groups"
[addExtraChips]="true" [separators]="[',']"
[formInput]="target" [options]="groups" [hint]="'Add a target group of your service'">
<div note>Separate groups with commas</div>
</div>
<div class="uk-width-1-1">
<label class="uk-text-bold">Security Level</label>
<div id="security-hint" class="uk-margin">Register your service to get a client id and a client
@ -226,6 +237,8 @@ export class ApisComponent implements OnInit, OnDestroy {
advanced: boolean = false;
byValue: boolean = true;
hint = '{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}';
frequency: string[] = ['Daily', 'Weekly', 'Monthly'];
groups: string[] = ['Commerce', 'Education', 'Health', 'Non profit', 'Public Sector'];
@ViewChild("editModal") editModal: AlertModal;
@ViewChild("deleteModal") deleteModal: AlertModal;
@ViewChild("infoModal") infoModal: AlertModal;
@ -260,6 +273,14 @@ export class ApisComponent implements OnInit, OnDestroy {
})
}
get target():FormArray {
if(this.form) {
return <FormArray>this.form.get('target');
} else {
return this.fb.array([]);
}
}
openEditModal(index: number = -1) {
let api = new API();
this.index = index;
@ -275,14 +296,26 @@ export class ApisComponent implements OnInit, OnDestroy {
this.form = this.fb.group({
name: this.fb.control(api.service.name, Validators.required),
keyType: this.fb.control(api.service.keyType),
description: this.fb.control(api.service.description),
frequency: this.fb.control(api.service.frequency, Validators.required),
target: this.fb.array([], Validators.required),
logoURL: this.fb.control(api.details.logoUri, [StringUtils.urlValidator()]),
url: this.fb.control(api.service.url, [Validators.required, StringUtils.urlValidator()]),
uri: this.fb.control(api.details.jwksUri, [StringUtils.urlValidator()]),
value: this.fb.control(null, [StringUtils.jsonValidator('The format should be {"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}')])
});
if(api.service.target) {
api.service.target.forEach(target => {
this.target.push(this.fb.control(target));
});
}
if(api.details?.jwks?.keys) {
this.form.get('value').setValue(JSON.stringify(api.details.jwks.keys[0]));
}
if(api.invalid) {
this.form.markAllAsTouched();
this.cdr.detectChanges();
}
this.advanced = !!this.form.get('keyType').getRawValue();
this.byValue = this.advanced && this.form.get('keyType').getRawValue() === 'value';
this.formChanges();
@ -323,7 +356,7 @@ export class ApisComponent implements OnInit, OnDestroy {
} else {
this.subscriptions.push(this.apisService.save(this.apis[this.index].service.id, this.form.getRawValue()).subscribe(api => {
this.apis[this.index] = api;
NotificationHandler.rise('Your service has been created successfully.');
NotificationHandler.rise('Your service has been saved successfully.');
this.loading = false;
}, error => {
console.error(error);

View File

@ -20,7 +20,7 @@ import {Header} from "./openaireLibrary/sharedComponents/navigationBar.component
[class.sidebar_mini]="!open && hasSidebar"
[class.sidebar_hover]="hover">
<div id="modal-container"></div>
<navbar *ngIf="hasHeader" portal="client-management" [header]="menuHeader"
<navbar *ngIf="hasHeader" portal="developers" [header]="menuHeader"
[userMenuItems]=userMenuItems [menuItems]="menuItems" [user]="user"></navbar>
<div>
<dashboard-sidebar *ngIf="hasSidebar" [items]="sideBarItems" [backItem]="backItem"></dashboard-sidebar>

@ -1 +1 @@
Subproject commit 5645deec97d1bd3cb35cec792ac8dc963c0f4d8a
Subproject commit 55a045433077a4fb866345456694e6490654c89f

View File

@ -27,7 +27,9 @@ import {NavigationEnd, Router} from "@angular/router";
[placeholder]="'Name'"></div>
<div class="uk-width-1-2@m uk-width-1-1" input [formInput]="form.get('surname')"
[placeholder]="'Surname'"></div>
<div class="uk-width-1-1" input [formInput]="form.get('email')" [placeholder]="'Email'"></div>
<div class="uk-width-1-2@m uk-width-1-1" input [formInput]="form.get('email')" [placeholder]="'Email'"></div>
<div class="uk-width-1-2@m uk-width-1-1" input [formInput]="form.get('affiliationType')"
[placeholder]="'Affiliation Type'" [type]="'select'" [options]="affiliationTypeOptions"></div>
<div class="uk-width-1-2@m uk-width-1-1" input [formInput]="form.get('affiliation')"
[placeholder]="'Affiliation'"></div>
<div class="uk-width-1-2@m uk-width-1-1" input [formInput]="form.get('position')"
@ -50,6 +52,7 @@ export class PersonalInfoComponent implements OnInit, OnDestroy {
subscriptions: any[] = [];
user: User;
info: PersonalInfo = null;
affiliationTypeOptions: string[] = ['Organization', 'University', 'SME', 'Public Sector'];
message: boolean = false;
constructor(private fb: FormBuilder,
@ -88,6 +91,7 @@ export class PersonalInfoComponent implements OnInit, OnDestroy {
surname: this.fb.control(this.info.surname, Validators.required),
email: this.fb.control({value: this.info.email, disabled: true}, Validators.required),
affiliation: this.fb.control(this.info.affiliation, Validators.required),
affiliationType: this.fb.control(this.info.affiliationType, Validators.required),
position: this.fb.control(this.info.position, Validators.required),
});
} else {
@ -96,6 +100,7 @@ export class PersonalInfoComponent implements OnInit, OnDestroy {
surname: this.fb.control(this.user.lastname, Validators.required),
email: this.fb.control({value: this.user.email, disabled: true}, Validators.required),
affiliation: this.fb.control('', Validators.required),
affiliationType: this.fb.control(null, Validators.required),
position: this.fb.control('', Validators.required),
});
}

View File

@ -3,6 +3,10 @@ import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";
import {properties} from "../../environments/environment";
import {CustomOptions} from "../openaireLibrary/services/servicesUtils/customOptions.class";
import {map} from "rxjs/operators";
export type Frequency = 'Daily' | 'Weekly' | 'Monthly';
export type Group = 'Commerce' | 'Education' | 'Health' |'Non profit' | 'Public Sector';
export class RegisteredService {
id: number;
@ -13,6 +17,9 @@ export class RegisteredService {
owner: string;
registrationAccessToken: string;
url: string;
description: string;
frequency: Frequency;
target: Group[] = [];
}
export class Details {
@ -49,10 +56,12 @@ export class Details {
export class API {
service: RegisteredService;
details: Details;
invalid: boolean = false;
constructor() {
this.service = new RegisteredService();
this.details = new Details();
this.invalid = false;
}
}
@ -65,22 +74,31 @@ export class ApisService {
}
public getAll(): Observable<API[]> {
return this.http.get<API[]>(properties.developersApiUrl + "/apis/all", CustomOptions.registryOptions());
return this.http.get<API[]>(properties.developersApiUrl + "/apis/all", CustomOptions.registryOptions())
.pipe(map(apis => apis.map(api => this.setInvalid(api))));
}
public getMyServices(): Observable<API[]> {
return this.http.get<API[]>(properties.developersApiUrl + "/apis/my-services", CustomOptions.registryOptions());
return this.http.get<API[]>(properties.developersApiUrl + "/apis/my-services", CustomOptions.registryOptions())
.pipe(map(apis => apis.map(api => this.setInvalid(api))));
}
public create(form: any): Observable<API> {
return this.http.post<API>(properties.developersApiUrl + "/apis/save/new", form, CustomOptions.registryOptions());
return this.http.post<API>(properties.developersApiUrl + "/apis/save/new", form, CustomOptions.registryOptions())
.pipe(map(api => this.setInvalid(api)));
}
public save(id: number, form: any): Observable<API> {
return this.http.post<API>(properties.developersApiUrl + "/apis/save/" + id, form, CustomOptions.registryOptions());
return this.http.post<API>(properties.developersApiUrl + "/apis/save/" + id, form, CustomOptions.registryOptions())
.pipe(map(api => this.setInvalid(api)));
}
public delete(id: number): Observable<void> {
return this.http.delete<void>(properties.developersApiUrl + "/apis/delete/" + id, CustomOptions.registryOptions());
}
private setInvalid(api: API) {
api.invalid = !api.service.url || !api.service.frequency || !api.service.target || api.service.target.length == 0;
return api;
}
}

View File

@ -3,12 +3,15 @@ import {HttpClient} from "@angular/common/http";
import {properties} from "../../environments/environment";
import {CustomOptions} from "../openaireLibrary/services/servicesUtils/customOptions.class";
export type AffiliationType = 'Organization' | 'University' | 'SME' | 'Public Sector';
export interface PersonalInfo {
id: string;
email: string;
name: string;
surname: string;
affiliation: string;
affiliationType: string;
position: string;
}

View File

@ -4,10 +4,10 @@ export let properties: EnvProperties = {
environment: 'production',
dashboard: 'developers',
useCache: false,
loginUrl: "https://beta.services.openaire.eu/client-management/openid_connect_login",
userInfoUrl: "https://beta.services.openaire.eu/client-management/userInfo",
developersApiUrl: "https://beta.services.openaire.eu/client-management",
logoutUrl: "https://beta.services.openaire.eu/client-management/openid_logout",
loginUrl: "https://beta.services.openaire.eu/developers-api/openid_connect_login",
userInfoUrl: "https://beta.services.openaire.eu/developers-api/userInfo",
developersApiUrl: "https://beta.services.openaire.eu/developers-api",
logoutUrl: "https://beta.services.openaire.eu/developers-api/openid_logout",
cookieDomain: '.openaire.eu',
errorLink: '/error',
};

View File

@ -4,10 +4,10 @@ export let properties: EnvProperties = {
environment: 'production',
dashboard: 'developers',
useCache: false,
loginUrl: "https://services.openaire.eu/client-management/openid_connect_login",
userInfoUrl: "https://services.openaire.eu/client-management/userInfo",
developersApiUrl: "https://services.openaire.eu/client-management",
logoutUrl: "https://services.openaire.eu/client-management/openid_logout",
loginUrl: "https://services.openaire.eu/developers-api/openid_connect_login",
userInfoUrl: "https://services.openaire.eu/developers-api/userInfo",
developersApiUrl: "https://services.openaire.eu/developers-api",
logoutUrl: "https://services.openaire.eu/developers-api/openid_logout",
cookieDomain: '.openaire.eu',
errorLink: '/error',
};

View File

@ -9,10 +9,10 @@ export let properties: EnvProperties = {
environment: 'development',
dashboard: 'developers',
useCache: false,
loginUrl: "http://mpagasas.di.uoa.gr:19580/client-management/openid_connect_login",
userInfoUrl: "http://mpagasas.di.uoa.gr:19580/client-management/userInfo",
developersApiUrl: "http://mpagasas.di.uoa.gr:19580/client-management",
logoutUrl: "http://mpagasas.di.uoa.gr:19580/client-management/openid_logout",
loginUrl: "http://mpagasas.di.uoa.gr:19580/developers-api/openid_connect_login",
userInfoUrl: "http://mpagasas.di.uoa.gr:19580/developers-api/userInfo",
developersApiUrl: "http://mpagasas.di.uoa.gr:19580/developers-api",
logoutUrl: "http://mpagasas.di.uoa.gr:19580/developers-api/openid_logout",
cookieDomain: '.di.uoa.gr',
errorLink: '/error',
domain: 'http://mpagasas.di.uoa.gr:5001',