blob: fcccdf73524a80ffd0c5b5da747782f627b35abd [file] [log] [blame]
hebasta75cfca52019-02-19 13:15:27 +01001/**
2 * Guided Tour to explain the UI
3 *
4 * @author Helge Stallkamp
5 */
6
hebasta87f1b1f2019-07-30 13:03:23 +02007
8define(['lib/intro', 'vc', 'hint', 'menu', 'vc/doc', 'vc/docgroup'], function(introClass, vcClass, hintClass, menuClass, docClass, docGroup) {
hebasta5df796f2019-05-21 15:27:12 +02009
hebasta75cfca52019-02-19 13:15:27 +010010 //needed for localization of labels and contents of the tour
11 const loc = KorAP.Locale;
hebasta5df796f2019-05-21 15:27:12 +020012
hebasta75cfca52019-02-19 13:15:27 +010013 //labels for nextStep, previousStep, done and abort
14 loc.TOUR_lskip = loc.TOUR_lskip || "Abort";
15 loc.TOUR_lprev = loc.TOUR_lprev || "Back";
16 loc.TOUR_lnext = loc.TOUR_lnext || "Next";
17 loc.TOUR_ldone = loc.TOUR_ldone || "Done";
hebastaca61f812019-11-11 22:25:27 +010018 loc.TOUR_ldoneSearch = loc.TOUR_ldoneSearch || "Search";
19
hebasta5df796f2019-05-21 15:27:12 +020020 //localization guided tour gTstartSearch
hebasta1e2d98e2019-10-30 15:58:17 +010021 loc.TOUR_welc = loc.TOUR_welc || "<span class='tgreeting'> Welcome to our guided tour!</span>" +
hebasta7fa6f082019-11-17 19:00:52 +010022 "<p class='pfirstStep'> This tour should give you a quick introduction to KorAP. </p>";
hebasta75cfca52019-02-19 13:15:27 +010023 loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here.";
hebastad090a512019-07-10 16:36:01 +020024 loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'.";
hebastaf95226b2019-09-19 11:37:00 +020025 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper";
26 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 +020027 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus";
hebasta75cfca52019-02-19 13:15:27 +010028 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
hebasta94e47cb2019-07-24 22:24:27 +020029 loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic.";
30 loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic";
hebasta1e2d98e2019-10-30 15:58:17 +010031 loc.TOUR_qlfield = loc.TOUR_qlfield|| "Selection of the query language: You can use KorAP with different query languages.";
32 loc.TOUR_help = loc.TOUR_help || "Help and information about KorAP.";
hebastaca61f812019-11-11 22:25:27 +010033 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select this to show only the first hits in undefined order.";
hebasta1e2d98e2019-10-30 15:58:17 +010034 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search";
hebasta87f1b1f2019-07-30 13:03:23 +020035
hebasta5df796f2019-05-21 15:27:12 +020036 //localization guided Tour gTshowResults
hebasta87f1b1f2019-07-30 13:03:23 +020037 loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)";
38 loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet.";
hebasta1e2d98e2019-10-30 15:58:17 +010039 loc.TOUR_snippetb = loc.TOUR_snippetb || "Snippet";
40 loc.TOUR_metadatab = loc.TOUR_metadatab || "Display of metadata";
hebasta87f1b1f2019-07-30 13:03:23 +020041 loc.TOUR_metadata = loc.TOUR_metadata || "Metadata";
hebasta1e2d98e2019-10-30 15:58:17 +010042 loc.TOUR_tokenb = loc.TOUR_tokenb || "Display of token annotations";
hebasta87f1b1f2019-07-30 13:03:23 +020043 loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations.";
hebasta1e2d98e2019-10-30 15:58:17 +010044 loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations"
hebasta87f1b1f2019-07-30 13:03:23 +020045 loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views."
46 loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010047
48 //localization of button labels
hebasta5df796f2019-05-21 15:27:12 +020049 let labelOptions = {
50 'skipLabel': loc.TOUR_lskip,
51 'prevLabel': loc.TOUR_lprev,
52 'nextLabel': loc.TOUR_lnext,
53 'doneLabel': loc.TOUR_ldone,
54 'showStepNumbers': false,
hebasta75cfca52019-02-19 13:15:27 +010055 };
hebasta87f1b1f2019-07-30 13:03:23 +020056
57 var doe = document;
hebasta5df796f2019-05-21 15:27:12 +020058
hebasta75cfca52019-02-19 13:15:27 +010059 return{
hebasta5df796f2019-05-21 15:27:12 +020060
hebasta75cfca52019-02-19 13:15:27 +010061 /**
hebasta5df796f2019-05-21 15:27:12 +020062 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010063 */
hebasta5df796f2019-05-21 15:27:12 +020064 gTstartSearch:function(elparam){
hebasta5df796f2019-05-21 15:27:12 +020065 let intro = introClass();
66 intro.setOptions(labelOptions);
hebasta1e2d98e2019-10-30 15:58:17 +010067 intro.setOption('tooltipClass', 'gTstartSearch');
hebastaca61f812019-11-11 22:25:27 +010068 intro.setOption('hideNext', true);
69 intro.setOption('hidePrev', true);
70 /*
71 * Sets button labels for the last step of the tour
72 * Because Kalamar is a multipage webapplication, this tours starts by
73 * completion the gTshowResults Tour. Therefore the label of the done button changed.
74 */
75 intro.setOption('doneLabel', loc.TOUR_ldoneSearch );
76
hebasta5df796f2019-05-21 15:27:12 +020077 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010078 if(elparam){
79 doe = elparam;
80 }
hebasta5df796f2019-05-21 15:27:12 +020081
hebasta75cfca52019-02-19 13:15:27 +010082 let input = doe.querySelector("#q-field");
83 input.value="";
84
hebasta5df796f2019-05-21 15:27:12 +020085
hebasta75cfca52019-02-19 13:15:27 +010086 //steps of the example tour
87 let Steps =[
88 {
hebasta1e2d98e2019-10-30 15:58:17 +010089 intro: loc.TOUR_welc,
90 },
91 {
hebastaf95226b2019-09-19 11:37:00 +020092 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +010093 intro: loc.TOUR_sear1,
94 position: 'bottom'
95 },
96 {
hebastaf95226b2019-09-19 11:37:00 +020097 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +010098 intro: loc.TOUR_sear2,
99 position: 'bottom'
100 },
101 {
102 element: '#hint',
103 intro: loc.TOUR_searAnnot,
104 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +0200105 },
106 {
hebastaf95226b2019-09-19 11:37:00 +0200107 element: doe.querySelector("#hint > .menu.hint"),
108 intro: loc.TOUR_annotAss,
109 position: 'bottom',
110 },
111 {
hebasta75cfca52019-02-19 13:15:27 +0100112 element:'#vc-choose',
113 intro: loc.TOUR_vccho1,
114 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200115 },
116 {
117 element:'#vc-view',
118 intro: loc.TOUR_vccho2,
119 position: "bottom",
120 },
121 {
hebastad090a512019-07-10 16:36:01 +0200122 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200123 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200124 position: "left",
125 },
126 {
hebasta94e47cb2019-07-24 22:24:27 +0200127 element: doe.querySelector('.stattable'),
128 intro: loc.TOUR_vcStat2,
129 position: "bottom",
130 },
131 {
hebasta5df796f2019-05-21 15:27:12 +0200132 element: doe.querySelector('#ql-field').parentNode,
133 intro: loc.TOUR_qlfield,
134 position: "bottom",
135 },
136 {
137 element:'#glimpse',
138 intro: loc.TOUR_glimpse,
139 position: "bottom",
140 },
141 {
142 element:'#view-tutorial',
143 intro: loc.TOUR_help,
144 position: "bottom",
145 },
146 {
147 element: '#qsubmit',
148 intro: loc.TOUR_seargo,
149 position: "bottom",
150 },
151 ];
152
hebasta75cfca52019-02-19 13:15:27 +0100153 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200154 intro.setOptions({steps: Steps});
155 this.testPrerequ(Steps, intro);
hebastaca61f812019-11-11 22:25:27 +0100156
hebasta5df796f2019-05-21 15:27:12 +0200157 //changes before executing the single steps
158 intro.onbeforechange(function(targetedElement){
159 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200160 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200161 /*
162 * TODO:
163 * #268 is not merged at the time beeing:
164 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
165 */
hebasta1e2d98e2019-10-30 15:58:17 +0100166 if(this._currentStep == 2){
hebastaf95226b2019-09-19 11:37:00 +0200167 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200168 }
169 break;
hebasta5df796f2019-05-21 15:27:12 +0200170 case "vc-view":
171 vchoo = doe.querySelector("#vc-choose");
172 vcv = doe.querySelector("#vc-view");
173 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200174
175 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200176 if(!(vcv.querySelector(".active"))){
177 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200178 /*
179 * Intro.js caches elements at the beginning, so element and position has to be set again.
180 */
hebasta1e2d98e2019-10-30 15:58:17 +0100181 intro._introItems[7].element = doe.querySelector('.statistic');
182 intro._introItems[7].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200183 }
184 break;
hebasta75cfca52019-02-19 13:15:27 +0100185
hebasta5df796f2019-05-21 15:27:12 +0200186 }
hebasta94e47cb2019-07-24 22:24:27 +0200187
hebasta1e2d98e2019-10-30 15:58:17 +0100188 if(this._currentStep == 8){
hebasta94e47cb2019-07-24 22:24:27 +0200189 let statbut = doe.querySelector('.statistic');
190 statbut.click();
hebasta1e2d98e2019-10-30 15:58:17 +0100191 intro._introItems[8].element = doe.querySelector(".stattable");
192 intro._introItems[8].position = "bottom";
hebasta94e47cb2019-07-24 22:24:27 +0200193 }
hebasta75cfca52019-02-19 13:15:27 +0100194 });
hebasta5df796f2019-05-21 15:27:12 +0200195
hebastaf95226b2019-09-19 11:37:00 +0200196 intro.onbeforeexit(function(){
197 if(KorAP.Hint.active() && KorAP.Hint.active().dontHide){
198 KorAP.Hint.unshow();
199 }
200 });
201
202 intro.onchange(function(targetElement) {
203 var that = this;
204 switch(this._currentStep){
205 //hides Hint if back button is pressed
hebasta1e2d98e2019-10-30 15:58:17 +0100206 case 3:
hebastaf95226b2019-09-19 11:37:00 +0200207 if(KorAP.Hint.active()){
208 KorAP.Hint.unshow();
209 }
210 break;
hebasta1e2d98e2019-10-30 15:58:17 +0100211 case 4:
hebastaf95226b2019-09-19 11:37:00 +0200212 KorAP.Hint.show(false);
213 KorAP.Hint.active().dontHide = true;
hebasta1e2d98e2019-10-30 15:58:17 +0100214 intro._introItems[4].element = doe.querySelector(".menu.roll.hint");
215 intro._introItems[4].position = doe.querySelector("bottom");
hebastaf95226b2019-09-19 11:37:00 +0200216 break;
hebasta1e2d98e2019-10-30 15:58:17 +0100217 case 5:
hebastaf95226b2019-09-19 11:37:00 +0200218 KorAP.Hint.unshow();
219 break;
220 }
221 });
222
hebasta5df796f2019-05-21 15:27:12 +0200223 // Execute at the end of the tour (By clicking at the done-Button)
224 intro.oncomplete(function(){
225 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200226 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200227 });
228
229 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100230 },
hebasta5df796f2019-05-21 15:27:12 +0200231
232
233 /* Guided Tour to explain the different views of the results */
hebastaca61f812019-11-11 22:25:27 +0100234 gTshowResults: function(elparam){
235
236 let tourR = introClass();
237 tourR.setOption('hideNext', true);
238 tourR.setOption('hidePrev', true);
239
hebasta87f1b1f2019-07-30 13:03:23 +0200240 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200241 if(elparam){
242 doe = elparam;
243 }
hebasta5df796f2019-05-21 15:27:12 +0200244 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200245 //Step 1, intro_item 0
246 {
247 element: '#search',
248 intro: loc.TOUR_kwic ,
249 position: "auto",
250 },
251 //Step 2, intro_item 1
252 {
253 element: doe.querySelector("#search > ol > li"),
254 intro: loc.TOUR_snippet,
255 position: "bottom",
256 },
257 //Step 3, intro_item 2
258 {
259 element: doe.querySelector("#search > ol > li"),
260 intro: loc.TOUR_snippetb,
261 position: "bottom",
262 },
263 //Step 4, intro_item 3
264 {
265 element: doe.querySelector(".action > .metatable"),
266 intro: loc.TOUR_metadatab,
267 position: "bottom",
268 },
269 //Step 5, intro_item 4
270 {
271 element: doe.querySelector(".view.metatable"),
272 intro: loc.TOUR_metadata,
273 position: "auto",
274 },
275 //Step 6, intro_item 5
276 {
277 element: doe.querySelector(".action > .info"),
278 intro: loc.TOUR_tokenb,
279 position: "bottom",
280 },
281 //Step 7, intro_item 6
282 {
283 element: doe.querySelector(".view.tokentable"),
284 intro: loc.TOUR_token,
285 position: "auto",
286 },
287 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200288 {
hebasta87f1b1f2019-07-30 13:03:23 +0200289 element: doe.querySelector(".tree"),
290 intro: loc.TOUR_treeb,
291 position: "bottom",
292 },
293 //Step 9, intro_item 8
294 {
hebastaf95226b2019-09-19 11:37:00 +0200295 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200296 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200297 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200298 },
299 //Step 10, intro_item 9
300 {
301 intro: loc.TOUR_tourdone,
302 }
hebasta5df796f2019-05-21 15:27:12 +0200303 ]
hebasta5df796f2019-05-21 15:27:12 +0200304
hebasta87f1b1f2019-07-30 13:03:23 +0200305 tourR.setOptions({steps:StepsSR});
306 tourR.setOptions(labelOptions);
hebastaf95226b2019-09-19 11:37:00 +0200307
308 tourR.onbeforeexit(function(){
309 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200310 });
hebasta87f1b1f2019-07-30 13:03:23 +0200311 //See also: https://introjs.com/docs/intro/options/
312 tourR.setOption('scrollToElement', true);
313 tourR.setOption('scrollTo','tooltip');
314 this.testPrerequ(StepsSR, tourR);
315
316 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
317 tourR.onbeforechange(function(targetedElement){
318
319 if(this._currentStep == 1){
320 KorAP.session.set("tour", false);
321 }
322
323 if(this._currentStep == 2){
324 doe.querySelector("#search > ol > li").click();
325 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
326 tourR._introItems[3].position = "bottom";
327 }
328
329 if(this._currentStep == 4){
330 doe.querySelector(".metatable").click();
331 tourR._introItems[4].element = doe.querySelector('.view.metatable');
332 tourR._introItems[5].element = doe.querySelector('.action > .info');
333 tourR._introItems[5].position = "bottom";
334 }
335
336 if(this._currentStep == 6){
337 doe.querySelector(".info").click();
338 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
339 tourR._introItems[7].element = doe.querySelector('.tree');
340 tourR._introItems[7].position = "bottom";
341 }
342
343 if(this._currentStep == 8){
344 doe.querySelector(".tree").click();
hebasta7fa6f082019-11-17 19:00:52 +0100345 let collect = document.querySelectorAll(".button-group-list")[0].querySelectorAll('li');
346 for(let i = 0; i < collect.length; i++){
347 if (collect[i].innerText == loc.TOUR_Relations) {
348 collect[i].click();
349 break;
350 }
351 }
hebastaf95226b2019-09-19 11:37:00 +0200352 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200353 }
354 });
hebastaf95226b2019-09-19 11:37:00 +0200355
hebasta5df796f2019-05-21 15:27:12 +0200356 return tourR;
357 },
hebasta87f1b1f2019-07-30 13:03:23 +0200358 /*
359 * The total number of steps and the text of the tooltips are needed for jasmine testing.
360 */
361 testPrerequ: function(steps, tour){
362 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
363 let StepsT = steps;
364 let gtour = tour;
365 gtour.stepCount = StepsT.length;
366
367 //Array of intro content needed for efficient testing
368 gtour.testIntros = [];
369
370 for(let i = 0; i< StepsT.length; i++){
371 gtour.testIntros.push(StepsT[i].intro);
372 }
373 },
hebasta5df796f2019-05-21 15:27:12 +0200374
hebasta75cfca52019-02-19 13:15:27 +0100375 }
376});