implemented search in wiki pages
This commit is contained in:
@@ -7,18 +7,19 @@
|
|||||||
|
|
||||||
import Bookmark from '../bookmark/Template.svelte';
|
import Bookmark from '../bookmark/Template.svelte';
|
||||||
|
|
||||||
const router = useTinyRouter();
|
const router = useTinyRouter();
|
||||||
let bookmarks = $state(null);
|
let bookmarks = $state(null);
|
||||||
let companies = $state(null);
|
let companies = $state(null);
|
||||||
let documents = $state(null);
|
let documents = $state(null);
|
||||||
let error = $state(null);
|
let error = $state(null);
|
||||||
let fulltext = false;
|
let fulltext = false;
|
||||||
let key = $state(router.getQueryParam('key'));
|
let key = $state(router.getQueryParam('key'));
|
||||||
let input = $state(router.getQueryParam('key'));
|
let input = $state(router.getQueryParam('key'));
|
||||||
let notes = $state(null);
|
let notes = $state(null);
|
||||||
let projects = $state(null);
|
let pages = $state(null);
|
||||||
let tasks = $state(null);
|
let projects = $state(null);
|
||||||
let times = $state(null);
|
let tasks = $state(null);
|
||||||
|
let times = $state(null);
|
||||||
|
|
||||||
async function setKey(ev){
|
async function setKey(ev){
|
||||||
if (ev) ev.preventDefault();
|
if (ev) ev.preventDefault();
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
fetch(api('project/search'),options).then(handleProjects);
|
fetch(api('project/search'),options).then(handleProjects);
|
||||||
fetch(api('task/search'),options).then(handleTasks);
|
fetch(api('task/search'),options).then(handleTasks);
|
||||||
fetch(api('time/search'),options).then(handleTimes);
|
fetch(api('time/search'),options).then(handleTimes);
|
||||||
|
fetch(api('wiki/search'),options).then(handleWikiPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onclick(e){
|
function onclick(e){
|
||||||
@@ -122,6 +124,15 @@
|
|||||||
error = await resp.text();
|
error = await resp.text();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleWikiPages(resp){
|
||||||
|
if (resp.ok){
|
||||||
|
const res = await resp.json();
|
||||||
|
pages = Object.keys(res).length ? res : null;
|
||||||
|
} else {
|
||||||
|
error = await resp.text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => doSearch(key))
|
$effect(() => doSearch(key))
|
||||||
</script>
|
</script>
|
||||||
@@ -260,3 +271,19 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if pages}
|
||||||
|
<fieldset>
|
||||||
|
<legend>
|
||||||
|
{t('wiki_pages')}
|
||||||
|
</legend>
|
||||||
|
<ul>
|
||||||
|
{#each Object.values(pages) as page}
|
||||||
|
<li>
|
||||||
|
<a href="/wiki/{page.id}/view" {onclick} >
|
||||||
|
{page.title}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -268,6 +268,7 @@
|
|||||||
|
|
||||||
"welcome" : "Willkommen, {0}",
|
"welcome" : "Willkommen, {0}",
|
||||||
"wiki": "Wiki",
|
"wiki": "Wiki",
|
||||||
|
"wiki_pages": "Wiki-Seiten",
|
||||||
|
|
||||||
"version": "Version",
|
"version": "Version",
|
||||||
"version_of": "Version {version} von {element}",
|
"version_of": "Version {version} von {element}",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package de.srsoftware.umbrella.wiki;
|
package de.srsoftware.umbrella.wiki;
|
||||||
|
|
||||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||||
|
import static de.srsoftware.tools.jdbc.Condition.like;
|
||||||
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;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
@@ -151,7 +152,25 @@ public class SqliteDb extends BaseDb implements WikiDb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public Map<Long, WikiPage> find(long userId, List<String> keys, boolean fulltext) {
|
||||||
|
try {
|
||||||
|
var query = select(ALL).from(TABLE_PAGES).leftJoin(ID,TABLE_PAGES_USERS,PAGE_ID).where(USER_ID,equal(userId));
|
||||||
|
for (var key : keys) query.where(TITLE,like("%"+key+"%"));
|
||||||
|
var rs = query.exec(db);
|
||||||
|
var map = new HashMap<Long,WikiPage>();
|
||||||
|
while (rs.next()) {
|
||||||
|
var page = WikiPage.of(rs);
|
||||||
|
map.put(page.id(),page);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
return map;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw databaseException("Failed to search \"{0}\" in wiki pages",String.join(" "+keys));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isAvailable(String title) {
|
public boolean isAvailable(String title) {
|
||||||
if (title==null||title.isBlank())return false;
|
if (title==null||title.isBlank())return false;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ public interface WikiDb {
|
|||||||
|
|
||||||
WikiPage drop(WikiPage page);
|
WikiPage drop(WikiPage page);
|
||||||
|
|
||||||
|
Map<Long,WikiPage> find(long userId, List<String> keys, boolean fulltext);
|
||||||
|
|
||||||
long getNextId();
|
long getNextId();
|
||||||
|
|
||||||
boolean isAvailable(String title);
|
boolean isAvailable(String title);
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
package de.srsoftware.umbrella.wiki;
|
package de.srsoftware.umbrella.wiki;
|
||||||
|
|
||||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||||
import static de.srsoftware.umbrella.core.Constants.VERSION;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
|
import static de.srsoftware.umbrella.core.Constants.FULLTEXT;
|
||||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||||
import static de.srsoftware.umbrella.core.Paths.AVAILABLE;
|
import static de.srsoftware.umbrella.core.Paths.*;
|
||||||
import static de.srsoftware.umbrella.core.Paths.PAGE;
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
||||||
import static de.srsoftware.umbrella.wiki.Constants.*;
|
import static de.srsoftware.umbrella.wiki.Constants.*;
|
||||||
@@ -20,7 +21,9 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
|||||||
import de.srsoftware.umbrella.core.model.*;
|
import de.srsoftware.umbrella.core.model.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WikiModule extends BaseHandler implements WikiService {
|
public class WikiModule extends BaseHandler implements WikiService {
|
||||||
private final WikiDb wikiDb;
|
private final WikiDb wikiDb;
|
||||||
@@ -105,15 +108,25 @@ public class WikiModule extends BaseHandler implements WikiService {
|
|||||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
var user = userService().loadUser(token);
|
var user = userService().loadUser(token);
|
||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
var title = path.pop();
|
var head = path.pop();
|
||||||
if (!path.empty()) return super.doPost(path,ex);
|
if (!path.empty()) return super.doPost(path,ex);
|
||||||
return postNewPage(title,user.get(),ex);
|
if (SEARCH.equals(head)) return postSearch(user.get(),ex);
|
||||||
|
return postNewPage(head,user.get(),ex);
|
||||||
} catch (UmbrellaException e){
|
} catch (UmbrellaException e){
|
||||||
return send(ex,e);
|
return send(ex,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getAvailability(Path path, HttpExchange ex) throws IOException {
|
private boolean postSearch(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
|
var json = json(ex);
|
||||||
|
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
|
||||||
|
var keys = Arrays.asList(key.split(" "));
|
||||||
|
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
|
||||||
|
var pages = wikiDb.find(user.id(),keys,fulltext);
|
||||||
|
return sendContent(ex,mapValues(pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean getAvailability(Path path, HttpExchange ex) throws IOException {
|
||||||
return sendContent(ex,wikiDb.isAvailable(path.pop()));
|
return sendContent(ex,wikiDb.isAvailable(path.pop()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user