Improved collection and koralquery view
diff --git a/dev/demo/all.html b/dev/demo/all.html
index 473a653..ff77d97 100644
--- a/dev/demo/all.html
+++ b/dev/demo/all.html
@@ -35,7 +35,7 @@
<!-- Search in the following virtual collection -->
<div id="vc-view"></div>
in
- <input id="collection-show" name="cs" type="hidden">
+ <input id="show" name="show" type="hidden" />
<input id="collection-name" name="collection-name" type="hidden">
<input id="collection" name="collection" type="text" value="">
with <span class="select">
diff --git a/dev/js/src/init.js b/dev/js/src/init.js
index 1749e6d..80257e6 100644
--- a/dev/js/src/init.js
+++ b/dev/js/src/init.js
@@ -7,6 +7,7 @@
'hint/array',
'vc/array',
'lib/alertify',
+ 'session',
'api',
'mailToChiffre',
'lib/highlight/highlight.pack',
@@ -18,17 +19,18 @@
domReady,
hintArray,
vcArray,
- alertifyClass) {
+ alertifyClass,
+ sessionClass) {
// Set hint array for hint helper
KorAP.hintArray = hintArray;
// Localization values
var loc = KorAP.Locale;
- loc.VC_allCorpora = loc.VC_allCorpora || 'all Corpora';
- loc.VC_oneCollection = loc.VC_oneCollection || 'one Collection';
- loc.TOGGLE_ALIGN = loc.TOGGLE_ALIGN || 'toggle Alignment';
- loc.SHOW_KQ = loc.SHOW_KQ || 'show KoralQuery';
+ loc.VC_allCorpora = loc.VC_allCorpora || 'all Corpora';
+ loc.VC_oneCollection = loc.VC_oneCollection || 'one Collection';
+ loc.TOGGLE_ALIGN = loc.TOGGLE_ALIGN || 'toggle Alignment';
+ loc.SHOW_KQ = loc.SHOW_KQ || 'show KoralQuery';
// Override KorAP.log
window.alertify = alertifyClass;
@@ -45,6 +47,10 @@
domReady(function (event) {
var obj = {};
+ var session = sessionClass.create('KalamarJS');
+
+ // What should be visible?
+ var show = session.get('show') || {};
/**
* Release notifications
@@ -107,37 +113,50 @@
};
// There is a koralQuery
- if (KorAP.koralQuery !== undefined && resultButton !== null) {
- var kq;
-
- var toggle = document.createElement('a');
- toggle.setAttribute('title', loc.SHOW_KQ)
- toggle.classList.add('show-kq', 'button');
- toggle.appendChild(document.createElement('span'))
- .appendChild(document.createTextNode(loc.SHOW_KQ));
- resultButton.appendChild(toggle);
+ if (KorAP.koralQuery !== undefined) {
- if (toggle !== undefined) {
-
- // Show koralquery
- toggle.addEventListener(
- 'click', function () {
- if (kq === undefined) {
- kq = document.createElement('div');
- kq.setAttribute('id', 'koralquery');
- kq.style.display = 'none';
- var kqInner = document.createElement('div');
- kq.appendChild(kqInner);
- kqInner.innerHTML = JSON.stringify(KorAP.koralQuery, null, ' ');
- hljs.highlightBlock(kqInner);
- var sb = document.getElementById('search');
- sb.insertBefore(kq, sb.firstChild);
- };
+ if (resultButton !== null) {
+ var kq;
+ var toggle = document.createElement('a');
+ toggle.setAttribute('title', loc.SHOW_KQ)
+ toggle.classList.add('show-kq', 'button');
+ toggle.appendChild(document.createElement('span'))
+ .appendChild(document.createTextNode(loc.SHOW_KQ));
+ resultButton.appendChild(toggle);
- kq.style.display = (kq.style.display === 'none') ? 'block' : 'none';
+ var showKQ = function () {
+ if (kq === undefined) {
+ kq = document.createElement('div');
+ kq.setAttribute('id', 'koralquery');
+ kq.style.display = 'none';
+ var kqInner = document.createElement('div');
+ kq.appendChild(kqInner);
+ kqInner.innerHTML = JSON.stringify(KorAP.koralQuery, null, ' ');
+ hljs.highlightBlock(kqInner);
+ var sb = document.getElementById('search');
+ sb.insertBefore(kq, sb.firstChild);
+ };
+
+ if (kq.style.display === 'none') {
+ kq.style.display = 'block';
+ show['kq'] = true;
}
- );
+ else {
+ kq.style.display = 'none';
+ delete show['kq'];
+ };
+ };
+
+ if (toggle !== undefined) {
+
+ // Show koralquery
+ toggle.addEventListener('click', showKQ);
+ };
};
+
+ // Session has KQ visibility stored
+ if (show["kq"])
+ showKQ.apply();
};
@@ -168,16 +187,15 @@
* Toggle the Virtual Collection builder
*/
if (vcname) {
- var collectionShow = document.getElementById('collection-show');
var vc;
var vcclick = function () {
var view = document.getElementById('vc-view');
// The vc is visible
- if (this.classList.contains('active')) {
+ if (vcname.classList.contains('active')) {
view.removeChild(vc.element());
- this.classList.remove('active');
- delete collectionShow['value'];
+ vcname.classList.remove('active');
+ delete show['collection'];
}
// The vc is not visible
@@ -185,12 +203,12 @@
if (vc === undefined)
vc = _getCurrentVC(vcClass, vcArray);
view.appendChild(vc.element());
- this.classList.add('active');
- collectionShow.value = 'true';
+ vcname.classList.add('active');
+ show['collection'] = true;
};
};
vcname.onclick = vcclick;
- if (collectionShow.value === 'true') {
+ if (show['collection']) {
vcclick.apply();
};
};
@@ -201,7 +219,8 @@
*/
if (document.getElementById('view-tutorial')) {
window.tutorial = tutClass.create(
- document.getElementById('view-tutorial')
+ document.getElementById('view-tutorial'),
+ session
);
obj.tutorial = window.tutorial;
}
@@ -225,11 +244,30 @@
var form = document.getElementById('searchform');
if (form !== undefined) {
form.addEventListener('submit', function (e) {
- if (vc === undefined)
- vc = _getCurrentVC(vcClass, vcArray);
+ var qf = document.getElementById('q-field');
- if (vc !== undefined)
+ // No query was defined
+ if (qf.value === undefined || qf.value === '') {
+ qf.focus();
+ e.halt();
+ KorAP.log(700, "No query given");
+ return;
+ };
+
+ // Store session information
+ session.set("show", show);
+
+ // Set Virtual collection
+ if (vc === undefined) {
+ vc = _getCurrentVC(vcClass, vcArray);
+ };
+
+ if (vc !== undefined) {
input.value = vc.toQuery();
+ }
+ else {
+ delete input['value'];
+ };
});
};
diff --git a/dev/js/src/tutorial.js b/dev/js/src/tutorial.js
index 55c2415..5009a17 100644
--- a/dev/js/src/tutorial.js
+++ b/dev/js/src/tutorial.js
@@ -17,16 +17,22 @@
* Create new tutorial object.
* Accepts an element to bind the tutorial window to.
*/
- create : function (obj) {
+ create : function (obj,session) {
if (!obj)
return null;
- return Object.create(this)._init(obj);
+ return Object.create(this)._init(obj,session);
},
// Initialize Tutorial object
- _init : function (obj) {
+ _init : function (obj, session) {
- this._session = sessionClass.create();
+ if (session === undefined) {
+ this._session = sessionClass.create();
+ }
+ else {
+ this._session = session;
+ };
+
if (obj) {
this._show = obj;
diff --git a/kalamar.dict b/kalamar.dict
index 971407d..b5964f5 100644
--- a/kalamar.dict
+++ b/kalamar.dict
@@ -22,7 +22,7 @@
},
about => 'Über KorAP',
login => 'Anmelden',
- searchtitle => 'KorAP: Finde "<%== $q %>" (<%= $ql %>)',
+ searchtitle => 'KorAP: Finde »<%== $q %>« <% if (param("collection-name")) { %>in <%== param("collection-name") %><% } %> mit <%== loc("QL_" . $ql, "unbekannter Anfragesprache") %>',
searchplaceholder => 'Finde ...',
go => 'Los!',
in => 'in',
@@ -60,7 +60,7 @@
about => 'About KorAP',
login => 'Login',
go => 'Go!',
- searchtitle => 'KorAP: Find "<%== $q %>" (<%= $ql %>)',
+ searchtitle => 'KorAP: Find »<%== $q %>« <% if (param("collection-name")) { %>in <%== param("collection-name") %><% } %> with <%== loc("QL_". $ql, "unknown query language") %>)',
searchplaceholder => 'Find ...',
in => 'in',
by => 'by',
@@ -80,6 +80,12 @@
-short => 'KorAP',
desc => 'KorAP - Corpus Analysis Platform',
overview => 'KorAP - Overview'
+ },
+ QL => {
+ poliqarp => 'Poliqarp',
+ cosmas2 => 'Cosmas II',
+ annis => 'Annis QL',
+ cql => 'CQL v1.2'
}
}
};
diff --git a/templates/partial/header.html.ep b/templates/partial/header.html.ep
index e363989..c3e7e6e 100644
--- a/templates/partial/header.html.ep
+++ b/templates/partial/header.html.ep
@@ -17,14 +17,12 @@
<div id="vc-view"></div>
<%= loc 'in' %>
%# TODO: Create 'align' parameter
- %# TODO: Create 'show' parameter with comma separated list
- %= hidden_field 'cs' => stash('cs'), id => 'collection-show'
- %= hidden_field 'collection-name' => stash('collection-name'), id => 'collection-name'
+ %= hidden_field 'collection-name' => param('collection-name'), id => 'collection-name'
%= text_field 'collection', id => 'collection'
<%= loc 'with' %>
<span class="select">
- %= select_field 'ql', [[Poliqarp => 'poliqarp'], ['Cosmas II' => 'cosmas2'], ['Annis' => 'annis'], ['CQL v1.2' => 'cql']], id => 'ql-field'
+ %= select_field 'ql', [[loc('QL_poliqarp') => 'poliqarp'], [loc('QL_cosmas2') => 'cosmas2'], [loc('QL_annis') => 'annis'], [loc('QL_cql') => 'cql']], id => 'ql-field'
</span>
<div class="button right">
% param(cutoff => 1) unless param 'q';