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