implemented tagging of bookmarks
This commit is contained in:
@@ -62,14 +62,14 @@ public class Application {
|
||||
var server = HttpServer.create(new InetSocketAddress(port), 0);
|
||||
|
||||
var userModule = new UserModule(config,messageSystem);
|
||||
var bookmarkApi = new BookmarkApi(config,userModule);
|
||||
var tagModule = new TagModule(config,userModule);
|
||||
var bookmarkApi = new BookmarkApi(config,tagModule);
|
||||
var companyModule = new CompanyModule(config, userModule);
|
||||
var documentApi = new DocumentApi(companyModule, translationModule, config);
|
||||
var itemApi = new ItemApi(config,companyModule);
|
||||
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
||||
var markdownApi = new MarkdownApi(userModule);
|
||||
var messageApi = new MessageApi(messageSystem);
|
||||
var tagModule = new TagModule(config,userModule);
|
||||
var notesModule = new NoteModule(config,userModule);
|
||||
var projectModule = new ProjectModule(config,companyModule,tagModule);
|
||||
var taskModule = new TaskModule(config,projectModule,tagModule,notesModule);
|
||||
|
||||
@@ -3,8 +3,7 @@ package de.srsoftware.umbrella.bookmarks;
|
||||
|
||||
import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||
import static de.srsoftware.umbrella.core.Constants.COMMENT;
|
||||
import static de.srsoftware.umbrella.core.Constants.URL;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
@@ -15,21 +14,27 @@ 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.api.TagService;
|
||||
import de.srsoftware.umbrella.core.api.UserService;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import org.json.JSONArray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BookmarkApi extends BaseHandler {
|
||||
private final BookmarkDb db;
|
||||
private final UserService users;
|
||||
private final TagService tags;
|
||||
|
||||
public BookmarkApi(Configuration config, UserService userService) {
|
||||
public BookmarkApi(Configuration config, TagService tagService) {
|
||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||
db = new SqliteDb(connect(dbFile));
|
||||
users = userService;
|
||||
tags = tagService;
|
||||
users = tagService.userService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +85,10 @@ public class BookmarkApi extends BaseHandler {
|
||||
if (!(json.has(URL) && json.get(URL) instanceof String url)) throw missingFieldException(URL);
|
||||
if (!(json.has(COMMENT) && json.get(COMMENT) instanceof String comment)) throw missingFieldException(COMMENT);
|
||||
var bookmark = db.save(url,comment, user.id());
|
||||
if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray tagList){
|
||||
var list = tagList.toList().stream().map(Object::toString).toList();
|
||||
tags.save(BOOKMARK,bookmark.id(), List.of(user.id()),list);
|
||||
}
|
||||
return sendContent(ex,bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class Constants {
|
||||
public static final String AUTHORIZATION = "Authorization";
|
||||
|
||||
public static final String BODY = "body";
|
||||
public static final String BOOKMARK = "bookmark";
|
||||
|
||||
public static final String CODE = "code";
|
||||
public static final String COMMENT = "comment";
|
||||
|
||||
@@ -13,4 +13,6 @@ public interface TagService {
|
||||
void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags);
|
||||
|
||||
String save(String module, long entityId, Collection<Long> userIds, String tag);
|
||||
|
||||
UserService userService();
|
||||
}
|
||||
|
||||
@@ -111,4 +111,4 @@
|
||||
{#if editing}
|
||||
<textarea bind:value={editValue.source} onkeyup={typed} autofocus={!simple}></textarea>
|
||||
{/if}
|
||||
<svelte:element this={type} {onmousedown} {onmouseup} {ontouchstart} {ontouchend} class={{editable}} title={t('double_click_to_edit')} >{@html editValue.rendered}</svelte:element>
|
||||
<svelte:element this={type} {onmousedown} {onmouseup} {ontouchstart} {ontouchend} class={{editable}} title={t('long_click_to_edit')} >{@html editValue.rendered}</svelte:element>
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
<textarea bind:value={editValue} onkeyup={typed} autofocus></textarea>
|
||||
{:else}
|
||||
{#if value}
|
||||
<svelte:element this={type} {onmousedown} {onmouseup} {ontouchstart} {ontouchend} class={{editable}} title={t('double_click_to_edit')} >
|
||||
<svelte:element this={type} {onmousedown} {onmouseup} {ontouchstart} {ontouchend} class={{editable}} title={t('long_click_to_edit')} >
|
||||
{#each value.split("\n") as line}
|
||||
{line}<br/>
|
||||
{/each}
|
||||
|
||||
@@ -5,11 +5,18 @@
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
import Editor from '../../Components/MarkdownEditor.svelte';
|
||||
import Tags from '../tags/TagList.svelte';
|
||||
|
||||
let bookmarks = $state(null);
|
||||
let comment = $state({source:null,rendered:null});
|
||||
let error = $state(null);
|
||||
let link = $state(null);
|
||||
let bookmarks = $state(null);
|
||||
let new_bookmark = $state({
|
||||
comment:{
|
||||
source:null,
|
||||
rendered:null
|
||||
},
|
||||
tags:[],
|
||||
url:null
|
||||
});
|
||||
let error = $state(null);
|
||||
|
||||
async function loadBookmarks(){
|
||||
const url = api('bookmark/list');
|
||||
@@ -28,11 +35,13 @@
|
||||
}
|
||||
|
||||
async function onclick(ev){
|
||||
let data = {
|
||||
url : link,
|
||||
comment : comment.source
|
||||
};
|
||||
delete new_bookmark.comment.rendered;
|
||||
const url = api('bookmark/save');
|
||||
const data = {
|
||||
comment : new_bookmark.comment.source,
|
||||
url : new_bookmark.url,
|
||||
tags : new_bookmark.tags
|
||||
}
|
||||
const resp = await fetch(url,{
|
||||
credentials : 'include',
|
||||
method : 'POST',
|
||||
@@ -56,12 +65,13 @@
|
||||
{/if}
|
||||
<label>
|
||||
{t('URL')}
|
||||
<input bind:value={link} />
|
||||
<input bind:value={new_bookmark.url} />
|
||||
</label>
|
||||
<label>
|
||||
{t('Comment')}
|
||||
<Editor simple={true} bind:value={comment} />
|
||||
<Editor simple={true} bind:value={new_bookmark.comment} />
|
||||
</label>
|
||||
<Tags module="bookmark" bind:tags={new_bookmark.tags} />
|
||||
<button {onclick}>{t('save')}</button>
|
||||
{#if bookmarks}
|
||||
{#each bookmarks as bookmark}
|
||||
@@ -73,6 +83,7 @@
|
||||
{bookmark.timestamp.replace('T',' ')}
|
||||
</legend>
|
||||
{bookmark.comment}
|
||||
<Tags module="bookmark" id={bookmark.id} />
|
||||
</fieldset>
|
||||
{/each}
|
||||
{/if}
|
||||
|
||||
@@ -136,4 +136,9 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
save(module,entityId,userIds,List.of(tag));
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserService userService() {
|
||||
return users;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user