Skip to content

Commit

Permalink
update[OrganizationPage]: Update OrganizationPage's description to fe…
Browse files Browse the repository at this point in the history
…tch and display the description in a more neatly manner
  • Loading branch information
Fredrik Marjoni committed Apr 10, 2026
1 parent 427f4e5 commit 441155e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public OrganizationRepository(Object[] input, OrganizationScraper scraper) {
boolean trusted = "approved".equalsIgnoreCase((String) contentMap.get("status"));
String websiteURL = (String) contentMap.get("url");
boolean isPreApproved = Boolean.TRUE.equals(contentMap.get("is_pre_approved"));
String description = scraper.fetchDescription(websiteURL) != null ? scraper.fetchDescription(websiteURL) : "Information about " + name;
String description = scraper.fetchDescription(websiteURL);
description = description != null ? description : "Information about " + name;
Organization org = new Organization(orgNumber, name, trusted, websiteURL, isPreApproved, description, null);

grandMap.put(org.orgNumber(), org);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;

import java.util.stream.Collectors;

import java.util.HashMap;
Expand Down Expand Up @@ -47,18 +50,22 @@ public String fetchDescription(String pageUrl) {

Element section = doc.selectFirst("section.information");
if (section != null) {
// Try to get all <p> tags (skip first one if multiple exist)
String description = section.select("p").stream()
.skip(1) // Skip first paragraph (usually a heading)
section.select("div.extra-info").remove();
section.select("a.read-more").remove();

// Extract all <p> tags and <div> elements as separate paragraphs
String description = section.select("p, div").stream()
.filter(el -> !el.hasClass("extra-info") && !el.hasClass("logo"))
.map(Element::text)
.map(text -> text.replace("Les mer", "").trim())
.filter(text -> !text.isBlank())
.map(String::trim)
.collect(Collectors.joining("\n\n"));

// Fallback: if no paragraphs after first, get all text from section
// Fallback: if no paragraphs found, get all text from section
if (description.isBlank()) {
description = section.text().trim();
}
description = description.replace("Les mer", "").trim();

// Only cache and return if we found something meaningful
if (!description.isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,30 @@ private VBox createOrgInfoSection() {
VBox descriptionBox = new VBox();
descriptionBox.setSpacing(15);
descriptionBox.setId("description-container");
descriptionBox.setMaxWidth(750);

if (org != null && org.description() != null) {
String[] paragraphs = org.description().split("\n\n");
for (String para : paragraphs) {
if (!para.isBlank()) {
Label paragraph = new Label(para.trim());
String[] rawParagraphs = org.description().split("\n{2,}");

for (String para : rawParagraphs) {
String cleaned = para.trim();
if (!cleaned.isBlank()) {
Label paragraph = new Label(cleaned);
paragraph.setId("description-paragraph");
paragraph.setWrapText(true);
descriptionBox.getChildren().add(paragraph);
}
}
}

orgNameAndDescription.getChildren().addAll(orgName, descriptionBox);
ScrollPane descriptionScroll = new ScrollPane(descriptionBox);
descriptionScroll.setId("description-scroll");
descriptionScroll.setFitToWidth(true);
descriptionScroll.setStyle("-fx-focus-color: transparent; -fx-faint-focus-color: transparent;");
descriptionScroll.setPrefHeight(400);
descriptionScroll.setMaxHeight(400);

orgNameAndDescription.getChildren().addAll(orgName, descriptionScroll);

Button donateBtn = new Button("Donate");
donateBtn.setId("donate-button");
Expand Down
34 changes: 27 additions & 7 deletions src/main/resources/organizationpage/organizationpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
}

#description-container {
-fx-padding: 30 0 30 0;
-fx-spacing: 25;
-fx-padding: 30;
-fx-spacing: 22;
-fx-max-width: 750;
-fx-background-color: #f8f9fa;
-fx-border-radius: 8;
}

#description-paragraph {
-fx-font-size: 16;
-fx-text-fill: #222;
-fx-font-size: 18;
-fx-text-fill: #333;
-fx-font-family: "Segoe UI", Arial, sans-serif;
-fx-padding: 15 50 15 50;
-fx-line-spacing: 6;
-fx-line-spacing: 13;
-fx-text-alignment: Left;
-fx-wrap-text: true;

-fx-padding: 10 0 10 0;
}

#donate-button {
Expand All @@ -42,4 +44,22 @@

#donate-button:hover {
-fx-background-color: #c02020;
}

#description-scroll {
-fx-control-inner-background: #f8f9fa;
-fx-padding: 0;
}

#description-scroll .scroll-bar:vertical {
-fx-pref-width: 8;
}

#description-scroll .scroll-bar:vertical .thumb {
-fx-background-radius: 4;
-fx-background-color: #cccccc;
}

#description-scroll .scroll-bar:vertical .thumb:hover {
-fx-background-color: #999999;
}

0 comments on commit 441155e

Please sign in to comment.