Example #1
0
 def create_document_structure(self):
     self.document = HTMLgen.SimpleDocument(
         title='trendMANAGER',
         stylesheet='/omega/trendmanager/styles.css',
         script=[HTMLgen.Script(src="/webapi/js/ColorPicker2.js"),
                 HTMLgen.Script(code="""
                 window.ColorPicker_targetButton = null;
                 function pickColor(color) {
                     ColorPicker_targetInput.value = color;
                     ColorPicker_targetButton.style.backgroundColor = color;
                     return;
                 }
                 var cp = new ColorPicker('window');
                 function open_color_selector(input_id, button_id) {
                     var input = document.getElementById(input_id);
                     var button = document.getElementById(button_id);
                     window.ColorPicker_targetButton = button;
                     cp.select(input, input_id);
                     return;
                 }
                 function change_button_color(input_id, button_id) {
                     var input = document.getElementById(input_id);
                     var button = document.getElementById(button_id);
                     var color = input.value;
                     button.style.backgroundColor = color;
                     return;
                 }
                 """)
                 ]
         )
     # Hack-around to set the class on the BODY for HTMLGen
     self.document.append(
         HTMLgen.Script(code="""
           document.body.className = 'manager';
           """)
         )
     page_heading = HTMLgen.Heading(2, "Trend Preferences",
                                    id="editorlabel")
     self.document.append(page_heading)
     section = HTMLgen.Div(**{'class':'section'})
     form = CustomForm('/trendmanager')
     #
     # Also, create methods in request handler to extract the values
     # to make changing the form easier.
     #
     self.generalpreferencescontainer = HTMLgen.Div(
         **{'id':'generalpreferencescontainer'}
         )
     form.append(self.generalpreferencescontainer)
     self.pointpreferencescontainer = HTMLgen.Div(
         **{'id':'pointpreferencescontainer'}
         )
     form.append(self.pointpreferencescontainer)
     self.axespreferencescontainer = HTMLgen.Div(
         **{'id':'axespreferencescontainer'}
         )
     form.append(self.axespreferencescontainer)
     form.submit = HTMLgen.Span(**{"class":"savespan"})
     form.submit.append(
         CustomInput(type='hidden', name='trend', value=self.encoded_name)
         )
     form.submit.append(
         CustomInput(type='submit', name='commitpreferences',
                     value='Commit')
         )
     form.submit.append(
         CustomInput(type='submit', name='cancelpreferences',
                     value='Cancel')
         )
     form.submit.append(
         CustomInput(type='submit', name='reloadpreferences',
                     value='Reload')
         )
     section.append(form)
     self.document.append(section)
     return
Example #2
0
    def render(self):
        # @todo Restructure like preferences, point_form -> form...
        self.trend_configuration = self.trend.configuration()
        document = HTMLgen.SimpleDocument(
            title='trendMANAGER',
            stylesheet='/omega/trendmanager/styles.css',
            script=[HTMLgen.Script(code=nodeselectscript),
                    HTMLgen.Script(code=updatenamescript),]
            )
        # Hack-around to set the class on the BODY for HTMLGen
        document.append(
            HTMLgen.Script(code="""
              document.body.className = 'manager';
              """)
            )
        page_heading = HTMLgen.Heading(2, "Trend Point Configuration",
                                       id="editorlabel")
        document.append(page_heading)
        section = HTMLgen.Div(**{'class':'section'})
        point_form = CustomForm('/trendmanager')

        self.globalsettingscontainer = HTMLgen.Div(
            **{'id':'globalsettingscontainer'}
            )
        point_form.append(self.globalsettingscontainer)
        self.add_global_settings()
        point_section = HTMLgen.Div(**{'class':'section'})
        point_table = HTMLgen.TableLite(**{'class':'nodeEditTable'})
        point_header = HTMLgen.TR(**{'class':'trend_table_headers'})
        for header in ['Point Name', 'Node Path']:
            header_id = "%sheader" % header.replace(' ','').lower()
            headcell = HTMLgen.TH(header, scope="col", abbr=header,
                                  id=header_id)
            point_header.append(headcell)
        point_table.append(point_header)
        rowclasses = ['light', 'dark']
        cd_points = self.trend_configuration['points']
        for point_position in xrange(1,10):
            point_row = HTMLgen.TR(**{'class':rowclasses[point_position % 2]})
            point_name_value = ""
            point_node_value = ""
            if len(cd_points) >= point_position:
                point_cfg = cd_points[point_position-1]
                point_name_value = point_cfg['name']
                point_node_value = point_cfg['node']
            point_name_id = "point%d" % point_position
            name_input = DojoInput(**{
                'value':point_name_value,
                'name':point_name_id,
                'id':point_name_id,
                })
            name_column = HTMLgen.TD(**{"nowrap":True})
            name_column.append(name_input)
            point_row.append(name_column)
            point_node_id = "node%d" % point_position
            node_input = DojoInput(**{
                'value':point_node_value,
                'name':point_node_id,
                'id':point_node_id,
                })
            # @fixme Cool idea, need to swap order of node and name and
            #        adding +/- capability would be extremely helpful in
            #        user experience.
            #node_input.onChange = "update_point_name('%s','%s');" % (
            #    point_node_id,
            #    point_name_id
            #    )
            node_column = HTMLgen.TD(**{"class":"configuration",
                                        "nowrap":True})
            node_column.append(node_input)
            browse_node_id = "browse%d" % point_position
            node_browse = CustomInput(**{
                'type':'button',
                'name':browse_node_id,
                'value':'...',
                })
            node_browse.onClick = "open_node_selector('%s');" % point_node_id
            button_column = HTMLgen.TD(**{"nowrap":True})
            button_column.append(node_browse)
            point_row.append(node_column)
            point_row.append(button_column)
            point_table.append(point_row)
        point_table.append(
            CustomInput(type='hidden', name='commitpoints', value='Commit')
            )
        point_form.append(point_table)
        point_form.submit = HTMLgen.Span(**{"class":"savespan"})
        point_form.submit.append(
            CustomInput(type='hidden', name='trend', value=self.encoded_name)
            )
        point_form.submit.append(
            CustomInput(type='submit', name='commitpoints', value='Commit')
            )
        point_form.submit.append(
            CustomInput(type='submit', name='cancelpoints', value='Cancel')
            )
        point_form.submit.append(
            CustomInput(type='submit', name='reloadpoints', value='Reload')
            )        
        section.append(point_form)
        document.append(section)
        return str(document)
Example #3
0
 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)
Example #4
0
 def create_document_structure(self):
     self.document = HTMLgen.SimpleDocument(
         title='trendMANAGER',
         stylesheet='/omega/trendmanager/styles.css',
         script=[
             HTMLgen.Script(src="/webapi/js/ColorPicker2.js"),
             HTMLgen.Script(code="""
                 window.ColorPicker_targetButton = null;
                 function pickColor(color) {
                     ColorPicker_targetInput.value = color;
                     ColorPicker_targetButton.style.backgroundColor = color;
                     return;
                 }
                 var cp = new ColorPicker('window');
                 function open_color_selector(input_id, button_id) {
                     var input = document.getElementById(input_id);
                     var button = document.getElementById(button_id);
                     window.ColorPicker_targetButton = button;
                     cp.select(input, input_id);
                     return;
                 }
                 function change_button_color(input_id, button_id) {
                     var input = document.getElementById(input_id);
                     var button = document.getElementById(button_id);
                     var color = input.value;
                     button.style.backgroundColor = color;
                     return;
                 }
                 """)
         ])
     # Hack-around to set the class on the BODY for HTMLGen
     self.document.append(
         HTMLgen.Script(code="""
           document.body.className = 'manager';
           """))
     page_heading = HTMLgen.Heading(2,
                                    "Trend Preferences",
                                    id="editorlabel")
     self.document.append(page_heading)
     section = HTMLgen.Div(**{'class': 'section'})
     form = CustomForm('/trendmanager')
     #
     # Also, create methods in request handler to extract the values
     # to make changing the form easier.
     #
     self.generalpreferencescontainer = HTMLgen.Div(
         **{'id': 'generalpreferencescontainer'})
     form.append(self.generalpreferencescontainer)
     self.pointpreferencescontainer = HTMLgen.Div(
         **{'id': 'pointpreferencescontainer'})
     form.append(self.pointpreferencescontainer)
     self.axespreferencescontainer = HTMLgen.Div(
         **{'id': 'axespreferencescontainer'})
     form.append(self.axespreferencescontainer)
     form.submit = HTMLgen.Span(**{"class": "savespan"})
     form.submit.append(
         CustomInput(type='hidden', name='trend', value=self.encoded_name))
     form.submit.append(
         CustomInput(type='submit',
                     name='commitpreferences',
                     value='Commit'))
     form.submit.append(
         CustomInput(type='submit',
                     name='cancelpreferences',
                     value='Cancel'))
     form.submit.append(
         CustomInput(type='submit',
                     name='reloadpreferences',
                     value='Reload'))
     section.append(form)
     self.document.append(section)
     return
Example #5
0
    def render(self):
        # @todo Restructure like preferences, point_form -> form...
        self.trend_configuration = self.trend.configuration()
        document = HTMLgen.SimpleDocument(
            title='trendMANAGER',
            stylesheet='/omega/trendmanager/styles.css',
            script=[
                HTMLgen.Script(code=nodeselectscript),
                HTMLgen.Script(code=updatenamescript),
            ])
        # Hack-around to set the class on the BODY for HTMLGen
        document.append(
            HTMLgen.Script(code="""
              document.body.className = 'manager';
              """))
        page_heading = HTMLgen.Heading(2,
                                       "Trend Point Configuration",
                                       id="editorlabel")
        document.append(page_heading)
        section = HTMLgen.Div(**{'class': 'section'})
        point_form = CustomForm('/trendmanager')

        self.globalsettingscontainer = HTMLgen.Div(
            **{'id': 'globalsettingscontainer'})
        point_form.append(self.globalsettingscontainer)
        self.add_global_settings()
        point_section = HTMLgen.Div(**{'class': 'section'})
        point_table = HTMLgen.TableLite(**{'class': 'nodeEditTable'})
        point_header = HTMLgen.TR(**{'class': 'trend_table_headers'})
        for header in ['Point Name', 'Node Path']:
            header_id = "%sheader" % header.replace(' ', '').lower()
            headcell = HTMLgen.TH(header,
                                  scope="col",
                                  abbr=header,
                                  id=header_id)
            point_header.append(headcell)
        point_table.append(point_header)
        rowclasses = ['light', 'dark']
        cd_points = self.trend_configuration['points']
        for point_position in xrange(1, 10):
            point_row = HTMLgen.TR(**{'class': rowclasses[point_position % 2]})
            point_name_value = ""
            point_node_value = ""
            if len(cd_points) >= point_position:
                point_cfg = cd_points[point_position - 1]
                point_name_value = point_cfg['name']
                point_node_value = point_cfg['node']
            point_name_id = "point%d" % point_position
            name_input = DojoInput(
                **{
                    'value': point_name_value,
                    'name': point_name_id,
                    'id': point_name_id,
                })
            name_column = HTMLgen.TD(**{"nowrap": True})
            name_column.append(name_input)
            point_row.append(name_column)
            point_node_id = "node%d" % point_position
            node_input = DojoInput(
                **{
                    'value': point_node_value,
                    'name': point_node_id,
                    'id': point_node_id,
                })
            # @fixme Cool idea, need to swap order of node and name and
            #        adding +/- capability would be extremely helpful in
            #        user experience.
            #node_input.onChange = "update_point_name('%s','%s');" % (
            #    point_node_id,
            #    point_name_id
            #    )
            node_column = HTMLgen.TD(**{
                "class": "configuration",
                "nowrap": True
            })
            node_column.append(node_input)
            browse_node_id = "browse%d" % point_position
            node_browse = CustomInput(**{
                'type': 'button',
                'name': browse_node_id,
                'value': '...',
            })
            node_browse.onClick = "open_node_selector('%s');" % point_node_id
            button_column = HTMLgen.TD(**{"nowrap": True})
            button_column.append(node_browse)
            point_row.append(node_column)
            point_row.append(button_column)
            point_table.append(point_row)
        point_table.append(
            CustomInput(type='hidden', name='commitpoints', value='Commit'))
        point_form.append(point_table)
        point_form.submit = HTMLgen.Span(**{"class": "savespan"})
        point_form.submit.append(
            CustomInput(type='hidden', name='trend', value=self.encoded_name))
        point_form.submit.append(
            CustomInput(type='submit', name='commitpoints', value='Commit'))
        point_form.submit.append(
            CustomInput(type='submit', name='cancelpoints', value='Cancel'))
        point_form.submit.append(
            CustomInput(type='submit', name='reloadpoints', value='Reload'))
        section.append(point_form)
        document.append(section)
        return str(document)
Example #6
0
 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)