working on tak use list
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -116,6 +116,7 @@ public class Constants {
|
||||
public static final String USER = "user";
|
||||
public static final String USER_ID = "user_id";
|
||||
public static final String USER_LIST = "user_list";
|
||||
public static final String USES = "uses";
|
||||
public static final String UTF8 = UTF_8.displayName();
|
||||
|
||||
public static final String VALUE = "value";
|
||||
|
||||
@@ -7,19 +7,24 @@
|
||||
|
||||
let { tag } = $props();
|
||||
let error = $state(null);
|
||||
let router = useTinyRouter();
|
||||
let uses = $state(null);
|
||||
|
||||
async function loadUses(){
|
||||
const url = api(`tags/uses/${tag}`);
|
||||
const resp = await fetch(api,{credentials:'include'});
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
uses = await resp.json;
|
||||
uses = await resp.json();
|
||||
error = null;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
function go(module,id){
|
||||
router.navigate(`/${module}/${id}/view`);
|
||||
}
|
||||
|
||||
onMount(loadUses);
|
||||
</script>
|
||||
<fieldset>
|
||||
@@ -27,4 +32,12 @@
|
||||
{#if error}
|
||||
<span class="error">{error}</span>
|
||||
{/if}
|
||||
{#if uses}
|
||||
{#each Object.entries(uses) as [module,ids]}
|
||||
<h2>{t(module)}</h2>
|
||||
{#each ids as id}
|
||||
<button onclick={() => go(module,id)}>{t(module)} {id}</button>
|
||||
{/each}
|
||||
{/each}
|
||||
{/if}
|
||||
</fieldset>
|
||||
@@ -4,6 +4,7 @@ package de.srsoftware.umbrella.tags;
|
||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||
import static de.srsoftware.tools.jdbc.Condition.isNull;
|
||||
import static de.srsoftware.tools.jdbc.Query.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
|
||||
import static de.srsoftware.umbrella.core.Constants.USER_ID;
|
||||
@@ -16,9 +17,7 @@ import de.srsoftware.tools.jdbc.Query;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class SqliteDb implements TagDB{
|
||||
private static final int INITIAL_DB_VERSION = 1;
|
||||
@@ -110,6 +109,23 @@ CREATE TABLE IF NOT EXISTS "{0}" (
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<Long>> getUses(String tag, long userId) {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_TAGS).where(TAG,equal(tag)).where(USER_ID,equal(userId)).exec(db);
|
||||
var result = new HashMap<String,List<Long>>();
|
||||
while (rs.next()){
|
||||
var module = rs.getString(MODULE);
|
||||
var entityId = rs.getLong(ID);
|
||||
result.computeIfAbsent(module, k -> new ArrayList<>()).add(entityId);
|
||||
}
|
||||
rs.close();
|
||||
return result;
|
||||
} catch (SQLException e){
|
||||
throw new UmbrellaException("Failed to load uses of tag \"{0}\"!",tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void init(){
|
||||
var version = createTables();
|
||||
LOG.log(INFO,"Updated task db to version {0}",version);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
package de.srsoftware.umbrella.tags;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface TagDB {
|
||||
@@ -9,6 +11,8 @@ public interface TagDB {
|
||||
|
||||
void deleteEntity(String module, long entityId);
|
||||
|
||||
Map<String, List<Long>> getUses(String tag, long id);
|
||||
|
||||
Set<String> list(long id, String module, long entityId);
|
||||
|
||||
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
|
||||
|
||||
@@ -68,6 +68,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
var head = path.pop();
|
||||
if (USES.equals(module)) return getTagUses(ex,head,user.get());
|
||||
long entityId = Long.parseLong(head);
|
||||
return sendContent(ex, getTags(module,entityId,user.get()));
|
||||
} catch (NumberFormatException e){
|
||||
@@ -77,6 +78,10 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getTagUses(HttpExchange ex, String tag, UmbrellaUser user) throws IOException {
|
||||
return sendContent(ex,tagDb.getUses(tag,user.id()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
|
||||
Reference in New Issue
Block a user