implemented selector for parent task
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -15,6 +15,7 @@ public class Field {
|
||||
public static final String BODY = "body";
|
||||
|
||||
public static final String CACHE_CONTROL = "Cache-Control";
|
||||
public static final String CHILDREN = "Children";
|
||||
public static final String CODE = "code";
|
||||
public static final String COMMENT = "comment";
|
||||
public static final String COMPANY = "company";
|
||||
|
||||
@@ -33,13 +33,14 @@ public class Path {
|
||||
|
||||
public static final String OPTION = "option";
|
||||
|
||||
public static final String PAGE = "page";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PERMISSIONS = "permissions";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
public static final String PURPOSES = "purposes";
|
||||
public static final String PAGE = "page";
|
||||
public static final String PARENT_CANDIDATES = "parent_candidates";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String PERMISSIONS = "permissions";
|
||||
public static final String PROJECT = "project";
|
||||
public static final String PROPERTIES = "properties";
|
||||
public static final String PROPERTY = "property";
|
||||
public static final String PURPOSES = "purposes";
|
||||
|
||||
public static final String READ = "read";
|
||||
public static final String REDIRECT = "redirect";
|
||||
|
||||
@@ -144,4 +144,9 @@ public class Project implements Mappable {
|
||||
map.put(TAG_COLORS,tagColors);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import TaskTree from './Tree.svelte';
|
||||
|
||||
let { project, select = o => {}, task } = $props();
|
||||
let tree = $state({});
|
||||
|
||||
async function loadParentCandidates(){
|
||||
let url = api(`task/${task.id}/parent_candidates`);
|
||||
let res = await get(url);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
tree = await res.json();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
onMount(loadParentCandidates);
|
||||
</script>
|
||||
|
||||
<div class="overlay parent_selector">
|
||||
<h2>{t('select a new parent for {entity}',{entity:task.name})}</h2>
|
||||
{t('project')}: {project.name}
|
||||
<TaskTree {tree} {select} />
|
||||
</div>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script>
|
||||
let { select = o => {}, tree } = $props();
|
||||
|
||||
let nodes = $derived(Object.values(tree).sort((a,b) => a.name.localeCompare(b.name)))
|
||||
|
||||
function onclick(ev,node){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
select(node);
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<ul>
|
||||
{#each nodes as node (node.id)}
|
||||
<li onclick={ev => onclick(ev,node)}>
|
||||
{node.name}
|
||||
{#if node.Children}
|
||||
<svelte:self tree={node.Children} {select} />
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
|
||||
import ParentSelector from './ParentSelector.svelte';
|
||||
import PermissionEditor from '../../Components/PermissionEditor.svelte';
|
||||
import Notes from '../notes/RelatedNotes.svelte';
|
||||
import StateSelector from '../../Components/StateSelector.svelte';
|
||||
@@ -22,6 +23,7 @@
|
||||
let children = $state(null);
|
||||
let dummy = $derived(updateOn(id));
|
||||
let est_time = $state({sum:0});
|
||||
let select_parent = $state(false);
|
||||
let project = $state(null);
|
||||
const router = useTinyRouter();
|
||||
let showSettings = $state(router.fullPath.endsWith('/edit'));
|
||||
@@ -74,12 +76,6 @@
|
||||
router.navigate(`/project/${project.id}/kanban`)
|
||||
}
|
||||
|
||||
|
||||
function gotoParent(){
|
||||
if (!task.parent_task_id) return;
|
||||
router.navigate(`/task/${task.parent_task_id}/view`)
|
||||
}
|
||||
|
||||
function gotoProject(){
|
||||
if (!project) return;
|
||||
router.navigate(`/project/${project.id}/view`)
|
||||
@@ -136,6 +132,19 @@
|
||||
} else error(await resp.text());
|
||||
}
|
||||
|
||||
function parentClick(ev){
|
||||
ev.preventDefault();
|
||||
if (!task.parent_task_id) return;
|
||||
router.navigate(`/task/${task.parent_task_id}/view`);
|
||||
return false;
|
||||
}
|
||||
|
||||
function parentRightClick(ev){
|
||||
ev.preventDefault();
|
||||
select_parent = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function showClosed(){
|
||||
show_closed = !show_closed;
|
||||
children = null;
|
||||
@@ -182,6 +191,11 @@
|
||||
loadTask();
|
||||
}
|
||||
|
||||
function update_parent(newVal){
|
||||
select_parent = false;
|
||||
update({parent_task_id:newVal.id});
|
||||
}
|
||||
|
||||
function updatePermission(user_id,permission){
|
||||
let members = {};
|
||||
members[user_id] = permission.code;
|
||||
@@ -207,13 +221,18 @@
|
||||
<button class="symbol" title={t('files')} onclick={showPrjFiles}></button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if task.parent}
|
||||
<div>{t('parent_task')}</div>
|
||||
<div class="parent">
|
||||
<a href="#" onclick={gotoParent}>{task.parent.name}</a>
|
||||
{#if select_parent}
|
||||
<ParentSelector {task} {project} select={update_parent} />
|
||||
{:else}
|
||||
{#if task.parent}
|
||||
<a href="/task/{task.parent.id}/view" onclick={parentClick} oncontextmenu={parentRightClick}>{task.parent.name}</a>
|
||||
<button class="symbol" title={t('unlink')} onclick={unlink_parent}></button>
|
||||
{/if}
|
||||
<button class="symbol" title={t('edit')} onclick={parentRightClick}></button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div>{t('task')}</div>
|
||||
<div class="name">
|
||||
<LineEditor bind:value={task.name} editable={true} onSet={val => update({name:val})} />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package de.srsoftware.umbrella.task;
|
||||
|
||||
|
||||
import static de.srsoftware.tools.Optionals.is0;
|
||||
import static de.srsoftware.tools.jdbc.Condition.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
@@ -236,7 +237,7 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
public Map<Long, Task> listProjectTasks(Long projectId, Long parentTaskId, boolean noIndex) throws UmbrellaException {
|
||||
try {
|
||||
var query = select(ALL).from(TABLE_TASKS).where(PROJECT_ID,equal(projectId));
|
||||
if (parentTaskId != 0) query.where(PARENT_TASK_ID,equal(parentTaskId));
|
||||
if (!is0(parentTaskId)) query.where(PARENT_TASK_ID,equal(parentTaskId));
|
||||
if (!noIndex) query.where(NO_INDEX,notIn(1));
|
||||
var tasks = new HashMap<Long,Task>();
|
||||
var rs = query.exec(db);
|
||||
|
||||
@@ -32,6 +32,7 @@ import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.api.*;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
@@ -110,8 +111,11 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
case null -> getUserTasks(user.get(), ex);
|
||||
default -> {
|
||||
var taskId = Long.parseLong(head);
|
||||
head = path.pop();
|
||||
yield head == null ? getTask(ex, taskId, user.get()) : super.doGet(path, ex);
|
||||
yield switch (path.pop()){
|
||||
case null -> getTask(ex,taskId,user.get());
|
||||
case PARENT_CANDIDATES -> getParentCandidates(ex,taskId, user.get());
|
||||
default -> super.doGet(path,ex);
|
||||
};
|
||||
}
|
||||
};
|
||||
} catch (UmbrellaException e) {
|
||||
@@ -188,6 +192,33 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
return sendContent(ex, result);
|
||||
}
|
||||
|
||||
private boolean getParentCandidates(HttpExchange ex, long taskId, UmbrellaUser user) throws IOException {
|
||||
var task = taskDb.load(taskId);
|
||||
var project = projectService().load(task.projectId());
|
||||
var projectTasks = taskDb.listProjectTasks(project.id(),null, false);
|
||||
var mapped = projectTasks.values().stream().collect(Collectors.toMap(Task::id,Task::toMap));
|
||||
var roots = new HashMap<Long,Map<String,Object>>();
|
||||
for (var map : mapped.values()){
|
||||
if (!(map.get(ID) instanceof Long id)) continue;
|
||||
if (id == taskId) continue;
|
||||
if (map.get(PARENT_TASK_ID) instanceof Long parentId) {
|
||||
var parent = mapped.get(parentId);
|
||||
if (parent != null) {
|
||||
var o = parent.get(Field.CHILDREN);
|
||||
Map<Long,Object> children;
|
||||
if (o == null) {
|
||||
children = new HashMap<>();
|
||||
parent.put(Field.CHILDREN,children);
|
||||
} else children = (Map<Long, Object>) o;
|
||||
children.put(id, map);
|
||||
}
|
||||
} else {
|
||||
roots.put(id, map);
|
||||
}
|
||||
}
|
||||
return sendContent(ex,roots);
|
||||
}
|
||||
|
||||
private boolean getPermissionList(HttpExchange ex) throws IOException {
|
||||
var map = new HashMap<Integer, String>();
|
||||
for (var permission : Permission.values()) map.put(permission.code(),permission.name());
|
||||
@@ -293,7 +324,7 @@ public class TaskModule extends BaseHandler implements TaskService {
|
||||
Task parent = taskMap.get(task.parentTaskId());
|
||||
var trunk = placeInTree(parent, taskTree, taskMap);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArrayList<Object> children = (ArrayList<Object>) trunk.computeIfAbsent(CHILDREN, k -> new ArrayList<>());
|
||||
ArrayList<Object> children = (ArrayList<Object>) trunk.computeIfAbsent(Field.CHILDREN, k -> new ArrayList<>());
|
||||
children.add(mappedTask);
|
||||
return mappedTask;
|
||||
}
|
||||
|
||||
@@ -325,6 +325,7 @@
|
||||
"save_object": "{object} speichern",
|
||||
"search": "Suche",
|
||||
"searching…": "suche…",
|
||||
"select a new parent for {entity}": "Neue Über-Aufgabe für „{entity}“ wählen",
|
||||
"select_company" : "Wählen Sie eine ihrer Firmen:",
|
||||
"select_customer": "Kunde auswählen",
|
||||
"select_property": "Eigenschaft auswählen",
|
||||
|
||||
@@ -325,6 +325,7 @@
|
||||
"save_object": "save {object}",
|
||||
"search": "search",
|
||||
"searching…": "searhcing…",
|
||||
"select a new parent for {entity}": "select a new parent for '{entity}'",
|
||||
"select_company" : "select on of you companies:",
|
||||
"select_customer": "select customer",
|
||||
"select_property": "select property",
|
||||
|
||||
@@ -761,3 +761,12 @@ fieldset.vcard{
|
||||
white-space: nowrap;
|
||||
display: inline flow-root;
|
||||
}
|
||||
|
||||
.parent_selector > ul {
|
||||
position: absolute;
|
||||
top: 120px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
Reference in New Issue
Block a user