1
0

35 Commits

Author SHA1 Message Date
27db87792d Merge remote-tracking branch 'origin/master' 2026-01-17 23:39:19 +01:00
0af399275d #26 Enable docker build 2026-01-17 23:38:52 +01:00
7b707e5bb5 [maven-release-plugin] prepare for next development iteration 2026-01-17 23:27:51 +01:00
634ae4365f [maven-release-plugin] prepare release v25 2026-01-17 23:27:49 +01:00
49008be24a #26 Fix repo param 2026-01-17 23:27:26 +01:00
eca68b7bbf [maven-release-plugin] prepare for next development iteration 2026-01-17 23:10:42 +01:00
d0b5b92fc7 [maven-release-plugin] prepare release v24 2026-01-17 23:10:40 +01:00
4386dc4449 Fix repo param name 2026-01-17 23:10:20 +01:00
32c7719942 Fix repo param name 2026-01-17 23:08:38 +01:00
950ab8c568 [maven-release-plugin] prepare for next development iteration 2026-01-17 23:06:45 +01:00
73043da77c [maven-release-plugin] prepare release v23 2026-01-17 23:06:43 +01:00
30d6252992 Bump to 23-SNAPSHOT and fix repo URL 2026-01-17 23:05:25 +01:00
66ccf4b263 [maven-release-plugin] prepare release v22 2026-01-17 22:42:17 +01:00
5cc6bd6305 #26 Try usr/pwd again 2026-01-17 22:40:54 +01:00
c42313e022 #26 Try dev connection with credentials 2026-01-17 22:32:35 +01:00
ac439261f0 #26 Update scm connection 2026-01-17 22:29:48 +01:00
be19d2881e #26 Try usr/pwd 2026-01-17 22:24:15 +01:00
71bc53488d #26 Readd origin 2026-01-17 20:53:41 +01:00
89db72a316 #26 Use developerConnection for release plugin 2026-01-17 20:43:51 +01:00
06e72a794f #26 Add GPG signing 2026-01-17 20:34:48 +01:00
ea45ef73f4 #26 Do semi dry run 2026-01-17 20:10:37 +01:00
ef9c56f6c9 #26 Add more debug 2026-01-17 13:08:56 +01:00
718f3e4a51 #26 Add debug 2026-01-17 12:01:08 +01:00
9cb1bab118 #26 Try to some more 2026-01-17 11:59:35 +01:00
90dbeecdca #26 Try to fix bad sub 2026-01-17 11:56:13 +01:00
b6545e2f62 #26 Add missing env var 2026-01-17 11:49:04 +01:00
c1ca25ea24 #26 Use pkgx instead of pixi 2026-01-17 11:46:30 +01:00
046124464e #26 Dockerize 2026-01-17 11:12:53 +01:00
2eab631796 [maven-release-plugin] prepare for next development iteration 2023-02-21 18:33:05 +01:00
ed23426690 [maven-release-plugin] prepare release v21 2023-02-21 18:33:02 +01:00
b6e6a94a1e #24 todo app 2023-02-21 18:31:01 +01:00
455cb63652 [maven-release-plugin] prepare for next development iteration 2023-01-23 23:14:16 +01:00
4573df557f [maven-release-plugin] prepare release v20 2023-01-23 23:14:13 +01:00
1cac696dde #2 Folder sharing fixup 2023-01-23 23:13:22 +01:00
7be52466d2 [maven-release-plugin] prepare for next development iteration 2023-01-23 21:03:32 +01:00
36 changed files with 675 additions and 47 deletions

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

13
build/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM eclipse-temurin:25-jre-alpine
# Create a non-root user for security
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
EXPOSE 8082
ENTRYPOINT ["java", "-jar", "/app.jar"]

85
build/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,85 @@
pipeline {
agent { label 'docker' }
parameters {
booleanParam(name: 'DRY_RUN', defaultValue: true, description: 'If checked, no code will be pushed to Gitea, Reposilite, or Docker.')
}
environment {
REPO_URL = credentials('reposilite-url')
DOCKER_REGISTRY = credentials('docker-registry-url')
GIT_URL_CLEAN = sh(script: "echo ${GIT_URL} | sed 's|https://||'", returnStdout: true).trim()
IS_DRY_RUN = "${params.DRY_RUN}"
}
stages {
stage('Version & Tag') {
steps {
withCredentials([usernamePassword(credentialsId: 'Jenkins_Gitea',
usernameVariable: 'GITEA_CREDS_USR',
passwordVariable: 'GITEA_CREDS_PSW'),
file(credentialsId: 'jenkins-gpg-key', variable: 'GPG_KEY_FILE')]) {
sh '''
gpg --batch --import "${GPG_KEY_FILE}"
KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub:/ { print $5; exit }')
git config user.email "jenkins@77zzcx7.de"
git config user.name "Jenkins"
git config user.signingkey "$KEY_ID"
git config commit.gpgsign true
git config tag.gpgSign true
// We need to pass the repo url in -Darguments again because of insane maven lifecycle forking
pkgx mvn release:prepare -B \
-s build/settings.xml \
-Dpassword="${GITEA_CREDS_PSW}" \
-Dusername="${GITEA_CREDS_USR}" \
-DdryRun=${IS_DRY_RUN} \
-Drepository.url=${REPO_URL} \
-DtagNameFormat="v@{project.version}" \
-Darguments="-Drepository.url=${REPO_URL} -Dtag=v\\${project.version} -DskipTests"
'''
}
}
}
stage('Deploy Release') {
steps {
withCredentials([usernamePassword(credentialsId: 'reposilite-jenkins-cred',
usernameVariable: 'REPO_USER',
passwordVariable: 'REPO_TOKEN')]) {
sh '''
pkgx mvn release:perform -B \
-s build/settings.xml \
-DdryRun=${DRY_RUN} \
-Drepository.url=${REPO_URL} \
-Darguments="-Drepository.url=${REPO_URL} -DskipTests"
'''
}
}
}
stage('Docker Build & Push') {
steps {
script {
sh "pwd"
sh "ls -R"
def jarPath = sh(script: "ls target/checkout/web-container/target/*.jar | head -n 1", returnStdout: true).trim()
def releaseVer = sh(script: "pkgx mvn help:evaluate -Dexpression=project.version -q -DforceStdout -f target/checkout/web-container/pom.xml", returnStdout: true).trim()
docker.withRegistry("${env.DOCKER_REGISTRY}", '') {
def customImage = docker.build("${env.DOCKER_REGISTRY}/my-app:${releaseVer}",
"-f build/Dockerfile --build-arg JAR_FILE=${jarPath} .")
if (params.DRY_RUN) {
echo "DRY_RUN - do not push image to registry"
}
else {
customImage.push("latest")
}
}
}
}
}
}
}

20
build/settings.xml Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>77zzcx7-releases</id>
<username>${env.REPO_USER}</username>
<password>${env.REPO_TOKEN}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<name>77zzcx7-central</name>
<url>${env.REPO_URL}/releases</url>
</mirror>
</mirrors>
</settings>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>nbs-cloud-aggregator</artifactId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

View File

@@ -65,7 +65,7 @@ public interface FilesService {
}
}
void createAppDirectory(App app);
void createAppDirectoryIfNotExists(App app);
void createDirectory(App app, Path path);
@@ -81,7 +81,7 @@ public interface FilesService {
* Paths in return list are always relative to the appDir. Non-recursive list.
*
* @param app to list the files for
* @param path in case of {@link Optional#EMPTY} the appDir is used as start dir. If not empty, path has to be relative
* @param path in case of an empty optional the appDir is used as start dir. If not empty, path has to be relative
* to the appDir
*/
List<ContentContainer> list(App app, Optional<Path> path);

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>nbs-cloud-aggregator</artifactId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

View File

@@ -28,7 +28,7 @@ public class FilesServiceImpl implements FilesService {
}
@Override
public void createAppDirectory(App app) {
public void createAppDirectoryIfNotExists(App app) {
try {
this.fileSystemService.createDirectory(resolve(app, Path.of("")));
}

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.nbscloud.files.FileSystemService;
import de.nbscloud.files.LocationTracker;
import de.nbscloud.files.SessionInfo;
import de.nbscloud.files.Share;
import de.nbscloud.files.api.FilesService.ContentContainer;
import de.nbscloud.files.config.FilesConfig;
@@ -12,9 +13,9 @@ import de.nbscloud.files.form.PasswordForm;
import de.nbscloud.files.form.RenameForm;
import de.nbscloud.files.form.ShareForm;
import de.nbscloud.webcontainer.MessageHelper;
import de.nbscloud.files.SessionInfo;
import de.nbscloud.webcontainer.registry.AppRegistry;
import de.nbscloud.webcontainer.shared.config.WebContainerSharedConfig;
import de.nbscloud.webcontainer.shared.util.ControllerUtils;
import org.apache.commons.io.input.ObservableInputStream;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -43,7 +44,6 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -83,6 +83,7 @@ public class FilesController implements InitializingBean {
model.addAttribute("sortOrder", order);
model.addAttribute("apps", this.appRegistry.getAll());
model.addAttribute("restricted", this.sessionInfo.isRestrictedSession());
model.addAttribute("prefix", "");
this.webContainerSharedConfig.addDefaults(model);
return "files/filesIndex";
@@ -121,6 +122,7 @@ public class FilesController implements InitializingBean {
model.addAttribute("apps", this.appRegistry.getAll());
model.addAttribute("filename", filename);
model.addAttribute("restricted", this.sessionInfo.isRestrictedSession());
model.addAttribute("prefix", "");
this.webContainerSharedConfig.addDefaults(model);
return "files/rename";
@@ -148,6 +150,11 @@ public class FilesController implements InitializingBean {
return "redirect:/files/browse/" + this.locationTracker.getRelativeLocation();
}
@GetMapping("/files/shares/files/download")
public ResponseEntity sharesDownloadFile(HttpServletResponse response, String filename) {
return downloadFile(response, filename);
}
@GetMapping("/files/download")
public ResponseEntity downloadFile(HttpServletResponse response, String filename) {
final Path targetPath = this.locationTracker.resolve(filename);
@@ -226,6 +233,7 @@ public class FilesController implements InitializingBean {
model.addAttribute("apps", this.appRegistry.getAll());
model.addAttribute("filename", filename);
model.addAttribute("restricted", this.sessionInfo.isRestrictedSession());
model.addAttribute("prefix", "");
this.webContainerSharedConfig.addDefaults(model);
return "files/share";
@@ -240,11 +248,6 @@ public class FilesController implements InitializingBean {
final Path filePath = this.locationTracker.getRelativeToBaseDir(this.locationTracker.resolve(filename));
final String shareUuid = UUID.randomUUID().toString();
final Share share = new Share();
// The format is always "yyyy-MM-dd", see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
final LocalDate expiryDate = Optional.ofNullable(expiryDateString)
.map(ed -> ed.isBlank() ? null : ed)
.map(ed -> LocalDate.parse(ed, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.orElse(null);
if(StringUtils.isEmpty(password)) {
password = null; // if no real password has been provided assume no password
@@ -252,7 +255,7 @@ public class FilesController implements InitializingBean {
share.setUuid(shareUuid);
share.setPath(filePath.toString());
share.setExpiryDate(expiryDate);
share.setExpiryDate(ControllerUtils.parseDate(expiryDateString));
share.setOneTime(oneTime);
share.setPassword(password);
@@ -271,6 +274,21 @@ public class FilesController implements InitializingBean {
return "redirect:/files/browse/" + this.locationTracker.getRelativeLocation();
}
@GetMapping("/files/shares/files/browse/**")
public String sharesStart(Model model, HttpServletRequest httpServletRequest, String sortOrder) {
if(!this.sessionInfo.isRestrictedSession()) {
throw new IllegalStateException();
}
final String start = start(model, httpServletRequest, sortOrder);
model.addAttribute("prefix", "/files/shares");
return start;
}
// We need to copy all functions for shares because they should be available without auth and that is
// controlled by the URI via htaccess/htpasswd
@GetMapping("files/shares")
public Object shares(Model model, String shareUuid) {
this.locationTracker.reset();
@@ -282,8 +300,6 @@ public class FilesController implements InitializingBean {
final Optional<LocalDate> optExpiryDate = Optional.ofNullable(share.getExpiryDate());
final boolean expired = optExpiryDate.map(expiryDate -> LocalDate.now().isAfter(expiryDate)).orElse(false);
this.sessionInfo.setRestrictedSession(true);
if(share.getPassword() != null) {
model.addAttribute("form", new PasswordForm(shareUuid, null));
this.webContainerSharedConfig.addDefaults(model);
@@ -299,8 +315,11 @@ public class FilesController implements InitializingBean {
if(this.fileSystemService.isDirectory(sharedFilePath)) {
this.locationTracker.setBaseDirPath(share.getPath());
this.locationTracker.resetCurrentLocation();
return "redirect:/files/browse";
this.sessionInfo.setRestrictedSession(true);
return "redirect:/files/browse/";
}
else {
return doShares(shareUuid);
@@ -332,8 +351,11 @@ public class FilesController implements InitializingBean {
if(this.fileSystemService.isDirectory(sharedFilePath)) {
this.locationTracker.setBaseDirPath(share.getPath());
this.locationTracker.resetCurrentLocation();
return "redirect:/files/browse";
this.sessionInfo.setRestrictedSession(true);
return "redirect:/files/browse/";
}
else {
return doShares(shareUuid);
@@ -385,6 +407,15 @@ public class FilesController implements InitializingBean {
}
}
@GetMapping("/files/shares/files/preview")
public void sharesPreview(HttpServletResponse response, String filename) {
if(!this.sessionInfo.isRestrictedSession()) {
throw new IllegalStateException();
}
preview(response, filename);
}
@GetMapping("files/preview")
public void preview(HttpServletResponse response, String filename) {
try {
@@ -398,6 +429,19 @@ public class FilesController implements InitializingBean {
}
}
@GetMapping("/files/shares/files/gallery")
public String sharesGallery(Model model) {
if(!this.sessionInfo.isRestrictedSession()) {
throw new IllegalStateException();
}
final String gallery = gallery(model);
model.addAttribute("prefix", "/files/shares");
return gallery;
}
@GetMapping("files/gallery")
public String gallery(Model model) {
try {
@@ -406,6 +450,7 @@ public class FilesController implements InitializingBean {
model.addAttribute("files", files);
model.addAttribute("apps", this.appRegistry.getAll());
model.addAttribute("restricted", this.sessionInfo.isRestrictedSession());
model.addAttribute("prefix", "");
this.webContainerSharedConfig.addDefaults(model);
return "files/gallery";

View File

@@ -49,9 +49,9 @@
<td th:if="${fileEntry.directory}" class="no-mobile">d</td>
<td th:if="${!fileEntry.directory}" class="no-mobile">-</td>
<td th:if="${fileEntry.directory}">
<a th:if="${fileEntry.name != '..'}" th:href="@{/files/browse/__${fileEntry.path}__}"
<a th:if="${fileEntry.name != '..'}" th:href="@{__${prefix}__/files/browse/__${fileEntry.path}__}"
th:text="${fileEntry.name}"/>
<a th:if="${fileEntry.name == '..'}" th:href="@{/files/browse/__${fileEntry.path}__}"
<a th:if="${fileEntry.name == '..'}" th:href="@{__${prefix}__/files/browse/__${fileEntry.path}__}"
th:text="${fileEntry.name}"/>
</td>
<td th:if="${!fileEntry.directory && @filesFormatter.needsTruncate(fileEntry.name)}"
@@ -78,12 +78,12 @@
th:text="#{nbscloud.files-content-table.table.actions.delete}"/>
</div>
<div id="files-content-table-show-actions-detail-container-download">
<a th:href="@{/files/download(filename=${fileEntry.name})}"
<a th:href="@{__${prefix}__/files/download(filename=${fileEntry.name})}"
th:text="#{nbscloud.files-content-table.table.actions.download}"/>
</div>
<div th:if="${!fileEntry.directory}"
id="files-content-table-show-actions-detail-container-preview">
<a th:href="@{/files/preview(filename=${fileEntry.name})}"
<a th:href="@{__${prefix}__/files/preview(filename=${fileEntry.name})}"
th:text="#{nbscloud.files-content-table.table.actions.preview}"/>
</div>
<div id="files-content-table-show-actions-detail-container-share"

View File

@@ -16,7 +16,7 @@
<div id="main-container">
<div th:replace="includes/header :: header"/>
<div id="gallery-container">
<img class="galleryImage" th:each="file : ${files}" th:src="@{/files/preview(filename=${file})}">
<img class="galleryImage" th:each="file : ${files}" th:src="@{__${prefix}__/files/preview(filename=${file})}">
</div>
<div th:replace="includes/footer :: footer"/>
</div>

View File

@@ -28,7 +28,7 @@
</div>
<div class="menu-spacer"></div>
<div>
<a id="gallery-link" th:href="@{/files/gallery}">
<a id="gallery-link" th:href="@{__${prefix}__/files/gallery}">
<span class="icon menu-icon">&#xe3b6;</span>
</a>
</div>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

View File

@@ -20,7 +20,7 @@ import java.nio.file.Path;
import java.util.Optional;
@Controller
public class NotesController implements InitializingBean {
public class NotesController {
private static final Logger logger = LoggerFactory.getLogger(NotesController.class);
@Autowired
@@ -42,6 +42,8 @@ public class NotesController implements InitializingBean {
@GetMapping("/notes")
public String start(Model model, @RequestParam(required = false) String notePath) {
this.filesService.createAppDirectoryIfNotExists(this.app);
final Optional<Path> optNotePath = notePathToPath(notePath);
if(optNotePath.isPresent()) {
@@ -121,9 +123,4 @@ public class NotesController implements InitializingBean {
return "redirect:?notePath=" + currentPath;
}
@Override
public void afterPropertiesSet() throws Exception {
//this.filesService.createAppDirectory(this.app);
}
}

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

16
pom.xml
View File

@@ -10,7 +10,7 @@
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>nbs-cloud-aggregator</artifactId>
<version>19</version>
<version>26-SNAPSHOT</version>
<packaging>pom</packaging>
<description>The umbrella for all No BullShit cloud projects</description>
<name>nbs-cloud-aggregator</name>
@@ -31,26 +31,26 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>18</java.version>
<scmDeveloperConnectionProp />
<repository.url>http://reposilite.intern.77zzcx7.de</repository.url>
</properties>
<distributionManagement>
<snapshotRepository>
<id>77zzcx7-snapshots</id>
<url>http://192.168.10.4:8100/snapshots/</url>
<url>${repository.url}/snapshots/</url>
</snapshotRepository>
<repository>
<id>77zzcx7-releases</id>
<url>http://192.168.10.4:8100/releases/</url>
<url>${repository.url}/releases/</url>
</repository>
</distributionManagement>
<scm>
<connection>scm:git:https://77zzcx7.de/gitea/MK13/NoBullShit-cloud.git</connection>
<developerConnection>${scmDeveloperConnectionProp}</developerConnection>
<connection>scm:git:https://gitea.77zzcx7.de/MK13/NoBullShit-cloud.git</connection>
<developerConnection>scm:git:https://gitea.77zzcx7.de/MK13/NoBullShit-cloud.git</developerConnection>
<url>https://77zzcx7.de/gitea/MK13/NoBullShit-cloud</url>
<tag>v19</tag>
</scm>
<tag>v22</tag>
</scm>
<dependencyManagement>
<dependencies>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>
@@ -31,5 +31,9 @@
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>files-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,5 @@
package de.nbscloud.todo;
public enum Category {
A, B, C;
}

View File

@@ -1,19 +1,26 @@
package de.nbscloud.todo;
import de.nbscloud.todo.widget.TodoWidget;
import de.nbscloud.webcontainer.registry.App;
import de.nbscloud.webcontainer.registry.AppRegistry;
import de.nbscloud.webcontainer.registry.Widget;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
@Component
public class TodoApp implements App, InitializingBean {
public static final String ID = "todo";
@Autowired
private AppRegistry appRegistry;
@Override
public String getId() {
return "todo";
return ID;
}
@Override
@@ -31,6 +38,11 @@ public class TodoApp implements App, InitializingBean {
return 40;
}
@Override
public Collection<Widget> getWidgets() {
return List.of(new TodoWidget());
}
@Override
public void afterPropertiesSet() throws Exception {
this.appRegistry.registerApp(this);

View File

@@ -0,0 +1,74 @@
package de.nbscloud.todo;
import java.time.LocalDate;
import java.util.UUID;
public class TodoItem {
private String id;
private boolean done;
private String text;
private Category category;
private LocalDate added;
private LocalDate due;
public static final TodoItem create(boolean done, String text, Category category, LocalDate added, LocalDate due) {
final TodoItem item = new TodoItem();
item.setDone(done);
item.setText(text);
item.setCategory(category);
item.setAdded(added);
item.setDue(due);
item.setId(UUID.randomUUID().toString());
return item;
}
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public LocalDate getAdded() {
return added;
}
public void setAdded(LocalDate added) {
this.added = added;
}
public LocalDate getDue() {
return due;
}
public void setDue(LocalDate due) {
this.due = due;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,16 @@
package de.nbscloud.todo;
import java.util.ArrayList;
import java.util.List;
public class TodoList {
private List<TodoItem> todos = new ArrayList<>();
public List<TodoItem> getTodos() {
return todos;
}
public void setTodos(List<TodoItem> todos) {
this.todos = todos;
}
}

View File

@@ -0,0 +1,159 @@
package de.nbscloud.todo.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.nbscloud.files.api.FilesService;
import de.nbscloud.todo.Category;
import de.nbscloud.todo.TodoApp;
import de.nbscloud.todo.TodoItem;
import de.nbscloud.todo.TodoList;
import de.nbscloud.webcontainer.MessageHelper;
import de.nbscloud.webcontainer.registry.AppRegistry;
import de.nbscloud.webcontainer.shared.config.WebContainerSharedConfig;
import de.nbscloud.webcontainer.shared.util.ControllerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.nio.charset.StandardCharsets;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@Controller
public class TodoController {
private static final Logger logger = LoggerFactory.getLogger(TodoController.class);
public static final Comparator<TodoItem> TODO_ITEM_COMPARATOR = Comparator.comparing(TodoItem::isDone)
.thenComparing(TodoItem::getDue,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(TodoItem::getAdded);
static final Path FILENAME = Path.of("todo");
@Autowired
private AppRegistry appRegistry;
@Autowired
private FilesService filesService;
@Autowired
private WebContainerSharedConfig webContainerSharedConfig;
@Autowired
private TodoApp app;
@Autowired
private MessageHelper messageHelper;
@Autowired
private ObjectMapper mapper;
@GetMapping("/todo")
public String start(Model model) {
try {
this.filesService.createAppDirectoryIfNotExists(this.app);
final String todoListJson = new String(this.filesService.get(app, FILENAME));
final TodoList todos = mapper.readValue(todoListJson, TodoList.class);
final Map<Category, List<TodoItem>> categoryMap = new TreeMap<>(Comparator.comparing(Category::name));
todos.getTodos().stream().collect(Collectors.groupingBy(TodoItem::getCategory, () -> categoryMap, Collectors.toList()));
if(categoryMap.containsKey(Category.A)) {
Collections.sort(categoryMap.get(Category.A), TODO_ITEM_COMPARATOR);
}
if(categoryMap.containsKey(Category.B)) {
Collections.sort(categoryMap.get(Category.B), TODO_ITEM_COMPARATOR);
}
if(categoryMap.containsKey(Category.C)) {
Collections.sort(categoryMap.get(Category.C), TODO_ITEM_COMPARATOR);
}
model.addAttribute("todosByCategory", categoryMap);
}
catch(JsonProcessingException e) {
logger.error("Error while parsing todo file", e);
this.messageHelper.addError(e.getMessage());
}
catch(RuntimeException re) {
if(re.getCause() instanceof NoSuchFileException) {
logger.debug("Todo file does not exist, create it");
try {
this.filesService.createFile(app, FILENAME, mapper.writeValueAsString(new TodoList()).getBytes(StandardCharsets.UTF_8));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
else {
logger.error("Error while reading todo file", re);
this.messageHelper.addError(re.getMessage());
}
}
model.addAttribute("categories", Category.values());
this.messageHelper.addAndClearAll(model);
model.addAttribute("apps", this.appRegistry.getAll());
this.webContainerSharedConfig.addDefaults(model);
return "todo/todoIndex";
}
@PostMapping("/todo/addItem")
public String addItem(Model model, String text, Category category, String due) {
try {
final String todoListJson = new String(this.filesService.get(app, FILENAME));
final TodoList todos = mapper.readValue(todoListJson, TodoList.class);
todos.getTodos().add(TodoItem.create(false, text, category, LocalDate.now(), ControllerUtils.parseDate(due)));
this.filesService.overwriteFile(app, FILENAME, mapper.writeValueAsBytes(todos));
this.messageHelper.addInfo("nbscloud.todo.item.add");
} catch (JsonProcessingException e) {
logger.error("Error", e);
this.messageHelper.addError(e.getMessage());
}
model.addAttribute("categories", Category.values());
model.addAttribute("apps", this.appRegistry.getAll());
this.webContainerSharedConfig.addDefaults(model);
return "redirect:";
}
@PostMapping("/todo/toggle")
public String toggle(Model model, String id, boolean done) {
try {
final String todoListJson = new String(this.filesService.get(app, FILENAME));
final TodoList todos = mapper.readValue(todoListJson, TodoList.class);
todos.getTodos().stream().filter(item -> item.getId().equals(id)).findFirst().ifPresent(item -> item.setDone(done));
this.filesService.overwriteFile(app, FILENAME, mapper.writeValueAsBytes(todos));
if(done) {
this.messageHelper.addInfo("nbscloud.todo.item.toggle.done");
}
else {
this.messageHelper.addInfo("nbscloud.todo.item.toggle.inprogress");
}
} catch (JsonProcessingException e) {
logger.error("Error", e);
this.messageHelper.addError(e.getMessage());
}
model.addAttribute("categories", Category.values());
model.addAttribute("apps", this.appRegistry.getAll());
this.webContainerSharedConfig.addDefaults(model);
return "redirect:";
}
}

View File

@@ -0,0 +1,58 @@
package de.nbscloud.todo.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.nbscloud.files.api.FilesService;
import de.nbscloud.todo.Category;
import de.nbscloud.todo.TodoApp;
import de.nbscloud.todo.TodoItem;
import de.nbscloud.todo.TodoList;
import de.nbscloud.webcontainer.shared.config.WebContainerSharedConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
@Controller
public class TodoWidgetController {
private static final Logger logger = LoggerFactory.getLogger(TodoWidgetController.class);
@Autowired
private WebContainerSharedConfig webContainerSharedConfig;
@Autowired
private FilesService filesService;
@Autowired
private TodoApp app;
@Autowired
private ObjectMapper mapper;
@GetMapping("todo/widgets/todoOverview")
public String getTodoOverview(HttpServletRequest request, HttpServletResponse response, Model model) {
try {
this.filesService.createAppDirectoryIfNotExists(this.app);
final String todoListJson = new String(this.filesService.get(app, TodoController.FILENAME));
final TodoList todos = mapper.readValue(todoListJson, TodoList.class);
final List<TodoItem> topFiveTodos = todos.getTodos().stream().filter(item -> !item.isDone()).sorted(
Comparator.comparing(TodoItem::getDue,
Comparator.nullsLast(Comparator.naturalOrder()))
.thenComparing(TodoItem::getCategory)
.thenComparing(TodoItem::getAdded)).limit(5).collect(Collectors.toList());
model.addAttribute("todos", topFiveTodos);
}
catch(JsonProcessingException e) {
logger.error("Error while parsing todo file", e);
}
return "todo/widgets/todoOverview :: todo-overview";
}
}

View File

@@ -0,0 +1,11 @@
package de.nbscloud.todo.widget;
import de.nbscloud.todo.TodoApp;
import de.nbscloud.webcontainer.registry.Widget;
public class TodoWidget implements Widget {
@Override
public String getPath() {
return TodoApp.ID + "/widgets/todoOverview";
}
}

View File

@@ -0,0 +1,7 @@
nbscloud.todo.index.title=nbscloud - todo
nbscloud.todo.widget.heading=todo overview
nbscloud.todo.item.add=Todo added
nbscloud.todo.item.toggle.done=Done
nbscloud.todo.item.toggle.inprogress=In progress

View File

@@ -0,0 +1,7 @@
nbscloud.todo.index.title=nbscloud - todo
nbscloud.todo.widget.heading=todo \u00FCbersicht
nbscloud.todo.item.add=Todo hinzugef\u00FCgt
nbscloud.todo.item.toggle.done=Fertig
nbscloud.todo.item.toggle.inprogress=Unfertig

View File

@@ -0,0 +1,24 @@
#content-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
row-gap: 2em;
column-gap: 2em;
}
.todo-category {
flex-grow: 1;
background-color:var(--background-color-highlight);
padding: 1em;
align-self: stretch;
word-break: break-all;
flex-basis: 100%;
}
.todo-category-header {
text-decoration-line: underline;
}
.todo-item > td:nth-child(2) {
padding-inline: 3em;
}

View File

@@ -0,0 +1,24 @@
<div id="menu-container" th:fragment="menu">
<div class="menu-spacer"></div>
<div id="add-item-container" class="menu-container">
<details>
<summary>
<span id="add-item-container-span-input" class="icon menu-icon">&#xf23a;</span>
</summary>
<div class="menu-modal">
<div class="menu-modal-content">
<form method="POST" action="#" th:action="@{/todo/addItem}" enctype="multipart/form-data">
<input id="add-item-container-text" type="text" name="text" />
<select size="1" id="add-item-category" name="category">
<option th:each="category : ${categories}"
th:value="${category}"
th:text="${category}" />
</select>
<input type="date" id="add-item-due" name="due"/>
<input type="submit" value="Add"/>
</form>
</div>
</div>
</details>
</div>
</div>

View File

@@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{nbscloud.todo.index.title}"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link th:if="${darkMode}" rel="stylesheet" th:href="@{/css/darkModeColors.css}"/>
<link th:if="${!darkMode}" rel="stylesheet" th:href="@{/css/lightModeColors.css}"/>
<link rel="stylesheet" th:href="@{/css/main.css}"/>
<link rel="stylesheet" th:href="@{/css/todo_main.css}"/>
<link rel="shortcut icon" th:href="@{/favicon.ico}"/>
</head>
<body>
<div id="main-container">
<div th:replace="includes/header :: header"/>
<div th:replace="includes/messages :: messages"/>
<div th:replace="todo/includes/menu :: menu"/>
<div id="content-container">
<div class="todo-category" th:each="entry : ${todosByCategory}">
<p th:text="${#strings.prepend(#strings.append(entry.key, #strings.repeat('&nbsp;', 10)), '&nbsp;')}"
class="todo-category-header"/>
<table id="todo-item-table">
<tr class="todo-item" th:each="todo : ${entry.value}">
<td>
<form method="POST" th:action="@{/todo/toggle}" enctype="multipart/form-data">
<input type="checkbox" th:checked="${todo.done}" name="done" onClick="this.form.submit()" /> <!-- fucking javascript -->
<input type="hidden" name="id" th:value="${todo.id}" class="display-none"/>
</form>
</td>
<td th:text="${todo.text}"/>
<td th:text="${todo.due}"/>
</tr>
</table>
</div>
</div>
<div th:replace="includes/footer :: footer"/>
</div>
</body>
</html>

View File

@@ -0,0 +1,12 @@
<div id="todo-widget" class="widget" th:fragment="todo-overview">
<p class="widget-heading" th:text="#{nbscloud.todo.widget.heading}"/>
<table id="todo-widget-table">
<tbody>
<tr th:each="todo : ${todos}">
<td th:text="${todo.category}"/>
<td th:text="${todo.text}"/>
<td th:text="${todo.due}"/>
</tr>
</tbody>
</table>
</div>

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<artifactId>web-container-config</artifactId>

View File

@@ -0,0 +1,16 @@
package de.nbscloud.webcontainer.shared.util;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
public class ControllerUtils {
public static LocalDate parseDate(String date) {
// The format is always "yyyy-MM-dd", see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
return Optional.ofNullable(date)
.map(ed -> ed.isBlank() ? null : ed)
.map(ed -> LocalDate.parse(ed, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.orElse(null);
}
}

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>nbs-cloud-aggregator</artifactId>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<artifactId>web-container-registry</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>
<artifactId>nbs-cloud-aggregator</artifactId>
<version>19</version>
<version>26-SNAPSHOT</version>
</parent>
<groupId>de.77zzcx7.nbs-cloud</groupId>

View File

@@ -9,7 +9,7 @@ info.build.group=@project.groupId@
info.build.artifact=@project.artifactId@
info.build.version=@project.version@
spring.messages.basename=i18n/container_messages,i18n/files_messages,i18n/dashboard_messages,i18n/notes_messages
spring.messages.basename=i18n/container_messages,i18n/files_messages,i18n/dashboard_messages,i18n/notes_messages,i18n/todo_messages
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1