Improved response view
diff --git a/Gruntfile.js b/Gruntfile.js
index 8b90975..7dd4651 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -114,7 +114,7 @@
files: ['dev/scss/{util,base,fonts,kalamar,media}.scss',
'dev/scss/footer/footer.scss',
'dev/scss/header/{header,hint,menu,searchbar,vc,datepicker}.scss',
- 'dev/scss/main/{alertify,highlight,kwic,logos,' +
+ 'dev/scss/main/{alertify,koralquery,highlight,kwic,logos,' +
'main,matchinfo,pagination,query,'+
'resultinfo,sidebar,tutorial}.scss'
],
diff --git a/dev/demo/alldemo.js b/dev/demo/alldemo.js
index d7e8525..25aade7 100644
--- a/dev/demo/alldemo.js
+++ b/dev/demo/alldemo.js
@@ -532,7 +532,7 @@
}
});
-// KorAP.currentQuery = queryExample;
+KorAP.currentQuery = queryExample;
require(['app/en', 'init'], function (lang, init) {
KorAP.hintArray = hintArray;
diff --git a/dev/demo/vcdemo.js b/dev/demo/vcdemo.js
index 53ab75e..73cb805 100644
--- a/dev/demo/vcdemo.js
+++ b/dev/demo/vcdemo.js
@@ -64,6 +64,35 @@
]
};
+var collections = [
+ {
+ "statistics":{
+ "paragraphs":2034752,
+ "documents":196510,
+ "tokens":51545081,
+ "sentences":4116282
+ },
+ "query":[
+ {
+ "@value":{
+ "@field":"korap:field#corpusID",
+ "@value":"WPD",
+ "@type":"korap:term"
+ },
+ "@type":"korap:meta-filter"
+ }
+ ],
+ "name":"Wikipedia",
+ "path":"Wikipedia",
+ "description":"Die freie Enzyklopädie",
+ "shared":false,
+ "managed":true,
+ "created":"2015-04-01T23:04:32.000+02:00",
+ "foundries":"",
+ "id":"ZGU0ZTllNTFkYzc3M2VhZmViYzdkYWE2ODI5NDc3NTk4NGQ1YThhOTMwOTNhOWYxNWMwN2M3Y2YyZmE3N2RlNQ=="
+ }
+];
+
require(['vc','lib/domReady', 'lib/highlight/highlight.pack'], function (vcClass, domReady) {
var loc = KorAP.Locale;
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index d6493cb..87073d6 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -10,6 +10,9 @@
KorAP.API = KorAP.API || {};
+ /**
+ * Retrieve information about a match
+ */
KorAP.API.getMatchInfo = function (match, param, cb) {
// match is a KorAP.Match object
@@ -38,6 +41,16 @@
KorAP.API.getJSON(url, cb);
};
+ /**
+ * Retrieve information about collections
+ */
+ KorAP.API.getCollections = function (cb) {
+ KorAP.API.getJSON(KorAP.URL + '/collection', cb);
+ };
+
+ /**
+ * General method to retrieve JSON information
+ */
KorAP.API.getJSON = function (url, onload) {
var req = new XMLHttpRequest();
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index c960ec2..0f6c1e8 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -153,16 +153,19 @@
// Initialize documentation links
obj.tutorial.initDocLinks(document);
-/*
+ // There is a currentQuery
if (KorAP.currentQuery !== undefined) {
- var sb = document.getElementById('searchbar');
var kq = document.createElement('div');
kq.setAttribute('id', 'koralquery');
- sb.parentNode.insertBefore(kq, sb.nextSibling);
- kq.innerHTML = JSON.stringify(KorAP.currentQuery, null, ' ');
- hljs.highlightBlock(kq);
+
+ var kqInner = document.createElement('div');
+ kq.appendChild(kqInner);
+ kqInner.innerHTML = JSON.stringify(KorAP.currentQuery, null, ' ');
+ hljs.highlightBlock(kqInner);
+
+ var sb = document.getElementById('search');
+ sb.insertBefore(kq, sb.firstChild);
};
-*/
/**
* Add VC creation on submission.
@@ -192,12 +195,14 @@
});
// Render Virtual collection
+// TODO:: Use currentQuery!!!
function _getCurrentVC (vcClass) {
var vc = vcClass.create([
['title', 'string'],
['subTitle', 'string'],
['pubDate', 'date'],
- ['author', 'string']
+ ['author', 'string'],
+ ['corpusID', 'string']
]);
if (KorAP.currentVC !== undefined)
vc.fromJson(KorAP.currentVC);
diff --git a/dev/js/src/vc/chooseitem.js b/dev/js/src/vc/chooseitem.js
new file mode 100644
index 0000000..81ee4ca
--- /dev/null
+++ b/dev/js/src/vc/chooseitem.js
@@ -0,0 +1,89 @@
+define(['menu/item', 'util'], function (itemClass) {
+
+ var loc = KorAP.Locale;
+
+ return {
+
+ /**
+ * Create new menu item.
+ * Pass two parameters: value and type.
+ * the value may be localized by a name in
+ * KorAP.Locale with the prefix 'VC_',
+ * e.g. 'VC_subTitle'.
+ */
+ create : function (params) {
+ return Object.create(itemClass)
+ .upgradeTo(this)
+ ._init(params);
+ },
+
+ // Initialize item object
+ _init : function (params) {
+ if (params[0] === undefined)
+ throw new Error("Missing parameters");
+
+ this._id = params[0];
+ this._name = params[1];
+ this._desc = params[2];
+
+ this._lcField = ' ' + this._name.toLowerCase();
+ this._lcField += ' ' + this._desc.toLowerCase();
+
+ return this;
+ },
+
+ /**
+ * Override click event by passing all clicks
+ * to the menu object.
+ */
+ onclick : function (e) {
+ this.menu().release(
+ this._id,
+ this._name
+ );
+ e.halt();
+ },
+
+ /**
+ * Get the name of the item.
+ */
+ name : function () {
+ return this._name;
+ },
+
+ /**
+ * Get the identifier of the item.
+ */
+ id : function () {
+ return this._id;
+ },
+
+ /**
+ * Get the description of the item.
+ */
+ desc : function () {
+ return this._desc;
+ },
+
+ /**
+ * Get the HTML element associated with the item.
+ */
+ element : function () {
+
+ // already defined
+ if (this._element !== undefined)
+ return this._element;
+
+ // Create list item
+ var li = document.createElement("li");
+ li.setAttribute("data-type", this._type);
+ li.setAttribute("data-key", this._key);
+
+ // Connect action
+ li["onclick"] = this.onclick.bind(this);
+
+ li.ap pendChild(document.createTextNode(this._name));
+ return this._element = li;
+ }
+ }
+});
diff --git a/dev/js/src/vc/choosemenu.js b/dev/js/src/vc/choosemenu.js
new file mode 100644
index 0000000..7e00d44
--- /dev/null
+++ b/dev/js/src/vc/choosemenu.js
@@ -0,0 +1,21 @@
+/**
+ * Menu showing all predefined virtual collections.
+ * THIS IS EXPERIMENTAL AND MAY BE REMOVED!
+ */
+define(['vc/menu', 'api'], function (menuClass, itemClass) {
+ return {
+ create : function (params) {
+ return Object.create(menuClass)
+ .upgradeTo(this)
+ ._init(itemClass, undefined, params);
+ },
+
+ /**
+ * A click event was released
+ */
+ release : function (id, name) {
+ if (this._cb !== undefined)
+ this._cb(id, name);
+ }
+ };
+});
diff --git a/dev/scss/header/searchbar.scss b/dev/scss/header/searchbar.scss
index e0f241e..d383e73 100644
--- a/dev/scss/header/searchbar.scss
+++ b/dev/scss/header/searchbar.scss
@@ -74,21 +74,6 @@
}
}
-#koralquery {
- margin-top: 10px;
- margin-right: 40px;
- border: {
- radius: $standard-border-radius;
- color: $dark-green;
- style: solid;
- width: $border-size;
- }
- white-space: pre;
- background-color: $nearly-white;
- color: $dark-grey;
-}
-
-
/**
* Checkbox styling
* http://stackoverflow.com/questions/4148499/how-to-style-checkbox-using-css
diff --git a/dev/scss/main/koralquery.scss b/dev/scss/main/koralquery.scss
new file mode 100644
index 0000000..d569d77
--- /dev/null
+++ b/dev/scss/main/koralquery.scss
@@ -0,0 +1,19 @@
+@charset "utf-8";
+@import "../util";
+
+$border-size: 2px;
+
+#koralquery {
+ border: 1px solid $kwic-border;
+ white-space: pre;
+ background-color: $dark-orange;
+ > div {
+ background-color: $nearly-white;
+ margin: {
+ top: 2pt;
+ right: $right-match-distance; // 3em;
+ bottom: 2pt;
+ left: 2pt;
+ }
+ }
+}
diff --git a/dev/scss/main/main.scss b/dev/scss/main/main.scss
index f0ff84b..2bd308d 100644
--- a/dev/scss/main/main.scss
+++ b/dev/scss/main/main.scss
@@ -7,6 +7,7 @@
@import "resultinfo"; // Information on results
@import "sidebar"; // Navigation on the left side
@import "tutorial"; // Embedded and non-embedded tutorial
+@import "koralquery"; // KoralQuery
@import "alertify";
div.intro {
diff --git a/kalamar.conf b/kalamar.conf
index 085fdf4..7ae4c9b 100644
--- a/kalamar.conf
+++ b/kalamar.conf
@@ -1,7 +1,4 @@
{
- Kalamar => {
- 'api-0.1' => 'http://10.0.10.13:7070/api/v0.1/'
- },
Notifications => {
Alertify => {
base_timeout => 10_000
@@ -11,6 +8,7 @@
Search => {
engine => 'Kalamar::API',
api => 'http://10.0.10.13:7070/api/v0.1/'
+# api => 'http://localhost:9999/api/v0.1/'
},
CHI => {
default => {
diff --git a/lib/Kalamar.pm b/lib/Kalamar.pm
index 60833a8..7af4508 100644
--- a/lib/Kalamar.pm
+++ b/lib/Kalamar.pm
@@ -82,6 +82,10 @@
# Base query route
$r->get('/')->to('search#query')->name('index');
+ # Collection route
+ $r->get('/collection')->to('Search#collections')->name('collections');
+ $r->get('/collection/:id')->to('Search#collection')->name('collection');
+
# Documentation routes
$r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start');
$r->get('/doc/:page')->to('documentation#page', scope => undef);
diff --git a/lib/Kalamar/API.pm b/lib/Kalamar/API.pm
index a41550b..fa5d4db 100644
--- a/lib/Kalamar/API.pm
+++ b/lib/Kalamar/API.pm
@@ -427,6 +427,9 @@
$index->collection_jsonld($json->{request}->{collection});
};
+ # Temp
+ $index->collection_jsonld($collection_query);
+
$index->results(_map_matches($json->{matches}));
# Total results not set by stash
diff --git a/lib/Kalamar/Controller/Search.pm b/lib/Kalamar/Controller/Search.pm
index 66b602e..8445c9f 100644
--- a/lib/Kalamar/Controller/Search.pm
+++ b/lib/Kalamar/Controller/Search.pm
@@ -50,10 +50,10 @@
) if $query;
# Search resource (async)
- $c->search->resource(
- type => 'collection',
- $delay->begin
- );
+ # $c->search->resource(
+ # type => 'collection',
+ # $delay->begin
+ # );
},
# Collected search
@@ -121,6 +121,23 @@
};
+# Get information about collections
+sub collections {
+ my $c = shift;
+
+ # Async
+ $c->render_later;
+
+ # Get resource (for all)
+ $c->search->resource(
+ type => 'collection',
+ sub {
+ my $notes = $c->notifications(json => $c->stash('search.resource'));
+ return $c->render(json => $notes);
+ }
+ );
+};
+
1;
diff --git a/templates/search.html.ep b/templates/search.html.ep
index 20353d0..47ec86a 100644
--- a/templates/search.html.ep
+++ b/templates/search.html.ep
@@ -24,16 +24,16 @@
% };
-% if (search->total_results != 0 && search->results->size) {
<div id="search">
+% if (search->total_results != 0 && search->results->size) {
<ol class="align-left">
%= search_results begin
%= include 'match', match => $_
% end
</ol>
-</div>
% } else {
<p id="no-results"><%== loc 'noMatches', q => search->query %></p>
% }
+</div>
%= include 'query'