Skip to content

Commit

Permalink
Merge pull request #7 from dhlab-basel/passage-fix
Browse files Browse the repository at this point in the history
Passage fix
  • Loading branch information
lrosenth authored Nov 25, 2021
2 parents 159c281 + 63dbb0c commit 9434033
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "0826-wordweb-app",
"version": "2.10.16",
"version": "2.10.17",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
40 changes: 24 additions & 16 deletions src/app/edit/edit-book/edit-book.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class BookIds {
<mat-label>Written by &rarr; (person) *</mat-label>
<div *ngFor="let writtenByItem of getWrittenBys().controls; let i=index">
<mat-form-field [formGroup]="writtenByItem">
<input matInput [matAutocomplete]="autoWrittenBy" required
<input matInput required
[matAutocomplete]="autoWrittenBy"
formControlName="writtenByName"
class="knora-link-input-element klnkie-val full-width"
placeholder="Written by (person)"
Expand Down Expand Up @@ -353,7 +354,7 @@ class BookIds {
<mat-label>Is Lexia &rarr; (lexia)</mat-label>
<div *ngFor="let lexiaItem of getLexias().controls; let i=index">
<mat-form-field [formGroup]="lexiaItem">
<input matInput [matAutocomplete]="autoLexia" required
<input matInput [matAutocomplete]="autoLexia"
formControlName="lexiaName"
class="knora-link-input-element klnkie-val full-width"
placeholder="Mentioned in (passage)"
Expand Down Expand Up @@ -392,7 +393,7 @@ class BookIds {
<mat-label>Performed by (company)</mat-label>
<div *ngFor="let performedByItem of getPerformedBys().controls; let i=index">
<mat-form-field [formGroup]="performedByItem">
<input matInput [matAutocomplete]="autoPerformedBy" required
<input matInput [matAutocomplete]="autoPerformedBy"
formControlName="performedByName"
class="knora-link-input-element klnkie-val full-width"
placeholder="Performed by &rarr; (company)"
Expand Down Expand Up @@ -431,7 +432,7 @@ class BookIds {
<mat-label>Performed by actor (person)</mat-label>
<div *ngFor="let performedByActorItem of getPerformedByActors().controls; let i=index">
<mat-form-field [formGroup]="performedByActorItem">
<input matInput [matAutocomplete]="autoPerformedByActor" required
<input matInput [matAutocomplete]="autoPerformedByActor"
formControlName="performedByActorName"
class="knora-link-input-element klnkie-val full-width"
placeholder="Performed by actor &rarr; (person)"
Expand Down Expand Up @@ -470,7 +471,7 @@ class BookIds {
<mat-label>Performed in (venue)</mat-label>
<div *ngFor="let performedInItem of getPerformedIns().controls; let i=index">
<mat-form-field [formGroup]="performedInItem">
<input matInput [matAutocomplete]="autoPerformedIn" required
<input matInput [matAutocomplete]="autoPerformedIn"
formControlName="performedInName"
class="knora-link-input-element klnkie-val full-width"
placeholder="Performed in &rarr; (venue)"
Expand Down Expand Up @@ -805,7 +806,7 @@ export class EditBookComponent implements OnInit {
this.valIds.writtenBy[0] = {id: '', changed: false, toBeDeleted: false};
wbInitial = [
this.fb.group({
writtenByIri: ['', [Validators.required]], writtenByName: [, []]
writtenByIri: ['', []], writtenByName: [, []]
})
];
} else {
Expand Down Expand Up @@ -905,7 +906,7 @@ export class EditBookComponent implements OnInit {
if (subject === undefined) {
subjects.push(this.fb.group({subjectIri: this.subjectTypes[0].iri}));
this.data.subjects.push({subjectIri: this.subjectTypes[0].iri});
this.valIds.subjects.push({id: undefined, changed: false, toBeDeleted: false});
this.valIds.subjects.push({id: undefined, changed: true, toBeDeleted: false});
} else {
subjects.push(this.fb.group({subjectIri: subject.iri}));
this.data.subjects.push({subjectIri: subject.iri});
Expand Down Expand Up @@ -1115,9 +1116,10 @@ export class EditBookComponent implements OnInit {
case 'performedIn':
const performedIn = this.getPerformedIns();
const performedInName = performedIn.value[index].performedInName;
console.log('performedIn', index, performedInName);

this.valIds.performedIn[index].changed = true;
if (performedInName >= 3) {
if (performedInName.length >= 3) {
this.knoraService.getResourcesByLabel(performedInName, this.knoraService.wwOntology + 'venue').subscribe(
res => {
this.options = res;
Expand Down Expand Up @@ -1420,18 +1422,23 @@ export class EditBookComponent implements OnInit {
this.working = true;
console.log('this.value:', this.value);
if (this.inData.bookIri === undefined) {
if (this.form.valid) {
if (this.form.valid
&& this.value.genres[0].genreIri
&& this.value.writtenBy[0].writtenByIri
&& !this.value.creationDate.isEmpty()) {
this.knoraService.createBook(this.value).subscribe(
res => {
console.log('CREATE_RESULT:', res);
this.working = false;
this.location.back();
if (res === 'error') {
this.snackBar.open('Error storing the book object!', 'OK', {duration: 10000});
} else {
this.location.back();
}
},
error => {
this.snackBar.open('Error storing the passage object!', 'OK');
console.log('EditCompany.save(): ERROR', error);
this.working = false;
this.location.back();
}
);
} else {
Expand Down Expand Up @@ -1520,9 +1527,7 @@ export class EditBookComponent implements OnInit {
this.knoraService.wwOntology + 'hasCreationDate',
creationDateValue);
} else {
console.log('**********> UPDATE KNORA started...');
const creationDateValue = this.form.controls.creationDate.value;
console.log('**********> UPDATE KNORA TO DATE:', creationDateValue);
gaga = this.knoraService.updateDateValue(
this.resId,
this.knoraService.wwOntology + 'book',
Expand Down Expand Up @@ -1962,7 +1967,7 @@ export class EditBookComponent implements OnInit {
this.location.back();
},
error => {
this.snackBar.open('Fehler beim Speichern der Daten des book-Eintrags!', 'OK');
this.snackBar.open('Fehler beim Speichern der Daten des book-Eintrags!', 'OK', {duration: 10000});
this.working = false;
this.location.back();
});
Expand All @@ -1986,10 +1991,13 @@ export class EditBookComponent implements OnInit {
this.knoraService.deleteResource(this.resId, 'book', this.lastmod, data.comment).subscribe(
res => {
this.working = false;
if (res === 'error') {
this.snackBar.open('Error while deleting the book entry!', 'OK', {duration: 10000});
}
this.location.back();
},
error => {
this.snackBar.open('Error while deleting the book entry!', 'OK');
this.snackBar.open('Error while deleting the book entry!', 'OK', {duration: 10000});
console.log('deleteResource:ERROR:: ', error);
this.working = false;
this.location.back();
Expand Down
15 changes: 11 additions & 4 deletions src/app/edit/edit-company/edit-company.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,14 @@ export class EditCompanyComponent implements OnInit {
res => {
console.log('CREATE_RESULT:', res);
this.working = false;
this.location.back();
if (res === 'error') {
this.snackBar.open('Error storing the company object!', 'OK', {duration: 10000});
} else {
this.location.back();
}
},
error => {
this.snackBar.open('Error storing the company object!', 'OK');
this.snackBar.open('Error storing the company object!', 'OK', {duration: 10000});
console.log('EditCompany.save(): ERROR', error);
this.working = false;
this.location.back();
Expand Down Expand Up @@ -717,7 +721,7 @@ export class EditCompanyComponent implements OnInit {
this.location.back();
},
error => {
this.snackBar.open('Fehler beim Speichern der Daten des company-Eintrags!', 'OK');
this.snackBar.open('Fehler beim Speichern der Daten des company-Eintrags!', 'OK', {duration: 10000});
this.working = false;
this.location.back();
});
Expand All @@ -742,10 +746,13 @@ export class EditCompanyComponent implements OnInit {
this.knoraService.deleteResource(this.resId, 'company', this.lastmod, data.comment).subscribe(
res => {
this.working = false;
if (res === 'error') {
this.snackBar.open('Error while deleting the company entry!', 'OK', {duration: 10000});
}
this.location.back();
},
error => {
this.snackBar.open('Error while deleting the company entry!', 'OK');
this.snackBar.open('Error while deleting the company entry!', 'OK', {duration: 10000});
console.log('deleteResource:ERROR:: ', error);
this.working = false;
this.location.back();
Expand Down
12 changes: 8 additions & 4 deletions src/app/edit/edit-lexia/edit-lexia.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {MatSnackBar} from '@angular/material/snack-bar';
import {Location} from '@angular/common';
import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
import {ConfirmationComponent, ConfirmationResult} from '../confirmation/confirmation.component';
import {toArray} from "rxjs/operators";
import {toArray} from 'rxjs/operators';


interface ValInfo {
Expand Down Expand Up @@ -376,7 +376,7 @@ export class EditLexiaComponent implements OnInit {
if (formalClassIri === undefined) {
formalClasses.push(this.fb.group({formalClassIri: this.formalClassTypes[0].iri}));
this.data.formalClassIris.push(this.formalClassTypes[0].iri);
this.valIds.formalClasses.push({id: undefined, changed: false, toBeDeleted: false});
this.valIds.formalClasses.push({id: undefined, changed: true, toBeDeleted: false});
} else {
formalClasses.push(this.fb.group({formalClassIri}));
this.data.formalClassIris.push(formalClassIri);
Expand Down Expand Up @@ -526,12 +526,16 @@ export class EditLexiaComponent implements OnInit {
save(): void {
this.working = true;
if (this.inData.lexiaIri === undefined) {
if (this.form.valid) {
if (this.form.valid && this.value.formalClassIris[0]) {
this.knoraService.createLexia(this.value).subscribe(
res => {
console.log('CREATE_RESULT:', res);
this.working = false;
this.location.back();
if (res === 'error') {
this.snackBar.open('Error storing the lexia object!', 'OK');
} else {
this.location.back();
}
},
error => {
this.snackBar.open('Error storing the lexia object!', 'OK');
Expand Down
42 changes: 28 additions & 14 deletions src/app/edit/edit-passage/edit-passage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class PassageIds {
<mat-label>Function voices *</mat-label>
<div *ngFor="let functionVoiceItem of getFunctionVoices().controls; let i=index">
<mat-form-field [formGroup]="functionVoiceItem" [style.width.px]=300>
<mat-select matInput
<mat-select matInput required
placeholder="functionVoices"
formControlName="functionVoiceIri"
(selectionChange)="_handleInput('functionVoices', i)">
Expand Down Expand Up @@ -165,7 +165,7 @@ class PassageIds {
<mat-label>Markings *</mat-label>
<div *ngFor="let markingItem of getMarkings().controls; let i=index">
<mat-form-field [formGroup]="markingItem" [style.width.px]=300>
<mat-select matInput
<mat-select matInput required
placeholder="marking"
formControlName="markingIri"
(selectionChange)="_handleInput('markings', i)">
Expand Down Expand Up @@ -597,6 +597,7 @@ export class EditPassageComponent implements OnInit {
[{containsName: '', containsIri: ''}], '',
'', '', '', '', '', '',
[{mentionedInName: '', mentionedInIri: ''}]);

this.form.setValue({label, internalId, displayedTitle, functionVoices, markings, researchField,
status, text, occursInName: occursIn.occursInName, occursInIri: occursIn.occursInIri,
contributedByName: contributedBy.contributedByName, contributedByIri: contributedBy.contributedByIri,
Expand Down Expand Up @@ -800,7 +801,7 @@ export class EditPassageComponent implements OnInit {
if (functionVoice === undefined) {
functionVoices.push(this.fb.group({functionVoiceIri: this.functionVoiceTypes[0].iri}));
this.data.functionVoices.push({functionVoiceIri: this.functionVoiceTypes[0].iri});
this.valIds.functionVoices.push({id: undefined, changed: false, toBeDeleted: false});
this.valIds.functionVoices.push({id: undefined, changed: true, toBeDeleted: false});
} else {
functionVoices.push(this.fb.group({functionVoiceIri: functionVoice.iri}));
this.data.functionVoices.push({functionVoiceIri: functionVoice.iri});
Expand All @@ -826,7 +827,7 @@ export class EditPassageComponent implements OnInit {
if (marking === undefined) {
markings.push(this.fb.group({markingIri: this.markingTypes[0].iri}));
this.data.markings.push({markingIri: this.markingTypes[0].iri});
this.valIds.markings.push({id: undefined, changed: false, toBeDeleted: false});
this.valIds.markings.push({id: undefined, changed: true, toBeDeleted: false});
} else {
markings.push(this.fb.group({markingIri: marking.iri}));
this.data.markings.push({markingIri: marking.iri});
Expand Down Expand Up @@ -949,9 +950,10 @@ export class EditPassageComponent implements OnInit {
case 'mentionedIn':
const mentionedIn = this.getMentionedIn();
const mentionedInName = mentionedIn.value[index].mentionedInName;
console.log('mentionedIn', mentionedInName);

this.valIds.mentionedIn[index].changed = true;
if (mentionedIn.length >= 3) {
if (mentionedInName.length >= 3) {
this.knoraService.getResourcesByLabel(mentionedInName, this.knoraService.wwOntology + 'passage').subscribe(
res => {
this.options = res;
Expand All @@ -971,19 +973,21 @@ export class EditPassageComponent implements OnInit {
}
switch(what) {
case 'occursIn':
this.form.controls.occursInIri.setValue(res[0].id); // must be for unknown reasons
this.form.value.occursInName = res[0].label;
this.form.value.occursInIri = res[0].id;
this.value.occursIn = {
occursInName: this.form.value.occursInName,
occursInIri: this.form.value.occursInIri
occursInName: res[0].label,
occursInIri: res[0].id
};
break;
case 'contributedBy':
this.form.controls.contributedByIri.setValue(res[0].id); // must be for unknown reasons
this.form.value.contributedByName = res[0].label;
this.form.value.contributedByIri = res[0].id;
this.value.contributedBy = {
contributedByName: this.form.value.contributedByName,
contributedByIri: this.form.value.contributedByIri
contributedByName: res[0].label,
contributedByIri: res[0].id
};
break;
case 'contains':
Expand All @@ -1001,6 +1005,7 @@ export class EditPassageComponent implements OnInit {
}

_handleInput(what: string, index?: number): void {
console.log('_handleInput');
this.onChange(this.form.value);
switch (what) {
case 'label':
Expand Down Expand Up @@ -1224,22 +1229,28 @@ export class EditPassageComponent implements OnInit {

save(): void {
this.working = true;
console.log('this.value:', this.value);
if (this.inData.passageIri === undefined) {
if (this.form.valid) {
if (this.form.valid && this.value.occursIn.occursInIri && this.value.contributedBy.contributedByIri) {
this.knoraService.createPassage(this.value).subscribe(
res => {
console.log('CREATE_RESULT:', res);
this.working = false;
this.location.back();
if (res === 'error') {
this.snackBar.open('Error storing the passage object!', 'OK', {duration: 10000});
} else {
this.location.back();
}
},
error => {
this.snackBar.open('Error storing the passage object!', 'OK');
this.snackBar.open('Error storing the passage object!', 'OK', {duration: 10000});
console.log('EditCompany.save(): ERROR', error);
this.working = false;
this.location.back();
}
);
} else {
console.log('Incomplete:', this.value);
this.snackBar.open('Invalid/incomplete data in form – Please check!',
'OK',
{duration: 10000});
Expand Down Expand Up @@ -1746,7 +1757,7 @@ export class EditPassageComponent implements OnInit {
this.location.back();
},
error => {
this.snackBar.open('Fehler beim Speichern der Daten des company-Eintrags!', 'OK');
this.snackBar.open('Fehler beim Speichern der Daten des company-Eintrags!', 'OK', {duration: 10000});
this.working = false;
this.location.back();
});
Expand All @@ -1772,10 +1783,13 @@ export class EditPassageComponent implements OnInit {
this.knoraService.deleteResource(this.resId, 'passage', this.lastmod, data.comment).subscribe(
res => {
this.working = false;
if (res === 'error') {
this.snackBar.open('Error while deleting the passage entry!', 'OK', {duration: 10000});
}
this.location.back();
},
error => {
this.snackBar.open('Error while deleting the passage entry!', 'OK');
this.snackBar.open('Error while deleting the passage entry!', 'OK', {duration: 10000});
console.log('deleteResource:ERROR:: ', error);
this.working = false;
this.location.back();
Expand Down
Loading

0 comments on commit 9434033

Please sign in to comment.