[Monitor Dashboard | Trunk]: Fix number indicator form, add validation

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@59811 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2020-11-11 09:20:54 +00:00
parent 2ce065b70e
commit 02f9cf4f40
8 changed files with 121 additions and 74 deletions

View File

@ -175,33 +175,37 @@ export class EditStakeholderComponent implements OnDestroy {
}));
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, Validators.required));
}
if (Session.isPortalAdministrator(this.user)) {
if (this.disableAlias) {
if (!isNew) {
if (this.isAdmin) {
if (this.disableAlias) {
setTimeout(() => {
this.stakeholderFb.get('alias').disable();
}, 0);
}
} else {
setTimeout(() => {
this.stakeholderFb.get('alias').disable();
this.stakeholderFb.get('index_id').disable();
this.stakeholderFb.get('index_name').disable();
this.stakeholderFb.get('index_shortName').disable();
}, 0);
}
} else {
setTimeout(() => {
this.stakeholderFb.get('alias').disable();
this.stakeholderFb.get('index_id').disable();
this.stakeholderFb.get('index_name').disable();
this.stakeholderFb.get('index_shortName').disable();
}, 0);
}
if (isNew) {
setTimeout(() => {
this.stakeholderFb.get('type').enable();
}, 0);
} else {
setTimeout(() => {
this.stakeholderFb.get('type').disable();
}, 0);
} else {
setTimeout(() => {
this.stakeholderFb.get('type').enable();
}, 0);
}
}
));
}
public get isAdmin() {
return Session.isPortalAdministrator(this.user);
}
public get disabled(): boolean {
return (this.stakeholderFb && this.stakeholderFb.invalid) ||
(this.stakeholderFb && this.stakeholderFb.pristine && !this.isNew && !this.file) ||

View File

@ -9,3 +9,10 @@ div[id*="number-"] .uk-card-body {
div[id*="chart-"] .uk-card-body {
padding-top: 75px;
}
.number-preview {
border: 1px solid #D1D1D1;
border-radius: 4px;
min-width: 100px;
min-height: 70px;
}

View File

@ -243,7 +243,8 @@
[formInput]="numberIndicatorFb.get('description')"
label="Description" type="textarea">
</div>
<div dashboard-input *ngIf="isAdministrator || indicator.defaultId" class="uk-width-1-1" [formInput]="numberIndicatorFb.get('additionalDescription')"
<div dashboard-input *ngIf="isAdministrator || indicator.defaultId" class="uk-width-1-1"
[formInput]="numberIndicatorFb.get('additionalDescription')"
label="Additional information" type="textarea">
</div>
@ -261,10 +262,8 @@
<div class="uk-width-1-1">
<div class="uk-grid" uk-grid>
<div class="uk-width-1-1">
<div dashboard-input [formInput]="indicatorPath.get('url')" label="Number URL"></div>
</div>
<div *ngIf="urlParameterizedMessage.length > 0" class="uk-alert-warning uk-alert uk-width-1-1">
{{urlParameterizedMessage}}
<div dashboard-input [formInput]="indicatorPath.get('url')" label="Number URL"
[warning]="urlParameterizedMessage"></div>
</div>
<div class="uk-width-1-1">
<div dashboard-input [formInput]="indicatorPath.get('source')" label="Source"
@ -274,10 +273,17 @@
</div>
</div>
<div formArrayName="jsonPath" class="uk-width-1-1">
<h6 class="uk-text-bold">
JSON Path
<h6 class="uk-text-bold uk-flex uk-flex-middle uk-margin-remove-bottom"
[class.uk-text-danger]="numberIndicatorPaths.at(i).get('result').invalid && numberIndicatorPaths.at(i).get('result').errors.required">
<span>JSON Path</span>
</h6>
<div class="uk-grid uk-child-width-1-3@m uk-child-width-1-1" uk-grid>
<div *ngIf="numberIndicatorPaths.at(i).get('result').invalid && numberIndicatorPaths.at(i).get('result').errors.required">
<div class="uk-text-danger uk-text-small">
This JSON path is not valid or the result has not been calculated yet.
Please press calculate on box below to see the result.
</div>
</div>
<div class="uk-grid uk-child-width-1-3@m uk-child-width-1-1 uk-margin-top" uk-grid>
<div *ngFor="let jsonPath of getJsonPath(i).controls; let j=index" class="uk-flex uk-flex-middle">
<div dashboard-input class="uk-width-1-1"
[extraLeft]="false"
@ -296,20 +302,29 @@
</div>
</div>
<div class="uk-flex uk-flex-middle">
<button class="uk-icon-button uk-button-secondary uk-margin-medium-top"
(click)="addJsonPath(i)">
<button class="uk-icon-button uk-button-secondary uk-margin-medium-top"
(click)="addJsonPath(i)">
<icon name="add"></icon>
</button>
<!--<span *ngIf="getJsonPath(i).invalid" class="uk-margin-small-left uk-margin-medium-top">
<button *ngIf="getJsonPath(i).errors.invalid" class="uk-icon-button uk-button-primary"
(click)="validateJsonPath(i)">
<icon name="done"></icon>
</button>
</span>
<span *ngIf="getJsonPath(i).disabled" class="uk-text-primary uk-margin-small-left uk-margin-medium-top">Validating...</span>
<span *ngIf="getJsonPath(i).valid" class="uk-text-success uk-margin-small-left uk-margin-medium-top">
<icon name="done"></icon>
</span>-->
</div>
</div>
</div>
<div class="uk-width-1-1 uk-flex uk-flex-center">
<div class="uk-flex uk-position-relative">
<span class="uk-padding number number-preview">
<span *ngIf="numberIndicatorPaths.at(i).get('result').valid">{{numberIndicatorPaths.at(i).get('result').value | number}}</span>
</span>
<div *ngIf="numberIndicatorPaths.at(i).get('result').invalid" class="uk-width-1-1 uk-height-1-1 refresh-indicator">
<div class="uk-position-relative uk-height-1-1">
<div class="uk-position-center uk-text-center clickable uk-text-small"
(click)="validateJsonPath(i)">
<div>
<icon name="refresh"></icon>
</div>
<span *ngIf="numberIndicatorPaths.at(i).get('result').errors.required">Calculate</span>
<span *ngIf="numberIndicatorPaths.at(i).get('result').errors.validating">Calculating...</span>
</div>
</div>
</div>
</div>
</div>
@ -330,7 +345,8 @@
[formInput]="chartIndicatorFb.get('description')"
label="Description" type="textarea">
</div>
<div dashboard-input *ngIf="isAdministrator || indicator.defaultId" class="uk-width-1-1" [formInput]="chartIndicatorFb.get('additionalDescription')"
<div dashboard-input *ngIf="isAdministrator || indicator.defaultId" class="uk-width-1-1"
[formInput]="chartIndicatorFb.get('additionalDescription')"
label="Additional information" type="textarea">
</div>
<div dashboard-input class="uk-width-1-2@m" [formInput]="chartIndicatorFb.get('visibility')"
@ -345,11 +361,8 @@
[formGroup]="indicatorPath" class="uk-grid" uk-grid>
<div dashboard-input class="uk-width-1-1"
[title]="indicatorPath.get('url').disabled?'Default chart URLs cannot change':''"
[formInput]="indicatorPath.get('url')"
[formInput]="indicatorPath.get('url')" [warning]="urlParameterizedMessage"
label="Chart URL"></div>
<div *ngIf="urlParameterizedMessage.length > 0" class="uk-alert-warning uk-alert uk-width-1-1">
{{urlParameterizedMessage}}
</div>
<div class="uk-width-1-1" formArrayName="parameters">
<div class="uk-grid" uk-grid>
<div *ngIf="getParameter(i, 'title')" class="uk-width-1-1">
@ -402,7 +415,7 @@
<div *ngIf="indicator && indicator.indicatorPaths[i] && indicator.indicatorPaths[i].safeResourceUrl"
class="uk-margin-medium-top uk-position-relative uk-width-1-1 uk-flex uk-flex-center">
<div *ngIf="(hasDifference(i)) && !indicatorPath.invalid"
class="uk-width-1-1 uk-height-large refresh-iframe">
class="uk-width-1-1 uk-height-large refresh-indicator">
<div class="uk-position-relative uk-height-1-1">
<div class="uk-position-center uk-text-center clickable"
(click)="refreshIndicator()">

View File

@ -95,7 +95,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
public sectionChildrenActionOnDelete: string;
public indicatorChildrenActionOnDelete: string;
urlParameterizedMessage = "";
urlParameterizedMessage = null;
constructor(private layoutService: LayoutService,
private stakeholderService: StakeholderService,
@ -171,9 +171,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
result = result[jsonPath];
}
});
if (typeof result == 'string' || typeof result == 'number') {
this.numberResults.set(i + '-' + j, Number(result));
}
this.numberResults.set(i + '-' + j, result);
});
});
});
@ -428,6 +426,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
public validateJsonPath(index: number) {
let indicatorPath: FormGroup = <FormGroup>this.numberIndicatorPaths.at(index);
this.getJsonPath(index).disable();
indicatorPath.get('result').setErrors({validating: true});
this.statisticsService.getNumbers(null, indicatorPath.get('url').value).subscribe(response => {
let result = JSON.parse(JSON.stringify(response));
this.getJsonPath(index).controls.forEach(jsonPath => {
@ -435,15 +434,20 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
result = result[jsonPath.value];
}
});
setTimeout( () => {
if (typeof result == 'string') {
this.getJsonPath(index).enable();
this.getJsonPath(index).setErrors(null);
setTimeout(() => {
this.getJsonPath(index).enable();
indicatorPath.get('result').setErrors(null);
if(typeof result === 'string' || typeof result === 'number') {
result = Number(result);
if (result !== Number.NaN) {
indicatorPath.get('result').setValue(result);
} else {
indicatorPath.get('result').setValue(null);
}
} else {
this.getJsonPath(index).enable();
this.getJsonPath(index).setErrors({invalid: true});
indicatorPath.get('result').setValue(null);
}
}, 1000);
}, 500);
});
}
@ -479,13 +483,17 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.numberIndicatorPaths.push(this.fb.group({
url: this.fb.control(url, Validators.required),
jsonPath: jsonPath,
result: this.fb.control(0, Validators.required),
// parameters: parameters,
source: this.fb.control(source, Validators.required)
}
));
for (let index = 0; index < this.numberIndicatorPaths.length; index++) {
if(this.numberIndicatorPaths.at(index).get('url').valid) {
this.validateJsonPath(index);
}
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
this.numberIndicatorPaths.at(index).get('result').setValue(null);
if (this.numberIndicatorPaths.at(index).get('url').valid) {
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value);
if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1)
@ -497,24 +505,33 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder."
}
} else {
this.urlParameterizedMessage = "";
this.urlParameterizedMessage = null;
}
/* if(value != indicatorPath.url) {
(this.numberIndicatorPaths.at(index) as FormGroup).get('url').setValue( indicatorPath.url);
}*/
this.indicator.indicatorPaths[index] = indicatorPath;
(this.numberIndicatorPaths.at(index) as FormGroup).get('source').setValue(indicatorPath.source);
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
} else {
this.indicator.indicatorPaths.push(indicatorPath);
}
if(indicatorPath.source) {
this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
}
} else {
this.urlParameterizedMessage = null;
}
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
this.indicator.indicatorPaths[index].jsonPath = value;
//this.getJsonPath(index).setErrors({invalid: true});
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].jsonPath = value;
}
this.numberIndicatorPaths.at(index).get('result').setValue(null);
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => {
this.indicator.indicatorPaths[index].source = value;
if (this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].source = value;
}
})
);
}
@ -547,7 +564,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.urlParameterizedMessage = "This chart couldn't be generated properly. Please make sure chart data is for the current stakeholder."
}
} else {
this.urlParameterizedMessage = "";
this.urlParameterizedMessage = null;
}
(this.chartIndicatorPaths.at(index) as FormGroup).get('type').setValue(indicatorPath.type);
let parameters = this.getParametersAsFormArray(indicatorPath);
@ -559,6 +576,8 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
indicatorPath.safeResourceUrl = this.indicator.indicatorPaths[index].safeResourceUrl;
this.indicator.indicatorPaths[index] = indicatorPath;
}
} else {
this.urlParameterizedMessage = null;
}
})
);
@ -599,7 +618,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
public editNumberIndicatorOpen(section: Section, id = null) {
this.urlParameterizedMessage = "";
this.urlParameterizedMessage = null;
this.section = section;
this.index = (id) ? section.indicators.findIndex(value => value._id === id) : -1;
if (this.index !== -1) {
@ -633,7 +652,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
this.addNumberIndicatorPath();
}
if(this.indicator.defaultId) {
if (this.indicator.defaultId) {
setTimeout(() => {
this.numberIndicatorFb.get('additionalDescription').disable();
}, 0);
@ -652,7 +671,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
public editChartIndicatorOpen(section: Section, id = null) {
this.urlParameterizedMessage = "";
this.urlParameterizedMessage = null;
this.urlSubscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
@ -691,7 +710,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
});
this.addChartIndicatorPath();
}
if(this.indicator.defaultId) {
if (this.indicator.defaultId) {
setTimeout(() => {
this.chartIndicatorFb.get('additionalDescription').disable();
}, 0);

View File

@ -561,7 +561,7 @@ export class IndicatorUtils {
return indicatorPath;
}
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
let indicatorPath = new IndicatorPath(type, source, "", "", []);
let indicatorPath = new IndicatorPath(type, source, null, null, []);
try {
if (source === 'stats-tool') {
indicatorPath.url = url.split("json=")[0] + "json=";

View File

@ -1,4 +1,4 @@
.refresh-iframe {
.refresh-indicator {
background-color: rgba(0, 0, 0, 0.50);
position: absolute;
}

View File

@ -235,7 +235,7 @@
left: 3px;
}
.refresh-iframe {
.refresh-indicator {
background-color: rgba(0, 0, 0, 0.50);
border-radius: 4px;
position: absolute;

View File

@ -17,7 +17,7 @@ export let properties: EnvProperties = {
framesAPIURL: "https://beta.openaire.eu/stats3/",
statisticsAPIURL: "https://beta.services.openaire.eu/stats-api/",
statisticsFrameAPIURL: "https://beta.openaire.eu/stats/",
statisticsFrameNewAPIURL: "https://beta.services.openaire.eu/stats-tool/",
statisticsFrameNewAPIURL: "https://stats.madgik.di.uoa.gr/stats-api/",
useNewStatistisTool: false,
claimsAPIURL: "http://scoobydoo.di.uoa.gr:8080/dnet-claims-service-2.0.0-SNAPSHOT/rest/claimsService/",
searchAPIURLLAst: "https://beta.services.openaire.eu/search/v2/api/",
@ -50,11 +50,15 @@ export let properties: EnvProperties = {
vocabulariesAPI: "https://dev-openaire.d4science.org/provision/mvc/vocabularies/",
piwikBaseUrl: "https://analytics.openaire.eu/piwik.php?idsite=",
piwikSiteId: "80",
registryUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/",
registryUrl: 'http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/',
loginUrl: "http://mpagasas.di.uoa.gr:8180/dnet-login/openid_connect_login",
userInfoUrl: "http://mpagasas.di.uoa.gr:8080/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
logoutUrl: 'http://mpagasas.di.uoa.gr:8180/dnet-login/openid_logout',
/*registryUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/",
loginUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-login/openid_connect_login",
userInfoUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/users/getUserInfo?accessToken=",
/*logoutUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-login/openid_logout",*/
logoutUrl: "https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",
/!*logoutUrl: "http://dl170.madgik.di.uoa.gr:8180/dnet-login/openid_logout",*!/
logoutUrl: "https://aai.openaire.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=",*/
cookieDomain: ".di.uoa.gr",
feedbackmail: "openaire.test@gmail.com",
cacheUrl: "http://scoobydoo.di.uoa.gr:3000/get?url=",