blob: 69d739254a17ca0285b027e97f78e79d0ab55aae [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 + "'.";
hebasta94e47cb2019-07-24 22:24:27 +020022 loc.TOUR_searAnnot = loc.TOUR_searAnnot || "Annotation helper: By clicking, the annotations of the differents layers are displayed and can be selected.";
hebasta75cfca52019-02-19 13:15:27 +010023 loc.TOUR_annotAss = loc.TOUR_annotAss || "The annoation assistant helps to formulate queries with annotations";
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";
hebasta75cfca52019-02-19 13:15:27 +010028 loc.TOUR_qlfield = loc.TOUR_qlfield|| "You can use KorAP with different query languages, select the query language here.";
29 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 {
78 element: '#searchbar',
79 intro: loc.TOUR_sear1,
80 position: 'bottom'
81 },
82 {
83 element: '#searchbar',
84 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 {
hebasta75cfca52019-02-19 13:15:27 +010093 element:'#vc-choose',
94 intro: loc.TOUR_vccho1,
95 position: "bottom",
hebasta5df796f2019-05-21 15:27:12 +020096 },
97 {
98 element:'#vc-view',
99 intro: loc.TOUR_vccho2,
100 position: "bottom",
101 },
102 {
hebastad090a512019-07-10 16:36:01 +0200103 element: doe.querySelector('.statistic'),
hebasta94e47cb2019-07-24 22:24:27 +0200104 intro: loc.TOUR_vcStat1,
hebastad090a512019-07-10 16:36:01 +0200105 position: "left",
106 },
107 {
hebasta94e47cb2019-07-24 22:24:27 +0200108 element: doe.querySelector('.stattable'),
109 intro: loc.TOUR_vcStat2,
110 position: "bottom",
111 },
112 {
hebasta5df796f2019-05-21 15:27:12 +0200113 element: doe.querySelector('#ql-field').parentNode,
114 intro: loc.TOUR_qlfield,
115 position: "bottom",
116 },
117 {
118 element:'#glimpse',
119 intro: loc.TOUR_glimpse,
120 position: "bottom",
121 },
122 {
123 element:'#view-tutorial',
124 intro: loc.TOUR_help,
125 position: "bottom",
126 },
127 {
128 element: '#qsubmit',
129 intro: loc.TOUR_seargo,
130 position: "bottom",
131 },
132 ];
133
hebasta75cfca52019-02-19 13:15:27 +0100134 //pass in the Steps array created earlier
hebasta87f1b1f2019-07-30 13:03:23 +0200135 intro.setOptions({steps: Steps});
136 this.testPrerequ(Steps, intro);
137
hebasta5df796f2019-05-21 15:27:12 +0200138 //changes before executing the single steps
139 intro.onbeforechange(function(targetedElement){
140 switch(targetedElement.id){
141 case "searchbar":
hebastad090a512019-07-10 16:36:01 +0200142 /*
143 * TODO:
144 * #268 is not merged at the time beeing:
145 * introJs.currentStep() merge requested https://github.com/usablica/intro.js/pull/268/files
146 */
hebasta5df796f2019-05-21 15:27:12 +0200147 if(this._currentStep == 1){
148 input = doe.querySelector('#q-field');
149 input.value= loc.TOUR_Qexample;
150 }
151 break;
152
153 case "vc-view":
154 vchoo = doe.querySelector("#vc-choose");
155 vcv = doe.querySelector("#vc-view");
156 KorAP._delete.apply(KorAP.vc.root());
hebasta94e47cb2019-07-24 22:24:27 +0200157
158 KorAP.vc.fromJson(loc.TOUR_vcQuery);
hebasta5df796f2019-05-21 15:27:12 +0200159 if(!(vcv.querySelector(".active"))){
160 vchoo.click();
hebastad090a512019-07-10 16:36:01 +0200161 /*
162 * Intro.js caches elements at the beginning, so element and position has to be set again.
163 */
hebasta94e47cb2019-07-24 22:24:27 +0200164 intro._introItems[5].element = doe.querySelector('.statistic');
165 intro._introItems[5].position = "left";
hebasta5df796f2019-05-21 15:27:12 +0200166 }
167 break;
hebasta75cfca52019-02-19 13:15:27 +0100168
hebasta5df796f2019-05-21 15:27:12 +0200169 /*
170 * Sets button labels for the last step of the tour
171 * Because Kalamar is a multipage webapplication, this tours starts by
172 * completion the gTshowResults Tour. Therefore, the skip-button is removed
173 * and the label of the done button changed.
174 */
hebasta5df796f2019-05-21 15:27:12 +0200175 case "qsubmit":
176 intro.setOption('hideNext', true);
177 break;
178 }
hebasta94e47cb2019-07-24 22:24:27 +0200179
180 if(this._currentStep == 6){
181 let statbut = doe.querySelector('.statistic');
182 statbut.click();
183 intro._introItems[6].element = doe.querySelector(".stattable");
184 intro._introItems[6].position = "bottom";
185 }
hebasta75cfca52019-02-19 13:15:27 +0100186 });
hebasta5df796f2019-05-21 15:27:12 +0200187
188
189 // Execute at the end of the tour (By clicking at the done-Button)
190 intro.oncomplete(function(){
191 KorAP.session.set("tour", true);
hebasta94e47cb2019-07-24 22:24:27 +0200192 doe.getElementById("qsubmit").click();
hebasta5df796f2019-05-21 15:27:12 +0200193 });
194
195 return intro;
hebasta75cfca52019-02-19 13:15:27 +0100196 },
hebasta5df796f2019-05-21 15:27:12 +0200197
198
199 /* Guided Tour to explain the different views of the results */
hebasta87f1b1f2019-07-30 13:03:23 +0200200 gTshowResults: function(elparam){
201 //for testing purposes
hebasta5df796f2019-05-21 15:27:12 +0200202 if(elparam){
203 doe = elparam;
204 }
205 let tourR = introClass();
206 let StepsSR = [
hebasta87f1b1f2019-07-30 13:03:23 +0200207 //Step 1, intro_item 0
208 {
209 element: '#search',
210 intro: loc.TOUR_kwic ,
211 position: "auto",
212 },
213 //Step 2, intro_item 1
214 {
215 element: doe.querySelector("#search > ol > li"),
216 intro: loc.TOUR_snippet,
217 position: "bottom",
218 },
219 //Step 3, intro_item 2
220 {
221 element: doe.querySelector("#search > ol > li"),
222 intro: loc.TOUR_snippetb,
223 position: "bottom",
224 },
225 //Step 4, intro_item 3
226 {
227 element: doe.querySelector(".action > .metatable"),
228 intro: loc.TOUR_metadatab,
229 position: "bottom",
230 },
231 //Step 5, intro_item 4
232 {
233 element: doe.querySelector(".view.metatable"),
234 intro: loc.TOUR_metadata,
235 position: "auto",
236 },
237 //Step 6, intro_item 5
238 {
239 element: doe.querySelector(".action > .info"),
240 intro: loc.TOUR_tokenb,
241 position: "bottom",
242 },
243 //Step 7, intro_item 6
244 {
245 element: doe.querySelector(".view.tokentable"),
246 intro: loc.TOUR_token,
247 position: "auto",
248 },
249 //Step 8, intro_item 7
hebasta5df796f2019-05-21 15:27:12 +0200250 {
hebasta87f1b1f2019-07-30 13:03:23 +0200251 element: doe.querySelector(".tree"),
252 intro: loc.TOUR_treeb,
253 position: "bottom",
254 },
255 //Step 9, intro_item 8
256 {
257 element: doe.querySelector("view.relations"),
258 intro: loc.TOUR_tree,
259 position: "auto",
260 },
261 //Step 10, intro_item 9
262 {
263 intro: loc.TOUR_tourdone,
264 }
hebasta5df796f2019-05-21 15:27:12 +0200265 ]
hebasta5df796f2019-05-21 15:27:12 +0200266
hebasta87f1b1f2019-07-30 13:03:23 +0200267 tourR.setOptions({steps:StepsSR});
268 tourR.setOptions(labelOptions);
269
270 tourR.onbeforechange(function (){
hebasta5df796f2019-05-21 15:27:12 +0200271 KorAP.session.set("tour", false);
hebasta87f1b1f2019-07-30 13:03:23 +0200272 });
hebasta5df796f2019-05-21 15:27:12 +0200273
hebasta87f1b1f2019-07-30 13:03:23 +0200274 //See also: https://introjs.com/docs/intro/options/
275 tourR.setOption('scrollToElement', true);
276 tourR.setOption('scrollTo','tooltip');
277 this.testPrerequ(StepsSR, tourR);
278
279 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
280 tourR.onbeforechange(function(targetedElement){
281
282 if(this._currentStep == 1){
283 KorAP.session.set("tour", false);
284 }
285
286 if(this._currentStep == 2){
287 doe.querySelector("#search > ol > li").click();
288 tourR._introItems[3].element = doe.querySelector('.action > .metatable');
289 tourR._introItems[3].position = "bottom";
290 }
291
292 if(this._currentStep == 4){
293 doe.querySelector(".metatable").click();
294 tourR._introItems[4].element = doe.querySelector('.view.metatable');
295 tourR._introItems[5].element = doe.querySelector('.action > .info');
296 tourR._introItems[5].position = "bottom";
297 }
298
299 if(this._currentStep == 6){
300 doe.querySelector(".info").click();
301 tourR._introItems[6].element = doe.querySelector('.view.tokentable');
302 tourR._introItems[7].element = doe.querySelector('.tree');
303 tourR._introItems[7].position = "bottom";
304 }
305
306 if(this._currentStep == 8){
307 doe.querySelector(".tree").click();
308 document.querySelectorAll(".button-group-list")[0].querySelectorAll('li')[1].click();
309 }
310 });
311
hebasta5df796f2019-05-21 15:27:12 +0200312 return tourR;
313 },
hebasta87f1b1f2019-07-30 13:03:23 +0200314 /*
315 * The total number of steps and the text of the tooltips are needed for jasmine testing.
316 */
317 testPrerequ: function(steps, tour){
318 //TODO see also: introJS.totalSteps() merge requested: //github.com/usablica/intro.js/pull/268/files
319 let StepsT = steps;
320 let gtour = tour;
321 gtour.stepCount = StepsT.length;
322
323 //Array of intro content needed for efficient testing
324 gtour.testIntros = [];
325
326 for(let i = 0; i< StepsT.length; i++){
327 gtour.testIntros.push(StepsT[i].intro);
328 }
329 },
hebasta5df796f2019-05-21 15:27:12 +0200330
hebasta75cfca52019-02-19 13:15:27 +0100331 }
332});