def test_custom_top_nav(self): # Add a new top level navigation action DashboardHandler.add_nav_mapping(self.ACTION, 'CUSTOM_MOD') class CustomNavHandler(object): @classmethod def show_page(cls, dashboard_handler): dashboard_handler.render_page({ 'page_title': dashboard_handler.format_title('CustomNav'), 'main_content': 'MainContent' }) DashboardHandler.add_custom_get_action(self.ACTION, CustomNavHandler.show_page) dom = self.parse_html_string(self.get('dashboard').body) selected_nav_path = ('.//tr[@class="gcb-nav-bar-level-1"]' '//a[@class="selected"]') self.assertEquals('Edit', dom.find(selected_nav_path).text) dom = self.parse_html_string(self.get(self.URL).body) self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text) self.assertEquals('MainContent', dom.find(self.CONTENT_PATH).text.strip()) DashboardHandler.remove_custom_get_action(self.ACTION) # Add a new tab under the new navigation action class CustomTabHandler(object): @classmethod def display_html(cls, unused_dashboard_handler): return 'MainTabContent' dashboard.DashboardHandler.add_sub_nav_mapping( self.ACTION, 'cu_tab', 'CustomTab', action=self.ACTION, contents=CustomTabHandler) dom = self.parse_html_string(self.get(self.URL).body) self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text) self.assertEquals('MainTabContent', dom.find(self.CONTENT_PATH).text.strip()) selected_tab_path = ('.//*[@class="gcb-nav-bar-level-2"]' '//a[@class="selected"]') self.assertEquals('CustomTab', dom.find(selected_tab_path).text)
def add_actions(): def cluster_prepare_template(dashboard_instance): key = dashboard_instance.request.get('key') template_values = {} template_values['page_title'] = dashboard_instance.format_title( 'Edit Cluster') template_values['main_content'] = dashboard_instance.get_form( clustering.ClusterRESTHandler, key, '/dashboard?action=analytics&tab=clustering', auto_return=True, app_context=dashboard_instance.app_context) dashboard_instance.render_page(template_values, 'clusters') DashboardHandler.add_custom_get_action('add_cluster', cluster_prepare_template) DashboardHandler.add_custom_get_action('edit_cluster', cluster_prepare_template)
def add_actions(): def cluster_prepare_template(dashboard_instance): key = dashboard_instance.request.get('key') template_values = {} template_values['page_title'] = dashboard_instance.format_title( 'Edit Cluster') template_values['main_content'] = dashboard_instance.get_form( clustering.ClusterRESTHandler, key, '/dashboard?action=analytics&tab=clustering', auto_return=True, app_context=dashboard_instance.app_context) dashboard_instance.render_page(template_values, 'clusters') DashboardHandler.add_custom_get_action('add_cluster', cluster_prepare_template) DashboardHandler.add_custom_get_action('edit_cluster', cluster_prepare_template)
def test_custom_top_nav(self): # Add a new top level navigation action DashboardHandler.add_nav_mapping(self.ACTION, 'CUSTOM_MOD') class CustomNavHandler(object): @classmethod def show_page(cls, dashboard_handler): dashboard_handler.render_page({ 'page_title': dashboard_handler.format_title('CustomNav'), 'main_content': 'MainContent'}) DashboardHandler.add_custom_get_action( self.ACTION, CustomNavHandler.show_page) dom = self.parse_html_string(self.get('dashboard').body) selected_nav_path = ('.//tr[@class="gcb-nav-bar-level-1"]' '//a[@class="selected"]') self.assertEquals('Edit', dom.find(selected_nav_path).text) dom = self.parse_html_string(self.get(self.URL).body) self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text) self.assertEquals( 'MainContent', dom.find(self.CONTENT_PATH).text.strip()) DashboardHandler.remove_custom_get_action(self.ACTION) # Add a new tab under the new navigation action class CustomTabHandler(object): @classmethod def display_html(cls, unused_dashboard_handler): return 'MainTabContent' dashboard.DashboardHandler.add_sub_nav_mapping( self.ACTION, 'cu_tab', 'CustomTab', action=self.ACTION, contents=CustomTabHandler) dom = self.parse_html_string(self.get(self.URL).body) self.assertEquals('CUSTOM_MOD', dom.find(selected_nav_path).text) self.assertEquals( 'MainTabContent', dom.find(self.CONTENT_PATH).text.strip()) selected_tab_path = ('.//*[@class="gcb-nav-bar-level-2"]' '//a[@class="selected"]') self.assertEquals('CustomTab', dom.find(selected_tab_path).text)