Skip to content

Commit

Permalink
Merge branch 'GT-2095-tool-group-tester' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Dec 8, 2023
2 parents 79b9b6d + b847e83 commit 49ba447
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
</div>

<div class="row mb-3" *ngIf="praxisType !== 'confidence' && !hideExclude">
<div class="row mb-3" *ngIf="praxisType !== 'confidence'">
<div class="col-12">
<div class="pl-4" style="position: relative">
<input
Expand Down
3 changes: 3 additions & 0 deletions src/app/components/tool-groups/tool-groups.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ <h5>Test Suggestions</h5>
[rule]="testerLanguageRule"
[ruleType]="'language'"
(selectedItemsEmit)="updateSelected($event, 'language', null)"
(negativeRuleOutput)="updateNegativeRule($event, 'language')"
[hideExclude]="true"
>
</admin-tool-group-rule-reuseable>
<admin-tool-group-rule-reuseable
[rule]="testerCountryRule"
[ruleType]="'country'"
(selectedItemsEmit)="updateSelected($event, 'country', null)"
(negativeRuleOutput)="updateNegativeRule($event, 'country')"
[hideExclude]="true"
[limitOneAnswer]="true"
>
Expand All @@ -55,6 +57,7 @@ <h5>Test Suggestions</h5>
[ruleType]="'praxis'"
[praxisType]="'openness'"
(selectedItemsEmit)="updateSelected($event, 'praxis', 'openness')"
(negativeRuleOutput)="updateNegativeRule($event, 'praxis')"
[limitOneAnswer]="true"
>
</admin-tool-group-rule-reuseable>
Expand Down
34 changes: 24 additions & 10 deletions src/app/components/tool-groups/tool-groups.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ export class ToolGroupsComponent implements OnInit {

this.toolGroupService
.getToolGroupSuggestions(
this.testerSelectedCountries,
this.testerSelectedLanguages,
this.testerSelectedPraxisConfidence,
this.testerSelectedPraxisOpenness,
this.testerCountryRule,
this.testerLanguageRule,
this.testerPraxisRule,
)
.then((data) => {
this.suggestedTools = data;
Expand All @@ -116,12 +115,13 @@ export class ToolGroupsComponent implements OnInit {
this.testerSelectedCountries = codes[0];
this.testerCountryRule.countries = [codes[0]];
break;
case RuleTypeEnum.LANGUAGE:
this.testerSelectedLanguages = codes;
break;
case RuleTypeEnum.PRAXIS:
switch (subType) {
case PraxisTypeEnum.CONFIDENCE:
case RuleTypeEnum.LANGUAGE:
this.testerSelectedLanguages = codes;
this.testerLanguageRule.languages = codes;
break;
case RuleTypeEnum.PRAXIS:
switch (subType) {
case PraxisTypeEnum.CONFIDENCE:
this.testerSelectedPraxisConfidence = codes[0];
this.testerPraxisRule.confidence = [codes[0]];
break;
Expand All @@ -134,6 +134,20 @@ export class ToolGroupsComponent implements OnInit {
}
}

updateNegativeRule(negativeRule: boolean, type: RuleType): void {
switch (type) {
case RuleTypeEnum.COUNTRY:
this.testerCountryRule['negative-rule'] = negativeRule;
break;
case RuleTypeEnum.LANGUAGE:
this.testerLanguageRule['negative-rule'] = negativeRule;
break;
case RuleTypeEnum.PRAXIS:
this.testerPraxisRule['negative-rule'] = negativeRule;
break;
}
}

protected handleError(message): void {
this.errorMessage = message;
}
Expand Down
20 changes: 15 additions & 5 deletions src/app/service/tool-group/tool-group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { JsonApiDataStore } from 'jsonapi-datastore';
import { AuthService } from '../auth/auth.service';
import { AbstractService } from '../abstract.service';
import { Resource } from '../../models/resource';
import { ToolGroup, RuleTypeEnum } from '../../models/tool-group';
import { ToolGroup, RuleTypeEnum, ToolGroupRule } from '../../models/tool-group';
import { environment } from '../../../environments/environment';

interface PraxisData {
Expand Down Expand Up @@ -281,14 +281,21 @@ export class ToolGroupService extends AbstractService {
}

getToolGroupSuggestions(
countries: string,
languages: string[],
confidence: string,
openness: string,
countryRule: ToolGroupRule,
languageRule: ToolGroupRule,
praxisRule: ToolGroupRule,
): Promise<Resource[]> {
let filter = '';
const languages = languageRule.languages;
const excludeLanguages = languageRule['negative-rule'] || '';
const countries = countryRule.countries;
const excludeCountries = countryRule['negative-rule'] || '';
const confidence = praxisRule.confidence;
const openness = praxisRule.openness;
const excludePraxis = praxisRule['negative-rule'] || '';

const createFilters = (items: string | string[], filterString) => {
if (!items) { return; }
if (Array.isArray(items)) {
const filters = items.reduce(
(result: string, currentItem: string) =>
Expand All @@ -305,6 +312,9 @@ export class ToolGroupService extends AbstractService {
createFilters(languages, 'filter[language][]');
createFilters(confidence, 'filter[confidence]');
createFilters(openness, 'filter[openness]');
createFilters(excludeLanguages.toString(), 'filter[language_negative_rule]');
createFilters(excludeCountries.toString(), 'filter[country_negative_rule]');
createFilters(excludePraxis.toString(), 'filter[praxis_negative_rule]');

// Remove last "&" from string.
filter = filter.slice(0, -1);
Expand Down

0 comments on commit 49ba447

Please sign in to comment.