preparing search in stock items
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { useTinyRouter } from 'svelte-tiny-router';
|
import { useTinyRouter } from 'svelte-tiny-router';
|
||||||
import { api, target } from '../../urls.svelte.js';
|
import { api, post, target } from '../../urls.svelte.js';
|
||||||
import { error, yikes } from '../../warn.svelte';
|
import { error, yikes } from '../../warn.svelte';
|
||||||
import { t } from '../../translations.svelte.js';
|
import { t } from '../../translations.svelte.js';
|
||||||
import { display } from '../../time.svelte';
|
import { display } from '../../time.svelte';
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
let notes = $state(null);
|
let notes = $state(null);
|
||||||
let pages = $state(null);
|
let pages = $state(null);
|
||||||
let projects = $state(null);
|
let projects = $state(null);
|
||||||
|
let stock = $state(null);
|
||||||
let tasks = $state(null);
|
let tasks = $state(null);
|
||||||
let times = $state(null);
|
let times = $state(null);
|
||||||
|
|
||||||
@@ -38,19 +39,16 @@
|
|||||||
window.history.replaceState(history.state, '', url);
|
window.history.replaceState(history.state, '', url);
|
||||||
|
|
||||||
const data = { key : key, fulltext : fulltext };
|
const data = { key : key, fulltext : fulltext };
|
||||||
const options = {
|
|
||||||
credentials:'include',
|
post(api('bookmark/search'),data).then(handleBookmarks);
|
||||||
method: 'POST',
|
post(api('company/search '),data).then(handleCompanies);
|
||||||
body: JSON.stringify(data)
|
post(api('document/search'),data).then(handleDocuments);
|
||||||
};
|
post(api('notes/search' ),data).then(handleNotes);
|
||||||
fetch(api('bookmark/search'),options).then(handleBookmarks);
|
post(api('project/search' ),data).then(handleProjects);
|
||||||
fetch(api('company/search'),options).then(handleCompanies);
|
post(api('task/search' ),data).then(handleTasks);
|
||||||
fetch(api('document/search'),options).then(handleDocuments);
|
post(api('stock/search' ),data).then(handleStock);
|
||||||
fetch(api('notes/search'),options).then(handleNotes);
|
post(api('time/search' ),data).then(handleTimes);
|
||||||
fetch(api('project/search'),options).then(handleProjects);
|
post(api('wiki/search' ),data).then(handleWikiPages);
|
||||||
fetch(api('task/search'),options).then(handleTasks);
|
|
||||||
fetch(api('time/search'),options).then(handleTimes);
|
|
||||||
fetch(api('wiki/search'),options).then(handleWikiPages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onclick(e){
|
function onclick(e){
|
||||||
@@ -107,6 +105,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleStock(resp){
|
||||||
|
if (resp.ok){
|
||||||
|
const res = await resp.json();
|
||||||
|
stock = Object.keys(res).length ? res : null;
|
||||||
|
} else {
|
||||||
|
error(resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleTasks(resp){
|
async function handleTasks(resp){
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
const res = await resp.json();
|
const res = await resp.json();
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package de.srsoftware.umbrella.stock;
|
|||||||
|
|
||||||
import static de.srsoftware.tools.Optionals.is0;
|
import static de.srsoftware.tools.Optionals.is0;
|
||||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
import static de.srsoftware.tools.jdbc.Condition.*;
|
||||||
import static de.srsoftware.tools.jdbc.Condition.isNull;
|
import static de.srsoftware.tools.jdbc.Condition.like;
|
||||||
import static de.srsoftware.tools.jdbc.Query.*;
|
import static de.srsoftware.tools.jdbc.Query.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
@@ -17,6 +17,7 @@ import static java.text.MessageFormat.format;
|
|||||||
import de.srsoftware.tools.jdbc.Query;
|
import de.srsoftware.tools.jdbc.Query;
|
||||||
import de.srsoftware.umbrella.core.BaseDb;
|
import de.srsoftware.umbrella.core.BaseDb;
|
||||||
import de.srsoftware.umbrella.core.api.Owner;
|
import de.srsoftware.umbrella.core.api.Owner;
|
||||||
|
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.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -189,6 +190,28 @@ public class SqliteDb extends BaseDb implements StockDb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<Long, Item> find(long userId, Collection<String> keys, boolean fulltext) {
|
||||||
|
try {
|
||||||
|
var items = new HashMap<Long,Item>();
|
||||||
|
var query = select(ALL).from(TABLE_ITEMS).where(USER_ID, equal(userId));
|
||||||
|
if (fulltext) {
|
||||||
|
// TODO: implement full-text search
|
||||||
|
} else {
|
||||||
|
for (var key : keys) query.where(NAME,like("%"+key+"%"));
|
||||||
|
}
|
||||||
|
var rs = query.exec(db);
|
||||||
|
while (rs.next()){
|
||||||
|
var project = Item.of(rs);
|
||||||
|
items.put(project.id(),project);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
return items;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new UmbrellaException("Failed to load items from database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<DbLocation> listChildLocations(long parentId) {
|
public Collection<DbLocation> listChildLocations(long parentId) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ import de.srsoftware.umbrella.core.api.Owner;
|
|||||||
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.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface StockDb {
|
public interface StockDb {
|
||||||
Property addNewProperty(long itemId, String name, Object value, String unit);
|
Property addNewProperty(long itemId, String name, Object value, String unit);
|
||||||
Location delete(DbLocation location);
|
Location delete(DbLocation location);
|
||||||
|
Map<Long, Item> find(long userId, Collection<String> keys, boolean fulltext);
|
||||||
Collection<DbLocation> listChildLocations(long parentId);
|
Collection<DbLocation> listChildLocations(long parentId);
|
||||||
Collection<DbLocation> listCompanyLocations(Company company);
|
Collection<DbLocation> listCompanyLocations(Company company);
|
||||||
Collection<Item> listItemsAt(Location location);
|
Collection<Item> listItemsAt(Location location);
|
||||||
@@ -24,5 +26,6 @@ public interface StockDb {
|
|||||||
Map<String,Object> pathToLocation(Location location);
|
Map<String,Object> pathToLocation(Location location);
|
||||||
DbLocation save(DbLocation location);
|
DbLocation save(DbLocation location);
|
||||||
Item save(Item item);
|
Item save(Item item);
|
||||||
|
|
||||||
Property setProperty(long itemId, long existingPropId, Object value);
|
Property setProperty(long itemId, long existingPropId, Object value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import static de.srsoftware.umbrella.core.Field.ITEM;
|
|||||||
import static de.srsoftware.umbrella.core.ModuleRegistry.companyService;
|
import static de.srsoftware.umbrella.core.ModuleRegistry.companyService;
|
||||||
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
|
||||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||||
|
import static de.srsoftware.umbrella.core.Paths.SEARCH;
|
||||||
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
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;
|
||||||
@@ -174,6 +176,7 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
case LIST -> postItemList(user.get(), path, ex);
|
case LIST -> postItemList(user.get(), path, ex);
|
||||||
case LOCATION -> postLocation(user.get(),ex);
|
case LOCATION -> postLocation(user.get(),ex);
|
||||||
case PROPERTY -> postProperty(user.get(),ex);
|
case PROPERTY -> postProperty(user.get(),ex);
|
||||||
|
case SEARCH -> postSearch(user.get(),ex);
|
||||||
case null, default -> super.doPost(path,ex);
|
case null, default -> super.doPost(path,ex);
|
||||||
};
|
};
|
||||||
} catch (UmbrellaException e){
|
} catch (UmbrellaException e){
|
||||||
@@ -389,6 +392,15 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
return sendContent(ex,property);
|
return sendContent(ex,property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean postSearch(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||||
|
var json = json(ex);
|
||||||
|
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
|
||||||
|
var keys = Arrays.asList(key.split(" "));
|
||||||
|
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
|
||||||
|
var items = stockDb.find(user.id(),keys,fulltext);
|
||||||
|
return sendContent(ex,mapValues(items));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Object> redefineMe(long company_id) {
|
public Collection<Object> redefineMe(long company_id) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user