implemented GUI update on cloning items
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -49,11 +49,11 @@ public class MessageApi extends BaseHandler{
|
|||||||
if (++counter > 300) counter = sendBeacon(addr,stream);
|
if (++counter > 300) counter = sendBeacon(addr,stream);
|
||||||
} else {
|
} else {
|
||||||
var event = eventQueue.removeFirst();
|
var event = eventQueue.removeFirst();
|
||||||
//if (event.isIntendedFor(user.get())) {
|
if (event.isIntendedFor(user.get())) {
|
||||||
LOG.log(DEBUG, "sending event to {0}", addr);
|
LOG.log(DEBUG, "sending event to {0}", addr);
|
||||||
sendEvent(stream, event);
|
sendEvent(stream, event);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.log(INFO,"{0} disconnected from event stream.",addr);
|
LOG.log(INFO,"{0} disconnected from event stream.",addr);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class MessageBus {
|
|||||||
|
|
||||||
private MessageBus(){}
|
private MessageBus(){}
|
||||||
|
|
||||||
public void dispatch(Event event){
|
public void dispatch(Event<?> event){
|
||||||
new Thread(() -> { // TODO: use thread pool
|
new Thread(() -> { // TODO: use thread pool
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package de.srsoftware.umbrella.messagebus.events;
|
||||||
|
|
||||||
|
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||||
|
import de.srsoftware.umbrella.core.api.Owner;
|
||||||
|
import de.srsoftware.umbrella.core.constants.Field;
|
||||||
|
import de.srsoftware.umbrella.core.model.*;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||||
|
import static de.srsoftware.umbrella.core.model.Translatable.t;
|
||||||
|
|
||||||
|
public class ItemEvent extends Event<Item>{
|
||||||
|
public ItemEvent(UmbrellaUser initiator, String module, Item item, EventType type) {
|
||||||
|
super(initiator, module, item, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<UmbrellaUser> audience() {
|
||||||
|
Owner owner = payload().location().resolve().owner().resolve();
|
||||||
|
if (owner instanceof UmbrellaUser user) return List.of(user);
|
||||||
|
if (owner instanceof Company company) return ModuleRegistry.companyService().getMembers(company.id());
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Translatable describe() {
|
||||||
|
return switch (eventType()){
|
||||||
|
case CREATE -> describeCreate();
|
||||||
|
case null, default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Translatable describeCreate() {
|
||||||
|
var loc = payload().location().resolve().name();
|
||||||
|
return t("{user} added \"{item}\" to \"{location}\"", USER,initiator().name(), ITEM, payload().name(), LOCATION, loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Translatable subject() {
|
||||||
|
var loc = payload().location().resolve().name();
|
||||||
|
return switch (eventType()){
|
||||||
|
case CREATE -> t("A new item has been added to \"{location}\":",LOCATION,loc);
|
||||||
|
case null, default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,39 @@
|
|||||||
<script>
|
<script>
|
||||||
import { api, post } from '../../urls.svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
import { api, eventStream, post } from '../../urls.svelte';
|
||||||
import { error, yikes } from '../../warn.svelte';
|
import { error, yikes } from '../../warn.svelte';
|
||||||
import { t } from '../../translations.svelte';
|
import { t } from '../../translations.svelte';
|
||||||
|
|
||||||
let { items, selected = $bindable(null), location = null, drag_start = item => console.log({dragging:item}) } = $props();
|
let { items, selected = $bindable(null), location = null, drag_start = item => console.log({dragging:item}) } = $props();
|
||||||
|
let eventSource = null;
|
||||||
let newItem = $state({name:null, code: null});
|
let newItem = $state({name:null, code: null});
|
||||||
|
|
||||||
|
function handleCreateEvent(evt){
|
||||||
|
let json = JSON.parse(evt.data);
|
||||||
|
if (json.item.location.id == location.id){
|
||||||
|
items = [...items,json.item];
|
||||||
|
selected = json.item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEvent(evt,method){
|
||||||
|
console.log(evt,method);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDeleteEvent(evt){
|
||||||
|
handleEvent(evt,'delete');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleUpdateEvent(evt){
|
||||||
|
handleEvent(evt,'update');
|
||||||
|
}
|
||||||
|
|
||||||
|
function load(){
|
||||||
|
try {
|
||||||
|
eventSource = eventStream(handleCreateEvent,handleUpdateEvent,handleDeleteEvent);
|
||||||
|
} catch (ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
async function saveNewItem(){
|
async function saveNewItem(){
|
||||||
newItem.location = location;
|
newItem.location = location;
|
||||||
const url = api('stock/item');
|
const url = api('stock/item');
|
||||||
@@ -17,6 +45,12 @@
|
|||||||
items = [...items, it];
|
items = [...items, it];
|
||||||
} else error(res);
|
} else error(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (eventSource) eventSource.close();
|
||||||
|
});
|
||||||
|
onMount(load);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
{#if item}
|
{#if item}
|
||||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => update('name',v)} />
|
<LineEditor type="h3" editable={true} value={item.name} onSet={v => update('name',v)} />
|
||||||
<button class="clone symbol" title={t('clone')} onclick={doClone}>C</button>
|
<button class="clone symbol" title={t('clone')} onclick={doClone}></button>
|
||||||
<div>
|
<div>
|
||||||
{@html item.description.rendered}
|
{@html item.description.rendered}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
description = "Umbrella : Stock"
|
description = "Umbrella : Stock"
|
||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
|
implementation(project(":bus"))
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation("de.srsoftware:configuration.json:1.0.3")
|
implementation("de.srsoftware:configuration.json:1.0.3")
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ import static de.srsoftware.umbrella.core.constants.Module.USER;
|
|||||||
import static de.srsoftware.umbrella.core.constants.Path.*;
|
import static de.srsoftware.umbrella.core.constants.Path.*;
|
||||||
import static de.srsoftware.umbrella.core.constants.Path.PROPERTY;
|
import static de.srsoftware.umbrella.core.constants.Path.PROPERTY;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
|
import static de.srsoftware.umbrella.messagebus.MessageBus.messageBus;
|
||||||
import static de.srsoftware.umbrella.stock.Constants.*;
|
import static de.srsoftware.umbrella.stock.Constants.*;
|
||||||
import static java.lang.System.Logger.Level.WARNING;
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
import static java.util.Comparator.comparing;
|
import static java.util.Comparator.comparing;
|
||||||
@@ -26,13 +27,18 @@ import de.srsoftware.umbrella.core.*;
|
|||||||
import de.srsoftware.umbrella.core.api.Owner;
|
import de.srsoftware.umbrella.core.api.Owner;
|
||||||
import de.srsoftware.umbrella.core.api.StockService;
|
import de.srsoftware.umbrella.core.api.StockService;
|
||||||
import de.srsoftware.umbrella.core.constants.Field;
|
import de.srsoftware.umbrella.core.constants.Field;
|
||||||
|
import de.srsoftware.umbrella.core.constants.Module;
|
||||||
import de.srsoftware.umbrella.core.constants.Path;
|
import de.srsoftware.umbrella.core.constants.Path;
|
||||||
import de.srsoftware.umbrella.core.constants.Text;
|
import de.srsoftware.umbrella.core.constants.Text;
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.core.model.*;
|
import de.srsoftware.umbrella.core.model.*;
|
||||||
import de.srsoftware.umbrella.core.model.Location;
|
import de.srsoftware.umbrella.core.model.Location;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||||
|
import de.srsoftware.umbrella.messagebus.events.ItemEvent;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class StockModule extends BaseHandler implements StockService {
|
public class StockModule extends BaseHandler implements StockService {
|
||||||
@@ -350,7 +356,9 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
if (!assigned(owner,user)) throw forbidden("You are not allowed to add items to \"{location}\"!", Text.LOCATION,location.name());
|
if (!assigned(owner,user)) throw forbidden("You are not allowed to add items to \"{location}\"!", Text.LOCATION,location.name());
|
||||||
var newItem = new Item(0,owner,0,location,item.code(),item.name(),item.description());
|
var newItem = new Item(0,owner,0,location,item.code(),item.name(),item.description());
|
||||||
for (var property : item.properties()) newItem.properties().add(property);
|
for (var property : item.properties()) newItem.properties().add(property);
|
||||||
return sendContent(ex,stockDb.save(newItem));
|
newItem = stockDb.save(newItem);
|
||||||
|
messageBus().dispatch(new ItemEvent(user, Module.STOCK, newItem, Event.EventType.CREATE));
|
||||||
|
return sendContent(ex,newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean postItem(UmbrellaUser user, HttpExchange ex) throws IOException {
|
private boolean postItem(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
@@ -362,8 +370,10 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
var location = stockDb.loadLocation(locationData.getLong(ID));
|
var location = stockDb.loadLocation(locationData.getLong(ID));
|
||||||
var owner = location.owner().resolve();
|
var owner = location.owner().resolve();
|
||||||
if (!assigned(owner,user)) throw forbidden("You are not allowed to add items to {location}!", Field.LOCATION,location);
|
if (!assigned(owner,user)) throw forbidden("You are not allowed to add items to {location}!", Field.LOCATION,location);
|
||||||
var newItem = new Item(0,owner,0,location,code,name,description);
|
var newItem = stockDb.save(new Item(0,owner,0,location,code,name,description));
|
||||||
return sendContent(ex,stockDb.save(newItem));
|
messageBus().dispatch(new ItemEvent(user, Module.STOCK, newItem, Event.EventType.CREATE));
|
||||||
|
return sendContent(ex,newItem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean postItemList(UmbrellaUser user, de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
|
private boolean postItemList(UmbrellaUser user, de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user