blob: 4193f280e55a4c51cb70b3e5948545e40ba438f4 [file] [log] [blame]
hebasta75cfca52019-02-19 13:15:27 +01001/**
2 * Guided Tour to explain the UI
3 *
4 * @author Helge Stallkamp
5 */
Akrone51eaa32020-11-10 09:35:53 +01006"use strict";
hebasta75cfca52019-02-19 13:15:27 +01007
Akrone51eaa32020-11-10 09:35:53 +01008define(['lib/intro', 'vc', 'hint', 'menu', 'vc/doc', 'vc/docgroup'],
9 function(introClass, vcClass, hintClass, menuClass, docClass, docGroup) {
hebasta5df796f2019-05-21 15:27:12 +020010
hebasta75cfca52019-02-19 13:15:27 +010011 //needed for localization of labels and contents of the tour
12 const loc = KorAP.Locale;
hebasta5df796f2019-05-21 15:27:12 +020013
hebasta75cfca52019-02-19 13:15:27 +010014 //labels for nextStep, previousStep, done and abort
15 loc.TOUR_lskip = loc.TOUR_lskip || "Abort";
16 loc.TOUR_lprev = loc.TOUR_lprev || "Back";
17 loc.TOUR_lnext = loc.TOUR_lnext || "Next";
18 loc.TOUR_ldone = loc.TOUR_ldone || "Done";
hebastaca61f812019-11-11 22:25:27 +010019 loc.TOUR_ldoneSearch = loc.TOUR_ldoneSearch || "Search";
20
hebasta5df796f2019-05-21 15:27:12 +020021 //localization guided tour gTstartSearch
hebasta1e2d98e2019-10-30 15:58:17 +010022 loc.TOUR_welc = loc.TOUR_welc || "<span class='tgreeting'> Welcome to our guided tour!</span>" +
hebastaee7b8a82020-01-20 12:45:04 +010023 "<p class='pfirstStep'> This tour should give you a quick introduction to KorAP. " +
24 "We lead you step by step through an example. </p>";
25 loc.TOUR_sear1 = loc.TOUR_sear1 || "Input field for the query, for example the search for '" + loc.TOUR_Qexample + "'.";
hebastaf95226b2019-09-19 11:37:00 +020026 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper";
27 loc.TOUR_annotAss = loc.TOUR_annotAss || "The assistant displays the annotations of the different layers and helps to formulate queries.";
hebasta94e47cb2019-07-24 22:24:27 +020028 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus";
hebasta75cfca52019-02-19 13:15:27 +010029 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
hebasta94e47cb2019-07-24 22:24:27 +020030 loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic.";
31 loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic";
hebasta1e2d98e2019-10-30 15:58:17 +010032 loc.TOUR_qlfield = loc.TOUR_qlfield|| "Selection of the query language: You can use KorAP with different query languages.";
33 loc.TOUR_help = loc.TOUR_help || "Help and information about KorAP.";
hebastaca61f812019-11-11 22:25:27 +010034 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select this to show only the first hits in undefined order.";
hebasta1e2d98e2019-10-30 15:58:17 +010035 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search";
hebasta87f1b1f2019-07-30 13:03:23 +020036
hebasta5df796f2019-05-21 15:27:12 +020037 //localization guided Tour gTshowResults
hebasta87f1b1f2019-07-30 13:03:23 +020038 loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)";
39 loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet.";
hebasta1e2d98e2019-10-30 15:58:17 +010040 loc.TOUR_snippetb = loc.TOUR_snippetb || "Snippet";
41 loc.TOUR_metadatab = loc.TOUR_metadatab || "Display of metadata";
hebasta87f1b1f2019-07-30 13:03:23 +020042 loc.TOUR_metadata = loc.TOUR_metadata || "Metadata";
hebasta1e2d98e2019-10-30 15:58:17 +010043 loc.TOUR_tokenb = loc.TOUR_tokenb || "Display of token annotations";
hebasta87f1b1f2019-07-30 13:03:23 +020044 loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations.";
hebasta1e2d98e2019-10-30 15:58:17 +010045 loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations"
hebasta87f1b1f2019-07-30 13:03:23 +020046 loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views."
47 loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010048
49 //localization of button labels
hebastaee7b8a82020-01-20 12:45:04 +010050 let labelOpts= {
hebasta5df796f2019-05-21 15:27:12 +020051 'skipLabel': loc.TOUR_lskip,
52 'prevLabel': loc.TOUR_lprev,
53 'nextLabel': loc.TOUR_lnext,
54 'doneLabel': loc.TOUR_ldone,
hebastaee7b8a82020-01-20 12:45:04 +010055 'showStepNumbers': false
56 };
57
58 //usability options of tours
59 let usabilityOpts ={
60 'showBullets': false,
61 'overlayOpacity': 0.7,
62 'exitOnOverlayClick': false,
63 'disableInteraction': true,
64 'hideNext': true,
65 'hidePrev': true
hebasta75cfca52019-02-19 13:15:27 +010066 };
hebasta87f1b1f2019-07-30 13:03:23 +020067
68 var doe = document;
hebasta5df796f2019-05-21 15:27:12 +020069
hebasta75cfca52019-02-19 13:15:27 +010070 return{
hebasta5df796f2019-05-21 15:27:12 +020071
hebasta75cfca52019-02-19 13:15:27 +010072 /**
hebasta5df796f2019-05-21 15:27:12 +020073 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010074 */
hebasta5df796f2019-05-21 15:27:12 +020075 gTstartSearch:function(elparam){
hebasta5df796f2019-05-21 15:27:12 +020076 let intro = introClass();
hebastaee7b8a82020-01-20 12:45:04 +010077 intro.setOptions(labelOpts);
hebasta1e2d98e2019-10-30 15:58:17 +010078 intro.setOption('tooltipClass', 'gTstartSearch');
hebastaca61f812019-11-11 22:25:27 +010079 /*
80 * Sets button labels for the last step of the tour
81 * Because Kalamar is a multipage webapplication, this tours starts by
82 * completion the gTshowResults Tour. Therefore the label of the done button changed.
83 */
84 intro.setOption('doneLabel', loc.TOUR_ldoneSearch );
hebastaee7b8a82020-01-20 12:45:04 +010085 intro.setOptions(usabilityOpts);
hebastaca61f812019-11-11 22:25:27 +010086
hebasta5df796f2019-05-21 15:27:12 +020087 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010088 if(elparam){
89 doe = elparam;
90 }
hebasta5df796f2019-05-21 15:27:12 +020091
hebasta75cfca52019-02-19 13:15:27 +010092 let input = doe.querySelector("#q-field");
93 input.value="";
94
hebasta5df796f2019-05-21 15:27:12 +020095
hebasta75cfca52019-02-19 13:15:27 +010096 //steps of the example tour
97 let Steps =[
98 {
hebasta1e2d98e2019-10-30 15:58:17 +010099 intro: loc.TOUR_welc,
100 },
101 {
hebastaf95226b2019-09-19 11:37:00 +0200102 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +0100103 intro: loc.TOUR_sear1,
104 position: 'bottom'
105 },
106 {
hebasta75cfca52019-02-19 13:15:27 +0100107 element: '#hint',
108 intro: loc.TOUR_searAnnot,
109 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +0200110 },
111 {
hebastaf95226b2019-09-19 11:37:00 +0200112 element: doe.querySelector("#hint > .menu.hint"),
113 intro: loc.TOUR_annotAss,
114 position: 'bottom',
115 },
116 {
hebasta75cfca52019-02-19 13:15:27 +0100117 element:'#vc-choose',
118 intro: loc.TOUR_vccho1,
119 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200120 },
121 {
122 element:'#vc-view',
123 intro: loc.TOUR_vccho2,
124 position: "bottom",
125 },
126 {
hebastad090a512019-07-10 16:36:01 +0200127 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200128 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200129 position: "left",
130 },
131 {
hebasta94e47cb2019-07-24 22:24:27 +0200132 element: doe.querySelector('.stattable'),
133 intro: loc.TOUR_vcStat2,
134 position: "bottom",
135 },
136 {
hebasta5df796f2019-05-21 15:27:12 +0200137 element: doe.querySelector('#ql-field').parentNode,
138 intro: loc.TOUR_qlfield,
139 position: "bottom",
140 },
141 {
142 element:'#glimpse',
143 intro: loc.TOUR_glimpse,
144 position: "bottom",
145 },
146 {
147 element:'#view-tutorial',
148 intro: loc.TOUR_help,
149 position: "bottom",
150 },
151 {
152 element: '#qsubmit',
153 intro: loc.TOUR_seargo,
154 position: "bottom",
155 },
156 ];
157
hebasta75cfca52019-02-19 13:15:27 +0100158 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200159 intro.setOptions({steps: Steps});
160 this.testPrerequ(Steps, intro);
hebastaca61f812019-11-11 22:25:27 +0100161
hebasta5df796f2019-05-21 15:27:12 +0200162 //changes before executing the single steps
163 intro.onbeforechange(function(targetedElement){
164 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200165 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200166 /*
167 * TODO:
168 * #268 is not merged at the time beeing:
169 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
170 */
hebastaf95226b2019-09-19 11:37:00 +0200171 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200172 break;
hebasta5df796f2019-05-21 15:27:12 +0200173 case "vc-view":
174 vchoo = doe.querySelector("#vc-choose");
175 vcv = doe.querySelector("#vc-view");
176 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200177
178 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200179 if(!(vcv.querySelector(".active"))){
180 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200181 /*
182 * Intro.js caches elements at the beginning, so element and position has to be set again.
183 */
hebastaee7b8a82020-01-20 12:45:04 +0100184 intro._introItems[6].element = doe.querySelector('.statistic');
185 intro._introItems[6].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200186 }
187 break;
hebasta75cfca52019-02-19 13:15:27 +0100188
hebasta5df796f2019-05-21 15:27:12 +0200189 }
hebasta94e47cb2019-07-24 22:24:27 +0200190
hebastaee7b8a82020-01-20 12:45:04 +0100191 if(this._currentStep == 7){
hebasta94e47cb2019-07-24 22:24:27 +0200192 let statbut = doe.querySelector('.statistic');
193 statbut.click();
hebastaee7b8a82020-01-20 12:45:04 +0100194 intro._introItems[7].element = doe.querySelector(".stattable");
195 intro._introItems[7].position = "bottom";
hebasta94e47cb2019-07-24 22:24:27 +0200196 }
hebasta75cfca52019-02-19 13:15:27 +0100197 });
hebasta5df796f2019-05-21 15:27:12 +0200198
hebastaf95226b2019-09-19 11:37:00 +0200199 intro.onbeforeexit(function(){
200 if(KorAP.Hint.active() && KorAP.Hint.active().dontHide){
201 KorAP.Hint.unshow();
202 }
203 });
204
205 intro.onchange(function(targetElement) {
206 var that = this;
207 switch(this._currentStep){
208 //hides Hint if back button is pressed
hebastaee7b8a82020-01-20 12:45:04 +0100209 case 2:
hebastaf95226b2019-09-19 11:37:00 +0200210 if(KorAP.Hint.active()){
211 KorAP.Hint.unshow();
212 }
213 break;
hebastaee7b8a82020-01-20 12:45:04 +0100214 case 3:
hebastaf95226b2019-09-19 11:37:00 +0200215 KorAP.Hint.show(false);
216 KorAP.Hint.active().dontHide = true;
hebastaee7b8a82020-01-20 12:45:04 +0100217 intro._introItems[3].element = doe.querySelector(".menu.roll.hint");
218 intro._introItems[3].position = doe.querySelector("bottom");
hebastaf95226b2019-09-19 11:37:00 +0200219 break;
hebastaee7b8a82020-01-20 12:45:04 +0100220 case 4:
hebastaf95226b2019-09-19 11:37:00 +0200221 KorAP.Hint.unshow();
222 break;
223 }
224 });
225
hebasta5df796f2019-05-21 15:27:12 +0200226 // Execute at the end of the tour (By clicking at the done-Button)
227 intro.oncomplete(function(){
228 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200229 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200230 });
231
232 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100233 },
hebasta5df796f2019-05-21 15:27:12 +0200234
235
236 /* Guided Tour to explain the different views of the results */
hebastaca61f812019-11-11 22:25:27 +0100237 gTshowResults: function(elparam){
238
239 let tourR = introClass();
hebastaee7b8a82020-01-20 12:45:04 +0100240 tourR.setOptions(usabilityOpts);
hebastaca61f812019-11-11 22:25:27 +0100241
hebasta87f1b1f2019-07-30 13:03:23 +0200242 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200243 if(elparam){
244 doe = elparam;
245 }
hebasta5df796f2019-05-21 15:27:12 +0200246 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200247 //Step 1, intro_item 0
248 {
249 element: '#search',
250 intro: loc.TOUR_kwic ,
251 position: "auto",
252 },
253 //Step 2, intro_item 1
254 {
255 element: doe.querySelector("#search > ol > li"),
256 intro: loc.TOUR_snippet,
257 position: "bottom",
258 },
259 //Step 3, intro_item 2
260 {
261 element: doe.querySelector("#search > ol > li"),
262 intro: loc.TOUR_snippetb,
263 position: "bottom",
264 },
265 //Step 4, intro_item 3
266 {
267 element: doe.querySelector(".action > .metatable"),
268 intro: loc.TOUR_metadatab,
269 position: "bottom",
270 },
271 //Step 5, intro_item 4
272 {
273 element: doe.querySelector(".view.metatable"),
274 intro: loc.TOUR_metadata,
275 position: "auto",
276 },
277 //Step 6, intro_item 5
278 {
279 element: doe.querySelector(".action > .info"),
280 intro: loc.TOUR_tokenb,
281 position: "bottom",
282 },
283 //Step 7, intro_item 6
284 {
285 element: doe.querySelector(".view.tokentable"),
286 intro: loc.TOUR_token,
287 position: "auto",
288 },
289 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200290 {
hebasta87f1b1f2019-07-30 13:03:23 +0200291 element: doe.querySelector(".tree"),
292 intro: loc.TOUR_treeb,
293 position: "bottom",
294 },
295 //Step 9, intro_item 8
296 {
hebastaf95226b2019-09-19 11:37:00 +0200297 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200298 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200299 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200300 },
301 //Step 10, intro_item 9
302 {
303 intro: loc.TOUR_tourdone,
304 }
hebasta5df796f2019-05-21 15:27:12 +0200305 ]
hebasta5df796f2019-05-21 15:27:12 +0200306
hebasta87f1b1f2019-07-30 13:03:23 +0200307 tourR.setOptions({steps:StepsSR});
hebastaee7b8a82020-01-20 12:45:04 +0100308 tourR.setOptions(labelOpts);
hebastaf95226b2019-09-19 11:37:00 +0200309
310 tourR.onbeforeexit(function(){
311 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200312 });
hebasta87f1b1f2019-07-30 13:03:23 +0200313 //See also: https://introjs.com/docs/intro/options/
314 tourR.setOption('scrollToElement', true);
315 tourR.setOption('scrollTo','tooltip');
316 this.testPrerequ(StepsSR, tourR);
317
318 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
319 tourR.onbeforechange(function(targetedElement){
320
321 if(this._currentStep == 1){
322 KorAP.session.set("tour", false);
323 }
324
325 if(this._currentStep == 2){
326 doe.querySelector("#search > ol > li").click();
327 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
328 tourR._introItems[3].position = "bottom";
329 }
330
331 if(this._currentStep == 4){
332 doe.querySelector(".metatable").click();
333 tourR._introItems[4].element = doe.querySelector('.view.metatable');
334 tourR._introItems[5].element = doe.querySelector('.action > .info');
335 tourR._introItems[5].position = "bottom";
336 }
337
338 if(this._currentStep == 6){
339 doe.querySelector(".info").click();
340 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
341 tourR._introItems[7].element = doe.querySelector('.tree');
342 tourR._introItems[7].position = "bottom";
343 }
344
345 if(this._currentStep == 8){
346 doe.querySelector(".tree").click();
hebasta7fa6f082019-11-17 19:00:52 +0100347 let collect = document.querySelectorAll(".button-group-list")[0].querySelectorAll('li');
348 for(let i = 0; i < collect.length; i++){
349 if (collect[i].innerText == loc.TOUR_Relations) {
350 collect[i].click();
351 break;
352 }
353 }
hebastaf95226b2019-09-19 11:37:00 +0200354 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200355 }
356 });
hebastaf95226b2019-09-19 11:37:00 +0200357
hebasta5df796f2019-05-21 15:27:12 +0200358 return tourR;
359 },
hebasta87f1b1f2019-07-30 13:03:23 +0200360 /*
361 * The total number of steps and the text of the tooltips are needed for jasmine testing.
362 */
363 testPrerequ: function(steps, tour){
364 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
365 let StepsT = steps;
366 let gtour = tour;
367 gtour.stepCount = StepsT.length;
368
369 //Array of intro content needed for efficient testing
370 gtour.testIntros = [];
371
372 for(let i = 0; i< StepsT.length; i++){
373 gtour.testIntros.push(StepsT[i].intro);
374 }
375 },
hebasta5df796f2019-05-21 15:27:12 +0200376
hebasta75cfca52019-02-19 13:15:27 +0100377 }
378});