working on wiki index
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package de.srsoftware.umbrella.core.model;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Mappable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.ID;
|
||||||
|
|
||||||
|
public class WikiPage implements Mappable {
|
||||||
|
|
||||||
|
private final long id;
|
||||||
|
|
||||||
|
public WikiPage(long id){
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> toMap() {
|
||||||
|
return Map.of(ID,id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
import ViewDoc from "./routes/document/View.svelte";
|
import ViewDoc from "./routes/document/View.svelte";
|
||||||
import ViewPrj from "./routes/project/View.svelte";
|
import ViewPrj from "./routes/project/View.svelte";
|
||||||
import ViewTask from "./routes/task/View.svelte";
|
import ViewTask from "./routes/task/View.svelte";
|
||||||
|
import WikiIndex from "./routes/wiki/Index.svelte";
|
||||||
|
|
||||||
let translations_ready = $state(false);
|
let translations_ready = $state(false);
|
||||||
|
|
||||||
@@ -87,6 +88,7 @@
|
|||||||
<Route path="/user/:user_id/edit" component={EditUser} />
|
<Route path="/user/:user_id/edit" component={EditUser} />
|
||||||
<Route path="/user/oidc/add" component={EditService} />
|
<Route path="/user/oidc/add" component={EditService} />
|
||||||
<Route path="/user/oidc/edit/:serviceName" component={EditService} />
|
<Route path="/user/oidc/edit/:serviceName" component={EditService} />
|
||||||
|
<Route path="/wiki" component={WikiIndex} />
|
||||||
<Route>
|
<Route>
|
||||||
Not found!
|
Not found!
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
37
frontend/src/routes/wiki/Index.svelte
Normal file
37
frontend/src/routes/wiki/Index.svelte
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { api } from '../../urls.svelte';
|
||||||
|
import { t } from '../../translations.svelte';
|
||||||
|
|
||||||
|
let error = $state(null);
|
||||||
|
let pages = $state(null);
|
||||||
|
let lastLetter = null;
|
||||||
|
|
||||||
|
async function loadPageList(){
|
||||||
|
const url = api('wiki');
|
||||||
|
const res = await fetch(url,{credentials:'include'});
|
||||||
|
if (res.ok){
|
||||||
|
pages = await res.json();
|
||||||
|
} else {
|
||||||
|
error = await res.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(loadPageList);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<span class="error">{error}</span>
|
||||||
|
{/if}
|
||||||
|
<h1>{t('wiki')}</h1>
|
||||||
|
{#if pages}
|
||||||
|
{#each pages as page}
|
||||||
|
{#if page.charAt(0).toUpperCase() != lastLetter}
|
||||||
|
|
||||||
|
<h2>{lastLetter = page.charAt(0).toUpperCase()||page.charAt(0).toUpperCase()}</h2>
|
||||||
|
{/if}
|
||||||
|
<div>
|
||||||
|
<a href={`/wiki/${page}/view`}>{page}</a>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
@@ -9,6 +9,6 @@ public class Constants {
|
|||||||
public static final String PAGE_ID = "page_id";
|
public static final String PAGE_ID = "page_id";
|
||||||
public static final String PERMISSIONS = "permissions";
|
public static final String PERMISSIONS = "permissions";
|
||||||
public static final String TABLE_PAGES = "pages";
|
public static final String TABLE_PAGES = "pages";
|
||||||
public static final String TABLE_PAGES_USERS = "pages_users";
|
public static final String TABLE_PAGES_USERS = "page_users";
|
||||||
public static final String VERSION = "version";
|
public static final String VERSION = "version";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
package de.srsoftware.umbrella.wiki;
|
package de.srsoftware.umbrella.wiki;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.jdbc.Condition;
|
||||||
import de.srsoftware.umbrella.core.BaseDb;
|
import de.srsoftware.umbrella.core.BaseDb;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static de.srsoftware.tools.jdbc.Query.select;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
import static de.srsoftware.umbrella.core.Constants.DESCRIPTION;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.DUE_DATE;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
|
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
|
||||||
import static de.srsoftware.umbrella.core.Constants.EST_TIME;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.NO_INDEX;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.SHOW_CLOSED;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.START_DATE;
|
|
||||||
import static de.srsoftware.umbrella.core.Constants.STATUS;
|
|
||||||
import static de.srsoftware.umbrella.core.model.Status.OPEN;
|
|
||||||
import static de.srsoftware.umbrella.wiki.Constants.*;
|
import static de.srsoftware.umbrella.wiki.Constants.*;
|
||||||
import static java.lang.System.Logger.Level.ERROR;
|
import static java.lang.System.Logger.Level.ERROR;
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
@@ -63,4 +58,17 @@ public class SqliteDb extends BaseDb implements WikiDb {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> listUserPages(long userId) {
|
||||||
|
try {
|
||||||
|
var rs = select(ID,"MAX(version) AS version").from(TABLE_PAGES).leftJoin(ID,TABLE_PAGES_USERS,PAGE_ID).where(USER_ID, Condition.equal(userId)).groupBy(ID).sort("ID COLLATE NOCASE ASC").exec(db);
|
||||||
|
var set = new ArrayList<String>();
|
||||||
|
while (rs.next()) set.add(rs.getString(ID));
|
||||||
|
rs.close();
|
||||||
|
return set;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw databaseException("Failed to list wiki articles for user {0}",userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,9 @@
|
|||||||
package de.srsoftware.umbrella.wiki;
|
package de.srsoftware.umbrella.wiki;
|
||||||
|
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
|
||||||
import de.srsoftware.umbrella.core.model.Permission;
|
|
||||||
import de.srsoftware.umbrella.core.model.Task;
|
|
||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface WikiDb {
|
public interface WikiDb {
|
||||||
|
|
||||||
|
List<String> listUserPages(long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
package de.srsoftware.umbrella.wiki;
|
package de.srsoftware.umbrella.wiki;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import de.srsoftware.configuration.Configuration;
|
import de.srsoftware.configuration.Configuration;
|
||||||
|
import de.srsoftware.tools.Path;
|
||||||
|
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.WikiService;
|
import de.srsoftware.umbrella.core.api.WikiService;
|
||||||
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
|
import de.srsoftware.umbrella.core.model.Token;
|
||||||
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||||
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
import static de.srsoftware.umbrella.wiki.Constants.CONFIG_DATABASE;
|
import static de.srsoftware.umbrella.wiki.Constants.CONFIG_DATABASE;
|
||||||
|
|
||||||
@@ -17,4 +27,28 @@ public class WikiModule extends BaseHandler implements WikiService {
|
|||||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||||
wikiDb = new SqliteDb(connect(dbFile));
|
wikiDb = new SqliteDb(connect(dbFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
|
addCors(ex);
|
||||||
|
try {
|
||||||
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
|
var user = userService().loadUser(token);
|
||||||
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
|
var head = path.pop();
|
||||||
|
return switch (head) {
|
||||||
|
case null -> getUserPages(user.get(),ex);
|
||||||
|
default -> super.doGet(path,ex);
|
||||||
|
};
|
||||||
|
} catch (UmbrellaException e){
|
||||||
|
return send(ex,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getUserPages(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
|
var pageList = wikiDb.listUserPages(user.id());
|
||||||
|
return sendContent(ex,pageList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user