Skip to content

Commit

Permalink
Adaptation to performedByActor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijeinath committed Dec 3, 2020
1 parent 5800755 commit 9cd5582
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 59 deletions.
11 changes: 6 additions & 5 deletions src/app/search/advanced-search/advanced-search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@
<!-- <td>-->
<!-- <mat-form-field>-->
<!-- <mat-label>First performance: Actor</mat-label>-->
<!-- <input matInput formControlName="performedActor" (keydown.escape)="clear('performedActor')">-->
<!-- <button *ngIf="form.get('performedActor').value" type="button" mat-button matSuffix-->
<!-- mat-icon-button aria-label="Clear" (click)="clear('performedActor')">-->
<!-- <mat-icon>close</mat-icon>-->
<!-- </button>-->
<!-- <mat-select formControlName="performedActor">-->
<!-- <mat-option value="">-</mat-option>-->
<!-- <mat-option *ngFor="let actor of actors" [value]="actor.id">-->
<!-- <span *ngIf="actor.hasFirstName">{{actor.hasFirstName}}</span> {{actor.hasLastName}}-->
<!-- </mat-option>-->
<!-- </mat-select>-->
<!-- </mat-form-field>-->
<!-- </td>-->
<!-- <td class="min">-->
Expand Down
81 changes: 57 additions & 24 deletions src/app/search/advanced-search/advanced-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ export class AdvancedSearchComponent implements OnInit {
}
]
}
},
{
name: "performedByActor",
priority: 1,
res: {
name: "person",
props: [
{
name: "hasFirstName",
priority: 1,
mandatory: true,
res: null
},
{
name: "hasLastName",
priority: 1,
res: null
}
]
}
}
]
}
Expand Down Expand Up @@ -347,6 +367,7 @@ export class AdvancedSearchComponent implements OnInit {
createdDateRef: IDisplayedProperty;
performedCompanyRef: IDisplayedProperty;
performedVenueRef: IDisplayedProperty;
performedActorRef: IDisplayedProperty;

genders: any[];
genres: any[];
Expand All @@ -369,9 +390,9 @@ export class AdvancedSearchComponent implements OnInit {
}

ngOnInit() {
// this.prepareActors();
this.prepareVenues();
this.prepareCompanies();
this.prepareVenues();
this.prepareActors();

const genresNode = this.listService.getList("genre").nodes;
this.genres = genresNode.reduce((acc, list) => this.treeTableService.flattenTree(acc, list), []);
Expand Down Expand Up @@ -400,6 +421,7 @@ export class AdvancedSearchComponent implements OnInit {
this.createdDateRef = this.myPassage.props[12].res.props[7];
this.performedCompanyRef = this.myPassage.props[12].res.props[12];
this.performedVenueRef = this.myPassage.props[12].res.props[13];
this.performedActorRef = this.myPassage.props[12].res.props[14];

this.form = new FormGroup({
text: new FormControl("", []),
Expand All @@ -419,35 +441,33 @@ export class AdvancedSearchComponent implements OnInit {
});
}

prepareActors() {
this.knoraService.getActorsCount()
prepareCompanies() {
this.knoraService.getCompaniesCount()
.subscribe(amount => {
const maxOffset = Math.ceil(amount / 25);

const requests = [];

for (let offset = 0; offset < maxOffset; offset++) {
requests.push(this.knoraService.getActors(offset));
requests.push(this.knoraService.getCompanies(offset));
}

forkJoin<any>(...requests)
.subscribe((res: Array<Array<any>>) => {
this.actors = []
this.companies = []
.concat(...res)
.map(actor => {
if (actor.hasLastName.length === 1) {
actor.hasLastName = actor.hasLastName[0].value;
}
if (actor.hasFirstName.length === 1) {
actor.hasFirstName = actor.hasFirstName[0].value;
.map(company => {
if (company.hasCompanyTitle.length === 1) {
company.hasCompanyTitle = company.hasCompanyTitle[0].value;
return company;
}
return actor;
})
.sort((res1, res2) => this.sortActors(res1, res2));
.sort((res1, res2) => this.sortCompanies(res1, res2));
}, error => {
requests.map(a => a.unsubscribe());
});
});

}

prepareVenues() {
Expand Down Expand Up @@ -479,33 +499,36 @@ export class AdvancedSearchComponent implements OnInit {
});
}

prepareCompanies() {
this.knoraService.getCompaniesCount()
prepareActors() {
this.knoraService.getActorsCount()
.subscribe(amount => {
const maxOffset = Math.ceil(amount / 25);

const requests = [];

for (let offset = 0; offset < maxOffset; offset++) {
requests.push(this.knoraService.getCompanies(offset));
requests.push(this.knoraService.getActors(offset));
}

forkJoin<any>(...requests)
.subscribe((res: Array<Array<any>>) => {
this.companies = []
this.actors = []
.concat(...res)
.map(company => {
if (company.hasCompanyTitle.length === 1) {
company.hasCompanyTitle = company.hasCompanyTitle[0].value;
return company;
.map(actor => {
if (actor.hasLastName.length === 1) {
actor.hasLastName = actor.hasLastName[0].value;
}
if (actor.hasFirstName.length === 1) {
actor.hasFirstName = actor.hasFirstName[0].value;
}
return actor;
})
.sort((res1, res2) => this.sortCompanies(res1, res2));
.sort((res1, res2) => this.sortActors(res1, res2));
console.log(this.actors);
}, error => {
requests.map(a => a.unsubscribe());
});
});

}

search() {
Expand All @@ -520,6 +543,7 @@ export class AdvancedSearchComponent implements OnInit {
&& !this.form.get("createdDate").value
&& !this.form.get("performedCompany").value
&& !this.form.get("performedVenue").value
// && !this.form.get("performedActor").value
&& (!this.form.get("plays").value && !this.form.get("genre").value)) {

const dialogConfig = new MatDialogConfig();
Expand Down Expand Up @@ -624,6 +648,14 @@ export class AdvancedSearchComponent implements OnInit {
this.performedVenueRef.priority = 1;
}

// if (this.form.get("performedActor").value) {
// this.performedActorRef.searchVal1 = this.form.get("performedActor").value;
// this.performedActorRef.priority = 0;
// } else {
// this.performedActorRef.searchVal1 = null;
// this.performedActorRef.priority = 1;
// }

if (this.form.get("plays").value) {
// Only plays means if genre is "Drama (Theatre)"
this.genreRef.searchVal1 = this.listService.getIdOfNode("ALL DRAMA");
Expand Down Expand Up @@ -712,6 +744,7 @@ export class AdvancedSearchComponent implements OnInit {
this.form.get("createdDate").reset("");
this.form.get("performedCompany").reset("");
this.form.get("performedVenue").reset("");
// this.form.get("performedActor").reset("");
this.form.get("plays").setValue(false);
}

Expand Down
61 changes: 42 additions & 19 deletions src/app/search/results/pipe/comments.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,30 @@ export class CommentsPipe implements PipeTransform {
const firstPerDate = book.hasFirstPerformanceDate ? (book.hasFirstPerformanceDate[0].start === book.hasFirstPerformanceDate[0].end ? `in ${book.hasFirstPerformanceDate[0].start}` : `between ${book.hasFirstPerformanceDate[0].start} and ${book.hasFirstPerformanceDate[0].end}`) : null;
const firstPrintDate = book.hasPublicationDate ? (book.hasPublicationDate[0].start === book.hasPublicationDate[0].end ? `in ${book.hasPublicationDate[0].start}` : `between ${book.hasPublicationDate[0].start} and ${book.hasPublicationDate[0].end}`) : null;
const perByCom = book.performedBy ? (book.performedBy.length === 2 ? `${book.performedBy[0].hasCompanyTitle[0].value} or ${book.performedBy[1].hasCompanyTitle[0].value}` : `${book.performedBy[0].hasCompanyTitle[0].value}`) : null;
const personPerIn = null;
let perByActors = null;
if (book.performedByActor) {
const actors = book.performedByActor
.map(author => (author.hasFirstName && author.hasFirstName[0].value !== "_") ? {firstName: author.hasFirstName[0].value, lastName: author.hasLastName[0].value} :
{lastName: author.hasLastName[0].value}
)
.sort((author1, author2) => author1.lastName < author2.lastName ? -1 : (author1.lastName > author2.lastName ? 1 : 0)
)
.map((author) =>
// Capitalize first name before string concatenation
author.firstName ? `${author.firstName.charAt(0).toUpperCase() + author.firstName.slice(1)} ${author.lastName}` : `${author.lastName.charAt(0).toUpperCase() + author.lastName.slice(1)}`
);

const numActors = actors.length;
const lastAuthor = actors[actors.length - 1];
// Concatenates last two authors with "and". Ignores if there is only one author.
if (numActors > 1) {
const secondLast = actors[numActors - 2];
actors.splice(numActors - 2, 2, `${secondLast} and ${lastAuthor}`);
}

perByActors = actors
.join(", ");
}
let perInVen = null;
if (book.performedIn) {
if (book.performedIn.length === 2) {
Expand All @@ -40,44 +63,44 @@ export class CommentsPipe implements PipeTransform {
const firstPerDateCode = firstPerDate ? "1" : "0";
const firstPrintDateCode = firstPrintDate ? "1" : "0";
const perByComCode = perByCom ? "1" : "0";
const personPerInCode = personPerIn ? "1" : "0";
const perByActorsCode = perByActors ? "1" : "0";
const perInVenCode = perInVen ? "1" : "0";

const fullCode = `${firstPrintDateCode}${perInVenCode}${personPerInCode}${perByComCode}${firstPerDateCode}${genreCode}`;
const fullCode = `${firstPrintDateCode}${perInVenCode}${perByActorsCode}${perByComCode}${firstPerDateCode}${genreCode}`;

const codeObject = {
"000001": ``,
"000011": `This ${genre} was first performed ${firstPerDate}.`,
"000101": `This ${genre} was first performed by ${perByCom}.`,
"000111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}.`,
"001001": `The cast of the first performance of this ${genre} included ${personPerIn}.`,
"001011": `This ${genre} was first performed ${firstPerDate}. The cast included ${personPerIn}.`,
"001101": `This ${genre} was first performed by ${perByCom}. The cast included ${personPerIn}.`,
"001111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${personPerIn}.`,
"001001": `The cast of the first performance of this ${genre} included ${perByActors}.`,
"001011": `This ${genre} was first performed ${firstPerDate}. The cast included ${perByActors}.`,
"001101": `This ${genre} was first performed by ${perByCom}. The cast included ${perByActors}.`,
"001111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${perByActors}.`,
"010001": `This ${genre} was first performed at ${perInVen}.`,
"010011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}.`,
"010101": `This ${genre} was first performed by ${perByCom} at ${perInVen}.`,
"010111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}.`,
"011001": `This ${genre} was first performed at ${perInVen}. The cast included ${personPerIn}.`,
"011011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}.`,
"011101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${personPerIn}.`,
"011111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}.`,
"011001": `This ${genre} was first performed at ${perInVen}. The cast included ${perByActors}.`,
"011011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${perByActors}.`,
"011101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${perByActors}.`,
"011111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${perByActors}.`,
"100001": `This ${genre} was first printed ${firstPrintDate}`,
"100011": `This ${genre} was first performed ${firstPerDate}. The text was first printed ${firstPrintDate}.`,
"100101": `This ${genre} was first performed by ${perByCom}. The text was first printed ${firstPrintDate}.`,
"100111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The text was first printed ${firstPrintDate}.`,
"101001": `The cast of the first performance of this ${genre} included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"101011": `This ${genre} was first performed ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"101101": `This ${genre} was first performed by ${perByCom}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"101111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"101001": `The cast of the first performance of this ${genre} included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"101011": `This ${genre} was first performed ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"101101": `This ${genre} was first performed by ${perByCom}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"101111": `This ${genre} was first performed by ${perByCom} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"110001": `This ${genre} was first performed at ${perInVen}. The text was first printed ${firstPrintDate}.`,
"110011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The text was first printed ${firstPrintDate}.`,
"110101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The text was first printed ${firstPrintDate}.`,
"110111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The text was first printed ${firstPrintDate}.`,
"111001": `This ${genre} was first performed at ${perInVen}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"111011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"111101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`,
"111111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${personPerIn}. The text was first printed ${firstPrintDate}.`
"111001": `This ${genre} was first performed at ${perInVen}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"111011": `This ${genre} was first performed at ${perInVen} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"111101": `This ${genre} was first performed by ${perByCom} at ${perInVen}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`,
"111111": `This ${genre} was first performed by ${perByCom} at ${perInVen} ${firstPerDate}. The cast included ${perByActors}. The text was first printed ${firstPrintDate}.`
};

return codeObject[fullCode] ? codeObject[fullCode] : "";
Expand Down
15 changes: 15 additions & 0 deletions src/app/search/results/results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,21 @@ export class ResultsComponent implements OnInit {
}
return book;
}),
// Checks if book has performedByActors and requests the actors (=persons)
mergeMap((book: any) => {
if (book.performedByActor) {
return forkJoin([of(book), from(book.performedByActor)
.pipe(mergeMap((actor: any) => this.knoraService.getPassageRes(actor.id)), toArray())]);
} else {
return forkJoin([of(book), of("empty")]);
}
}),
map(([book, actors]) => {
if (actors !== "empty") {
book.performedByActor = actors;
}
return book;
}),
// Requests the authors of the book
mergeMap((book: any) => forkJoin([of(book), from(book.isWrittenBy)
.pipe(
Expand Down
Loading

0 comments on commit 9cd5582

Please sign in to comment.