[Monitor Dashboard | Trunk]: Add alias error. Fix number indicator form validation

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@59775 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Konstantinos Triantafyllou 2020-11-04 23:11:00 +00:00
parent 5f6c0884b5
commit f6319eac64
6 changed files with 111 additions and 81 deletions

View File

@ -20,7 +20,7 @@ declare var UIkit;
[class.uk-padding-small]="!paddingLarge" [class.uk-padding-large]="paddingLarge"
class="uk-overflow-auto"
[formGroup]="stakeholderFb">
<div class="uk-flex uk-flex-bottom" uk-grid>
<div class="uk-grid" uk-grid uk-height-match=".uk-form-hint">
<div dashboard-input class="uk-width-1-2@m" [formInput]="stakeholderFb.get('name')" label="Name"
placeholder="Write a name..."
hint="Set a name for your profile."></div>

View File

@ -295,13 +295,22 @@
</div>
</div>
</div>
<div>
<div class="uk-flex uk-flex-middle">
<button
class="uk-button uk-button-secondary uk-button-small uk-flex uk-flex-middle uk-margin-medium-top"
class="uk-icon-button uk-button-secondary uk-margin-medium-top"
(click)="addJsonPath(i)">
<icon name="add" [flex]="true"></icon>
<span class="space">Add level</span>
<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>

View File

@ -96,6 +96,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
public indicatorChildrenActionOnDelete: string;
urlParameterizedMessage = "";
constructor(private layoutService: LayoutService,
private stakeholderService: StakeholderService,
private statisticsService: StatisticsService,
@ -330,7 +331,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
private filterStatus(sections: Section[], value): Section[] {
if (value !== 'all') {
sections.forEach(section =>
@ -420,13 +420,41 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
public removeJsonPath(i: number, j: number) {
this.getJsonPath(i).removeAt(j);
if (this.getJsonPath(i).length !== this.getCurrentJsonPath(i).length) {
this.getJsonPath(i).markAsDirty();
}
}
public validateJsonPath(index: number) {
let indicatorPath: FormGroup = <FormGroup>this.numberIndicatorPaths.at(index);
this.getJsonPath(index).disable();
this.statisticsService.getNumbers(null, indicatorPath.get('url').value).subscribe(response => {
let result = JSON.parse(JSON.stringify(response));
this.getJsonPath(index).controls.forEach(jsonPath => {
if (result) {
result = result[jsonPath.value];
}
});
setTimeout( () => {
if (typeof result == 'string') {
this.getJsonPath(index).enable();
this.getJsonPath(index).setErrors(null);
} else {
this.getJsonPath(index).enable();
this.getJsonPath(index).setErrors({invalid: true});
}
}, 1000);
});
}
public getJsonPath(index: number): FormArray {
return this.numberIndicatorPaths.at(index).get('jsonPath') as FormArray;
}
public getCurrentJsonPath(index: number): string[] {
return this.section.indicators[this.index].indicatorPaths[index].jsonPath;
}
public getParameters(index: number): FormArray {
return this.chartIndicatorPaths.at(index).get('parameters') as FormArray;
}
@ -474,31 +502,19 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
/* if(value != indicatorPath.url) {
(this.numberIndicatorPaths.at(index) as FormGroup).get('url').setValue( indicatorPath.url);
}*/
if (!this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
} else {
this.indicator.indicatorPaths[index] = indicatorPath;
}
(this.numberIndicatorPaths.at(index) as FormGroup).get('source').setValue(indicatorPath.source);
}
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
if (!this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].jsonPath = value;
} else {
this.indicator.indicatorPaths[index].jsonPath = value;
}
//this.getJsonPath(index).setErrors({invalid: true});
})
);
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => {
if (!this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index].source = value;
} else {
this.indicator.indicatorPaths[index].source = value;
}
})
);
}
@ -692,8 +708,6 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, false);
this.section = this.numbers.find(section => section._id === this.section._id);
}
console.debug("Indicator to svae");
console.debug(this.indicator);
let path = [
this.stakeholder._id,
this.stakeholder.topics[this.topicIndex]._id,

View File

@ -24,15 +24,16 @@ import {
group,
refresh,
close,
arrow_right
arrow_right, done
} from "../openaireLibrary/utils/icons/icons";
import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {PageContentModule} from "../openaireLibrary/dashboard/sharedComponents/page-content/page-content.module";
import {LoadingModule} from "../openaireLibrary/utils/loading/loading.module";
@NgModule({
imports: [
CommonModule, TopicRoutingModule, ClickModule, RouterModule, FormsModule, AlertModalModule,
ReactiveFormsModule, InputModule, IconsModule, PageContentModule
ReactiveFormsModule, InputModule, IconsModule, PageContentModule, LoadingModule
],
declarations: [
TopicComponent, IndicatorsComponent
@ -47,6 +48,6 @@ import {PageContentModule} from "../openaireLibrary/dashboard/sharedComponents/p
})
export class TopicModule {
constructor(private iconsService: IconsService) {
this.iconsService.registerIcons([preview, bullet, add, earth, lock, group, refresh, close, arrow_right]);
this.iconsService.registerIcons([preview, bullet, add, earth, lock, group, refresh, close, arrow_right, done]);
}
}

View File

@ -137,11 +137,11 @@ export class StakeholderUtils {
}
aliasValidator(elements: any[]): ValidatorFn {
return (control: AbstractControl): { [key: string]: boolean } | null => {
return (control: AbstractControl): { [key: string]: string } | null => {
if (control.value && elements.find(element =>
element.alias === control.value
)) {
return {'alias': true};
return {'error': 'Alias already in use'};
}
return null;
}

View File

@ -3,6 +3,7 @@ import {HttpClient} from "@angular/common/http";
import {EnvironmentSpecificService} from "../../openaireLibrary/utils/properties/environment-specific.service";
import {Observable} from "rxjs";
import {SourceType} from "../../openaireLibrary/monitor/entities/stakeholder";
import {el} from "@angular/platform-browser/testing/src/browser_util";
@Injectable({
@ -35,8 +36,13 @@ export class StatisticsService {
});
return sourceType;
}
getNumbers(source: SourceType, url: string): Observable<any> {
if(source !== null) {
return this.http.get<any>(this.numberSources.get(source)[0] + url);
} else {
return this.http.get<any>(url);
}
}
getChartUrl(source: SourceType, url: string): string {