def __render_trend_row(self, request_path, display_name, trend_map, count): trend = trend_map[display_name] if trend is None: return None rowclasses = ['light', 'dark'] row = HTMLgen.TR(**{'class':rowclasses[count % 2]}) span = HTMLgen.Span(display_name, **{'style': 'white-space: pre;'}) row.append(HTMLgen.TH(span)) try: if not trend.get_points(): domish(row).setAttribute('class', 'nopoints') actioncell = HTMLgen.TD(**{"nowrap":True}) last_action = actioncell encoded_name = urllib.quote_plus(trend.name) # @note Using display text as URL is a bad idea... # @note More of a combo box approach would be better. # @note I don't think all the forms and hidden inputs are needed. # either use a single form and the input name, or use # multiple forms with encoded request paths... Or? actions = ['view trend', 'configure points', 'trend preferences', ' - '] for action in actions: form_id = action.lstrip().rstrip() + cgi.escape(trend.name) if action == 'view trend': actionform = CustomForm(request_path) actionname = 'reload' elif action == 'trend preferences': actionform = CustomForm(request_path, targetType='ignore') if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.submit.id = ("%sbutton")%encoded_name actionform.submit.onClick = ("getTrendPreferences('%s', '%s');"%(encoded_name, actionform.submit.id)) elif action == ' - ': actionform = CustomForm(request_path, targetID='trend-config-table', id=form_id) actionname = action.replace(' ', '').lower() else: actionform = CustomForm(request_path, targetType='dialog') actionname = action.replace(' ', '').lower() actionform.name = action.title() actioninput = CustomInput( name=actionname, value=encoded_name, type='hidden') if trend.klass == 'log': if action in ['configure points', '-']: actionform.submit.disabled = True actioninput.disabled = True else: if action == ' - ': actionform.name = 'Remove Trend' actionform.submit.onClick = ( "return (confirmDialog('"+ form_id +"', 'Delete trend <b>%s</b> and its" " configuration?', false));" % trend.name ) actionform.klass = 'manual' if action == 'view trend': if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.klass = 'manual' preferences = trend.get_preferences() window_width = preferences['width'] window_height = preferences['height'] window_title = preferences['title'] #actionform.cgi=None actionform.submit.onClick = ( "openWindow('%s?viewtrend=%s','%s'); return false;" % (request_path, encoded_name, trend.name.replace(' ', '_').replace('.', '_')) ) if not trend.get_points(): # No point in viewing graph with no points. actionform.submit.disabled = True #actioninput.disabled=True actionform.append(actioninput) actionform.submit.value = action externally_managed = getattr(trend,'externally_managed',False) if externally_managed and action != 'view trend': actionform.submit.disabled = True actioncell.append(actionform) # Add row row.append(actioncell) except Exception, e: cell = HTMLgen.TD("Invalid configuration: Please validate the configuration using ConfigTool.") rowid='row%s'%count dots="[+]" js = "var element = document.getElementById('%s'); if(element.innerHTML == '%s'){element.innerHTML='[-]<BR>%s'}else{element.innerHTML='%s'}" % (rowid,dots, str(e).replace('\"', '').replace("\'", ""),dots); invalid_label=CustomLabel(id=rowid,onclick=js,style='color:red;text-decoration:underline;cursor: pointer') invalid_label.append(dots) cell.append(invalid_label) row.append(cell) msglog.exception() msg = ("Failed create row for: %s" % display_name) msglog.log('trendmanager', msglog.types.ERR, msg)
def __render_trend_row(self, request_path, display_name, trend_map, count): trend = trend_map[display_name] if trend is None: return None rowclasses = ['light', 'dark'] row = HTMLgen.TR(**{'class': rowclasses[count % 2]}) span = HTMLgen.Span(display_name, **{'style': 'white-space: pre;'}) row.append(HTMLgen.TH(span)) try: if not trend.get_points(): domish(row).setAttribute('class', 'nopoints') actioncell = HTMLgen.TD(**{"nowrap": True}) last_action = actioncell encoded_name = urllib.quote_plus(trend.name) # @note Using display text as URL is a bad idea... # @note More of a combo box approach would be better. # @note I don't think all the forms and hidden inputs are needed. # either use a single form and the input name, or use # multiple forms with encoded request paths... Or? actions = [ 'view trend', 'configure points', 'trend preferences', ' - ' ] for action in actions: form_id = action.lstrip().rstrip() + cgi.escape(trend.name) if action == 'view trend': actionform = CustomForm(request_path) actionname = 'reload' elif action == 'trend preferences': actionform = CustomForm(request_path, targetType='ignore') if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.submit.id = ("%sbutton") % encoded_name actionform.submit.onClick = ( "getTrendPreferences('%s', '%s');" % (encoded_name, actionform.submit.id)) elif action == ' - ': actionform = CustomForm(request_path, targetID='trend-config-table', id=form_id) actionname = action.replace(' ', '').lower() else: actionform = CustomForm(request_path, targetType='dialog') actionname = action.replace(' ', '').lower() actionform.name = action.title() actioninput = CustomInput(name=actionname, value=encoded_name, type='hidden') if trend.klass == 'log': if action in ['configure points', '-']: actionform.submit.disabled = True actioninput.disabled = True else: if action == ' - ': actionform.name = 'Remove Trend' actionform.submit.onClick = ( "return (confirmDialog('" + form_id + "', 'Delete trend <b>%s</b> and its" " configuration?', false));" % trend.name) actionform.klass = 'manual' if action == 'view trend': if (trend.klass == 'log') and (len(trend.get_points()) > 9): actionform.submit.onClick = ( "(alert('This trend is configured via /services/logger and has more than 9 points. Viewing/configuring points for this trend is currently not supported.'));return false;" ) else: actionform.klass = 'manual' preferences = trend.get_preferences() window_width = preferences['width'] window_height = preferences['height'] window_title = preferences['title'] #actionform.cgi=None actionform.submit.onClick = ( "openWindow('%s?viewtrend=%s','%s'); return false;" % (request_path, encoded_name, trend.name.replace(' ', '_').replace('.', '_'))) if not trend.get_points(): # No point in viewing graph with no points. actionform.submit.disabled = True #actioninput.disabled=True actionform.append(actioninput) actionform.submit.value = action externally_managed = getattr(trend, 'externally_managed', False) if externally_managed and action != 'view trend': actionform.submit.disabled = True actioncell.append(actionform) # Add row row.append(actioncell) except Exception, e: cell = HTMLgen.TD( "Invalid configuration: Please validate the configuration using ConfigTool." ) rowid = 'row%s' % count dots = "[+]" js = "var element = document.getElementById('%s'); if(element.innerHTML == '%s'){element.innerHTML='[-]<BR>%s'}else{element.innerHTML='%s'}" % ( rowid, dots, str(e).replace('\"', '').replace("\'", ""), dots) invalid_label = CustomLabel( id=rowid, onclick=js, style='color:red;text-decoration:underline;cursor: pointer') invalid_label.append(dots) cell.append(invalid_label) row.append(cell) msglog.exception() msg = ("Failed create row for: %s" % display_name) msglog.log('trendmanager', msglog.types.ERR, msg)