Compare commits

..

31 Commits

Author SHA1 Message Date
StephanRichter f43105d983 extended documentation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-06-05 15:32:49 +02:00
StephanRichter fbe2380034 extended documentation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-06-05 15:23:41 +02:00
StephanRichter 84bb908216 working on task description
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-06-05 08:57:48 +02:00
StephanRichter f80bccfa0c working on demodata
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-06-05 08:47:31 +02:00
StephanRichter 372e371a8f adding demodata
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 51b2a497cf working on demodata
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 81b6090d88 extended demo data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 1570aefc77 extended demo data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 55cad3c854 extending demo data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 747b2c1d48 started creating demo data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-30 15:00:01 +02:00
StephanRichter 31545b8b11 css improvement
Build Docker Image / Clean-Registry (push) Failing after 10m34s
Build Docker Image / Docker-Build (push) Failing after 14m39s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-24 20:21:48 +02:00
StephanRichter feafb44a9f Merge branch 'bugfix/autocomplete' into dev
Build Docker Image / Clean-Registry (push) Successful in 5s
Build Docker Image / Docker-Build (push) Failing after 14m59s
2026-05-22 08:46:39 +02:00
StephanRichter d187b6a2fc fixed typo
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-22 08:46:30 +02:00
StephanRichter 8d7de4b1b6 Merge branch 'bugfix/autocomplete' into dev
Build Docker Image / Clean-Registry (push) Failing after 11m24s
Build Docker Image / Docker-Build (push) Failing after 16m57s
2026-05-22 08:37:27 +02:00
StephanRichter e61e09d834 fixing dropdown disabling on dropdown click
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-22 08:37:22 +02:00
StephanRichter 3cff613335 Merge branch 'bugfix/autocomplete' into dev
Build Docker Image / Docker-Build (push) Successful in 3m13s
Build Docker Image / Clean-Registry (push) Has been cancelled
2026-05-22 08:26:25 +02:00
StephanRichter 0edeef2a9d implemented closing of autocomplete dropdown when leaving input
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-22 08:26:08 +02:00
StephanRichter 3a7779a665 Merge branch 'feature/easy-complete' into dev
Build Docker Image / Docker-Build (push) Successful in 2m52s
Build Docker Image / Clean-Registry (push) Successful in 6s
2026-05-19 16:06:22 +02:00
StephanRichter a1164e416a implemented saving of task/project from tag input field
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-19 16:05:43 +02:00
StephanRichter 2f8276c1be Merge branch 'bugfix/external-links' into dev
Build Docker Image / Docker-Build (push) Successful in 2m40s
Build Docker Image / Clean-Registry (push) Successful in 6s
2026-05-19 10:46:37 +02:00
StephanRichter 8b139b1bed moved markdown rendering from Util to MarkdownApi
Build Docker Image / Docker-Build (push) Successful in 2m44s
Build Docker Image / Clean-Registry (push) Successful in 6s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-19 10:46:28 +02:00
StephanRichter 3b2371ad64 Merge branch 'bugfix/external-links' into dev
Build Docker Image / Docker-Build (push) Successful in 2m56s
Build Docker Image / Clean-Registry (push) Successful in 6s
2026-05-19 09:54:03 +02:00
StephanRichter aa48bbcbf5 implemented adding targets to links in markdown
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-19 09:53:43 +02:00
StephanRichter c5e31db99e Merge branch 'feature/parent_selector' into dev
Build Docker Image / Docker-Build (push) Successful in 4m25s
Build Docker Image / Clean-Registry (push) Successful in 1s
2026-05-14 00:32:23 +02:00
StephanRichter ccf8fc2089 implemented selector for parent task
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-14 00:32:10 +02:00
StephanRichter 098811547a Merge branch 'module/projects' into dev
Build Docker Image / Docker-Build (push) Successful in 5m20s
Build Docker Image / Clean-Registry (push) Successful in 3s
2026-05-11 20:14:32 +02:00
StephanRichter 9bec33d5de implemented editing of custom states
Build Docker Image / Docker-Build (push) Successful in 3m32s
Build Docker Image / Clean-Registry (push) Successful in 1s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-11 20:14:24 +02:00
StephanRichter 6193b727bd Merge branch 'module/projects' into dev
Build Docker Image / Docker-Build (push) Successful in 3m5s
Build Docker Image / Clean-Registry (push) Successful in 3s
2026-05-07 18:26:44 +02:00
StephanRichter f35882c967 bugfix: moving of tasks in tree now works as intended
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-07 18:26:37 +02:00
StephanRichter 1d1520534c Merge branch 'module/notes' into dev
Build Docker Image / Docker-Build (push) Successful in 3m7s
Build Docker Image / Clean-Registry (push) Successful in 2s
2026-05-06 09:26:13 +02:00
StephanRichter fe57749d9c improving note lsit
Build Docker Image / Docker-Build (push) Successful in 2m39s
Build Docker Image / Clean-Registry (push) Successful in 3s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-05-06 09:25:45 +02:00
56 changed files with 500 additions and 295 deletions
@@ -14,7 +14,6 @@ import de.srsoftware.umbrella.bookmarks.BookmarkApi;
import de.srsoftware.umbrella.company.CompanyModule; import de.srsoftware.umbrella.company.CompanyModule;
import de.srsoftware.umbrella.contact.ContactModule; import de.srsoftware.umbrella.contact.ContactModule;
import de.srsoftware.umbrella.core.SettingsService; import de.srsoftware.umbrella.core.SettingsService;
import de.srsoftware.umbrella.core.Util;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.documents.DocumentApi; import de.srsoftware.umbrella.documents.DocumentApi;
import de.srsoftware.umbrella.files.FileModule; import de.srsoftware.umbrella.files.FileModule;
@@ -34,7 +33,6 @@ import de.srsoftware.umbrella.translations.Translations;
import de.srsoftware.umbrella.user.UserModule; import de.srsoftware.umbrella.user.UserModule;
import de.srsoftware.umbrella.web.WebHandler; import de.srsoftware.umbrella.web.WebHandler;
import de.srsoftware.umbrella.wiki.WikiModule; import de.srsoftware.umbrella.wiki.WikiModule;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -63,8 +61,6 @@ public class Application {
var port = config.get("umbrella.http.port", 8080); var port = config.get("umbrella.http.port", 8080);
var threads = config.get("umbrella.threads", 16); var threads = config.get("umbrella.threads", 16);
config.get("umbrella.plantuml").map(Object::toString).map(File::new).filter(File::exists).ifPresent(Util::setPlantUmlJar);
var server = HttpServer.create(new InetSocketAddress(port), 0); var server = HttpServer.create(new InetSocketAddress(port), 0);
try { try {
new Translations(config).bindPath("/api/translations").on(server); new Translations(config).bindPath("/api/translations").on(server);
@@ -80,7 +76,7 @@ public class Application {
new DocumentApi(config).bindPath("/api/document").on(server); new DocumentApi(config).bindPath("/api/document").on(server);
new UserLegacy(config).bindPath("/legacy/user").on(server); new UserLegacy(config).bindPath("/legacy/user").on(server);
new NotesLegacy(config).bindPath("/legacy/notes").on(server); new NotesLegacy(config).bindPath("/legacy/notes").on(server);
new MarkdownApi().bindPath("/api/markdown").on(server); new MarkdownApi(config).bindPath("/api/markdown").on(server);
new NoteModule(config).bindPath("/api/notes").on(server); new NoteModule(config).bindPath("/api/notes").on(server);
new StockModule(config).bindPath("/api/stock").on(server); new StockModule(config).bindPath("/api/stock").on(server);
new PollModule(config).bindPath("/api/poll").on(server); new PollModule(config).bindPath("/api/poll").on(server);
@@ -1,7 +1,6 @@
/* © SRSoftware 2025 */ /* © SRSoftware 2025 */
package de.srsoftware.umbrella.core; package de.srsoftware.umbrella.core;
import de.srsoftware.umbrella.core.api.*; import de.srsoftware.umbrella.core.api.*;
public class ModuleRegistry { public class ModuleRegistry {
@@ -7,6 +7,7 @@ import static de.srsoftware.tools.PathHandler.GET;
import static de.srsoftware.tools.PathHandler.POST; import static de.srsoftware.tools.PathHandler.POST;
import static de.srsoftware.tools.Strings.hex; import static de.srsoftware.tools.Strings.hex;
import static de.srsoftware.umbrella.core.Errors.INVALID_URL; import static de.srsoftware.umbrella.core.Errors.INVALID_URL;
import static de.srsoftware.umbrella.core.ModuleRegistry.markdownService;
import static de.srsoftware.umbrella.core.constants.Constants.TIME_FORMATTER; import static de.srsoftware.umbrella.core.constants.Constants.TIME_FORMATTER;
import static de.srsoftware.umbrella.core.constants.Field.*; import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.serverError; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.serverError;
@@ -14,7 +15,6 @@ import static java.lang.System.Logger.Level.*;
import static java.lang.System.Logger.Level.WARNING; import static java.lang.System.Logger.Level.WARNING;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.xrbpowered.jparsedown.JParsedown;
import de.srsoftware.tools.Mappable; import de.srsoftware.tools.Mappable;
import de.srsoftware.tools.Query; import de.srsoftware.tools.Query;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
@@ -31,18 +31,12 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import org.json.JSONObject; import org.json.JSONObject;
public class Util { public class Util {
public static final System.Logger LOG = System.getLogger("Util"); public static final System.Logger LOG = System.getLogger("Util");
private static final Pattern UML_PATTERN = Pattern.compile("@start(\\w+)(.*?)@end(\\1)",Pattern.DOTALL);
private static final Pattern SPREADSHEET_PATTERN = Pattern.compile("@startsheet(.*?)@endsheet",Pattern.DOTALL);
private static File plantumlJar = null;
private static final JParsedown MARKDOWN = new JParsedown();
public static final String SHA1 = "SHA-1"; public static final String SHA1 = "SHA-1";
private static final MessageDigest SHA1_DIGEST; private static final MessageDigest SHA1_DIGEST;
private static final Map<Integer,String> umlCache = new HashMap<>();
private static final String SCRIPT = """ private static final String SCRIPT = """
<script src="http://127.0.0.1:8080/js/jspreadsheet-ce.js"></script> <script src="http://127.0.0.1:8080/js/jspreadsheet-ce.js"></script>
@@ -111,71 +105,11 @@ jspreadsheet(document.getElementById('spreadsheet'), {
public static HashMap<String, Object> mapMarkdown(String source){ public static HashMap<String, Object> mapMarkdown(String source){
var map = new HashMap<String,Object>(); var map = new HashMap<String,Object>();
map.put(SOURCE,source); map.put(SOURCE,source);
map.put(RENDERED,markdown(source)); map.put(RENDERED,markdownService().markdown(source));
return map; return map;
} }
public static String markdown(String source){
if (source == null) return source;
try {
var matcher = SPREADSHEET_PATTERN.matcher(source);
var count = 0;
while (matcher.find()){
count++;
var sheetData = matcher.group(0).trim();
var start = matcher.start(0);
var end = matcher.end(0);
source = source.substring(0, start)
+ "<div class=\"spreadsheet\" id=\"spreadsheet-"+count+"\">"
+ sheetData.substring(11,sheetData.length()-10)
+ "</div>"
+ source.substring(end);
matcher = SPREADSHEET_PATTERN.matcher(source);
}
if (plantumlJar != null && plantumlJar.exists()) {
matcher = UML_PATTERN.matcher(source);
while (matcher.find()) {
var uml = matcher.group(0).trim();
var start = matcher.start(0);
var end = matcher.end(0);
var umlHash = uml.hashCode();
LOG.log(DEBUG,"Hash of Plantuml code: {0}",umlHash);
var svg = umlCache.get(umlHash);
if (svg != null){
LOG.log(DEBUG,"Serving Plantuml generated SVG from cache…");
source = source.substring(0, start) + svg + source.substring(end);
matcher = UML_PATTERN.matcher(source);
continue;
}
LOG.log(DEBUG,"Cache miss. Generating SVG from plantuml code…");
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", plantumlJar.getAbsolutePath(), "-tsvg", "-pipe");
var ignored = processBuilder.redirectErrorStream();
var process = processBuilder.start();
try (OutputStream os = process.getOutputStream()) {
os.write(uml.getBytes(UTF_8));
os.flush();
}
try (InputStream is = process.getInputStream()) {
byte[] out = is.readAllBytes();
LOG.log(DEBUG,"Generated SVG. Pushing to cache…");
svg = new String(out, UTF_8);
umlCache.put(umlHash,svg);
source = source.substring(0, start) + svg + source.substring(end);
matcher = UML_PATTERN.matcher(source);
}
}
}
return MARKDOWN.text(source);
} catch (Throwable e){
if (LOG.isLoggable(TRACE)){
LOG.log(TRACE,"Failed to render markdown, input was: \n{0}",source,e);
} else LOG.log(WARNING,"Failed to render markdown. Enable TRACE log level for details.");
return source;
}
}
public static HttpURLConnection open(URL url) throws IOException { public static HttpURLConnection open(URL url) throws IOException {
var conn = (HttpURLConnection) url.openConnection(); var conn = (HttpURLConnection) url.openConnection();
@@ -249,11 +183,6 @@ jspreadsheet(document.getElementById('spreadsheet'), {
return new Hash(hex(bytes),SHA1); return new Hash(hex(bytes),SHA1);
} }
public static void setPlantUmlJar(File file){
LOG.log(INFO,"Using plantuml @ {0}",file.getAbsolutePath());
plantumlJar = file;
}
public static String dateTimeOf(long epochMilis){ public static String dateTimeOf(long epochMilis){
return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilis), ZoneId.systemDefault()).format(TIME_FORMATTER); return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilis), ZoneId.systemDefault()).format(TIME_FORMATTER);
} }
@@ -2,4 +2,5 @@
package de.srsoftware.umbrella.core.api; package de.srsoftware.umbrella.core.api;
public interface MarkdownService { public interface MarkdownService {
String markdown(String source);
} }
@@ -15,6 +15,7 @@ public class Field {
public static final String BODY = "body"; public static final String BODY = "body";
public static final String CACHE_CONTROL = "Cache-Control"; public static final String CACHE_CONTROL = "Cache-Control";
public static final String CHILDREN = "Children";
public static final String CODE = "code"; public static final String CODE = "code";
public static final String COMMENT = "comment"; public static final String COMMENT = "comment";
public static final String COMPANY = "company"; public static final String COMPANY = "company";
@@ -34,6 +34,7 @@ public class Path {
public static final String OPTION = "option"; public static final String OPTION = "option";
public static final String PAGE = "page"; public static final String PAGE = "page";
public static final String PARENT_CANDIDATES = "parent_candidates";
public static final String PASSWORD = "password"; public static final String PASSWORD = "password";
public static final String PERMISSIONS = "permissions"; public static final String PERMISSIONS = "permissions";
public static final String PROJECT = "project"; public static final String PROJECT = "project";
@@ -91,10 +91,7 @@ public class Poll implements Mappable {
return Map.of( return Map.of(
ID,id, ID,id,
NAME,name, NAME,name,
DESCRIPTION, Map.of( DESCRIPTION, Util.mapMarkdown(description),
SOURCE,description,
RENDERED,Util.markdown(description)
),
STATUS,status STATUS,status
); );
} }
@@ -292,10 +289,7 @@ public class Poll implements Mappable {
ID, id, ID, id,
Field.OWNER, owner.toMap(), Field.OWNER, owner.toMap(),
NAME,name, NAME,name,
Field.DESCRIPTION, Map.of( Field.DESCRIPTION, Util.mapMarkdown(description),
Field.SOURCE,description,
Field.RENDERED,Util.markdown(description)
),
Field.OPTIONS, options.stream().collect(Collectors.toMap(Option::id,Option::toMap)), Field.OPTIONS, options.stream().collect(Collectors.toMap(Option::id,Option::toMap)),
Field.PERMISSION, mapPermissions(), Field.PERMISSION, mapPermissions(),
Field.PRIVATE, isPrivate, Field.PRIVATE, isPrivate,
@@ -144,4 +144,9 @@ public class Project implements Mappable {
map.put(TAG_COLORS,tagColors); map.put(TAG_COLORS,tagColors);
return map; return map;
} }
@Override
public String toString() {
return name();
}
} }
+1
View File
@@ -0,0 +1 @@
*.db-journal
Binary file not shown.
Binary file not shown.
Binary file not shown.
+74
View File
@@ -0,0 +1,74 @@
{
"umbrella": {
"base_url": "http://127.0.0.1:5173",
"logging": {
"rootLevel": "INFO"
},
"http": {
"port": 8080
},
"threads": 16,
"modules": {
"accounting": {
"database": "demodata/accounting.db"
},
"bookmark": {
"database": "demodata/bookmark.db"
},
"company": {
"database": "demodata/company.db"
},
"contact": {
"database": "demodata/contacts.db"
},
"document": {
"database": "demodata/documents.db",
"templates": "demodata/templates"
},
"files": {
"database": "demodata/files.db",
"base_dir": "demodata/filestore"
},
"journal": {
"database": "demodata/journal.db"
},
"message": {
"database": "demodata/message.db",
"smtp": {
"from": "umbrella@example.com",
"host": "none",
"pass": "none",
"port": 587,
"user": "none"
}
},
"notes": {
"database": "demodata/notes.db"
},
"poll": {
"database": "demodata/poll.db"
},
"project": {
"database": "demodata/projects.db"
},
"stock": {
"database": "demodata/stock.db"
},
"tags": {
"database": "demodata/tags.db"
},
"task": {
"database": "demodata/tasks.db"
},
"time": {
"database": "demodata/times.db"
},
"user": {
"database": "demodata/users.db"
},
"wiki": {
"database": "demodata/wiki.db"
}
}
}
}
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1
View File
@@ -116,6 +116,7 @@
<Route path="/project/:project_id/add_task" component={AddTask} /> <Route path="/project/:project_id/add_task" component={AddTask} />
<Route path="/project/:id/kanban" component={Kanban} /> <Route path="/project/:id/kanban" component={Kanban} />
<Route path="/project/:id/view" component={ViewPrj} /> <Route path="/project/:id/view" component={ViewPrj} />
<Route path="/project/:id" component={ViewPrj} />
<Route path="/search" component={Search} /> <Route path="/search" component={Search} />
<Route path="/stock" component={Stock} /> <Route path="/stock" component={Stock} />
<Route path="/stock/location/:location_id" component={Stock} /> <Route path="/stock/location/:location_id" component={Stock} />
+17 -14
View File
@@ -49,12 +49,16 @@
console.warn(`${candidate.display} selected, but onSelect not overridden!`) console.warn(`${candidate.display} selected, but onSelect not overridden!`)
} }
function disableDropdown(){
candidates = [];
selected = null;
}
async function ondblclick(evt){ async function ondblclick(evt){
const select = evt.target; const select = evt.target;
const idx = select.value; const idx = select.value;
candidate = candidates[idx]; candidate = candidates[idx];
candidates = []; disableDropdown();
selected = null;
onSelect(candidate); onSelect(candidate);
} }
@@ -63,6 +67,10 @@
selected = null; selected = null;
} }
function onblur(ev){
setTimeout(disableDropdown,400);
}
async function onkeyup(ev){ async function onkeyup(ev){
if (ignore.includes(ev.key)) return; if (ignore.includes(ev.key)) return;
if (ev.key == 'ArrowDown'){ if (ev.key == 'ArrowDown'){
@@ -83,22 +91,19 @@
ev.preventDefault(); ev.preventDefault();
if (selected != null && selected < candidates.length) { if (selected != null && selected < candidates.length) {
candidate = candidates[selected]; candidate = candidates[selected];
candidates = []; disableDropdown();
selected = null;
onSelect(candidate); onSelect(candidate);
return false; return false;
} }
if (ev.key == 'Enter') { if (ev.key == 'Enter') {
candidates = []; disableDropdown();
selected = null;
if (onCommit(candidate)) candidate = { display : '' }; if (onCommit(candidate)) candidate = { display : '' };
} }
return false; return false;
} }
if (ev.key == 'Escape'){ if (ev.key == 'Escape'){
ev.preventDefault(); ev.preventDefault();
candidates = []; disableDropdown();
selected = null;
return false; return false;
} }
@@ -110,10 +115,8 @@
function select(index){ function select(index){
candidate = candidates[index]; candidate = candidates[index];
selected = null; <disableDropdown></disableDropdown>();
candidates = [];
onSelect(candidate); onSelect(candidate);
} }
function scrollTo(index){ function scrollTo(index){
@@ -145,11 +148,11 @@
</style> </style>
<span class="autocomplete"> <span class="autocomplete">
<input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} {id} /> <input type="text" bind:value={candidate.display} {onkeyup} autofocus={autofocus} {id} {onblur} />
{#if candidates && candidates.length > 0} {#if candidates && candidates.length > 0}
<ul bind:this={list_elem} class="suggestions"> <ul bind:this={list_elem} class="suggestions" tabindex="-1">
{#each candidates as candidate,i} {#each candidates as candidate,i}
<li class="option {selected==i?'highlight':''}" onclick={e => select(i)} ondblclick={e => select(i)}>{candidate.display}</li> <li class="option {selected==i?'highlight':''}" tabindex="-1" onclick={e => select(i)} ondblclick={e => select(i)}>{candidate.display}</li>
{/each} {/each}
</ul> </ul>
{/if} {/if}
+2 -1
View File
@@ -33,6 +33,7 @@
authors = {...authors, ...data.authors}; authors = {...authors, ...data.authors};
loader.offset += loader.limit; loader.offset += loader.limit;
loader.active = false; loader.active = false;
console.log({authors});
yikes(); yikes();
if (Object.keys(data.notes).length) onscroll(null); // when notes were received, check whether they fill up the page if (Object.keys(data.notes).length) onscroll(null); // when notes were received, check whether they fill up the page
@@ -78,4 +79,4 @@
</svelte:head> </svelte:head>
<svelte:window {onscroll} /> <svelte:window {onscroll} />
<List {notes} /> <List {notes} {authors} />
+1
View File
@@ -64,6 +64,7 @@
<legend class="entity" onclick={() => goToEntity(note)}>{title(note)}</legend> <legend class="entity" onclick={() => goToEntity(note)}>{title(note)}</legend>
{/if} {/if}
<legend class="time"> <legend class="time">
{#if !module} {authors[note.user_id].name} {/if}
{note.timestamp.replace('T',' ')} {note.timestamp.replace('T',' ')}
{#if user.id == note.user_id} {#if user.id == note.user_id}
<button class="symbol" onclick={() => drop(note.id)}></button> <button class="symbol" onclick={() => drop(note.id)}></button>
+5 -11
View File
@@ -1,7 +1,7 @@
<script> <script>
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js'; import { api, post } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
@@ -21,13 +21,9 @@
}); });
async function onsubmit(ev){ async function onsubmit(ev){
ev.preventDefault(); if (ev) ev.preventDefault();
const url = api('project'); const url = api('project');
var resp = await fetch(url,{ var resp = await post(url,project);
credentials : 'include',
method : 'POST',
body : JSON.stringify(project)
});
if (resp.ok){ if (resp.ok){
var newProject = await resp.json(); var newProject = await resp.json();
router.navigate(`/project/${newProject.id}/view`); router.navigate(`/project/${newProject.id}/view`);
@@ -50,7 +46,6 @@
label{ display: block } label{ display: block }
</style> </style>
<form {onsubmit}>
<fieldset> <fieldset>
<legend> <legend>
{t('create_new_project')} {t('create_new_project')}
@@ -110,12 +105,11 @@
{t('tags')} {t('tags')}
</th> </th>
<td> <td>
<Tags module="project" bind:tags={project.tags} /> <Tags module={null} bind:tags={project.tags} onEmptyCommit={onsubmit} />
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</fieldset> </fieldset>
<button type="submit" disabled={!ready}>{t('create')}</button> <button onclick={onsubmit} disabled={!ready}>{t('create')}</button>
</fieldset> </fieldset>
</form>
+20 -12
View File
@@ -2,7 +2,7 @@
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, eventStream } from '../../urls.svelte'; import { api, eventStream, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
@@ -35,11 +35,7 @@
async function addState(){ async function addState(){
const url = api(`project/${id}/state`); const url = api(`project/${id}/state`);
const resp = await fetch(url,{ const resp = await post(url,new_state);
credentials: 'include',
method: 'POST',
body: JSON.stringify(new_state)
});
if (resp.ok){ if (resp.ok){
const json = await resp.json(); const json = await resp.json();
project.allowed_states[json.code] = json.name; project.allowed_states[json.code] = json.name;
@@ -139,11 +135,7 @@
async function update(data){ async function update(data){
const url = api(`project/${id}`); const url = api(`project/${id}`);
const resp = await fetch(url,{ const resp = await patch(url,data);
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
yikes(); yikes();
project = await resp.json(); project = await resp.json();
@@ -160,6 +152,20 @@
update({members:members}); update({members:members});
} }
async function updateStateName(state_id,name){
const url = api(`project/${id}/state`);
const resp = await patch(url,{id:state_id,name});
if (resp.ok){
const json = await resp.json();
project.allowed_states[json.code]=json.name;
yikes();
return true;
} else {
error(resp);
return false;
}
}
function showClosed(){ function showClosed(){
show_closed = !show_closed; show_closed = !show_closed;
loadTasks(); loadTasks();
@@ -243,7 +249,9 @@
{/if} {/if}
{key} {key}
</div> </div>
<div>{project.allowed_states[key]}</div> <div>
<LineEditor value={project.allowed_states[key]} editable={true} onSet={newName => updateStateName(+key,newName)} />
</div>
{/each} {/each}
<div> <div>
<input type="number" bind:value={new_state.code} /> <input type="number" bind:value={new_state.code} />
+4 -7
View File
@@ -2,7 +2,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, get } from '../../urls.svelte.js'; import { api, get, post } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js'; import { user } from '../../user.svelte.js';
@@ -79,6 +79,7 @@
task.members[assignee] = project.members[assignee]; task.members[assignee] = project.members[assignee];
task.members[assignee].permission = { name : "ASSIGNEE", code : 3 } task.members[assignee].permission = { name : "ASSIGNEE", code : 3 }
} }
if (task.taks.length < 1) task.tags = project.tags;
yikes(); yikes();
} else { } else {
error(resp); error(resp);
@@ -104,11 +105,7 @@
async function saveTask(){ async function saveTask(){
const url = api('task/add'); const url = api('task/add');
const resp = await fetch(url,{ const resp = await post(url,task);
credentials : 'include',
method : 'POST',
body : JSON.stringify(task)
});
if (resp.ok) { if (resp.ok) {
localStorage.removeItem(`task/${task.id}/description`); localStorage.removeItem(`task/${task.id}/description`);
if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else! if (!assignee) { // if assignee is set, this form was opened within an external context. hence we don`t want to navigate somewhere else!
@@ -158,7 +155,7 @@
</div> </div>
<div>{t('tags')}</div> <div>{t('tags')}</div>
<div> <div>
<Tags module="task" bind:tags={task.tags} /> <Tags module={null} bind:tags={task.tags} onEmptyCommit={saveTask} />
</div> </div>
{#if extendedSettings} {#if extendedSettings}
+6 -23
View File
@@ -3,7 +3,7 @@
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { dragged } from './dragndrop.svelte'; import { dragged } from './dragndrop.svelte';
import { api } from '../../urls.svelte'; import { api, drop, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
import { timetrack } from '../../user.svelte'; import { timetrack } from '../../user.svelte';
@@ -47,10 +47,7 @@
async function deleteTask(){ async function deleteTask(){
if (confirm(t('confirm_delete',{element:task.name}))){ if (confirm(t('confirm_delete',{element:task.name}))){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await drop(url);
credentials : 'include',
method : 'DELETE'
});
if (resp.ok){ if (resp.ok){
deleted = true; deleted = true;
} else { } else {
@@ -70,11 +67,7 @@
ev.stopPropagation(); ev.stopPropagation();
if (dragged.element.id == task.id) return; if (dragged.element.id == task.id) return;
const url = api(`task/${dragged.element.id}`); const url = api(`task/${dragged.element.id}`);
const resp = await fetch(url,{ const resp = await patch(url, { parent_task_id : task.id});
credentials : 'include',
method : 'PATCH',
body : JSON.stringify({ parent_task_id : task.id})
});
if (resp.ok) { if (resp.ok) {
yikes(); yikes();
} else { } else {
@@ -90,11 +83,7 @@
show_closed : show_closed show_closed : show_closed
}; };
if (task.show_closed) data.show_closed = true; if (task.show_closed) data.show_closed = true;
const resp = await fetch(url,{ const resp = await post(url,data);
credentials : 'include',
method : 'POST',
body : JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
children = await resp.json(); children = await resp.json();
yikes(); yikes();
@@ -112,11 +101,7 @@
async function patchTask(changeset){ async function patchTask(changeset){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await patch(url,changeset);
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(changeset)
});
if (resp.ok){ if (resp.ok){
task = await resp.json(); task = await resp.json();
return true; return true;
@@ -145,9 +130,7 @@
if (children && lastEvent && lastEvent.task) { if (children && lastEvent && lastEvent.task) {
if (lastEvent.event == 'delete' || lastEvent.task.parent_task_id != task.id){ if (lastEvent.event == 'delete' || lastEvent.task.parent_task_id != task.id){
delete children[lastEvent.task.id]; delete children[lastEvent.task.id];
} else { } else children[lastEvent.task.id] = lastEvent.task;
children[lastEvent.task.id] = lastEvent.task;
}
} }
}); });
@@ -0,0 +1,27 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import TaskTree from './Tree.svelte';
let { project, select = o => {}, task } = $props();
let tree = $state({});
async function loadParentCandidates(){
let url = api(`task/${task.id}/parent_candidates`);
let res = await get(url);
if (res.ok){
yikes();
tree = await res.json();
} else error(res);
}
onMount(loadParentCandidates);
</script>
<div class="overlay parent_selector">
<h2>{t('select a new parent for {entity}',{entity:task.name})}</h2>
{t('project')}: {project.name}
<TaskTree {tree} {select} />
</div>
+8 -18
View File
@@ -2,7 +2,7 @@
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte'; import { api, get, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
@@ -17,7 +17,7 @@
async function add(new_task_id){ async function add(new_task_id){
let url = api(`task/${new_task_id}`); let url = api(`task/${new_task_id}`);
let resp = await fetch(url,{ credentials : 'include' }); let resp = await get(url);
if (resp.ok){ if (resp.ok){
yikes(); yikes();
let newTask = await resp.json(); let newTask = await resp.json();
@@ -27,7 +27,7 @@
} }
task.required_tasks_ids.push(new_task_id); task.required_tasks_ids.push(new_task_id);
requiredTasks[new_task_id] = newTask; requiredTasks[new_task_id] = newTask;
await patch(); await update();
delete candidates[new_task_id]; delete candidates[new_task_id];
} else { } else {
error(resp); error(resp);
@@ -59,17 +59,11 @@
async function loadTasks(){ async function loadTasks(){
if (!task || !task.required_tasks_ids || !task.required_tasks_ids.length) return; if (!task || !task.required_tasks_ids || !task.required_tasks_ids.length) return;
const url = api('task/list'); const url = api('task/list');
const res = await fetch(url,{ const res = await post(url,{ids:task.required_tasks_ids});
credentials : 'include',
method : 'POST',
body : JSON.stringify({ids:task.required_tasks_ids})
});
if (res.ok){ if (res.ok){
yikes(); yikes();
requiredTasks = await res.json(); requiredTasks = await res.json();
} else { } else error(resp);
error(resp);
}
} }
function oninput(){ function oninput(){
@@ -84,19 +78,15 @@
return false; return false;
} }
async function patch(){ async function update(){
const url = api(`task/${task.id}`); const url = api(`task/${task.id}`);
const resp = await fetch(url,{ const resp = await patch(url,{required_tasks_ids:task.required_tasks_ids});
credentials : 'include',
method : 'PATCH',
body : JSON.stringify({required_tasks_ids:task.required_tasks_ids})
});
if (!resp.ok) error(resp); if (!resp.ok) error(resp);
} }
async function unlink(required_task){ async function unlink(required_task){
task.required_tasks_ids = task.required_tasks_ids.filter(item => item != required_task.id); task.required_tasks_ids = task.required_tasks_ids.filter(item => item != required_task.id);
patch(); update();
delete requiredTasks[required_task.id]; delete requiredTasks[required_task.id];
} }
+1 -1
View File
@@ -8,7 +8,7 @@
</script> </script>
<ul> <ul>
{#each sortedTasks as task} {#each sortedTasks as task (task.id)}
<ListTask {states} {task} {lastEvent} siblings={tasks} {est_time} show_closed={show_closed || task.show_closed} /> <ListTask {states} {task} {lastEvent} siblings={tasks} {est_time} show_closed={show_closed || task.show_closed} />
{/each} {/each}
</ul> </ul>
+23
View File
@@ -0,0 +1,23 @@
<script>
let { select = o => {}, tree } = $props();
let nodes = $derived(Object.values(tree).sort((a,b) => a.name.localeCompare(b.name)))
function onclick(ev,node){
ev.preventDefault();
ev.stopPropagation();
select(node);
return true;
}
</script>
<ul>
{#each nodes as node (node.id)}
<li onclick={ev => onclick(ev,node)}>
{node.name}
{#if node.Children}
<svelte:self tree={node.Children} {select} />
{/if}
</li>
{/each}
</ul>
+37 -34
View File
@@ -2,7 +2,7 @@
import { onDestroy } from 'svelte'; import { onDestroy } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router'; import { useTinyRouter } from 'svelte-tiny-router';
import { api, eventStream } from '../../urls.svelte'; import { api, eventStream, get, patch, post } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
import { timetrack } from '../../user.svelte.js'; import { timetrack } from '../../user.svelte.js';
@@ -10,6 +10,7 @@
import LineEditor from '../../Components/LineEditor.svelte'; import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte'; import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import ParentSelector from './ParentSelector.svelte';
import PermissionEditor from '../../Components/PermissionEditor.svelte'; import PermissionEditor from '../../Components/PermissionEditor.svelte';
import Notes from '../notes/RelatedNotes.svelte'; import Notes from '../notes/RelatedNotes.svelte';
import StateSelector from '../../Components/StateSelector.svelte'; import StateSelector from '../../Components/StateSelector.svelte';
@@ -22,6 +23,7 @@
let children = $state(null); let children = $state(null);
let dummy = $derived(updateOn(id)); let dummy = $derived(updateOn(id));
let est_time = $state({sum:0}); let est_time = $state({sum:0});
let select_parent = $state(false);
let project = $state(null); let project = $state(null);
const router = useTinyRouter(); const router = useTinyRouter();
let showSettings = $state(router.fullPath.endsWith('/edit')); let showSettings = $state(router.fullPath.endsWith('/edit'));
@@ -74,12 +76,6 @@
router.navigate(`/project/${project.id}/kanban`) router.navigate(`/project/${project.id}/kanban`)
} }
function gotoParent(){
if (!task.parent_task_id) return;
router.navigate(`/task/${task.parent_task_id}/view`)
}
function gotoProject(){ function gotoProject(){
if (!project) return; if (!project) return;
router.navigate(`/project/${project.id}/view`) router.navigate(`/project/${project.id}/view`)
@@ -99,32 +95,24 @@
parent_task_id : +task.id, parent_task_id : +task.id,
show_closed : show_closed show_closed : show_closed
}; };
const resp = await fetch(url,{ const resp = await post(url,data);
credentials : 'include',
method : 'POST',
body:JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
yikes(); yikes();
children = await resp.json(); children = await resp.json();
} else { } else error(resp);
error(resp);
}
} }
async function loadParent(){ async function loadParent(){
const url = api(`task/${task.parent_task_id}`); const url = api(`task/${task.parent_task_id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
task.parent = await resp.json(); task.parent = await resp.json();
} else { } else error(resp);
error(resp);
}
} }
async function loadTask(){ async function loadTask(){
const url = api(`task/${id}`); const url = api(`task/${id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
yikes(); yikes();
task = await resp.json(); task = await resp.json();
@@ -132,20 +120,29 @@
loadChildren(); loadChildren();
if (task.project_id) loadProject(); if (task.project_id) loadProject();
if (task.parent_task_id) loadParent(); if (task.parent_task_id) loadParent();
} else { } else error(resp);
error(resp);
}
} }
async function loadProject(){ async function loadProject(){
const url = api(`project/${task.project_id}`); const url = api(`project/${task.project_id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await get(url);
if (resp.ok){ if (resp.ok){
project = await resp.json(); project = await resp.json();
yikes(); yikes();
} else { } else error(await resp.text());
error(await resp.text());
} }
function parentClick(ev){
ev.preventDefault();
if (!task.parent_task_id) return;
router.navigate(`/task/${task.parent_task_id}/view`);
return false;
}
function parentRightClick(ev){
ev.preventDefault();
select_parent = true;
return false;
} }
function showClosed(){ function showClosed(){
@@ -169,11 +166,7 @@
async function update(data){ async function update(data){
const url = api(`task/${id}`); const url = api(`task/${id}`);
const resp = await fetch(url,{ const resp = await patch(url,data);
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
if (resp.ok){ if (resp.ok){
yikes(); yikes();
let json = await resp.json(); let json = await resp.json();
@@ -198,6 +191,11 @@
loadTask(); loadTask();
} }
function update_parent(newVal){
select_parent = false;
update({parent_task_id:newVal.id});
}
function updatePermission(user_id,permission){ function updatePermission(user_id,permission){
let members = {}; let members = {};
members[user_id] = permission.code; members[user_id] = permission.code;
@@ -223,13 +221,18 @@
<button class="symbol" title={t('files')} onclick={showPrjFiles}></button> <button class="symbol" title={t('files')} onclick={showPrjFiles}></button>
</div> </div>
{/if} {/if}
{#if task.parent}
<div>{t('parent_task')}</div> <div>{t('parent_task')}</div>
<div class="parent"> <div class="parent">
<a href="#" onclick={gotoParent}>{task.parent.name}</a> {#if select_parent}
<ParentSelector {task} {project} select={update_parent} />
{:else}
{#if task.parent}
<a href="/task/{task.parent.id}/view" onclick={parentClick} oncontextmenu={parentRightClick}>{task.parent.name}</a>
<button class="symbol" title={t('unlink')} onclick={unlink_parent}></button> <button class="symbol" title={t('unlink')} onclick={unlink_parent}></button>
</div>
{/if} {/if}
<button class="symbol" title={t('edit')} onclick={parentRightClick}></button>
{/if}
</div>
<div>{t('task')}</div> <div>{t('task')}</div>
<div class="name"> <div class="name">
<LineEditor bind:value={task.name} editable={true} onSet={val => update({name:val})} /> <LineEditor bind:value={task.name} editable={true} onSet={val => update({name:val})} />
@@ -3,9 +3,7 @@ package de.srsoftware.umbrella.legacy;
import static de.srsoftware.tools.Optionals.nullable; import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.ModuleRegistry.noteService; import static de.srsoftware.umbrella.core.ModuleRegistry.*;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.Util.markdown;
import static de.srsoftware.umbrella.core.constants.Field.TOKEN; import static de.srsoftware.umbrella.core.constants.Field.TOKEN;
import static de.srsoftware.umbrella.core.constants.Field.URI; import static de.srsoftware.umbrella.core.constants.Field.URI;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.invalidField;
@@ -72,7 +70,7 @@ public class NotesLegacy extends BaseHandler {
new Tag("fieldset") new Tag("fieldset")
.add(new Tag("legend").content(authorName)) .add(new Tag("legend").content(authorName))
.add(new Tag("legend").content(note.timestamp().format(DateTimeFormatter.ISO_DATE_TIME))) .add(new Tag("legend").content(note.timestamp().format(DateTimeFormatter.ISO_DATE_TIME)))
.add(new Tag("div").content(markdown(note.text()))) .add(new Tag("div").content(markdownService().markdown(note.text())))
.addTo(html); .addTo(html);
} }
return sendContent(ex,html.toString(2)); return sendContent(ex,html.toString(2));
@@ -3,21 +3,50 @@ package de.srsoftware.umbrella.markdown;
import static de.srsoftware.tools.MimeType.MIME_HTML; import static de.srsoftware.tools.MimeType.MIME_HTML;
import static de.srsoftware.umbrella.core.ModuleRegistry.userService; import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.constants.Field.BASE_URL;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingField;
import static java.lang.System.Logger.Level.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpExchange;
import com.xrbpowered.jparsedown.JParsedown;
import de.srsoftware.configuration.Configuration;
import de.srsoftware.tools.Path; import de.srsoftware.tools.Path;
import de.srsoftware.umbrella.core.BaseHandler; import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.ModuleRegistry; import de.srsoftware.umbrella.core.ModuleRegistry;
import de.srsoftware.umbrella.core.Util;
import de.srsoftware.umbrella.core.api.MarkdownService; import de.srsoftware.umbrella.core.api.MarkdownService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
public class MarkdownApi extends BaseHandler implements MarkdownService { public class MarkdownApi extends BaseHandler implements MarkdownService {
private static final System.Logger LOG = System.getLogger(MarkdownApi.class.getSimpleName());
private static final Pattern PATTERN_ANCHOR = Pattern.compile("(?is)<a\\b[^>]*>.*?</a>");
private static final Pattern PATTERN_HREF = Pattern.compile("(?i)\\bhref\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))");
private static final Pattern PATTERN_SPREADSHEET = Pattern.compile("@startsheet(.*?)@endsheet",Pattern.DOTALL);
private static final Pattern PATTERN_TARGET = Pattern.compile("(?i)\\btarget\\s*=");
private static final Pattern PATTERN_URL = Pattern.compile("@start(\\w+)(.*?)@end(\\1)",Pattern.DOTALL);
private static final Map<Integer,String> umlCache = new HashMap<>();
private static final JParsedown MARKDOWN = new JParsedown();
public MarkdownApi() {
private final String baseUrl;
private final File plantumlJar;
public MarkdownApi(Configuration config) {
super(); super();
Optional<String> baseUrl = config.get(BASE_URL);
if (baseUrl.isEmpty()) throw missingField(BASE_URL);
this.baseUrl = baseUrl.get();
plantumlJar = config.get("umbrella.plantuml").map(Object::toString).map(File::new).filter(File::exists).orElse(null);
if (plantumlJar != null) LOG.log(INFO,"Using plant uml @ {}",plantumlJar);
ModuleRegistry.add(this); ModuleRegistry.add(this);
} }
@@ -28,11 +57,98 @@ public class MarkdownApi extends BaseHandler implements MarkdownService {
var user = userService().refreshSession(ex); var user = userService().refreshSession(ex);
if (user.isEmpty()) throw UmbrellaException.forbidden("You must be logged in to use the markdown renderer!"); if (user.isEmpty()) throw UmbrellaException.forbidden("You must be logged in to use the markdown renderer!");
var rendered = Util.markdown(body(ex)); var rendered = markdown(body(ex));
ex.getResponseHeaders().add(CONTENT_TYPE,MIME_HTML); ex.getResponseHeaders().add(CONTENT_TYPE,MIME_HTML);
return sendContent(ex,rendered); return sendContent(ex,rendered);
} catch (UmbrellaException e){ } catch (UmbrellaException e){
return send(ex,e); return send(ex,e);
} }
} }
public String markdown(String source){
if (source == null || source.isBlank()) return source;
try {
var matcher = PATTERN_SPREADSHEET.matcher(source);
var count = 0;
while (matcher.find()){
LOG.log(DEBUG,"Processing spreadsheet code…");
count++;
var sheetData = matcher.group(0).trim();
var start = matcher.start(0);
var end = matcher.end(0);
source = source.substring(0, start)
+ "<div class=\"spreadsheet\" id=\"spreadsheet-"+count+"\">"
+ sheetData.substring(11,sheetData.length()-10)
+ "</div>"
+ source.substring(end);
LOG.log(DEBUG,"Updated markdown with spreadsheet div.");
matcher.reset(source);
}
if (plantumlJar != null && plantumlJar.exists()) {
matcher = PATTERN_URL.matcher(source);
while (matcher.find()) {
var uml = matcher.group(0).trim();
var start = matcher.start(0);
var end = matcher.end(0);
var umlHash = uml.hashCode();
LOG.log(DEBUG,"Hash of Plantuml code: {0}",umlHash);
var svg = umlCache.get(umlHash);
if (svg != null){
LOG.log(DEBUG,"Serving Plantuml generated SVG from cache…");
source = source.substring(0, start) + svg + source.substring(end);
matcher.reset(source);
continue;
}
LOG.log(DEBUG,"Cache miss. Generating SVG from plantuml code…");
ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", plantumlJar.getAbsolutePath(), "-tsvg", "-pipe");
var ignored = processBuilder.redirectErrorStream();
var process = processBuilder.start();
try (OutputStream os = process.getOutputStream()) {
os.write(uml.getBytes(UTF_8));
os.flush();
}
try (InputStream is = process.getInputStream()) {
byte[] out = is.readAllBytes();
LOG.log(DEBUG,"Generated SVG. Pushing to cache…");
svg = new String(out, UTF_8);
umlCache.put(umlHash,svg);
source = source.substring(0, start) + svg + source.substring(end);
matcher.reset(source);
}
}
}
var rendered = MARKDOWN.text(source);
if (baseUrl == null) return rendered;
var anchors = PATTERN_ANCHOR.matcher(rendered);
while (anchors.find()){
String anchor = anchors.group();
LOG.log(TRACE,"Processing anchor: {}",anchor);
var urls = PATTERN_HREF.matcher(anchor);
if (!urls.find()) continue; // no url nothing to do
var href = urls.group(1) != null ? urls.group(1) : (urls.group(2) != null ? urls.group(2) : urls.group(3));
LOG.log(TRACE," encountered href = {}",href);
if (!href.startsWith("http")) continue; // relative url? good!
LOG.log(TRACE," {} is not a relative url!",href);
var target = PATTERN_TARGET.matcher(anchor);
if (target.find()) continue; // target already set leave untouched
LOG.log(TRACE," anchor has no target!");
if (href.startsWith(baseUrl)) continue; // local url don`t touch
LOG.log(TRACE," {} is not an internal url, adding anchor…",href);
var replacement = "<a target=\"_blank\""+anchor.substring(2);
rendered = rendered.replace(anchor, replacement);
anchors.reset(rendered);
}
return rendered;
} catch (Throwable e){
if (LOG.isLoggable(TRACE)){
LOG.log(TRACE,"Failed to render markdown, input was: \n{0}",source,e);
} else LOG.log(WARNING,"Failed to render markdown. Enable TRACE log level for details.");
return source;
}
}
} }
@@ -97,6 +97,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
head = path.pop(); head = path.pop();
yield switch (head){ yield switch (head){
case null -> patchProject(ex,projectId,user.get()); case null -> patchProject(ex,projectId,user.get());
case Path.STATE -> patchProjectState(ex,projectId,user.get());
default -> super.doPatch(path,ex); default -> super.doPatch(path,ex);
}; };
} }
@@ -229,6 +230,19 @@ public class ProjectModule extends BaseHandler implements ProjectService {
return sendContent(ex,project.toMap()); return sendContent(ex,project.toMap());
} }
private boolean patchProjectState(HttpExchange ex, long projectId, UmbrellaUser user) throws IOException {
var project = loadMembers(projectDb.load(projectId));
if (!project.hasMember(user)) throw notAmember(t(PROJECT_WITH_ID,ID,project.name()));
var json = json(ex);
if (!json.has(ID)) throw missingField(ID);
if (!json.has(NAME)) throw missingField(NAME);
if (!(json.get(ID) instanceof Number fieldId)) throw invalidField(ID,Text.NUMBER);
var newName = json.getString(NAME);
if (newName.isBlank()) throw invalidField(NAME, STRING);
var newState = new Status(newName,fieldId.intValue());
return sendContent(ex, projectDb.save(projectId,newState));
}
private boolean postNewState(HttpExchange ex, long projectId, UmbrellaUser user) throws IOException { private boolean postNewState(HttpExchange ex, long projectId, UmbrellaUser user) throws IOException {
var project = loadMembers(load(projectId)); var project = loadMembers(load(projectId));
@@ -267,7 +267,7 @@ CREATE TABLE IF NOT EXISTS {0} (
@Override @Override
public Status save(long projectId, Status newState) { public Status save(long projectId, Status newState) {
try { try {
insertInto(TABLE_CUSTOM_STATES, PROJECT_ID, Field.CODE, NAME).values(projectId,newState.code(),newState.name()).execute(db).close(); replaceInto(TABLE_CUSTOM_STATES, PROJECT_ID, Field.CODE, NAME).values(projectId,newState.code(),newState.name()).execute(db).close();
return newState; return newState;
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException(FAILED_TO_CREATE_STATE).causedBy(e); throw databaseException(FAILED_TO_CREATE_STATE).causedBy(e);
@@ -2,6 +2,7 @@
package de.srsoftware.umbrella.task; package de.srsoftware.umbrella.task;
import static de.srsoftware.tools.Optionals.is0;
import static de.srsoftware.tools.jdbc.Condition.*; import static de.srsoftware.tools.jdbc.Condition.*;
import static de.srsoftware.tools.jdbc.Query.*; import static de.srsoftware.tools.jdbc.Query.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
@@ -236,7 +237,7 @@ CREATE TABLE IF NOT EXISTS {0} (
public Map<Long, Task> listProjectTasks(Long projectId, Long parentTaskId, boolean noIndex) throws UmbrellaException { public Map<Long, Task> listProjectTasks(Long projectId, Long parentTaskId, boolean noIndex) throws UmbrellaException {
try { try {
var query = select(ALL).from(TABLE_TASKS).where(PROJECT_ID,equal(projectId)); var query = select(ALL).from(TABLE_TASKS).where(PROJECT_ID,equal(projectId));
if (parentTaskId != 0) query.where(PARENT_TASK_ID,equal(parentTaskId)); if (!is0(parentTaskId)) query.where(PARENT_TASK_ID,equal(parentTaskId));
if (!noIndex) query.where(NO_INDEX,notIn(1)); if (!noIndex) query.where(NO_INDEX,notIn(1));
var tasks = new HashMap<Long,Task>(); var tasks = new HashMap<Long,Task>();
var rs = query.exec(db); var rs = query.exec(db);
@@ -32,6 +32,7 @@ import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.BaseHandler; import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.ModuleRegistry; import de.srsoftware.umbrella.core.ModuleRegistry;
import de.srsoftware.umbrella.core.api.*; import de.srsoftware.umbrella.core.api.*;
import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Text; import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*; import de.srsoftware.umbrella.core.model.*;
@@ -110,8 +111,11 @@ public class TaskModule extends BaseHandler implements TaskService {
case null -> getUserTasks(user.get(), ex); case null -> getUserTasks(user.get(), ex);
default -> { default -> {
var taskId = Long.parseLong(head); var taskId = Long.parseLong(head);
head = path.pop(); yield switch (path.pop()){
yield head == null ? getTask(ex, taskId, user.get()) : super.doGet(path, ex); case null -> getTask(ex,taskId,user.get());
case PARENT_CANDIDATES -> getParentCandidates(ex,taskId, user.get());
default -> super.doGet(path,ex);
};
} }
}; };
} catch (UmbrellaException e) { } catch (UmbrellaException e) {
@@ -188,6 +192,33 @@ public class TaskModule extends BaseHandler implements TaskService {
return sendContent(ex, result); return sendContent(ex, result);
} }
private boolean getParentCandidates(HttpExchange ex, long taskId, UmbrellaUser user) throws IOException {
var task = taskDb.load(taskId);
var project = projectService().load(task.projectId());
var projectTasks = taskDb.listProjectTasks(project.id(),null, false);
var mapped = projectTasks.values().stream().collect(Collectors.toMap(Task::id,Task::toMap));
var roots = new HashMap<Long,Map<String,Object>>();
for (var map : mapped.values()){
if (!(map.get(ID) instanceof Long id)) continue;
if (id == taskId) continue;
if (map.get(PARENT_TASK_ID) instanceof Long parentId) {
var parent = mapped.get(parentId);
if (parent != null) {
var o = parent.get(Field.CHILDREN);
Map<Long,Object> children;
if (o == null) {
children = new HashMap<>();
parent.put(Field.CHILDREN,children);
} else children = (Map<Long, Object>) o;
children.put(id, map);
}
} else {
roots.put(id, map);
}
}
return sendContent(ex,roots);
}
private boolean getPermissionList(HttpExchange ex) throws IOException { private boolean getPermissionList(HttpExchange ex) throws IOException {
var map = new HashMap<Integer, String>(); var map = new HashMap<Integer, String>();
for (var permission : Permission.values()) map.put(permission.code(),permission.name()); for (var permission : Permission.values()) map.put(permission.code(),permission.name());
@@ -293,7 +324,7 @@ public class TaskModule extends BaseHandler implements TaskService {
Task parent = taskMap.get(task.parentTaskId()); Task parent = taskMap.get(task.parentTaskId());
var trunk = placeInTree(parent, taskTree, taskMap); var trunk = placeInTree(parent, taskTree, taskMap);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<Object> children = (ArrayList<Object>) trunk.computeIfAbsent(CHILDREN, k -> new ArrayList<>()); ArrayList<Object> children = (ArrayList<Object>) trunk.computeIfAbsent(Field.CHILDREN, k -> new ArrayList<>());
children.add(mappedTask); children.add(mappedTask);
return mappedTask; return mappedTask;
} }
+1
View File
@@ -325,6 +325,7 @@
"save_object": "{object} speichern", "save_object": "{object} speichern",
"search": "Suche", "search": "Suche",
"searching…": "suche…", "searching…": "suche…",
"select a new parent for {entity}": "Neue Über-Aufgabe für „{entity}“ wählen",
"select_company" : "Wählen Sie eine ihrer Firmen:", "select_company" : "Wählen Sie eine ihrer Firmen:",
"select_customer": "Kunde auswählen", "select_customer": "Kunde auswählen",
"select_property": "Eigenschaft auswählen", "select_property": "Eigenschaft auswählen",
+1
View File
@@ -325,6 +325,7 @@
"save_object": "save {object}", "save_object": "save {object}",
"search": "search", "search": "search",
"searching…": "searhcing…", "searching…": "searhcing…",
"select a new parent for {entity}": "select a new parent for '{entity}'",
"select_company" : "select on of you companies:", "select_company" : "select on of you companies:",
"select_customer": "select customer", "select_customer": "select customer",
"select_property": "select property", "select_property": "select property",
@@ -74,6 +74,7 @@ tr:hover .taglist .tag button {
color: black; color: black;
} }
code,
.code{ .code{
color: chocolate; color: chocolate;
} }
+11 -1
View File
@@ -15,9 +15,10 @@ body {
background-position: 98% 70px; background-position: 98% 70px;
background-attachment: fixed; background-attachment: fixed;
} }
.code,
code { code {
font-size: 16px; font-size: 16px;
font-family: monospace;
} }
fieldset { fieldset {
@@ -761,3 +762,12 @@ fieldset.vcard{
white-space: nowrap; white-space: nowrap;
display: inline flow-root; display: inline flow-root;
} }
.parent_selector > ul {
position: absolute;
top: 120px;
left: 0;
right: 0;
bottom: 0;
overflow: auto;
}