Skip to content

Commit

Permalink
Merge pull request #4044 from inception-project/feature/4040-Ability-…
Browse files Browse the repository at this point in the history
…to-store-preferences-from-client-side-code

#4040 - Ability to store preferences from client-side code
  • Loading branch information
reckart authored May 30, 2023
2 parents 4aec95e + c4b5ee0 commit c78eef6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ protected Component makeView()
"Unsupported view: [" + getDescription().getView() + "]"));
}

@Override
protected ExternalAnnotationEditorFactory getFactory()
{
return (ExternalAnnotationEditorFactory) super.getFactory();
}

private ExternalEditorPluginDescripion getDescription()
{
return getFactory().getDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import de.tudarmstadt.ukp.inception.diam.model.ajax.DefaultAjaxResponse;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorBase;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorExtensionRegistry;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorFactory;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorRegistry;
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.editor.view.DocumentViewExtensionPoint;
Expand Down Expand Up @@ -129,11 +130,9 @@ protected void onInitialize()
LOG.trace("[{}][{}] {}", getMarkupId(), vis.getMarkupId(), getClass().getSimpleName());
}

protected ExternalAnnotationEditorFactory getFactory()
protected AnnotationEditorFactory getFactory()
{
var factory = (ExternalAnnotationEditorFactory) annotationEditorRegistry
.getEditorFactory(editorFactoryId);
return factory;
return annotationEditorRegistry.getEditorFactory(editorFactoryId);
}

protected DiamAjaxBehavior createDiamBehavior()
Expand Down Expand Up @@ -218,25 +217,6 @@ private String getPropertiesAsJson()
}
}

private String getUserPreferencesAsJson()
{
var userPreferencesKey = getFactory().getUserPreferencesKey();
if (userPreferencesKey.isEmpty()) {
return "{}";
}

try {
var sessionOwner = userService.getCurrentUser();
var prefs = preferencesService.loadTraitsForUserAndProject(userPreferencesKey.get(),
sessionOwner, getModelObject().getProject());

return JSONUtil.toInterpretableJsonString(prefs);
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}

private CharSequence destroyScript()
{
return "ExternalEditor.destroy(document.getElementById('" + vis.getMarkupId() + "'));";
Expand Down Expand Up @@ -268,8 +248,8 @@ private String assembleScript(CommandQueue aCommandQueue)
private String getOrInitializeEditorScript()
{
return format(
"ExternalEditor.getOrInitialize(document.getElementById('%s'), Diam.factory(), %s, %s)",
vis.getMarkupId(), getPropertiesAsJson(), getUserPreferencesAsJson());
"ExternalEditor.getOrInitialize(document.getElementById('%s'), Diam.factory(), %s)",
vis.getMarkupId(), getPropertiesAsJson());
}

@Override
Expand Down

0 comments on commit c78eef6

Please sign in to comment.