diff options
| author | Zog | 2018-01-10 10:47:23 +0100 |
|---|---|---|
| committer | Zog | 2018-01-10 10:47:23 +0100 |
| commit | aaa9ee2fabe87209df028bb225339108bf389f64 (patch) | |
| tree | 48344f89677b30b4d1c988f8e0d75b716150a7f2 /app/javascript/helpers | |
| parent | d0e51ea2058163b76863797a4e337ba3f5d6611d (diff) | |
| download | chouette-core-aaa9ee2fabe87209df028bb225339108bf389f64.tar.bz2 | |
Refs #5437 @1h; Refactor code
Diffstat (limited to 'app/javascript/helpers')
| -rw-r--r-- | app/javascript/helpers/stop_area_header_manager.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/javascript/helpers/stop_area_header_manager.js b/app/javascript/helpers/stop_area_header_manager.js new file mode 100644 index 000000000..54d957be9 --- /dev/null +++ b/app/javascript/helpers/stop_area_header_manager.js @@ -0,0 +1,42 @@ +import React, { Component } from 'react' + +export default class StopAreaHeaderManager { + constructor(ids_list, stopPointsList, features) { + this.ids_list = ids_list + this.stopPointsList = stopPointsList + this.features = features + } + + hasFeature(key) { + return this.features[key] + } + + stopPointHeader(object_id) { + let index = this.ids_list.indexOf(object_id) + let sp = this.stopPointsList[index] + let showHeadline = this.showHeader(object_id) + return ( + <div + className={(showHeadline) ? 'headlined' : ''} + data-headline={showHeadline} + title={sp.city_name + ' (' + sp.zip_code +')'} + > + <span><span>{sp.name}</span></span> + </div> + ) + } + + showHeader(object_id) { + let showHeadline = false + let headline = "" + let attribute_to_check = this.hasFeature('long_distance_routes') ? "country_code" : "city_name" + let index = this.ids_list.indexOf(object_id) + let sp = this.stopPointsList[index] + let previousBreakpoint = this.stopPointsList[index - 1] + if(index == 0 || (sp[attribute_to_check] != previousBreakpoint[attribute_to_check])){ + showHeadline = true + headline = this.hasFeature('long_distance_routes') ? sp.country_name : sp.city_name + } + return showHeadline ? headline : "" + } +} |
