Skip to content

Commit

Permalink
avniproject/avni-client#1256 | Introduce support for nested reportCar…
Browse files Browse the repository at this point in the history
…ds on customDashboard
  • Loading branch information
himeshr committed Jan 23, 2024
1 parent 735b866 commit a0f24a8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
31 changes: 31 additions & 0 deletions avni-server-api/src/main/java/org/avni/server/domain/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@JsonIgnoreProperties({"standardReportCardType"})
public class Card extends OrganisationAwareEntity {

public static final int INT_CONSTANT_DEFAULT_COUNT_OF_CARDS = 1;
public static final int INT_CONSTANT_MAX_COUNT_OF_CARDS = 9;
@NotNull
private String name;

Expand All @@ -22,6 +24,10 @@ public class Card extends OrganisationAwareEntity {

private String colour;

private boolean nested = false;

private int countOfCards = INT_CONSTANT_DEFAULT_COUNT_OF_CARDS;

@Column(name = "icon_file_s3_key")
private String iconFileS3Key;

Expand Down Expand Up @@ -61,12 +67,37 @@ public void setColour(String colour) {
this.colour = colour;
}

public boolean isNested() {
return getStandardReportCardType() == null && nested;
}

public void setNested(boolean nested) {
this.nested = getStandardReportCardType() == null && nested;
}

public int getCountOfCards() {
return isNested() ? this.countOfCards : INT_CONSTANT_DEFAULT_COUNT_OF_CARDS;
}

public void setCountOfCards(int countOfCards) {
this.countOfCards = isNested() ? countOfCards : INT_CONSTANT_DEFAULT_COUNT_OF_CARDS;
}

public StandardReportCardType getStandardReportCardType() {
return standardReportCardType;
}

public void setStandardReportCardType(StandardReportCardType standardReportCardType) {
Boolean reportCardTypeChangedFromQueryToStandard = (this.standardReportCardType == null && standardReportCardType != null);
this.standardReportCardType = standardReportCardType;
resetNestedCardInfoOnlyApplicableForQueryReportCardType(reportCardTypeChangedFromQueryToStandard);
}

private void resetNestedCardInfoOnlyApplicableForQueryReportCardType(Boolean reportCardTypeChangedFromQueryToStandard) {
if (reportCardTypeChangedFromQueryToStandard) {
this.setNested(false);
this.setCountOfCards(INT_CONSTANT_DEFAULT_COUNT_OF_CARDS);
}
}

public Long getStandardReportCardTypeId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ private void buildCard(CardContract cardContract, Card card) {
} else {
card.setStandardReportCardType(null);
}
card.setNested(cardContract.isNested());
if (cardContract.getCount() < Card.INT_CONSTANT_DEFAULT_COUNT_OF_CARDS || cardContract.getCount() > Card.INT_CONSTANT_MAX_COUNT_OF_CARDS) {
throw new BadRequestError(String.format("Nested ReportCard count should have minmum value of %d and maximum value of %d",
Card.INT_CONSTANT_DEFAULT_COUNT_OF_CARDS, Card.INT_CONSTANT_MAX_COUNT_OF_CARDS));
}
card.setCountOfCards(cardContract.getCount());
}

private void assertNewNameIsUnique(String newName, String oldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class CardContract extends CHSRequest {
private Double displayOrder;
private Long standardReportCardTypeId;
private String iconFileS3Key;
private boolean nested;
private int count;

public static CardContract fromEntity(Card card) {
CardContract cardContract = new CardContract();
Expand All @@ -23,6 +25,8 @@ public static CardContract fromEntity(Card card) {
cardContract.setColor(card.getColour());
cardContract.setStandardReportCardTypeId(card.getStandardReportCardTypeId());
cardContract.setIconFileS3Key(card.getIconFileS3Key());
cardContract.setNested(card.isNested());
cardContract.setCount(card.getCountOfCards());
return cardContract;
}

Expand Down Expand Up @@ -87,4 +91,20 @@ public String getIconFileS3Key() {
public void setIconFileS3Key(String iconFileS3Key) {
this.iconFileS3Key = iconFileS3Key;
}

public boolean isNested() {
return nested;
}

public void setNested(boolean nested) {
this.nested = nested;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE public.report_card
ADD COLUMN IF NOT EXISTS nested BOOLEAN DEFAULT FALSE,
ADD COLUMN IF NOT EXISTS init_count_of_cards SMALLINT NOT NULL DEFAULT 1;

0 comments on commit a0f24a8

Please sign in to comment.