Skip to content

Commit

Permalink
Merge pull request #3915 from inception-project/feature/3914-Allow-pi…
Browse files Browse the repository at this point in the history
…nning-label-groups-to-the-annotation-sidebar

#3914 - Allow pinning label groups to the annotation sidebar
  • Loading branch information
reckart committed Apr 1, 2023
2 parents 75473ca + 1a67bbe commit 28eb98d
Show file tree
Hide file tree
Showing 20 changed files with 536 additions and 23 deletions.
17 changes: 12 additions & 5 deletions inception/inception-diam-editor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-api</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-api-editor</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-model</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-preferences</artifactId>
</dependency>
<dependency>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-security</artifactId>
Expand Down Expand Up @@ -97,11 +109,6 @@
<artifactId>wicketstuff-annotationeventdispatcher</artifactId>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*/
package de.tudarmstadt.ukp.inception.diam.sidebar;

import static de.tudarmstadt.ukp.inception.diam.sidebar.preferences.DiamSidebarManagerPrefs.KEY_DIAM_SIDEBAR_MANAGER_PREFS;
import static de.tudarmstadt.ukp.inception.websocket.config.WebsocketConfig.WS_ENDPOINT;
import static java.lang.String.format;
import static java.lang.invoke.MethodHandles.lookup;
import static org.apache.wicket.markup.head.JavaScriptHeaderItem.forReference;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Map;

Expand All @@ -33,23 +32,22 @@
import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;

import de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.AnnotationPageBase;
import de.tudarmstadt.ukp.inception.diam.editor.DiamAjaxBehavior;
import de.tudarmstadt.ukp.inception.diam.editor.DiamJavaScriptReference;
import de.tudarmstadt.ukp.inception.diam.model.compactv2.CompactSerializerV2Impl;
import de.tudarmstadt.ukp.inception.diam.model.websocket.ViewportDefinition;
import de.tudarmstadt.ukp.inception.preferences.PreferencesService;
import de.tudarmstadt.ukp.inception.support.svelte.SvelteBehavior;

public class DiamAnnotationBrowser
extends WebMarkupContainer
{
private static final long serialVersionUID = 3956364643964484470L;

private static final Logger LOG = getLogger(lookup().lookupClass());

private @SpringBean ServletContext servletContext;
private @SpringBean PreferencesService userPrefService;

private DiamAjaxBehavior diamBehavior;

Expand Down Expand Up @@ -82,12 +80,16 @@ protected void onConfigure()
var viewport = new ViewportDefinition(state.getDocument(), state.getUser().getUsername(), 0,
Integer.MAX_VALUE, CompactSerializerV2Impl.ID);

var managerPrefs = userPrefService
.loadDefaultTraitsForProject(KEY_DIAM_SIDEBAR_MANAGER_PREFS, state.getProject());

Map<String, Object> properties = Map.of( //
"ajaxEndpointUrl", diamBehavior.getCallbackUrl(), //
"wsEndpointUrl", constructEndpointUrl(), //
"topicChannel", viewport.getTopic());
"topicChannel", viewport.getTopic(), //
"pinnedGroups", managerPrefs.getPinnedGroups());

// model will be added as props to vue component
// model will be added as props to Svelte component
setDefaultModel(Model.ofMap(properties));
}

Expand All @@ -102,7 +104,6 @@ private String constructEndpointUrl()
protected DiamAjaxBehavior createDiamBehavior()
{
var diam = new DiamAjaxBehavior();
// diam.addPriorityHandler(new ShowContextMenuHandler());
return diam;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Licensed to the Technische Universität Darmstadt under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The Technische Universität Darmstadt
licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<form wicket:id="form" class="card">
<div class="card-header">
<wicket:message key="title"/>
</div>
<div class="card-body">
<div class="row form-row">
<label class="col-sm-4 col-form-label">
<wicket:message key="pinnedGroups"/>
</label>
<div class="col-sm-8">
<div wicket:id="pinnedGroups"/>
</div>
</div>
</div>
</form>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.diam.sidebar.preferences;

import static de.tudarmstadt.ukp.inception.diam.sidebar.preferences.DiamSidebarManagerPrefs.KEY_DIAM_SIDEBAR_MANAGER_PREFS;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import de.tudarmstadt.ukp.clarin.webanno.api.ProjectService;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaForm;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorRegistry;
import de.tudarmstadt.ukp.inception.preferences.PreferencesService;

public class DiamSidebarManagerPrefPanel
extends Panel
{
private static final long serialVersionUID = 3635729182772294488L;

private @SpringBean AnnotationEditorRegistry annotationEditorRegistry;
private @SpringBean PreferencesService preferencesService;
private @SpringBean ProjectService projectService;

private CompoundPropertyModel<DiamSidebarManagerPrefs> sidebarPreferences;

public DiamSidebarManagerPrefPanel(String aId, IModel<Project> aProjectModel)
{
super(aId, aProjectModel);
setOutputMarkupPlaceholderTag(true);

sidebarPreferences = CompoundPropertyModel.of(actionLoad());

LambdaForm<DiamSidebarManagerPrefs> form = new LambdaForm<>("form", sidebarPreferences);

form.add(new PinnedGroupsPanel("pinnedGroups", sidebarPreferences.bind("pinnedGroups")));

form.onSubmit(this::actionSave);

add(form);
}

@SuppressWarnings("unchecked")
public IModel<Project> getModel()
{
return (IModel<Project>) getDefaultModel();
}

private DiamSidebarManagerPrefs actionLoad()
{
return preferencesService.loadDefaultTraitsForProject(KEY_DIAM_SIDEBAR_MANAGER_PREFS,
getModel().getObject());
}

private void actionSave(AjaxRequestTarget aTarget, Form<DiamSidebarManagerPrefs> aForm)
{
preferencesService.saveDefaultTraitsForProject(KEY_DIAM_SIDEBAR_MANAGER_PREFS,
getModel().getObject(), aForm.getModelObject());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Technische Universität Darmstadt under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The Technische Universität Darmstadt
# licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

title=Annotation sidebar
pinnedGroups=Pinned groups
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.diam.sidebar.preferences;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import de.tudarmstadt.ukp.inception.preferences.Key;

public class DiamSidebarManagerPrefs
implements Serializable
{
private static final long serialVersionUID = 8420554954400084375L;

public static final Key<DiamSidebarManagerPrefs> KEY_DIAM_SIDEBAR_MANAGER_PREFS = new Key<>(
DiamSidebarManagerPrefs.class, "annotation/editor/annotation-sidebar/manager");

private final List<String> pinnedGroups = new ArrayList<>();

public List<String> getPinnedGroups()
{
System.out.println("[" + hashCode() + "] GET " + String.join(",", pinnedGroups));
return pinnedGroups;
}

public void setPinnedGroups(List<String> aPinnedGroups)
{
pinnedGroups.clear();
if (aPinnedGroups != null) {
pinnedGroups.addAll(aPinnedGroups);
}
System.out.println("[" + hashCode() + "] SET " + String.join(",", aPinnedGroups));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<!--
Licensed to the Technische Universität Darmstadt under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The Technische Universität Darmstadt
licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div class="list-group">
<div class="list-group-item">
<div class="input-group">
<input type="text" wicket:id="newItemName" class="form-control"/>
<span class="input-group-btn">
<a wicket:id="addItem" class="btn btn-primary">
<i class="fas fa-plus" aria-hidden="true"></i>
</a>
</span>
</div>
</div>
<div wicket:id=items class="list-group-item">
<form wicket:id="itemForm">
<div class="input-group">
<a wicket:id="moveUp" class="btn btn-outline-secondary">
<i class="fas fa-arrow-up" aria-hidden="true"></i>
</a>
<a wicket:id="moveDown" class="btn btn-outline-secondary">
<i class="fas fa-arrow-down" aria-hidden="true"></i>
</a>
<input type="text" wicket:id="textField" class="form-control"/>
<a wicket:id="removeItem" class="btn btn-outline-danger">
<i class="fas fa-trash" aria-hidden="true"></i>
</a>
</div>
</form>
</div>
</div>
</wicket:panel>
</html>

0 comments on commit 28eb98d

Please sign in to comment.