2019-06-11 14:35:31 +00:00
"use strict" ;
import Sheperd from 'shepherd.js' ;
2019-09-18 21:41:42 +00:00
// import '../../node_modules/shepherd.js/dist/css/shepherd-theme-default.css';
2019-06-11 14:35:31 +00:00
class Tour {
constructor ( in _map _manager ) {
this . map _manager = in _map _manager ;
}
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
create _tour ( ) {
this . tour = new Sheperd . Tour ( {
useModalOverlay : true ,
defaultStepOptions : {
// Default settings for steps go here
}
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "welcome" , {
text : "Welcome to the air quality web interface! Press next to get a short tour." ,
2019-08-12 16:45:13 +00:00
buttons : this . get _buttons ( true , false )
2019-06-11 14:35:31 +00:00
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "map" , {
text : "Each device has a blue marker. The shape a marker is located in changes colour depending on the value of the measure it reported." ,
attachTo : {
element : "#map" ,
on : "bottom"
} ,
buttons : this . get _buttons ( )
} ) ;
this . tour . addStep ( "guage" , {
text : "This guage is a key to the colour of the shapes underneath the device markers." ,
attachTo : {
element : document . querySelector ( "#canvas-guage" ) ,
on : "left"
} ,
buttons : this . get _buttons ( )
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "reading-type" , {
2019-08-12 16:45:13 +00:00
text : "Devices report multiple types of measurement. <strong>Change to another reading type now.</strong>" ,
2019-06-11 14:35:31 +00:00
attachTo : {
element : document . querySelector ( "select" ) . parentNode ,
on : "top"
} ,
advanceOn : { selector : "select" , event : "change" } ,
2019-08-12 16:45:13 +00:00
buttons : this . get _buttons ( false )
2019-06-11 14:35:31 +00:00
} ) ;
this . tour . addStep ( "reading-type-complete" , {
text : "Hey, the map changed! Some devices only report certain types of measurement, and different measurements have different colour scales." ,
attachTo : { element : "#map" , on : "bottom" } ,
buttons : this . get _buttons ( )
} ) ;
this . tour . addStep ( "layer-showhide" , {
text : "You can show and hide the device markers and the heatmap here." ,
attachTo : {
element : ".leaflet-control-layers" ,
on : "left"
} ,
buttons : this . get _buttons ( )
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "map-controls" , {
text : "You can control the zoom level and go fullscreen here. You can also zoom with your mouse wheel if you have one, and pan by clicking and dragging." ,
attachTo : {
element : ".leaflet-top.leaflet-left" ,
on : "right"
} ,
buttons : this . get _buttons ( )
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "device-graph" , {
2019-08-12 16:45:13 +00:00
text : "By clicking a blue marker, you can view additional information about that device. Not all device are actively reporting data. <strong>Try clicking one now.</strong>" ,
2019-06-11 14:35:31 +00:00
attachTo : {
element : "#map" ,
on : "top"
} ,
2019-08-12 16:45:13 +00:00
buttons : this . get _buttons ( false )
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
} ) . on ( "show" , ( ( ) => {
this . map _manager . device _markers . once ( "marker-popup-opened" , this . tour . next . bind ( this . tour ) ) ;
} ) . bind ( this ) ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "device-graph-a" , {
text : "This is a device information popup. By default it displays recent data that the device has reported on the line graph, but you can control this with the blue buttons." ,
attachTo : {
element : ".popup-device" ,
on : "right"
} ,
buttons : this . get _buttons ( )
} ) ;
this . tour . addStep ( "device-graph-b" , {
2019-08-12 16:45:13 +00:00
text : "By clicking here, you can see the specification of the device, including its software, sensor models, exact location, more. <strong>Click this now.</strong>" ,
2019-06-11 14:35:31 +00:00
attachTo : {
element : ".tabs :first-child" ,
on : "left"
} ,
advanceOn : { selector : ".tabs :first-child a" , event : "click" } ,
2019-08-12 16:45:13 +00:00
buttons : this . get _buttons ( false )
2019-06-11 14:35:31 +00:00
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "report-bug" , {
text : "If you find a bug, you can report it by clicking this button." ,
attachTo : {
element : "button[value='Report bug']" ,
on : "right"
} ,
buttons : this . get _buttons ( )
} ) ;
this . tour . addStep ( "changelog" , {
text : "The changelog will be automatically shown every time this web interface updates. Click the version information here to review it again at other times." ,
attachTo : {
element : "button[value~='built']" ,
on : "right"
} ,
buttons : this . get _buttons ( )
} ) ;
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
this . tour . addStep ( "complete" , {
text : "Tour complete!\nIf you need any additional assistance, let us know :-)" ,
2019-08-12 16:45:13 +00:00
buttons : this . get _buttons ( false , true , true )
2019-06-11 14:35:31 +00:00
} ) ;
}
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
run _once ( ) {
2019-06-11 14:38:20 +00:00
if ( window . localStorage . getItem ( "completed_tour" ) === null )
2019-06-11 14:35:31 +00:00
this . run ( ) ;
2019-08-13 14:05:21 +00:00
2019-08-12 11:26:55 +00:00
//window.localStorage.setItem("completed_tour", (new Date()).toISOString()); -- removed due to an accidental refresh possiblity
2019-06-11 14:35:31 +00:00
}
2019-08-13 14:05:21 +00:00
2019-06-11 14:35:31 +00:00
run ( ) {
if ( typeof this . tour == "undefined" )
this . create _tour ( ) ;
this . tour . start ( ) ;
}
2019-08-13 14:05:21 +00:00
2019-08-12 11:47:54 +00:00
completed _tour ( )
{
window . localStorage . setItem ( "completed_tour" , ( new Date ( ) ) . toISOString ( ) ) ;
}
2019-08-13 14:05:21 +00:00
2019-08-12 16:45:13 +00:00
get _buttons ( isContinue = true , isPrev = true , isEnd = false ) {
2019-06-11 14:35:31 +00:00
let next = { text : "Next" , action : this . tour . next } ,
prev = { text : "Previous" , action : this . tour . back } ,
2019-08-12 16:45:13 +00:00
exit = { text : "Exit" , action : ( ) => {
2019-08-12 11:47:54 +00:00
this . completed _tour ( ) ;
this . tour . cancel ( ) ;
} } ,
2019-08-12 16:45:13 +00:00
end = { text : "Done" , action : ( ) => {
2019-08-12 11:47:54 +00:00
this . completed _tour ( ) ;
this . tour . next ( ) ;
} }
2019-08-01 18:37:38 +00:00
2019-06-11 14:35:31 +00:00
let result = [ ] ;
2019-08-12 11:47:54 +00:00
2019-08-12 16:45:13 +00:00
if ( isPrev ) result . push ( prev ) ;
if ( isContinue ) {
2019-06-30 17:23:44 +00:00
result . push ( next ) ;
result . push ( exit ) ;
}
2019-08-12 16:45:13 +00:00
if ( isEnd ) result . push ( end ) ;
2019-08-01 18:37:38 +00:00
2019-06-11 14:35:31 +00:00
return result ;
}
}
export default Tour ;