implemented autocomplete input for tag editor
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -10,6 +10,7 @@ import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Errors.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TAG;
|
||||
import static de.srsoftware.umbrella.core.constants.Field.TAGS;
|
||||
import static de.srsoftware.umbrella.core.constants.Module.BOOKMARK;
|
||||
import static de.srsoftware.umbrella.core.constants.Text.TABLE_WITH_NAME;
|
||||
@@ -25,8 +26,10 @@ import de.srsoftware.tools.Tuple;
|
||||
import de.srsoftware.tools.jdbc.Query;
|
||||
import de.srsoftware.umbrella.bookmarks.BookmarkDb;
|
||||
import de.srsoftware.umbrella.core.BaseDb;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.model.Translatable;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -333,6 +336,19 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> search(String key, UmbrellaUser user) {
|
||||
try {
|
||||
var tags = new HashSet<String>();
|
||||
var rs = select("DISTINCT tag").from(TABLE_TAGS).where(USER_ID,equal(user.id())).where(Field.TAG,like("%"+key+"%")).exec(db);
|
||||
while (rs.next()) tags.add(rs.getString(1));
|
||||
rs.close();
|
||||
return tags;
|
||||
} catch (SQLException s){
|
||||
throw failedToLoadObject(Text.TAGS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateId(String module, Object oldId, Object newId) {
|
||||
try {
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.srsoftware.umbrella.tags;
|
||||
|
||||
|
||||
import de.srsoftware.tools.Tuple;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,5 +33,7 @@ public interface TagDB {
|
||||
|
||||
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
|
||||
|
||||
Collection<String> search(String key, UmbrellaUser user);
|
||||
|
||||
void updateId(String module, Object oldId, Object newId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.USER_LIST;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.SEARCH;
|
||||
import static de.srsoftware.umbrella.core.constants.Path.USES;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||
import static de.srsoftware.umbrella.tags.Constants.*;
|
||||
@@ -66,11 +67,13 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
var user = userService().refreshSession(ex);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var module = path.pop();
|
||||
if (module == null) return getUserTags(ex, user.get());
|
||||
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()));
|
||||
return switch (module){
|
||||
case SEARCH -> searchTags(ex,path.pop(),user.get());
|
||||
case USES -> getTagUses(ex,path.pop(),user.get());
|
||||
case null -> getUserTags(ex, user.get());
|
||||
default -> sendContent(ex, getTags(module,Long.parseLong(path.pop()),user.get()));
|
||||
};
|
||||
|
||||
} catch (NumberFormatException e){
|
||||
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
|
||||
} catch (UmbrellaException e){
|
||||
@@ -150,6 +153,10 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
return tag;
|
||||
}
|
||||
|
||||
private boolean searchTags(HttpExchange ex, String head, UmbrellaUser user) throws IOException {
|
||||
return sendContent(ex, tagDb.search(head, user));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateId(String module, Object oldId, Object newId) {
|
||||
tagDb.updateId(module,oldId,newId);
|
||||
|
||||
Reference in New Issue
Block a user