-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
439 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.ui.website; | ||
|
||
import com.vaadin.flow.component.Component; | ||
import com.vaadin.flow.component.Html; | ||
import com.vaadin.flow.component.Text; | ||
import com.vaadin.flow.component.html.Anchor; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Footer; | ||
import com.vaadin.flow.component.html.H2; | ||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.komunumo.configuration.Configuration; | ||
import org.komunumo.data.service.DatabaseService; | ||
|
||
public class WebsiteFooter extends Footer { | ||
|
||
private final transient Configuration configuration; | ||
|
||
public WebsiteFooter(@NotNull final DatabaseService databaseService) { | ||
this.configuration = databaseService.configuration(); | ||
setId("website-footer"); | ||
|
||
add( | ||
createAbout(), | ||
createContact() | ||
); | ||
} | ||
|
||
private Component createAbout() { | ||
final var layout = new HorizontalLayout(); | ||
layout.setId("website-footer-about"); | ||
|
||
final var title = new Div(new H2("About")); | ||
final var about = new Html("<div>%s</div>".formatted(configuration.getWebsiteAboutText())); | ||
layout.add(new HorizontalLayout(title, about)); | ||
|
||
return layout; | ||
} | ||
|
||
private Component createContact() { | ||
final var layout = new HorizontalLayout(); | ||
layout.setId("website-footer-contact"); | ||
|
||
final var title = new H2("Contact"); | ||
final var name = new Div(new Text(configuration.getWebsiteName())); | ||
final var address = new Div(new Text(configuration.getWebsiteContactAddress())); | ||
final var email = createEmail(configuration.getWebsiteContactEmail()); | ||
final var copyright = new Div(new Text(configuration.getWebsiteCopyright())); | ||
layout.add(new HorizontalLayout(title, new Div(name, address, email, copyright))); | ||
|
||
return layout; | ||
} | ||
|
||
private Component createEmail(@NotNull final String email) { | ||
final var div = new Div(new Anchor(String.format("mailto:%s", email), email)); | ||
div.addClassName("contact-email"); | ||
return div; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.ui.website; | ||
|
||
import com.vaadin.flow.component.html.Image; | ||
import com.vaadin.flow.server.InvalidApplicationConfigurationException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.komunumo.data.service.DatabaseService; | ||
|
||
import java.io.Serial; | ||
import java.util.Random; | ||
|
||
public class WebsiteLogo extends Image { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 5073126350713287726L; | ||
private final String logoUrlTemplate; | ||
private final int minLogoNumber; | ||
private final int maxLogoNumber; | ||
private final boolean randomizeLogo; | ||
|
||
public WebsiteLogo(final @NotNull DatabaseService databaseService) { | ||
final var configuration = databaseService.configuration(); | ||
this.logoUrlTemplate = configuration.getWebsiteLogoTemplate(); | ||
this.minLogoNumber = configuration.getWebsiteMinLogoNumber(); | ||
this.maxLogoNumber = configuration.getWebsiteMaxLogoNumber(); | ||
this.randomizeLogo = minLogoNumber != 0 || maxLogoNumber != 0; | ||
|
||
if (logoUrlTemplate == null || logoUrlTemplate.isBlank()) { | ||
throw new InvalidApplicationConfigurationException("Missing website logo URL template!"); | ||
} | ||
|
||
setAlt("Website Logo"); | ||
setSrc(getLogoUrl()); | ||
addClassName("website-logo"); | ||
} | ||
|
||
private String getLogoUrl() { | ||
return randomizeLogo ? getRandomLogoUrl() : logoUrlTemplate; | ||
} | ||
|
||
private String getRandomLogoUrl() { | ||
final var randomNumber = new Random().nextInt(maxLogoNumber - minLogoNumber) + minLogoNumber; | ||
return String.format(logoUrlTemplate, randomNumber); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.ui.website; | ||
|
||
import com.vaadin.flow.component.Text; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Span; | ||
|
||
import static org.komunumo.util.FormatterUtil.formatNumber; | ||
|
||
public class WebsiteStats extends Div { | ||
|
||
public WebsiteStats() { | ||
final var stats = new Stats(8, "bits are a byte"); | ||
final var number = new Span(new Text(formatNumber(stats.number()))); | ||
number.addClassName("number"); | ||
final var text = new Span(new Text(stats.text())); | ||
text.addClassName("text"); | ||
|
||
add(number, text); | ||
addClassName("website-stats"); | ||
} | ||
|
||
private record Stats(int number, String text) { } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Komunumo - Open Source Community Manager | ||
* Copyright (C) Marcus Fihlon and the individual contributors to Komunumo. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.komunumo.util; | ||
|
||
import java.text.DecimalFormat; | ||
import java.text.NumberFormat; | ||
|
||
public final class FormatterUtil { | ||
|
||
private static final DecimalFormat LARGE_NUMBERS = createLargeNumberFormatter(); | ||
|
||
private static DecimalFormat createLargeNumberFormatter() { | ||
final var formatter = (DecimalFormat) NumberFormat.getInstance(); | ||
final var symbols = formatter.getDecimalFormatSymbols(); | ||
|
||
symbols.setGroupingSeparator('\''); | ||
formatter.setDecimalFormatSymbols(symbols); | ||
|
||
return formatter; | ||
} | ||
|
||
public static String formatNumber(final long number) { | ||
return LARGE_NUMBERS.format(number); | ||
} | ||
|
||
private FormatterUtil() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.