implemented configurable menu, needs testing!
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,19 +1,27 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.constants.Constants.CLASS;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.MENU;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.USERS;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.constants.Module;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.MENU;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SettingsService extends BaseHandler {
|
||||
|
||||
@@ -40,12 +48,68 @@ public class SettingsService extends BaseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private record MenuEntry(int pos, String module, String clazz, String title) implements Mappable {
|
||||
public static MenuEntry of(int pos, String module){
|
||||
return new MenuEntry(pos, module, module, module);
|
||||
}
|
||||
|
||||
public static MenuEntry of(int pos, String module, String title){
|
||||
return new MenuEntry(pos,module,module,title);
|
||||
}
|
||||
public static MenuEntry of(int pos, String module, String clazz, String title){
|
||||
return new MenuEntry(pos,module,clazz,title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(MODULE,module,CLASS,clazz,TITLE,title);
|
||||
}
|
||||
}
|
||||
private boolean getMenuSettings(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
Optional<JSONObject> modules = config.get("umbrella.modules");
|
||||
if (modules.isEmpty()) throw UmbrellaException.missingConfig("umbrella.modules");
|
||||
var key = modules.get().keySet();
|
||||
|
||||
var entries = new ArrayList<MenuEntry>();
|
||||
entries.add(MenuEntry.of(1, Module.USER, USERS));
|
||||
entries.add(MenuEntry.of(2, Module.COMPANY, COMPANIES));
|
||||
entries.add(MenuEntry.of(3, Module.PROJECT,Text.PROJECTS));
|
||||
entries.add(MenuEntry.of(4,Module.TASK,Text.TASKS));
|
||||
entries.add(MenuEntry.of(5,Module.TAGS));
|
||||
entries.add(MenuEntry.of(6,Module.DOCUMENT,"doc",Text.DOCUMENTS));
|
||||
entries.add(MenuEntry.of(7,Module.BOOKMARK,"mark",BOOKMARKS));
|
||||
entries.add(MenuEntry.of(8,Module.NOTES,"note",Text.NOTES));
|
||||
entries.add(MenuEntry.of(9,Module.FILES,"file", FILES));
|
||||
entries.add(MenuEntry.of(10,Module.TIME, Text.TIMETRACKING));
|
||||
entries.add(MenuEntry.of(11,Module.WIKI));
|
||||
entries.add(MenuEntry.of(12,Module.CONTACT, CONTACTS));
|
||||
entries.add(MenuEntry.of(13,Module.STOCK));
|
||||
entries.add(MenuEntry.of(14,Module.MESSAGE, MESSAGES));
|
||||
entries.add(MenuEntry.of(15,Module.POLL,Text.POLLS));
|
||||
|
||||
return notFound(ex);
|
||||
for (var i=0; i<entries.size(); i++){
|
||||
var entry = entries.get(i);
|
||||
var key = format("umbrella.modules.{0}.menuIndex",entry.module);
|
||||
Optional<Integer> val = config.get(key);
|
||||
if (val.isPresent()) {
|
||||
var index = val.get();
|
||||
if (index<0) {
|
||||
entries.remove(i);
|
||||
i--;
|
||||
continue;
|
||||
} else {
|
||||
entry = MenuEntry.of(index,entry.module,entry.clazz,entry.title);
|
||||
entries.set(i,entry);
|
||||
}
|
||||
}
|
||||
key = format("umbrella.modules.{0}.baseUrl",entry.module);
|
||||
Optional<String> baseUrl = config.get(key);
|
||||
if (baseUrl.isPresent()) {
|
||||
entry = MenuEntry.of(entry.pos,baseUrl.get(), entry.clazz,entry.title);
|
||||
entries.set(i,entry);
|
||||
}
|
||||
}
|
||||
var list = entries.stream().sorted((a,b) -> a.pos - b.pos)
|
||||
.map(MenuEntry::toMap).toList();
|
||||
return sendContent(ex,list);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public class Constants {
|
||||
// prevent instantiation
|
||||
}
|
||||
|
||||
public static final String CLASS = "class";
|
||||
public static final String CONFIG_SESSION_DURATION = "umbrella.session.duration";
|
||||
public static final String COUNT = "COUNT(*)";
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ public class Field {
|
||||
public static final String LOGIN = "login";
|
||||
|
||||
public static final String MEMBERS = "members";
|
||||
public static final String MENU_INDEX = "menu_index";
|
||||
public static final String MESSAGE_ID = "message_id";
|
||||
public static final String MIME = "mime";
|
||||
public static final String MODULE = "module";
|
||||
|
||||
@@ -4,8 +4,17 @@ package de.srsoftware.umbrella.core.constants;
|
||||
public class Module {
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String CONTACT = "contact";
|
||||
public static final String DOCUMENT = "document";
|
||||
public static final String FILES = "files";
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String NOTES = "notes";
|
||||
public static final String POLL = "poll";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String STOCK = "stock";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TASK = "task";
|
||||
public static final String TIME = "time";
|
||||
public static final String USER = "user";
|
||||
public static final String WIKI = "wiki";
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ package de.srsoftware.umbrella.core.constants;
|
||||
* This is a collection of messages that appear throughout the project
|
||||
*/
|
||||
public class Text {
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String BOOLEAN = "Boolean";
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
public static final String BOOKMARKS = "bookmarks";
|
||||
public static final String BOOLEAN = "Boolean";
|
||||
|
||||
public static final String COMPANIES = "companies";
|
||||
public static final String COMPANY = "company";
|
||||
@@ -24,6 +25,8 @@ public class Text {
|
||||
|
||||
public static final String EMAILS_FOR_RECEIVER = "emails for {email}";
|
||||
|
||||
public static final String FILES = "files";
|
||||
|
||||
public static final String INVALID_DB_CODE = "Encountered invalid dbCode: {code}";
|
||||
public static final String ITEM = "item";
|
||||
public static final String ITEMS = "items";
|
||||
@@ -34,13 +37,16 @@ public class Text {
|
||||
public static final String LONG = "Long";
|
||||
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String MESSAGES = "messages";
|
||||
|
||||
public static final String NOTE = "note";
|
||||
public static final String NOTES = "notes";
|
||||
public static final String NOTE_WITH_ID = "note ({id})";
|
||||
public static final String NUMBER = "number";
|
||||
|
||||
public static final String PATH = "path";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String POLLS = "polls";
|
||||
public static final String PROJECTS = "projects";
|
||||
public static final String PROJECT_WITH_ID = "project ({id})";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
@@ -52,18 +58,21 @@ public class Text {
|
||||
public static final String SERVICE_WITH_ID = "service ({id})";
|
||||
public static final String SESSION = "session";
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String STOCK = "stock";
|
||||
public static final String STRING = "string";
|
||||
|
||||
public static final String TABLE_WITH_NAME = "table {name}";
|
||||
public static final String TAGS = "tags";
|
||||
public static final String TASK = "task";
|
||||
public static final String TASKS = "tasks";
|
||||
public static final String TIMETRACKING = "timetracking";
|
||||
public static final String TIME_WITH_ID = "time ({id})";
|
||||
public static final String TYPE = "type";
|
||||
|
||||
public static final String UNIT = "unit";
|
||||
public static final String USER_WITH_ID = "user ({id})";
|
||||
|
||||
public static final String WIKI = "wiki";
|
||||
public static final String WIKI_PAGE = "wiki page";
|
||||
public static final String WIKI_PAGES = "wiki pages";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user