workin on search based on tags
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
import Bookmark from '../bookmark/Template.svelte';
|
||||
|
||||
const router = useTinyRouter();
|
||||
let counter = 9;
|
||||
let counter = 10;
|
||||
let bookmarks = $state(null);
|
||||
let companies = $state(null);
|
||||
let documents = $state(null);
|
||||
@@ -18,14 +18,13 @@
|
||||
let pages = $state(null);
|
||||
let projects = $state(null);
|
||||
let stock = $state(null);
|
||||
let tags = $state(null);
|
||||
let tasks = $state(null);
|
||||
let times = $state(null);
|
||||
|
||||
|
||||
|
||||
function doSearch(key){
|
||||
warn(t('searching…'));
|
||||
|
||||
console.log("doSearch");
|
||||
const data = { key : key, fulltext : fulltext };
|
||||
post(api('bookmark/search'),data).then(handleBookmarks);
|
||||
post(api('company/search '),data).then(handleCompanies);
|
||||
@@ -34,6 +33,7 @@
|
||||
post(api('project/search' ),data).then(handleProjects);
|
||||
post(api('task/search' ),data).then(handleTasks);
|
||||
post(api('stock/search' ),data).then(handleStock);
|
||||
post(api('tags/search' ),data).then(handleTags);
|
||||
post(api('time/search' ),data).then(handleTimes);
|
||||
post(api('wiki/search' ),data).then(handleWikiPages);
|
||||
}
|
||||
@@ -110,6 +110,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTags(resp){
|
||||
quitOne();
|
||||
if (resp.ok){
|
||||
const res = await resp.json();
|
||||
tags = Object.keys(res).length ? res : null;
|
||||
for (let [module, ids] of Object.entries(tags)){
|
||||
console.log("found "+module+" with tags:");
|
||||
// TODO: load entities from module
|
||||
}
|
||||
} else {
|
||||
error(resp);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTasks(resp){
|
||||
quitOne();
|
||||
if (resp.ok){
|
||||
@@ -364,3 +378,24 @@
|
||||
</ul>
|
||||
</fieldset>
|
||||
{/if}
|
||||
{#if tags}
|
||||
<fieldset>
|
||||
<legend>
|
||||
{t('tags')}
|
||||
</legend>
|
||||
<ul>
|
||||
{#each Object.entries(tags) as [module,items]}
|
||||
{#each items as item}
|
||||
<li>
|
||||
<a href="/{module}/{item}/view" {onclick} >{module} {item}</a>
|
||||
</li>
|
||||
{/each}
|
||||
{/each}
|
||||
</ul>
|
||||
</fieldset>
|
||||
{/if}
|
||||
<pre>
|
||||
<code>
|
||||
{JSON.stringify(tags,null,2)}
|
||||
</code>
|
||||
</pre>
|
||||
@@ -4,6 +4,7 @@ package de.srsoftware.umbrella.tags;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.KEY;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.USER_LIST;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.SEARCH;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.USES;
|
||||
@@ -94,7 +95,18 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
var user = userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
return switch (module) {
|
||||
case null -> throw unprocessable("Module missing in path.");
|
||||
case SEARCH -> postSearch(ex, path, user.get());
|
||||
default -> postTag(ex, module, path);
|
||||
};
|
||||
} catch (UmbrellaException e) {
|
||||
return send(ex, e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean postTag(HttpExchange ex, String module, Path path) throws IOException {
|
||||
try {
|
||||
var head = path.pop();
|
||||
long entityId = Long.parseLong(head);
|
||||
var json = json(ex);
|
||||
@@ -102,7 +114,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
List<Long> userList = null;
|
||||
if (!json.has(USER_LIST)) throw missingField(USER_LIST);
|
||||
var ul = json.isNull(USER_LIST) ? null : json.get(USER_LIST);
|
||||
if (ul instanceof JSONArray arr){
|
||||
if (ul instanceof JSONArray arr) {
|
||||
userList = arr.toList().stream()
|
||||
.filter(elem -> elem instanceof Number)
|
||||
.map(Number.class::cast)
|
||||
@@ -115,8 +127,6 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
return sendContent(ex, tag);
|
||||
} catch (NumberFormatException e) {
|
||||
return sendContent(ex, HTTP_UNPROCESSABLE, "Entity id missing in path.");
|
||||
} catch (UmbrellaException e) {
|
||||
return send(ex, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +159,13 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
return entry;
|
||||
}
|
||||
|
||||
private boolean postSearch(HttpExchange ex, Path path, UmbrellaUser user) throws IOException {
|
||||
var json = json(ex);
|
||||
if (!json.has(KEY)) throw missingField(KEY);
|
||||
var key = json.getString(KEY);
|
||||
return getTagUses(ex,key,user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags) {
|
||||
tagDb.save(userIds,module,entityId,tags.stream().map(String::trim).toList());
|
||||
|
||||
Reference in New Issue
Block a user