blob: 45992ce9e64f9b5d5883c44f7f5a2531f3ce1630 [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";
hebasta5df796f2019-05-21 15:27:12 +020018
19 //localization guided tour gTstartSearch
hebasta75cfca52019-02-19 13:15:27 +010020 loc.TOUR_sear1 = loc.TOUR_sear1 || "Enter your search enquiry here.";
hebastad090a512019-07-10 16:36:01 +020021 loc.TOUR_sear2 = loc.TOUR_sear2 || "For example the search for '" + loc.TOUR_Qexample + "'.";
hebastaf95226b2019-09-19 11:37:00 +020022 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper";
23 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 +020024 loc.TOUR_vccho1 = loc.TOUR_vccho1 || "Choose corpus";
hebasta75cfca52019-02-19 13:15:27 +010025 loc.TOUR_vccho2 = loc.TOUR_vccho2 || "Define your corpus here.";
hebasta94e47cb2019-07-24 22:24:27 +020026 loc.TOUR_vcStat1 = loc.TOUR_vcStat1 || "Click here to display corpus statistic.";
27 loc.TOUR_vcStat2 = loc.TOUR_vcStat2 || "Corpus statistic";
hebastaf95226b2019-09-19 11:37:00 +020028 loc.TOUR_qlfield = loc.TOUR_qlfield|| "Selection of the query language: You can use KorAP with different languages.";
hebasta75cfca52019-02-19 13:15:27 +010029 loc.TOUR_help = loc.TOUR_help || "Help and more information about KorAP.";
30 loc.TOUR_glimpse = loc.TOUR_glimpse || "Select to show only the first hits in arbitrary order.";
31 loc.TOUR_seargo = loc.TOUR_seargo || "Start the search.";
hebasta87f1b1f2019-07-30 13:03:23 +020032
hebasta5df796f2019-05-21 15:27:12 +020033 //localization guided Tour gTshowResults
hebasta87f1b1f2019-07-30 13:03:23 +020034 loc.TOUR_kwic = loc.TOUR_kwic || "KWIC result (keyword in context)";
35 loc.TOUR_snippet = loc.TOUR_snippet || "Click on a match to show a larger snippet.";
36 loc.TOUR_snippetb = loc.TOUR_snippetb || "Display of larger snippet";
37 loc.TOUR_metadatab = loc.TOUR_metadatab || "Click here to display the metadata.";
38 loc.TOUR_metadata = loc.TOUR_metadata || "Metadata";
39 loc.TOUR_tokenb = loc.TOUR_tokenb || "Click here to display the token annotations.";
40 loc.TOUR_token = loc.TOUR_token || "KorAP supports multiple annotations.";
41 loc.TOUR_treeb = loc.TOUR_treeb || "Display further annotations."
42 loc.TOUR_tree = loc.TOUR_tree || "Further annotations can be displayed as tree and arch views."
43 loc.TOUR_tourdone = loc.TOUR_tourdone || "Have fun with KorAP!";
hebasta75cfca52019-02-19 13:15:27 +010044
45 //localization of button labels
hebasta5df796f2019-05-21 15:27:12 +020046 let labelOptions = {
47 'skipLabel': loc.TOUR_lskip,
48 'prevLabel': loc.TOUR_lprev,
49 'nextLabel': loc.TOUR_lnext,
50 'doneLabel': loc.TOUR_ldone,
51 'showStepNumbers': false,
hebasta75cfca52019-02-19 13:15:27 +010052 };
hebasta87f1b1f2019-07-30 13:03:23 +020053
54 var doe = document;
hebasta5df796f2019-05-21 15:27:12 +020055
hebasta75cfca52019-02-19 13:15:27 +010056 return{
hebasta5df796f2019-05-21 15:27:12 +020057
hebasta75cfca52019-02-19 13:15:27 +010058 /**
hebasta5df796f2019-05-21 15:27:12 +020059 * Guided Tour gTstartSearch: Explains the search functionality
hebasta75cfca52019-02-19 13:15:27 +010060 */
hebasta5df796f2019-05-21 15:27:12 +020061 gTstartSearch:function(elparam){
hebasta5df796f2019-05-21 15:27:12 +020062 let intro = introClass();
63 intro.setOptions(labelOptions);
64 intro.setOption('doneLabel', loc.TOUR_seargo);
65
66 //for testing purposes
hebasta75cfca52019-02-19 13:15:27 +010067 if(elparam){
68 doe = elparam;
69 }
hebasta5df796f2019-05-21 15:27:12 +020070
hebasta75cfca52019-02-19 13:15:27 +010071 let input = doe.querySelector("#q-field");
72 input.value="";
73
hebasta5df796f2019-05-21 15:27:12 +020074
hebasta75cfca52019-02-19 13:15:27 +010075 //steps of the example tour
76 let Steps =[
77 {
hebastaf95226b2019-09-19 11:37:00 +020078 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +010079 intro: loc.TOUR_sear1,
80 position: 'bottom'
81 },
82 {
hebastaf95226b2019-09-19 11:37:00 +020083 element: '#q-field',
hebasta75cfca52019-02-19 13:15:27 +010084 intro: loc.TOUR_sear2,
85 position: 'bottom'
86 },
87 {
88 element: '#hint',
89 intro: loc.TOUR_searAnnot,
90 position: 'bottom'
hebasta5df796f2019-05-21 15:27:12 +020091 },
92 {
hebastaf95226b2019-09-19 11:37:00 +020093 element: doe.querySelector("#hint > .menu.hint"),
94 intro: loc.TOUR_annotAss,
95 position: 'bottom',
96 },
97 {
hebasta75cfca52019-02-19 13:15:27 +010098 element:'#vc-choose',
99 intro: loc.TOUR_vccho1,
100 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +0200101 },
102 {
103 element:'#vc-view',
104 intro: loc.TOUR_vccho2,
105 position: "bottom",
106 },
107 {
hebastad090a512019-07-10 16:36:01 +0200108 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200109 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200110 position: "left",
111 },
112 {
hebasta94e47cb2019-07-24 22:24:27 +0200113 element: doe.querySelector('.stattable'),
114 intro: loc.TOUR_vcStat2,
115 position: "bottom",
116 },
117 {
hebasta5df796f2019-05-21 15:27:12 +0200118 element: doe.querySelector('#ql-field').parentNode,
119 intro: loc.TOUR_qlfield,
120 position: "bottom",
121 },
122 {
123 element:'#glimpse',
124 intro: loc.TOUR_glimpse,
125 position: "bottom",
126 },
127 {
128 element:'#view-tutorial',
129 intro: loc.TOUR_help,
130 position: "bottom",
131 },
132 {
133 element: '#qsubmit',
134 intro: loc.TOUR_seargo,
135 position: "bottom",
136 },
137 ];
138
hebasta75cfca52019-02-19 13:15:27 +0100139 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200140 intro.setOptions({steps: Steps});
141 this.testPrerequ(Steps, intro);
142
hebasta5df796f2019-05-21 15:27:12 +0200143 //changes before executing the single steps
144 intro.onbeforechange(function(targetedElement){
145 switch(targetedElement.id){
hebastaf95226b2019-09-19 11:37:00 +0200146 case "q-field":
hebastad090a512019-07-10 16:36:01 +0200147 /*
148 * TODO:
149 * #268 is not merged at the time beeing:
150 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
151 */
hebasta5df796f2019-05-21 15:27:12 +0200152 if(this._currentStep == 1){
hebastaf95226b2019-09-19 11:37:00 +0200153 targetedElement.value = loc.TOUR_Qexample;
hebasta5df796f2019-05-21 15:27:12 +0200154 }
155 break;
hebasta5df796f2019-05-21 15:27:12 +0200156 case "vc-view":
157 vchoo = doe.querySelector("#vc-choose");
158 vcv = doe.querySelector("#vc-view");
159 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200160
161 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200162 if(!(vcv.querySelector(".active"))){
163 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200164 /*
165 * Intro.js caches elements at the beginning, so element and position has to be set again.
166 */
hebastaf95226b2019-09-19 11:37:00 +0200167 intro._introItems[6].element = doe.querySelector('.statistic');
168 intro._introItems[6].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200169 }
170 break;
hebasta75cfca52019-02-19 13:15:27 +0100171
hebasta5df796f2019-05-21 15:27:12 +0200172 /*
173 * Sets button labels for the last step of the tour
174 * Because Kalamar is a multipage webapplication, this tours starts by
175 * completion the gTshowResults Tour. Therefore, the skip-button is removed
176 * and the label of the done button changed.
177 */
hebasta5df796f2019-05-21 15:27:12 +0200178 case "qsubmit":
179 intro.setOption('hideNext', true);
180 break;
181 }
hebasta94e47cb2019-07-24 22:24:27 +0200182
hebastaf95226b2019-09-19 11:37:00 +0200183 if(this._currentStep == 7){
hebasta94e47cb2019-07-24 22:24:27 +0200184 let statbut = doe.querySelector('.statistic');
185 statbut.click();
hebastaf95226b2019-09-19 11:37:00 +0200186 intro._introItems[7].element = doe.querySelector(".stattable");
187 intro._introItems[7].position = "bottom";
hebasta94e47cb2019-07-24 22:24:27 +0200188 }
hebasta75cfca52019-02-19 13:15:27 +0100189 });
hebasta5df796f2019-05-21 15:27:12 +0200190
hebastaf95226b2019-09-19 11:37:00 +0200191 intro.onbeforeexit(function(){
192 if(KorAP.Hint.active() && KorAP.Hint.active().dontHide){
193 KorAP.Hint.unshow();
194 }
195 });
196
197 intro.onchange(function(targetElement) {
198 var that = this;
199 switch(this._currentStep){
200 //hides Hint if back button is pressed
201 case 2:
202 if(KorAP.Hint.active()){
203 KorAP.Hint.unshow();
204 }
205 break;
206 case 3:
207 KorAP.Hint.show(false);
208 KorAP.Hint.active().dontHide = true;
209 intro._introItems[3].element = doe.querySelector(".menu.roll.hint");
210 intro._introItems[3].position = doe.querySelector("bottom");
211 break;
212 case 4:
213 KorAP.Hint.unshow();
214 break;
215 }
216 });
217
hebasta5df796f2019-05-21 15:27:12 +0200218 // Execute at the end of the tour (By clicking at the done-Button)
219 intro.oncomplete(function(){
220 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200221 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200222 });
223
224 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100225 },
hebasta5df796f2019-05-21 15:27:12 +0200226
227
228 /* Guided Tour to explain the different views of the results */
hebasta87f1b1f2019-07-30 13:03:23 +0200229 gTshowResults: function(elparam){
230 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200231 if(elparam){
232 doe = elparam;
233 }
234 let tourR = introClass();
235 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200236 //Step 1, intro_item 0
237 {
238 element: '#search',
239 intro: loc.TOUR_kwic ,
240 position: "auto",
241 },
242 //Step 2, intro_item 1
243 {
244 element: doe.querySelector("#search > ol > li"),
245 intro: loc.TOUR_snippet,
246 position: "bottom",
247 },
248 //Step 3, intro_item 2
249 {
250 element: doe.querySelector("#search > ol > li"),
251 intro: loc.TOUR_snippetb,
252 position: "bottom",
253 },
254 //Step 4, intro_item 3
255 {
256 element: doe.querySelector(".action > .metatable"),
257 intro: loc.TOUR_metadatab,
258 position: "bottom",
259 },
260 //Step 5, intro_item 4
261 {
262 element: doe.querySelector(".view.metatable"),
263 intro: loc.TOUR_metadata,
264 position: "auto",
265 },
266 //Step 6, intro_item 5
267 {
268 element: doe.querySelector(".action > .info"),
269 intro: loc.TOUR_tokenb,
270 position: "bottom",
271 },
272 //Step 7, intro_item 6
273 {
274 element: doe.querySelector(".view.tokentable"),
275 intro: loc.TOUR_token,
276 position: "auto",
277 },
278 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200279 {
hebasta87f1b1f2019-07-30 13:03:23 +0200280 element: doe.querySelector(".tree"),
281 intro: loc.TOUR_treeb,
282 position: "bottom",
283 },
284 //Step 9, intro_item 8
285 {
hebastaf95226b2019-09-19 11:37:00 +0200286 element: doe.querySelector(".view.relations"),
hebasta87f1b1f2019-07-30 13:03:23 +0200287 intro: loc.TOUR_tree,
hebastaf95226b2019-09-19 11:37:00 +0200288 position: "bottom",
hebasta87f1b1f2019-07-30 13:03:23 +0200289 },
290 //Step 10, intro_item 9
291 {
292 intro: loc.TOUR_tourdone,
293 }
hebasta5df796f2019-05-21 15:27:12 +0200294 ]
hebasta5df796f2019-05-21 15:27:12 +0200295
hebasta87f1b1f2019-07-30 13:03:23 +0200296 tourR.setOptions({steps:StepsSR});
297 tourR.setOptions(labelOptions);
hebastaf95226b2019-09-19 11:37:00 +0200298
299 tourR.onbeforeexit(function(){
300 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200301 });
hebasta87f1b1f2019-07-30 13:03:23 +0200302 //See also: https://introjs.com/docs/intro/options/
303 tourR.setOption('scrollToElement', true);
304 tourR.setOption('scrollTo','tooltip');
305 this.testPrerequ(StepsSR, tourR);
306
307 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
308 tourR.onbeforechange(function(targetedElement){
309
310 if(this._currentStep == 1){
311 KorAP.session.set("tour", false);
312 }
313
314 if(this._currentStep == 2){
315 doe.querySelector("#search > ol > li").click();
316 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
317 tourR._introItems[3].position = "bottom";
318 }
319
320 if(this._currentStep == 4){
321 doe.querySelector(".metatable").click();
322 tourR._introItems[4].element = doe.querySelector('.view.metatable');
323 tourR._introItems[5].element = doe.querySelector('.action > .info');
324 tourR._introItems[5].position = "bottom";
325 }
326
327 if(this._currentStep == 6){
328 doe.querySelector(".info").click();
329 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
330 tourR._introItems[7].element = doe.querySelector('.tree');
331 tourR._introItems[7].position = "bottom";
332 }
333
334 if(this._currentStep == 8){
335 doe.querySelector(".tree").click();
336 document.querySelectorAll(".button-group-list")[0].querySelectorAll('li')[1].click();
hebastaf95226b2019-09-19 11:37:00 +0200337 tourR._introItems[8].element = doe.querySelector(".view.relations");
hebasta87f1b1f2019-07-30 13:03:23 +0200338 }
339 });
hebastaf95226b2019-09-19 11:37:00 +0200340
hebasta5df796f2019-05-21 15:27:12 +0200341 return tourR;
342 },
hebasta87f1b1f2019-07-30 13:03:23 +0200343 /*
344 * The total number of steps and the text of the tooltips are needed for jasmine testing.
345 */
346 testPrerequ: function(steps, tour){
347 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
348 let StepsT = steps;
349 let gtour = tour;
350 gtour.stepCount = StepsT.length;
351
352 //Array of intro content needed for efficient testing
353 gtour.testIntros = [];
354
355 for(let i = 0; i< StepsT.length; i++){
356 gtour.testIntros.push(StepsT[i].intro);
357 }
358 },
hebasta5df796f2019-05-21 15:27:12 +0200359
hebasta75cfca52019-02-19 13:15:27 +0100360 }
361});