Show module details block
Implements blueprint module-details Change-Id: Ibbd5a7eca9054d13a3cf3df62f36fa562c458fec
This commit is contained in:
		 Ilya Shakhat
					Ilya Shakhat
				
			
				
					committed by
					
						 Ilya Shakhat
						Ilya Shakhat
					
				
			
			
				
	
			
			
			 Ilya Shakhat
						Ilya Shakhat
					
				
			
						parent
						
							84d8435faa
						
					
				
				
					commit
					d1b217ece8
				
			| @@ -404,15 +404,17 @@ def templated(template=None, return_code=200): | ||||
|  | ||||
|             module = parameters.get_single_parameter(kwargs, 'module') | ||||
|             ctx['module'] = module | ||||
|             module_name = None | ||||
|             if module and module in vault_inst['module_id_index']: | ||||
|                 ctx['module_inst'] = vault_inst['module_id_index'][module] | ||||
|                 module_name = ctx['module_inst']['module_group_name'] | ||||
|  | ||||
|             ctx['user_id'] = parameters.get_single_parameter(kwargs, 'user_id') | ||||
|             if ctx['user_id']: | ||||
|                 ctx['user_inst'] = vault.get_user_from_runtime_storage( | ||||
|                     ctx['user_id']) | ||||
|             ctx['page_title'] = helpers.make_page_title( | ||||
|                 ctx['company'], ctx['user_id'], ctx['module'], ctx['release']) | ||||
|                 ctx['company'], ctx['user_id'], module_name, ctx['release']) | ||||
|             ctx['stackalytics_version'] = ( | ||||
|                 stackalytics_version.version_info.version_string()) | ||||
|             ctx['stackalytics_release'] = ( | ||||
|   | ||||
| @@ -111,6 +111,35 @@ def extend_user(user): | ||||
|     return user | ||||
|  | ||||
|  | ||||
| def extend_module(module_id): | ||||
|     module_id_index = vault.get_vault()['module_id_index'] | ||||
|     module_id = module_id.lower() | ||||
|  | ||||
|     if module_id not in module_id_index: | ||||
|         return None | ||||
|  | ||||
|     repos_index = vault.get_vault()['repos_index'] | ||||
|  | ||||
|     module = module_id_index[module_id] | ||||
|     name = module['module_group_name'] | ||||
|     if name[0].islower(): | ||||
|         name = name.capitalize() | ||||
|  | ||||
|     child_modules = [] | ||||
|     for m in module['modules']: | ||||
|         child = {'module_name': m} | ||||
|         if m in repos_index: | ||||
|             child['repo_uri'] = repos_index[m]['uri'] | ||||
|         child_modules.append(child) | ||||
|  | ||||
|     return { | ||||
|         'id': module_id, | ||||
|         'name': name, | ||||
|         'tag': module['tag'], | ||||
|         'modules': child_modules, | ||||
|     } | ||||
|  | ||||
|  | ||||
| def get_activity(records, start_record, page_size, query_message=None): | ||||
|     if query_message: | ||||
|         # note that all records are now dicts! | ||||
|   | ||||
							
								
								
									
										54
									
								
								stackalytics/dashboard/templates/_macros/module_details.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								stackalytics/dashboard/templates/_macros/module_details.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,54 @@ | ||||
| {% macro show_module_details(module) -%} | ||||
|  | ||||
| <script type="text/javascript"> | ||||
|     function load_module_details(extra_options) { | ||||
|         $.ajax({ | ||||
|             url: makeURI("/api/1.0/modules/{{ module }}", extra_options), | ||||
|             dataType: "json", | ||||
|             success: function (data) { | ||||
|                 var module = data["module"]; | ||||
|                 for (var i=0; i < module.modules.length; i++) { | ||||
|                     module.modules[i].uri = makeURI('/', {module: module.modules[i].module_name}); | ||||
|                 } | ||||
|                 console.log(module); | ||||
|                 $("#module_details_template").tmpl(data["module"]).appendTo("#module_details_container"); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     $(document).ready(function () { | ||||
|         var uri_options = {}; | ||||
|         load_module_details(uri_options); | ||||
|     }); | ||||
| </script> | ||||
|  | ||||
| <script id="module_details_template" type="text/x-jquery-tmpl"> | ||||
|     {% raw %} | ||||
|     <div> | ||||
|         <h2>${name}</h2> | ||||
|         <div style="font-style: italic; margin-bottom: 0.5em;"> | ||||
|             {%if tag == 'program' %} | ||||
|                 The official OpenStack program as defined in | ||||
|                 <a href="https://git.openstack.org/cgit/openstack/governance/tree/reference/programs.yaml" target="_blank">programs.yaml</a> | ||||
|             {%/if%} | ||||
|             {%if tag == 'group' %} | ||||
|                 Custom module group as defined in | ||||
|                 <a href="https://git.openstack.org/cgit/stackforge/stackalytics/tree/etc/default_data.json" target="_blank">default_data.json</a> | ||||
|             {%/if%} | ||||
|         </div> | ||||
|         <div> | ||||
|             {%if tag == 'module' %} | ||||
|             Repo: ${modules[0].repo_uri} | ||||
|             {%else%} | ||||
|             Modules: | ||||
|             {%each(index,module) modules %}{%if index>0 %}, {%/if%} | ||||
|                 <a href="${module.uri}">${module.module_name}</a>{%/each%} | ||||
|             {%/if%} | ||||
|         </div> | ||||
|     </div> | ||||
|     {% endraw %} | ||||
| </script> | ||||
|  | ||||
| <div id="module_details_container" style="margin-bottom: 2em;"></div> | ||||
|  | ||||
| {%- endmacro %} | ||||
| @@ -2,6 +2,7 @@ | ||||
| {% import '_macros/activity_log.html' as activity_log %} | ||||
| {% import '_macros/contribution_summary.html' as contribution_summary %} | ||||
| {% import '_macros/user_profile.html' as user_profile %} | ||||
| {% import '_macros/module_details.html' as module_details %} | ||||
|  | ||||
| {% set show_company_breakdown = (not company) and (not user_id) %} | ||||
| {% set show_engineer_breakdown = (not user_id) %} | ||||
| @@ -13,6 +14,7 @@ | ||||
| {% set show_contribution_on_left = (not user_id) and (module) %} | ||||
| {% set show_contribution_on_right = (user_id) or (company and not module) %} | ||||
| {% set show_user_profile = (user_id) %} | ||||
| {% set show_module_details = (module) %} | ||||
| {% set show_top_mentors_options = (metric == 'tm_marks') %} | ||||
| {% set show_review_ratio = (metric in ['marks', 'tm_marks']) %} | ||||
|  | ||||
| @@ -184,6 +186,10 @@ | ||||
|     </div> | ||||
|     {% endif %} | ||||
|  | ||||
|     {% if show_module_details %} | ||||
|         {{ module_details.show_module_details(module=module) }} | ||||
|     {% endif %} | ||||
|  | ||||
|     {% if show_bp_breakdown %} | ||||
|     <div id="bp_container"> | ||||
|     <h2>Blueprint popularity</h2> | ||||
|   | ||||
| @@ -89,6 +89,7 @@ def get_vault(): | ||||
|                 _init_releases(vault) | ||||
|                 _init_module_groups(vault) | ||||
|                 _init_project_types(vault) | ||||
|                 _init_repos(vault) | ||||
|                 _init_user_index(vault) | ||||
|  | ||||
|     return vault | ||||
| @@ -128,8 +129,14 @@ def _init_project_types(vault): | ||||
|     project_types = runtime_storage_inst.get_by_key('project_types') or {} | ||||
|  | ||||
|     vault['project_types'] = project_types | ||||
|     vault['project_types_index'] = dict([(pt['id'], pt) | ||||
|                                          for pt in project_types]) | ||||
|     vault['project_types_index'] = dict((pt['id'], pt) for pt in project_types) | ||||
|  | ||||
|  | ||||
| def _init_repos(vault): | ||||
|     runtime_storage_inst = vault['runtime_storage'] | ||||
|     repos = runtime_storage_inst.get_by_key('repos') or {} | ||||
|  | ||||
|     vault['repos_index'] = dict((r['module'], r) for r in repos) | ||||
|  | ||||
|  | ||||
| def _init_user_index(vault): | ||||
| @@ -173,7 +180,7 @@ def get_user_from_runtime_storage(user_id): | ||||
|     return user_index[user_id] | ||||
|  | ||||
|  | ||||
| def resolve_modules_for_releases(module_ids, releases): | ||||
| def _resolve_modules_for_releases(module_ids, releases): | ||||
|     module_id_index = get_vault().get('module_id_index') or {} | ||||
|  | ||||
|     for module_id in module_ids: | ||||
| @@ -201,7 +208,7 @@ def resolve_modules_for_releases(module_ids, releases): | ||||
|  | ||||
| def resolve_modules(module_ids, releases): | ||||
|     all_releases = get_vault()['releases'].keys() | ||||
|     for module, release in resolve_modules_for_releases(module_ids, releases): | ||||
|     for module, release in _resolve_modules_for_releases(module_ids, releases): | ||||
|         if release is None: | ||||
|             for r in all_releases: | ||||
|                 yield (module, r) | ||||
|   | ||||
| @@ -343,18 +343,15 @@ def get_company(company_name, **kwargs): | ||||
|     flask.abort(404) | ||||
|  | ||||
|  | ||||
| @app.route('/api/1.0/modules/<module>') | ||||
| @app.route('/api/1.0/modules/<module_id>') | ||||
| @decorators.response() | ||||
| @decorators.cached() | ||||
| @decorators.jsonify('module') | ||||
| def get_module(module, **kwargs): | ||||
|     module_id_index = vault.get_vault()['module_id_index'] | ||||
|     module = module.lower() | ||||
|     if module in module_id_index: | ||||
|         return {'id': module_id_index[module]['id'], | ||||
|                 'text': module_id_index[module]['module_group_name'], | ||||
|                 'tag': module_id_index[module]['tag']} | ||||
|     flask.abort(404) | ||||
| def get_module(module_id, **kwargs): | ||||
|     module = helpers.extend_module(module_id) | ||||
|     if not module: | ||||
|         flask.abort(404) | ||||
|     return module | ||||
|  | ||||
|  | ||||
| @app.route('/api/1.0/members') | ||||
|   | ||||
| @@ -79,7 +79,7 @@ class TestAPIModules(test_api.TestAPI): | ||||
|                  'module_groups': { | ||||
|                      'nova-group': {'id': 'nova-group', | ||||
|                                     'module_group_name': 'nova-group', | ||||
|                                     'modules': ['nova', 'nova-cli'], | ||||
|                                     'modules': ['nova-cli', 'nova'], | ||||
|                                     'tag': 'group'}, | ||||
|                      'nova': test_api.make_module('nova'), | ||||
|                      'nova-cli': test_api.make_module('nova-cli'), | ||||
| @@ -89,10 +89,20 @@ class TestAPIModules(test_api.TestAPI): | ||||
|             response = self.app.get('/api/1.0/modules/nova') | ||||
|             module = test_api.load_json(response)['module'] | ||||
|             self.assertEqual( | ||||
|                 {'id': 'nova', 'text': 'nova', 'tag': 'module'}, module) | ||||
|                 {'id': 'nova', | ||||
|                  'modules': [ | ||||
|                      {'module_name': 'nova', | ||||
|                       'repo_uri': 'git://git.openstack.org/openstack/nova.git'} | ||||
|                  ], | ||||
|                  'name': 'Nova', 'tag': 'module'}, module) | ||||
|  | ||||
|             response = self.app.get('/api/1.0/modules/nova-group') | ||||
|             module = test_api.load_json(response)['module'] | ||||
|             self.assertEqual( | ||||
|                 {'tag': 'group', 'id': 'nova-group', 'text': 'nova-group'}, | ||||
|                 module) | ||||
|                 {'id': 'nova-group', | ||||
|                  'modules': [ | ||||
|                      {'module_name': 'nova-cli'}, | ||||
|                      {'module_name': 'nova', | ||||
|                       'repo_uri': 'git://git.openstack.org/openstack/nova.git'} | ||||
|                  ], | ||||
|                  'name': 'Nova-group', 'tag': 'group'}, module) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user