Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Dec 12, 2023
1 parent 74dd02e commit b5d32a9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions projects/srm/src/app/result-card/result-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,19 @@ export class ResultCardComponent implements OnChanges {
}
}

const cardSituations = this.card.situations?.map((s) => Object.assign({}, s)) || [];
const cardResponses = this.card.responses?.map((r) => Object.assign({}, r)) || [];

this.selectedSituations = [];
this.card.situations?.forEach((s: TaxonomyItem) => {
cardSituations.forEach((s: TaxonomyItem) => {
if (this.searchParams?.allTaxonomyIds.includes(s.id || '')) {
s.__selected = true;
s.name = '<em>' + s.name + '</em>';
this.selectedSituations.push(s);
}
});
this.selectedResponses = [];
this.card.responses?.forEach((r: TaxonomyItem) => {
cardResponses.forEach((r: TaxonomyItem) => {
if (this.searchParams?.allTaxonomyIds.includes(r.id || '')) {
r.__selected = true;
r.name = '<em>' + r.name + '</em>';
Expand All @@ -90,7 +93,7 @@ export class ResultCardComponent implements OnChanges {
if (this.card?._highlights && this.card?._highlights['situations.name.hebrew']) {
const highlighted = this.card._highlights['situations.name.hebrew'];
if (highlighted.length === this.card?.situations?.length) {
this.card.situations.forEach((s, i) => {
cardSituations.forEach((s, i) => {
if (!s.__selected && highlighted[i]?.indexOf('<em>') >= 0) {
s.name = highlighted[i];
s.__selected = true;
Expand All @@ -102,7 +105,7 @@ export class ResultCardComponent implements OnChanges {
if (this.card?._highlights && this.card?._highlights['responses.name.hebrew']) {
const highlighted = this.card._highlights['responses.name.hebrew'];
if (highlighted.length === this.card?.responses?.length) {
this.card.responses.forEach((r, i) => {
cardResponses.forEach((r, i) => {
if (!r.__selected && highlighted[i]?.indexOf('<em>') >= 0) {
r.name = highlighted[i];
r.__selected = true;
Expand All @@ -111,19 +114,19 @@ export class ResultCardComponent implements OnChanges {
});
}
}
if (this.selectedSituations.length === 0 && this.card.situations?.length > 0) {
this.card.situations[0].__selected = true;
this.selectedSituations.push(this.card.situations[0]);
if (this.selectedSituations.length === 0 && cardSituations.length > 0) {
cardSituations[0].__selected = true;
this.selectedSituations.push(cardSituations[0]);
}
if (this.card.responses?.length > 0) {
this.card.responses.forEach((r) => {
if (cardResponses.length > 0) {
cardResponses.forEach((r) => {
r.category = r.id?.split(':')[1];
});
const requiredCategory = this.searchParams?.filter_response_categories?.length === 1 ?
this.searchParams.filter_response_categories[0].slice('human_services:'.length) :
this.card.response_category;
if ((this.selectedResponses.length > 0 && requiredCategory !== this.selectedResponses[0].category) || this.selectedResponses.length === 0) {
for (const r of this.card.responses) {
for (const r of cardResponses) {
if (r.category === requiredCategory) {
this.selectedResponses = [r, ...this.selectedResponses.filter((sr) => sr.id !== r.id)];
r.__selected = true;
Expand All @@ -135,7 +138,7 @@ export class ResultCardComponent implements OnChanges {

let deselectedCount = 0;
this.deselectedSituations = [];
this.card.situations?.forEach((s: TaxonomyItem) => {
cardSituations.forEach((s: TaxonomyItem) => {
if (!s.__selected && deselectedCount < 2) {
this.deselectedSituations.push({
id: s.id,
Expand All @@ -149,7 +152,7 @@ export class ResultCardComponent implements OnChanges {
deselectedCount = 0;
this.deselectedResponses = [];
let categories = this.selectedResponses.map((r) => r.category);
this.card.responses?.forEach((r: TaxonomyItem) => {
cardResponses.forEach((r: TaxonomyItem) => {
if (!r.__selected && deselectedCount < 2 && !categories.includes(r.category)) {
this.deselectedResponses.push({
id: r.id,
Expand All @@ -162,7 +165,7 @@ export class ResultCardComponent implements OnChanges {
}
});
if (deselectedCount < 2) {
this.card.responses?.forEach((r: TaxonomyItem) => {
cardResponses.forEach((r: TaxonomyItem) => {
if (!r.__selected && deselectedCount < 2) {
this.deselectedResponses.push({
id: r.id,
Expand Down

0 comments on commit b5d32a9

Please sign in to comment.