completed member addition by autocomplete form
This commit is contained in:
@@ -51,10 +51,13 @@ public class Constants {
|
|||||||
public static final String LOGIN = "login";
|
public static final String LOGIN = "login";
|
||||||
public static final String MEMBERS = "members";
|
public static final String MEMBERS = "members";
|
||||||
public static final String MESSAGES = "messages";
|
public static final String MESSAGES = "messages";
|
||||||
|
|
||||||
public static final String NAME = "name";
|
public static final String NAME = "name";
|
||||||
|
public static final String NEW_MEMBER = "new_member";
|
||||||
public static final String MIME = "mime";
|
public static final String MIME = "mime";
|
||||||
public static final String NO_INDEX = "no_index";
|
public static final String NO_INDEX = "no_index";
|
||||||
public static final String NUMBER = "number";
|
public static final String NUMBER = "number";
|
||||||
|
|
||||||
public static final String OPTIONAL = "optional";
|
public static final String OPTIONAL = "optional";
|
||||||
public static final String PARENT_TASK_ID = "parent_task_id";
|
public static final String PARENT_TASK_ID = "parent_task_id";
|
||||||
public static final String PASS = "pass";
|
public static final String PASS = "pass";
|
||||||
|
|||||||
@@ -7,6 +7,16 @@
|
|||||||
let text = $state('')
|
let text = $state('')
|
||||||
let options = $state({});
|
let options = $state({});
|
||||||
|
|
||||||
|
async function ondblclick(evt){
|
||||||
|
var select = evt.target;
|
||||||
|
let key = select.value;
|
||||||
|
text = options[key];
|
||||||
|
let result = {};
|
||||||
|
result[key]=text;
|
||||||
|
options={};
|
||||||
|
onSelect(result);
|
||||||
|
}
|
||||||
|
|
||||||
async function onkeyup(evt){
|
async function onkeyup(evt){
|
||||||
var select = evt.target;
|
var select = evt.target;
|
||||||
var key = evt.key;
|
var key = evt.key;
|
||||||
@@ -17,12 +27,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key == 'Enter'){
|
if (key == 'Enter'){
|
||||||
let key = select.value;
|
ondblclick(evt);
|
||||||
text = options[key];
|
|
||||||
let result = {};
|
|
||||||
result[key]=text;
|
|
||||||
options={};
|
|
||||||
onSelect(result);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key == 'Backspace'){
|
if (key == 'Backspace'){
|
||||||
@@ -41,7 +46,7 @@
|
|||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<select size={Object.keys(options).length<2?2:Object.keys(options).length+1} {onkeyup} autofocus width="40">
|
<select size={Object.keys(options).length<2?2:Object.keys(options).length+1} {onkeyup} {ondblclick} autofocus width="40">
|
||||||
<option>{text}</option>
|
<option>{text}</option>
|
||||||
{#each Object.entries(options) as [val,caption]}
|
{#each Object.entries(options) as [val,caption]}
|
||||||
<option value={val}>{caption}</option>
|
<option value={val}>{caption}</option>
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
import { t } from '../translations.svelte.js';
|
import { t } from '../translations.svelte.js';
|
||||||
import Autocomplete from './Autocomplete.svelte';
|
import Autocomplete from './Autocomplete.svelte';
|
||||||
import PermissionSelector from './PermissionSelector.svelte';
|
import PermissionSelector from './PermissionSelector.svelte';
|
||||||
let { members, updatePermission = (uid,perm) => console.log({user:uid,perm:perm}) } = $props();
|
let {
|
||||||
|
members,
|
||||||
|
updatePermission = (uid,perm) => console.log(`no handler for updatePermission(${uid}, ${perm})`),
|
||||||
|
addMember = (entry) => console.log(`no handler for addMember(${entry})`)
|
||||||
|
} = $props();
|
||||||
let error = $state(null);
|
let error = $state(null);
|
||||||
let sortedMembers = $derived.by(() => Object.values(members).sort((a, b) => a.user.name.localeCompare(b.user.name)));
|
let sortedMembers = $derived.by(() => Object.values(members).sort((a, b) => a.user.name.localeCompare(b.user.name)));
|
||||||
|
|
||||||
@@ -34,8 +38,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSelect(name){
|
function onSelect(entry){
|
||||||
console.log({selected_user:name})
|
addMember(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(loadPermissions);
|
onMount(loadPermissions);
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
let estimated_time = $state({sum:0});
|
let estimated_time = $state({sum:0});
|
||||||
let showSettings = $state(false);
|
let showSettings = $state(false);
|
||||||
|
|
||||||
|
async function addMember(entry){
|
||||||
|
const ids = Object.keys(entry);
|
||||||
|
console.log({entry:entry,ids:ids});
|
||||||
|
if (ids) update({new_member:+ids.pop()});
|
||||||
|
}
|
||||||
|
|
||||||
async function loadProject(){
|
async function loadProject(){
|
||||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project/${id}`;
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project/${id}`;
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await fetch(url,{credentials:'include'});
|
||||||
@@ -125,6 +131,6 @@
|
|||||||
{#if showSettings}
|
{#if showSettings}
|
||||||
<fieldset class="project settings">
|
<fieldset class="project settings">
|
||||||
<legend>{t('settings')}</legend>
|
<legend>{t('settings')}</legend>
|
||||||
<MemberEditor members={project.members} {updatePermission} />
|
<MemberEditor members={project.members} {updatePermission} {addMember} />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -6,8 +6,7 @@ import static de.srsoftware.umbrella.core.Constants.*;
|
|||||||
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.*;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
|
||||||
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
import static de.srsoftware.umbrella.core.model.Permission.*;
|
||||||
import static de.srsoftware.umbrella.core.model.Permission.OWNER;
|
|
||||||
import static de.srsoftware.umbrella.core.model.Status.OPEN;
|
import static de.srsoftware.umbrella.core.model.Status.OPEN;
|
||||||
import static de.srsoftware.umbrella.project.Constants.CONFIG_DATABASE;
|
import static de.srsoftware.umbrella.project.Constants.CONFIG_DATABASE;
|
||||||
import static java.lang.Boolean.TRUE;
|
import static java.lang.Boolean.TRUE;
|
||||||
@@ -41,6 +40,14 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|||||||
users = companies.userService();
|
users = companies.userService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMember(Project project, long userId) {
|
||||||
|
var user = users.loadUser(userId);
|
||||||
|
var member = new Member(user,READ_ONLY);
|
||||||
|
project.members().put(userId,member);
|
||||||
|
project.dirtyFields().add(MEMBERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompanyService companyService() {
|
public CompanyService companyService() {
|
||||||
return companies;
|
return companies;
|
||||||
@@ -188,12 +195,14 @@ public class ProjectModule extends BaseHandler implements ProjectService {
|
|||||||
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
|
||||||
var json = json(ex);
|
var json = json(ex);
|
||||||
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(project,memberJson);
|
if (json.has(MEMBERS) && json.get(MEMBERS) instanceof JSONObject memberJson) patchMembers(project,memberJson);
|
||||||
|
if (json.has(NEW_MEMBER) && json.get(NEW_MEMBER) instanceof Number num) addMember(project,num.longValue());
|
||||||
|
|
||||||
projects.save(project.patch(json));
|
projects.save(project.patch(json));
|
||||||
return sendContent(ex,project.toMap());
|
return sendContent(ex,project.toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean postProject(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
|
private boolean postProject(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||||
var json = json(ex);
|
var json = json(ex);
|
||||||
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
|
if (!(json.has(NAME) && json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
|
||||||
|
|||||||
Reference in New Issue
Block a user