Skip to content

Commit

Permalink
avniproject/avni-webapp#1203 - methods to support standard report car…
Browse files Browse the repository at this point in the history
…d types
  • Loading branch information
petmongrels committed May 20, 2024
1 parent 201b9e6 commit 637ee4b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/ReportCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class ReportCard extends BaseEntity {
isStandardReportType() {
return !_.isNil(this.standardReportCardType);
}

isSubjectTypeFilterSupported() {
return this.isStandardReportType() && this.standardReportCardType.isSubjectTypeFilterSupported();
}
}

export default ReportCard;
17 changes: 4 additions & 13 deletions src/StandardReportCardType.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ class StandardReportCardType extends BaseEntity {
DueChecklist: "Due checklist",
};

static subjectTypeFilterSupported = {
[StandardReportCardType.type.ScheduledVisits]: true,
[StandardReportCardType.type.OverdueVisits]: true,
[StandardReportCardType.type.LatestRegistrations]: false,
[StandardReportCardType.type.LatestEnrolments]: false,
[StandardReportCardType.type.LatestVisits]: false,
[StandardReportCardType.type.Total]: false,
[StandardReportCardType.type.Comments]: false,
[StandardReportCardType.type.CallTasks]: false,
[StandardReportCardType.type.OpenSubjectTasks]: false,
[StandardReportCardType.type.DueChecklist]: false
};

get iconName() {
const typeIcon = {
[StandardReportCardType.type.Approved]: 'check-circle',
Expand Down Expand Up @@ -142,6 +129,10 @@ class StandardReportCardType extends BaseEntity {
getApprovalStatusForType() {
return typeToStatusMap[this.name];
}

isSubjectTypeFilterSupported() {
return [StandardReportCardType.type.ScheduledVisits, StandardReportCardType.type.OverdueVisits].includes(this.name);
}
}

const typeToStatusMap = {
Expand Down
12 changes: 12 additions & 0 deletions test/ReportCardTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ReportCardFactory from "./ref/ReportCardFactory";
import StandardReportCardTypeFactory from "./ref/StandardReportCardTypeFactory";
import StandardReportCardType from "../src/StandardReportCardType";
import {assert} from 'chai';

it('is subject type filter supported', function () {
const approvedType = StandardReportCardTypeFactory.create({name: StandardReportCardType.type.Approved});
const reportCard = ReportCardFactory.create({standardReportCardType: approvedType});
assert.equal(reportCard.isSubjectTypeFilterSupported(), false);
reportCard.standardReportCardType = StandardReportCardTypeFactory.create({name: StandardReportCardType.type.ScheduledVisits});
assert.equal(reportCard.isSubjectTypeFilterSupported(), true);
});
12 changes: 12 additions & 0 deletions test/ref/ReportCardFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import _ from "lodash";
import {ReportCard} from "../../src";

class ReportCardFactory {
static create({standardReportCardType}) {
const reportCard = new ReportCard();
reportCard.standardReportCardType = standardReportCardType;
return reportCard;
}
}

export default ReportCardFactory;
11 changes: 11 additions & 0 deletions test/ref/StandardReportCardTypeFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import StandardReportCardType from "../../src/StandardReportCardType";

class StandardReportCardTypeFactory {
static create({name}) {
const standardReportCardType = new StandardReportCardType();
standardReportCardType.name = name;
return standardReportCardType;
}
}

export default StandardReportCardTypeFactory;

0 comments on commit 637ee4b

Please sign in to comment.