Exemplo n.º 1
0
 def create_confirm_form(self):
     confirm_form = CustomForm('/trendmanager')
     confirm_form.submit = HTMLgen.Span(**{"class":"savespan"})
     confirm_form.submit.append(
         CustomInput(type='hidden', name='trend',
                     value=self.confirmupdate.encoded_name)
         )
     confirm_form.submit.append(
         CustomInput(type='submit', name='confirmupdate', value='Commit')
         )
     confirm_form.submit.append(
         CustomInput(type='submit', name='cancelupdate', value='Cancel')
         )
     return confirm_form
Exemplo n.º 2
0
 def render(self):
     request_path = '/trendmanager'
     trend_section = HTMLgen.Div(**{'class': 'section'})
     trend_table = HTMLgen.TableLite(
         **{
             'class': 'configuration-table configureNodesTable',
             'id': 'trend-config-table'
         })
     trend_section.append(trend_table)
     trend_table_tr_th = HTMLgen.TR(**{'class': 'table-header'})
     trend_table.append(trend_table_tr_th)
     th_name = HTMLgen.TH('Trend', id='Nameheader')
     trend_table_tr_th.append(th_name)
     th_action = HTMLgen.TH('Action', id='Actionheader')
     trend_table_tr_th.append(th_action)
     trends = self.manager.get_trends()
     trend_map = {}
     for trend in trends:
         trend_name = None
         try:
             trend_name = trend.name
             display_name = trend.get_preferences()['title']
             if not display_name:
                 display_name = trend.name
             if display_name != trend.name:
                 display_name = "%s (%s)" % (display_name, trend.name)
             trend_map[display_name] = trend
         except:
             msg = ("Failed to get preferences for: %s, can't list." %
                    trend_name)
             msglog.log('trendmanager', msglog.types.ERR, msg)
             msglog.exception(prefix='Handled')
     display_names = trend_map.keys()
     display_names.sort(lambda a, b: cmp(a.lower(), b.lower()))
     count = 0
     for display_name in display_names:
         try:
             count += 1
             row = self.__render_trend_row(request_path, display_name,
                                           trend_map, count)
             trend_table.append(row)
         except:
             msglog.exception()
             msg = ("Failed create row for: %s" % display_name)
             msglog.log('trendmanager', msglog.types.ERR, msg)
     # Add + to the last actioncell (maybe the actionheader if no trends)
     actionform = CustomForm(request_path)
     actionform.submit.value = ' + '
     actionform.submit.name = 'Add Trend'
     trend_name = self.manager.generate_trend_name()
     add_form = (addform) % (trend_name)
     add_form = urllib.quote(add_form)
     actionform.submit.onClick = "return popup_form(this, '%s', true); return false;" % add_form
     trend_section.append(actionform)
     return str(trend_section)
Exemplo n.º 3
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
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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
Exemplo n.º 7
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)
Exemplo n.º 8
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)