From 9f2a5358da7677817c9bee2c318d894d207285d9 Mon Sep 17 00:00:00 2001 From: George Hunt Date: Tue, 2 Apr 2019 13:18:18 -0700 Subject: [PATCH] some fixes for splash page --- roles/osm-vector/tasks/main.yml | 55 +++++++++++----------- roles/osm-vector/templates/iiab-update-osm | 48 +++++++++++++------ vars/default_vars.yml | 2 +- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/roles/osm-vector/tasks/main.yml b/roles/osm-vector/tasks/main.yml index cf41bc064..51ac5ff7d 100644 --- a/roles/osm-vector/tasks/main.yml +++ b/roles/osm-vector/tasks/main.yml @@ -1,17 +1,30 @@ -- name: Fetch the javascript bundle with openlayers module, and map.js - get_url: - url: "{{ iiab_osm_url }}/map.js" - dest: "{{ doc_root }}/common/assets/" - - name: Fetch the catalog for osm maps get_url: url: "{{ iiab_osm_url }}/regions.json" - dest: "{{ iiab_dir }}/regions.json" + dest: '{{ doc_root }}/common/assets' + +- name: Make sure the osm-vector directory exists + file: + path: '{{ osm_vector_path }}/assets' + state: directory + owner: '{{ apache_user }}' + group: '{{ apache_user }}' + mode: '0755' + +- name: Fetch the javascript bundle with openlayers for test page + get_url: + url: "{{ iiab_osm_url }}/main.js" + dest: '{{ osm_vector_path }}/assets' + +- name: Fetch the index.html for test page + get_url: + url: "{{ iiab_osm_url }}/index.html" + dest: '{{ osm_vector_path }}/assets' - name: Fetch the bounding box description for osm maps get_url: url: "{{ iiab_osm_url }}/bboxes.geojson" - dest: "{{ doc_root }}/common/assets/bboxes.geojson" + dest: '{{ osm_vector_path }}/assets' - name: Install the script to update osm catalog template: @@ -19,13 +32,19 @@ dest: /usr/bin/iiab-update-osm mode: "0755" -- name: Generate the bounding bboxes.geojson file +- name: Run the script that does osm-vector housekeeping shell: /usr/bin/iiab-update-osm - name: Copy the Countries geojson to assets copy: src: countries.json - dest: "{{ doc_root }}/common/assets/" + dest: '{{ osm_vector_path }}/assets' + +# It is too complicated to use a single file for both iiab and admin-console +- name: Copy the duplicated javascript to assets + copy: + src: osm_functions.js + dest: '{{ osm_vector_path }}/assets' - name: Install /etc/{{ apache_config_dir }}/osm-vect.conf from template template: @@ -45,24 +64,6 @@ state: absent when: not osm_vector_enabled and is_debuntu -- name: Make sure the osm-vector directory exists - file: - path: '{{ osm_vector_path }}/splash' - state: directory - owner: '{{ apache_user }}' - group: '{{ apache_user }}' - mode: '0755' - -- name: Copy the splash page for osm-vector to the apache root for osm - template: - src: splash-index.html - dest: "{{ osm_vector_path }}/splash/index.html" - -- name: Copy the javascript for the splash page to assets - template: - src: main.js - dest: "{{ doc_root }}/common/assets/" - - name: Copy the php redirect to the splash page copy: src: splash-index.redirect diff --git a/roles/osm-vector/templates/iiab-update-osm b/roles/osm-vector/templates/iiab-update-osm index f17c90985..f08e9666e 100755 --- a/roles/osm-vector/templates/iiab-update-osm +++ b/roles/osm-vector/templates/iiab-update-osm @@ -9,7 +9,6 @@ import sys import fnmatch import re -#IIAB_PATH='{{ iiab_dir }}' IIAB_PATH='/etc/iiab' if not IIAB_PATH in sys.path: sys.path.append(IIAB_PATH) @@ -23,28 +22,37 @@ import iiab_update_menus as menus doc_root = get_iiab_env('WWWROOT') menuDefs = doc_root + "/js-menu/menu-files/menu-defs/" osm_vector_idx_dir = doc_root + "/common/assets/" +#map_doc_root = '{{ osm_vector_path }}' map_doc_root = '/library/osm-vector' # map_catalog will be global, assumed always available map_catalog = {} -map_menu_defs ={} +map_menu_def_list = [] def main(): global map_menu_defs get_map_catalog() #print(json.dumps(map_catalog,indent=2)) - map_menu_defs = get_menu_def_names() + map_menu_def_list = get_menu_def_names() #print(json.dumps(map_menu_defs,indent=2)) installed_maps = get_installed_regions() - #print(installed_maps) + print(installed_maps) write_osm_vector_idx(installed_maps) for region in installed_maps: #print('checking for %s region'%region) - item = map_catalog['regions'][region] - if not region in map_menu_defs: + if region != 'assets': + item = map_catalog['regions'][region] + menu_ref = item['perma_ref'] + else: + menu_ref = 'en-map_test' + if region != 'assets' and not (region in map_menu_def_list): + print('creating menu def for %s'%item['perma_ref']) create_menu_def(region,item['perma_ref'] + '.json') + if fetch_menu_json_value('autoupdate_menu'): + print('fetch_menu returned %s'%fetch_menu_json_value('autoupdate_menu')) # add this new menu def to home page - print('calling to insert %s.json'%item['perma_ref']) - menus.update_menu_json(item['perma_ref']) + print('calling to insert %s.json'%menu_ref) + menus.update_menu_json(menu_ref) + print('fetch_menu returned %s'%fetch_menu_json_value('autoupdate_menu')) def get_map_catalog(): global map_catalog @@ -56,7 +64,7 @@ def get_map_catalog(): #print(json.dumps(map_catalog,indent=2)) def get_menu_def_names(intended_use='map'): - menu_def_dict = {} + menu_def_list =[] os.chdir(menuDefs) for filename in os.listdir('.'): if fnmatch.fnmatch(filename, '*.json'): @@ -71,8 +79,8 @@ def get_menu_def_names(intended_use='map'): continue map_name = data.get('name','') if map_name != '': - menu_def_dict[data['name']] = menuDefs + filename - return menu_def_dict + menu_def_list.append(data['name']) + return menu_def_list def get_installed_regions(): installed = [] @@ -81,12 +89,16 @@ def get_installed_regions(): if fnmatch.fnmatch(filename, '??-osm-omt*'): region = re.sub(r'^..-osm-omt_(.*)',r'\1',filename) installed.append(region) + # add the splash page if no other maps are present + if len(installed) == 0: + installed.append('assets') return installed def write_osm_vector_idx(installed_maps): map_dict ={} map_dict['regions'] = {} for map in installed_maps: + if map == 'assets': continue # not a real region data_dict = map_catalog['regions'].get(map,'') map_dict['regions'][map] = data_dict with open(osm_vector_idx_dir + '/osm-vector-idx.json','w') as idx: @@ -107,15 +119,15 @@ def create_menu_def(region,default_name,intended_use='map'): menuDef["logo_url"] = default_logo menuitem = lang + '-' + item['perma_ref'] menuDef["menu_item_name"] = default_name - menuDef["title"] = item.get('title','') + menuDef["title"] = "OpenStreetMap: 18 Levels of Zoom for " + item.get('title','ERROR') + '' menuDef["map_name"] = item['perma_ref'] - menuDef["start_url"] = '' - menuDef["description"] = '

Open Street Map of ' + item.get('title','') + '

' + menuDef["start_url"] = lang + '-' + item['perma_ref'] + menuDef["description"] = '

Resolution of the Whole World to 5 KM. OpenStreetMap data for ' + item.get('title','') + ' with details down to 5 Meters

' menuDef["extra_html"] = "" menuDef["automatically_generated"] = "true" if not os.path.isfile(menuDefs + default_name): # logic to here can still overwrite existing menu def print("creating %s"%menuDefs + default_name) - with open(menuDefs + default_name + '.json','w') as menufile: + with open(menuDefs + default_name,'w') as menufile: menufile.write(json.dumps(menuDef,indent=2)) return default_name[:-5] @@ -132,5 +144,11 @@ def human_readable(num): return "%.0f%s"%(num,units[i]) num /= 1000.0 +def fetch_menu_json_value(key): + with open( doc_root + '/home/menu.json','r') as menudef: + data = json.loads(menudef.read()) + return data.get(key,'') + + if __name__ == '__main__': main() diff --git a/vars/default_vars.yml b/vars/default_vars.yml index 2b80b2e8c..7ec62cc17 100644 --- a/vars/default_vars.yml +++ b/vars/default_vars.yml @@ -15,7 +15,7 @@ pip_packages_dir: "{{ iiab_base }}/pip-packages" yum_packages_dir: "{{ iiab_base }}/yum-packages" downloads_dir: "{{ iiab_base }}/downloads" iiab_download_url: http://download.iiab.io/packages -iiab_osm_url : http://download.iiab.io/content/OSM/vector-tiles +iiab_osm_url : http://download.iiab.io/content/OSM/vector-tiles/assets content_base: "/library" doc_base: "{{ content_base }}/www"