Changeset 3014

Show
Ignore:
Timestamp:
01/09/08 15:35:07 (1 year ago)
Author:
bobbysmith007
Message:

Made quite a bit of progress loading the estimate object

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • estimatorplugin/0.11/estimatorplugin/dbhelper.py

    r3013 r3014  
    121121def get_result_set(sql, *params): 
    122122    """Executes the query and returns a Result Set""" 
    123     return ResultSet(get_all(sql, *params)) 
     123    tpl = get_all(sql, *params); 
     124    if tpl and tpl[0] and tpl[1]: 
     125        return ResultSet(tpl) 
     126    else: 
     127        return None 
    124128 
    125129 
     
    162166            print ("rs.value Type Failed col:%s  row:%s" % (type(col), type(row))) 
    163167    
     168    def json_out(self): 
     169        return "[%s]" % ','. join( 
     170            [("{%s}" % ','.join(["'%s':%r" %(key, self.value(val, row)) 
     171                                 for (key, val) in columnMap.items()])) 
     172             for row in rows]) 
  • estimatorplugin/0.11/estimatorplugin/templates/estimate.html

    r3013 r3014  
    3535          <tr> 
    3636            <td ><label for="rate">Rate</label></td> 
    37             <td><input id="rate" type="text" onkeyup="runCalculation()" value="" /></td> 
     37            <td><input id="rate" type="text" onkeyup="runCalculation()" value="${estimate.rate}" /></td> 
    3838          </tr> 
    3939          <tr> 
    4040            <td ><label for="variability">Variability</label></td> 
    41             <td><input id="variability" type="text" onkeyup="runCalculation()" value="" /></td> 
     41            <td><input id="variability" type="text" onkeyup="runCalculation()" value="${estimate.variability}" /></td> 
    4242          </tr> 
    4343          <tr> 
    4444            <td ><label for="communication">Communication</label></td> 
    45             <td><input id="communication" type="text" onkeyup="runCalculation()" value="" /></td> 
     45            <td><input id="communication" type="text" onkeyup="runCalculation()" value="${estimate.communication}" /></td> 
    4646          </tr> 
    4747        </table> 
     
    8282        </table> 
    8383        <script language="javascript" > 
    84            var lineItems = [ 
    85               <py:for each="item in estimate.lineitems" > 
    86               </py:for> 
    87            ]; 
     84           var lineItems = ${estimate.lineItems}; 
    8885           loadLineItems( ); 
    8986           newLineItem(); 
  • estimatorplugin/0.11/estimatorplugin/webui.py

    r3013 r3014  
    11import re 
     2import dbhelper 
    23from pkg_resources import resource_filename 
    34from trac.core import * 
     
    3031        return req.path_info.startswith('/Estimate') 
    3132 
     33    def load(self, req, addMessage, data): 
     34        try: 
     35            id = int(req.args['id']) 
     36            data["estimate"]["id"] = id 
     37            estimate_rs = dbhelper.get_result_set("SELECT * FROM estimate WHERE estimate_id=%s", id) 
     38            if estimate_rs: 
     39                data["estimate"]["rate"] = estimate_rs.get_value("rate", 0) 
     40                data["estimate"]["variability"] = estimate_rs.get_value("variability", 0) 
     41                data["estimate"]["communication"] = estimate_rs.get_value("communication", 0) 
     42                rs = dbhelper.get_result_set("SELECT * FROM estimate_line_item WHERE estimate_id=%s", id) 
     43                if rs: 
     44                    data["estimate"]["lineItems"] = rs.json_out() 
     45            else: 
     46                addMessage('Cant Find Estimate Id: %s' % id) 
     47        except Exception, e: 
     48            addMessage('Invalid Id: %s' % id) 
     49            addMessage('Error: %s' % e) 
     50         
    3251    def process_request(self, req): 
    3352        messages = [] 
     
    3958        data["estimate"]={"href":       req.href.Estimate(), 
    4059                          "messages":   messages, 
    41                           "lineitems": [], 
    42                    } 
     60                          "lineItems": '[]', 
     61                          "rate": self.config.get( 'estimator','default_rate') or 200, 
     62                          "variability": self.config.get( 'estimator','default_variability') or 1, 
     63                          "communication": self.config.get( 'estimator','default_communication') or 1, 
     64                          } 
     65         
     66        if req.args.has_key('id'): 
     67            self.load(req, addMessage, data) 
     68 
     69 
    4370        add_script(req, "Estimate/JSHelper.js") 
    4471        add_script(req, "Estimate/Controls.js")