This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit dc604f06 authored by Daniel Crazzolara's avatar Daniel Crazzolara
Browse files

Fixed bug by adding/removing creators in form

parent 3cebcad4
2 merge requests!71Merge for September Release,!70Improvement/adapt import to new artemis export
......@@ -84,14 +84,14 @@
[value]="exerciseInfo.creator[i].affiliation" class="col text-center my-auto form-control"/>
<input type="text" name="creatorEmail{{i}}" [(ngModel)]="exerciseInfo.creator[i].email"
[value]="exerciseInfo.creator[i].email" class="col text-center my-auto form-control"/>
<div class="btn btn-outline-primary col-1" (click)="removePerson(creator, exerciseInfo.creator)">-</div>
<div class="btn btn-outline-primary col-1" (click)="removePerson(creator, 'creator')">-</div>
</div>
</div>
<div class="row mb-2">
<input type="text" class="col form-control" [(ngModel)]="newCreator.name" name="creatorName"/>
<input type="text" class="col form-control" [(ngModel)]="newCreator.affiliation" name="creatorAffiliation"/>
<input type="text" class="col form-control" [(ngModel)]="newCreator.email" name="creatorEmail"/>
<div class="btn btn-outline-primary col-1" (click)="addPerson(newCreator, exerciseInfo.creator)">+</div>
<div class="btn btn-outline-primary col-1" (click)="addPerson(newCreator, 'creator')">+</div>
</div>
<div *ngIf="!isPersonSet(exerciseInfo.creator)" class="alert alert-danger">
<span jhiTranslate="exercise.validation.required"></span>
......@@ -117,14 +117,14 @@
[value]="exerciseInfo.publisher[i].affiliation" class="col text-center my-auto form-control"/>
<input type="text" name="publisherEmail{{i}}" [(ngModel)]="exerciseInfo.publisher[i].email"
[value]="exerciseInfo.publisher[i].email" class="col text-center my-auto form-control"/>
<div class="btn btn-outline-primary col-1" (click)="removePerson(publisher, exerciseInfo.publisher)">-</div>
<div class="btn btn-outline-primary col-1" (click)="removePerson(publisher, 'publisher')">-</div>
</div>
</div>
<div class="row mb-2">
<input type="text" class="col form-control" [(ngModel)]="newPublisher.name" name="publisherName"/>
<input type="text" class="col form-control" [(ngModel)]="newPublisher.affiliation" name="publisherAffiliation"/>
<input type="text" class="col form-control" [(ngModel)]="newPublisher.email" name="publisherEmail"/>
<div class="btn btn-outline-primary col-1" (click)="addPerson(newPublisher, exerciseInfo.publisher)">+</div>
<div class="btn btn-outline-primary col-1" (click)="addPerson(newPublisher, 'publisher')">+</div>
</div>
<div *ngIf="!isPersonSet(exerciseInfo.publisher)" class="alert alert-danger">
<span jhiTranslate="exercise.validation.required"></span>
......
......@@ -123,8 +123,11 @@ export class ExerciseImportComponent implements OnInit {
if (
this.exerciseInfo?.keyword === undefined ||
this.exerciseInfo?.language === undefined ||
this.exerciseInfo.creator === undefined ||
!(this.exerciseInfo.keyword.length > 0) ||
!(this.exerciseInfo.language.length > 0)
!(this.exerciseInfo.language.length > 0) ||
!(this.exerciseInfo.creator.length > 0) ||
(!this.isPublisherSameAsCreator && (this.exerciseInfo.publisher === undefined || !(this.exerciseInfo.publisher.length > 0)))
) {
return true;
}
......@@ -155,14 +158,21 @@ export class ExerciseImportComponent implements OnInit {
/**
* Used to add a new person to a given list of persons
* @param person to add
* @param personList to add the given person to
* @param personList to add the given person to (ex. 'creators', 'publishers')
*/
addPerson(person: Person, personList: Person[]) {
if (this.validatePerson(person)) {
if (this.exerciseInfo && personList === undefined) {
personList = [];
addPerson(person: Person, personList: string) {
if (this.validatePerson(person) && this.exerciseInfo) {
if (!personList.localeCompare('creator')) {
if (this.exerciseInfo.creator == null) {
this.exerciseInfo.creator = [];
}
this.exerciseInfo.creator.push(JSON.parse(JSON.stringify(person)));
} else if (!personList.localeCompare('publisher')) {
if (this.exerciseInfo.publisher == null) {
this.exerciseInfo.publisher = [];
}
this.exerciseInfo.publisher.push(JSON.parse(JSON.stringify(person)));
}
personList.push(person);
// needed in order to modify person object by reference
person.name = '';
......@@ -174,10 +184,14 @@ export class ExerciseImportComponent implements OnInit {
/**
* Used to remove a person from a given list of persons
* @param personToRemove to remove
* @param personList to remove the given person from
* @param personList to remove the given person from (ex. 'creators', 'publishers')
*/
removePerson(personToRemove: Person, personList: Person[]) {
personList.filter(person => person !== personToRemove);
removePerson(personToRemove: Person, personList: string) {
if (!personList.localeCompare('creator')) {
this.exerciseInfo!.creator = this.exerciseInfo!.creator.filter(person => person !== personToRemove);
} else if (!personList.localeCompare('publisher')) {
this.exerciseInfo!.publisher = this.exerciseInfo!.publisher.filter(person => person !== personToRemove);
}
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment