blob: 6889520738426b86d3d49e14bce2396ae6ca2811 [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>" +
22 "<p class='pfirstStep'> This tour should give you a quick introduction to KorAP. </p>" +
23 "<p> Please note, that if you already defined a corpus or query, these definitions are deleted during the guided tour. " +
24 "If you don't want that, you can stop the tour now with <code>" +
25 loc.TOUR_lskip + "</code>. </p> </div>";
hebasta75cfca52019-02-19 13:15:27 +010026 loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here.";
hebastad090a512019-07-10 16:36:01 +020027 loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'.";
hebastaf95226b2019-09-19 11:37:00 +020028 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper";
29 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 +020030 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus";
hebasta75cfca52019-02-19 13:15:27 +010031 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
hebasta94e47cb2019-07-24 22:24:27 +020032 loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic.";
33 loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic";
hebasta1e2d98e2019-10-30 15:58:17 +010034 loc.TOUR_qlfield = loc.TOUR_qlfield|| "Selection of the query language: You can use KorAP with different query languages.";
35 loc.TOUR_help = loc.TOUR_help || "Help and information about KorAP.";
hebastaca61f812019-11-11 22:25:27 +010036 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select this to show only the first hits in undefined order.";
hebasta1e2d98e2019-10-30 15:58:17 +010037 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search";
hebasta87f1b1f2019-07-30 13:03:23 +020038
hebasta5df796f2019-05-21 15:27:12 +020039 //localization guided Tour gTshowResults
hebasta87f1b1f2019-07-30 13:03:23 +020040 loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)";
41 loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet.";
hebasta1e2d98e2019-10-30 15:58:17 +010042 loc.TOUR_snippetb = loc.TOUR_snippetb || "Snippet";
43 loc.TOUR_metadatab = loc.TOUR_metadatab || "Display of metadata";
hebasta87f1b1f2019-07-30 13:03:23 +020044 loc.TOUR_metadata = loc.TOUR_metadata || "Metadata";
hebasta1e2d98e2019-10-30 15:58:17 +010045 loc.TOUR_tokenb = loc.TOUR_tokenb || "Display of token annotations";
hebasta87f1b1f2019-07-30 13:03:23 +020046 loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations.";
hebasta1e2d98e2019-10-30 15:58:17 +010047 loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations"
hebasta87f1b1f2019-07-30 13:03:23 +020048 loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views."
49 loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010050
51 //localization of button labels
hebasta5df796f2019-05-21 15:27:12 +020052 let labelOptions = {
53 'skipLabel': loc.TOUR_lskip,
54 'prevLabel': loc.TOUR_lprev,
55 'nextLabel': loc.TOUR_lnext,
56 'doneLabel': loc.TOUR_ldone,
57 'showStepNumbers': false,
hebasta75cfca52019-02-19 13:15:27 +010058 };
hebasta87f1b1f2019-07-30 13:03:23 +020059
60 var doe = document;
hebasta5df796f2019-05-21 15:27:12 +020061
hebasta75cfca52019-02-19 13:15:27 +010062 return{
hebasta5df796f2019-05-21 15:27:12 +020063
hebasta75cfca52019-02-19 13:15:27 +010064 /**
hebasta5df796f2019-05-21 15:27:12 +020065 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010066 */
hebasta5df796f2019-05-21 15:27:12 +020067 gTstartSearch:function(elparam){
hebasta5df796f2019-05-21 15:27:12 +020068 let intro = introClass();
69 intro.setOptions(labelOptions);
hebasta1e2d98e2019-10-30 15:58:17 +010070 intro.setOption('tooltipClass', 'gTstartSearch');
hebastaca61f812019-11-11 22:25:27 +010071 intro.setOption('hideNext', true);
72 intro.setOption('hidePrev', true);
73 /*
74 * Sets button labels for the last step of the tour
75 * Because Kalamar is a multipage webapplication, this tours starts by
76 * completion the gTshowResults Tour. Therefore the label of the done button changed.
77 */
78 intro.setOption('doneLabel', loc.TOUR_ldoneSearch );
79
hebasta5df796f2019-05-21 15:27:12 +020080 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010081 if(elparam){
82 doe = elparam;
83 }
hebasta5df796f2019-05-21 15:27:12 +020084
hebasta75cfca52019-02-19 13:15:27 +010085 let input = doe.querySelector("#q-field");
86 input.value="";
87
hebasta5df796f2019-05-21 15:27:12 +020088
hebasta75cfca52019-02-19 13:15:27 +010089 //steps of the example tour
90 let Steps =[
91 {
hebasta1e2d98e2019-10-30 15:58:17 +010092 intro: loc.TOUR_welc,
93 },
94 {
hebastaf95226b2019-09-19 11:37:00 +020095 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +010096 intro: loc.TOUR_sear1,
97 position: 'bottom'
98 },
99 {
hebastaf95226b2019-09-19 11:37:00 +0200100 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +0100101 intro: loc.TOUR_sear2,
102 position: 'bottom'
103 },
104 {
105 element: '#hint',
106 intro: loc.TOUR_searAnnot,
107 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +0200108 },
109 {
hebastaf95226b2019-09-19 11:37:00 +0200110 element: doe.querySelector("#hint > .menu.hint"),
111 intro: loc.TOUR_annotAss,
112 position: 'bottom',
113 },
114 {
hebasta75cfca52019-02-19 13:15:27 +0100115 element:'#vc-choose',
116 intro: loc.TOUR_vccho1,
117 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200118 },
119 {
120 element:'#vc-view',
121 intro: loc.TOUR_vccho2,
122 position: "bottom",
123 },
124 {
hebastad090a512019-07-10 16:36:01 +0200125 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200126 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200127 position: "left",
128 },
129 {
hebasta94e47cb2019-07-24 22:24:27 +0200130 element: doe.querySelector('.stattable'),
131 intro: loc.TOUR_vcStat2,
132 position: "bottom",
133 },
134 {
hebasta5df796f2019-05-21 15:27:12 +0200135 element: doe.querySelector('#ql-field').parentNode,
136 intro: loc.TOUR_qlfield,
137 position: "bottom",
138 },
139 {
140 element:'#glimpse',
141 intro: loc.TOUR_glimpse,
142 position: "bottom",
143 },
144 {
145 element:'#view-tutorial',
146 intro: loc.TOUR_help,
147 position: "bottom",
148 },
149 {
150 element: '#qsubmit',
151 intro: loc.TOUR_seargo,
152 position: "bottom",
153 },
154 ];
155
hebasta75cfca52019-02-19 13:15:27 +0100156 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200157 intro.setOptions({steps: Steps});
158 this.testPrerequ(Steps, intro);
hebastaca61f812019-11-11 22:25:27 +0100159
hebasta5df796f2019-05-21 15:27:12 +0200160 //changes before executing the single steps
161 intro.onbeforechange(function(targetedElement){
162 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200163 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200164 /*
165 * TODO:
166 * #268 is not merged at the time beeing:
167 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
168 */
hebasta1e2d98e2019-10-30 15:58:17 +0100169 if(this._currentStep == 2){
hebastaf95226b2019-09-19 11:37:00 +0200170 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200171 }
172 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 */
hebasta1e2d98e2019-10-30 15:58:17 +0100184 intro._introItems[7].element = doe.querySelector('.statistic');
185 intro._introItems[7].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
hebasta1e2d98e2019-10-30 15:58:17 +0100191 if(this._currentStep == 8){
hebasta94e47cb2019-07-24 22:24:27 +0200192 let statbut = doe.querySelector('.statistic');
193 statbut.click();
hebasta1e2d98e2019-10-30 15:58:17 +0100194 intro._introItems[8].element = doe.querySelector(".stattable");
195 intro._introItems[8].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
hebasta1e2d98e2019-10-30 15:58:17 +0100209 case 3:
hebastaf95226b2019-09-19 11:37:00 +0200210 if(KorAP.Hint.active()){
211 KorAP.Hint.unshow();
212 }
213 break;
hebasta1e2d98e2019-10-30 15:58:17 +0100214 case 4:
hebastaf95226b2019-09-19 11:37:00 +0200215 KorAP.Hint.show(false);
216 KorAP.Hint.active().dontHide = true;
hebasta1e2d98e2019-10-30 15:58:17 +0100217 intro._introItems[4].element = doe.querySelector(".menu.roll.hint");
218 intro._introItems[4].position = doe.querySelector("bottom");
hebastaf95226b2019-09-19 11:37:00 +0200219 break;
hebasta1e2d98e2019-10-30 15:58:17 +0100220 case 5:
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();
240 tourR.setOption('hideNext', true);
241 tourR.setOption('hidePrev', true);
242
hebasta87f1b1f2019-07-30 13:03:23 +0200243 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200244 if(elparam){
245 doe = elparam;
246 }
hebasta5df796f2019-05-21 15:27:12 +0200247 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200248 //Step 1, intro_item 0
249 {
250 element: '#search',
251 intro: loc.TOUR_kwic ,
252 position: "auto",
253 },
254 //Step 2, intro_item 1
255 {
256 element: doe.querySelector("#search > ol > li"),
257 intro: loc.TOUR_snippet,
258 position: "bottom",
259 },
260 //Step 3, intro_item 2
261 {
262 element: doe.querySelector("#search > ol > li"),
263 intro: loc.TOUR_snippetb,
264 position: "bottom",
265 },
266 //Step 4, intro_item 3
267 {
268 element: doe.querySelector(".action > .metatable"),
269 intro: loc.TOUR_metadatab,
270 position: "bottom",
271 },
272 //Step 5, intro_item 4
273 {
274 element: doe.querySelector(".view.metatable"),
275 intro: loc.TOUR_metadata,
276 position: "auto",
277 },
278 //Step 6, intro_item 5
279 {
280 element: doe.querySelector(".action > .info"),
281 intro: loc.TOUR_tokenb,
282 position: "bottom",
283 },
284 //Step 7, intro_item 6
285 {
286 element: doe.querySelector(".view.tokentable"),
287 intro: loc.TOUR_token,
288 position: "auto",
289 },
290 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200291 {
hebasta87f1b1f2019-07-30 13:03:23 +0200292 element: doe.querySelector(".tree"),
293 intro: loc.TOUR_treeb,
294 position: "bottom",
295 },
296 //Step 9, intro_item 8
297 {
hebastaf95226b2019-09-19 11:37:00 +0200298 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200299 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200300 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200301 },
302 //Step 10, intro_item 9
303 {
304 intro: loc.TOUR_tourdone,
305 }
hebasta5df796f2019-05-21 15:27:12 +0200306 ]
hebasta5df796f2019-05-21 15:27:12 +0200307
hebasta87f1b1f2019-07-30 13:03:23 +0200308 tourR.setOptions({steps:StepsSR});
309 tourR.setOptions(labelOptions);
hebastaf95226b2019-09-19 11:37:00 +0200310
311 tourR.onbeforeexit(function(){
312 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200313 });
hebasta87f1b1f2019-07-30 13:03:23 +0200314 //See also: https://introjs.com/docs/intro/options/
315 tourR.setOption('scrollToElement', true);
316 tourR.setOption('scrollTo','tooltip');
317 this.testPrerequ(StepsSR, tourR);
318
319 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
320 tourR.onbeforechange(function(targetedElement){
321
322 if(this._currentStep == 1){
323 KorAP.session.set("tour", false);
324 }
325
326 if(this._currentStep == 2){
327 doe.querySelector("#search > ol > li").click();
328 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
329 tourR._introItems[3].position = "bottom";
330 }
331
332 if(this._currentStep == 4){
333 doe.querySelector(".metatable").click();
334 tourR._introItems[4].element = doe.querySelector('.view.metatable');
335 tourR._introItems[5].element = doe.querySelector('.action > .info');
336 tourR._introItems[5].position = "bottom";
337 }
338
339 if(this._currentStep == 6){
340 doe.querySelector(".info").click();
341 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
342 tourR._introItems[7].element = doe.querySelector('.tree');
343 tourR._introItems[7].position = "bottom";
344 }
345
346 if(this._currentStep == 8){
347 doe.querySelector(".tree").click();
348 document.querySelectorAll(".button-group-list")[0].querySelectorAll('li')[1].click();
hebastaf95226b2019-09-19 11:37:00 +0200349 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200350 }
351 });
hebastaf95226b2019-09-19 11:37:00 +0200352
hebasta5df796f2019-05-21 15:27:12 +0200353 return tourR;
354 },
hebasta87f1b1f2019-07-30 13:03:23 +0200355 /*
356 * The total number of steps and the text of the tooltips are needed for jasmine testing.
357 */
358 testPrerequ: function(steps, tour){
359 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
360 let StepsT = steps;
361 let gtour = tour;
362 gtour.stepCount = StepsT.length;
363
364 //Array of intro content needed for efficient testing
365 gtour.testIntros = [];
366
367 for(let i = 0; i< StepsT.length; i++){
368 gtour.testIntros.push(StepsT[i].intro);
369 }
370 },
hebasta5df796f2019-05-21 15:27:12 +0200371
hebasta75cfca52019-02-19 13:15:27 +0100372 }
373});