Added query information API to plugin server
Change-Id: Ib4120ca18d1153fd454aa4354d7854a5685fb092
diff --git a/Changes b/Changes
index 46d7fa3..c1db812 100755
--- a/Changes
+++ b/Changes
@@ -1,4 +1,4 @@
-0.39 2020-08-25
+0.39 2020-08-28
- Add information on secret file to Readme.
- Change default API endpoint to korap.ids-mannheim.de.
- Fix label for toggle plugins.
@@ -6,6 +6,7 @@
- Forward 'pipe' parameter to backend.
- Introduce base css file for plugins.
- Refactoring of sass files.
+ - Added query form API to plugin server.
WARNING: If you relied on the former default API endpoint
being http://localhost:9999/, this will break your
diff --git a/dev/js/spec/pluginSpec.js b/dev/js/spec/pluginSpec.js
index 3d20942..c0d741d 100644
--- a/dev/js/spec/pluginSpec.js
+++ b/dev/js/spec/pluginSpec.js
@@ -1,4 +1,4 @@
-define(['plugin/server','plugin/widget','panel', 'panel/query', 'panel/result', 'plugin/service', 'pipe'], function (pluginServerClass, widgetClass, panelClass, queryPanelClass, resultPanelClass, serviceClass, pipeClass) {
+define(['plugin/server','plugin/widget','panel', 'panel/query', 'panel/result', 'plugin/service', 'pipe', 'vc','util'], function (pluginServerClass, widgetClass, panelClass, queryPanelClass, resultPanelClass, serviceClass, pipeClass, vcClass) {
describe('KorAP.Plugin.Server', function () {
@@ -290,8 +290,7 @@
});
});
- describe('KorAP.Plugin.ResultPanel', function () {
-
+ describe('KorAP.Plugin.ResultPanel', function () {
it('Plugin is registered second: buttons should be added to panel', function () {
var resultPanel = resultPanelClass.create();
@@ -322,7 +321,7 @@
// Clean up
KorAP.Panel['result'] = undefined;
manager.destroy();
- });
+ });
it('Plugin is registered first: Buttons should be added to panel and cleared', function () {
@@ -360,43 +359,32 @@
describe('KorAP.Plugin communications', function () {
it('should receive messages', function () {
var manager = pluginServerClass.create();
-
var id = manager.addService('Example 1', 'about:blank');
expect(id).toMatch(/^id-/);
-
var temp = KorAP.koralQuery;
KorAP.koralQuery = { "@type" : "koral:test" };
-
let data = {
"originID" : id,
"action" : "get",
"key" : "KQ"
};
-
manager._receiveMsg({
"data" : data
});
-
manager.destroy();
-
expect(data.value["@type"]).toEqual("koral:test");
-
// Recreate initial state
KorAP.koralQuery = temp;
});
-
it('should add to pipe', function () {
var manager = pluginServerClass.create();
-
var temp = KorAP.Pipe;
KorAP.Pipe = pipeClass.create();
-
expect(KorAP.Pipe.toString()).toEqual("");
var id = manager.addService('Example 2', 'about:blank');
expect(id).toMatch(/^id-/);
-
manager._receiveMsg({
"data" : {
"originID" : id,
@@ -405,9 +393,7 @@
"service" : "https://pipe-service.de"
}
});
-
expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de");
-
manager._receiveMsg({
"data" : {
"originID" : id,
@@ -416,9 +402,7 @@
"service" : "https://pipe-service-2.de"
}
});
-
expect(KorAP.Pipe.toString()).toEqual("https://pipe-service.de,https://pipe-service-2.de");
-
manager._receiveMsg({
"data" : {
"originID" : id,
@@ -427,13 +411,52 @@
"service" : "https://pipe-service.de"
}
});
-
expect(KorAP.Pipe.toString()).toEqual("https://pipe-service-2.de");
-
manager.destroy();
-
// Recreate initial state
KorAP.Pipe = temp;
});
+
+ it('should reply to query information requests', function () {
+ var manager = pluginServerClass.create();
+ var id = manager.addService('Service', 'about:blank');
+ expect(id).toMatch(/^id-/);
+ var temp = KorAP.vc;
+ // Create form for query form information
+ let f = document.createElement('form');
+ var qfield = f.addE('input');
+ qfield.setAttribute("id", "q-field");
+ qfield.value = "[orth=Baum]";
+ var qlfield = f.addE('select');
+ qlfield.setAttribute("id", "ql-field");
+ qlfield.addE('option').setAttribute('value', 'cosmas-2');
+ qlfield.addE('option').setAttribute('value', 'poliqarp');
+ qlfield.selectedIndex = 1;
+
+ KorAP.vc = vcClass.create().fromJson({
+ "key" : "title",
+ "type" : "type:regex",
+ "value" : "[^b]ee.+?",
+ "@type" : "koral:doc"
+ });
+ // console.log(KorAP.vc.toQuery());
+
+ document.body.appendChild(f);
+ let data = {
+ "originID" : id,
+ "action" : "get",
+ "key" : "QueryForm"
+ };
+ manager._receiveMsg({
+ "data" : data
+ });
+ manager.destroy();
+ expect(data.value["q"]).toEqual("[orth=Baum]");
+ expect(data.value["ql"]).toEqual("poliqarp");
+ expect(data.value["cq"]).toEqual("title = /[^b]ee.+?/");
+ // Recreate initial state
+ KorAP.vc = temp;
+ document.body.removeChild(f);
+ });
});
});
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index e5578be..7a2d305 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -407,10 +407,29 @@
// Get information from the embedding platform
case 'get':
+
+ // Get KoralQuery
if (d.key == 'KQ') {
if (KorAP.koralQuery !== undefined) {
d["value"] = KorAP.koralQuery;
};
+ }
+
+ // Get Query form information
+ else if (d.key == 'QueryForm') {
+ let doc = document;
+ let v = d["value"] = {};
+
+ var el;
+ if (el = doc.getElementById('q-field')) {
+ v["q"] = el.value;
+ };
+ if (el = doc.getElementById('ql-field')) {
+ v["ql"] = el.value;
+ };
+ if (el = KorAP.vc) {
+ v["cq"] = el.toQuery();
+ };
};
};