Changeset 3039

Show
Ignore:
Timestamp:
01/11/08 15:31:58 (1 year ago)
Author:
bobbysmith007
Message:

Got everything rough draft working. We now add a macro call to the ticket description to display the estimate. I make a ticket change to record the comment, but it is coming up as html instead of rendering

Files:

Legend:

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

    r3035 r3039  
    4141def getHtmlEstimate(id): 
    4242    return dbhelper.get_scalar("SELECT COMMENT FROM estimate WHERE ID=%s", 0, id) 
     43 
     44estimateChangeTicketComment = """ 
     45INSERT INTO ticket_change (ticket, time, author, field, oldvalue, newvalue) 
     46VALUES ( %s, %s, %s, 'estimate',  '', %s ) 
     47""" 
  • estimatorplugin/0.11/estimatorplugin/htdocs/estimate.js

    r3035 r3039  
    2626function evenDeeperClone(node){ 
    2727   //firefox 2 has a bug where it wont clone textarea values sometimes 
    28    var kids = []; 
     28   var kids = [], kid; 
     29    
    2930   for(var i=0 ; kid=node.childNodes[i] ; i++) 
    3031      kids[i] = evenDeeperClone(kid); 
     
    3334   if (node.value) hsh.value = node.value; 
    3435   if (node.type && node.type!='textarea') hsh.type = node.type 
    35  
    3636   if (node.tagName) newNode = cn(node.tagName, hsh, kids); 
    37    else newNode = node.cloneNode(true); 
     37   else 
     38      newNode = node.cloneNode(true); 
     39   /* 
     40   newNode = node.cloneNode(false); 
     41   for(var i=0 ; kid=node.childNodes[i] ; i++){ 
     42      var cloned = evenDeeperClone(kid); 
     43      newNode.appendChild(cloned); 
     44   } 
     45   */ 
    3846   return newNode; 
    3947} 
  • estimatorplugin/0.11/estimatorplugin/macro_provider.py

    r3035 r3039  
    4141        """ 
    4242        #try: 
    43         x = dir(self) 
    44         x.sort() 
    45         self.log.debug('what? : %s, %r' % (self, x)) 
    4643        return self.estimate_macro(int(content), formatter.req) 
    4744        #except: 
  • estimatorplugin/0.11/estimatorplugin/templates/estimate.html

    r3034 r3039  
    106106           var lineItems = ${estimate.lineItems}; 
    107107           loadLineItems(); 
    108            newLineItem(); 
     108           if(lineItems.length == 0) newLineItem(); 
    109109        </script > 
    110110      </div> 
  • estimatorplugin/0.11/estimatorplugin/webui.py

    r3035 r3039  
    99from trac.web.href import Href 
    1010from estimator import * 
    11  
     11from trac.ticket import Ticket 
     12import datetime 
     13from trac.util.datefmt import utc, to_timestamp 
    1214 
    1315class EstimationsPage(Component): 
     
    1517    def __init__(self): 
    1618        pass 
    17     def load(self, req, addMessage, data): 
     19    def load(self, id, addMessage, data): 
    1820        try: 
    19             id = int(req.args['id']) 
    2021            data["estimate"]["id"] = id 
    2122            estimate_rs = getEstimateResultSet(id) 
     
    3233                addMessage('Cant Find Estimate Id: %s' % id) 
    3334        except Exception, e: 
    34             addMessage('Invalid Id: %s' % req.args['id']
     35            addMessage('Invalid Id: %s' % id
    3536            addMessage('Error: %s' % e) 
     37             
    3638    def line_item_hash_from_args(self, args): 
    3739        not_line_items=['__FORM_TOKEN','tickets','variability','communication', 
     
    4749         if not(not_line_items.__contains__(item[0]))] 
    4850        return lineItems 
     51 
     52    def notify_old_tickets(self, req, id, addMessage, changer): 
     53        try: 
     54            estimate_rs = getEstimateResultSet(id) 
     55            tickets = estimate_rs.value('tickets', 0) 
     56            comment = estimate_rs.value('comment', 0) 
     57            tickets = [int(t.strip()) for t in tickets.split(',')] 
     58            self.log.debug('Notifying old tickets of estimate change: %s' % tickets) 
     59            return [(estimateChangeTicketComment, 
     60                     [t, 
     61                      to_timestamp(datetime.datetime.now(utc)), 
     62                      req.authname, 
     63                      "<del>%s</del>" % comment]) 
     64                    for t in tickets] 
     65        except Exception, e: 
     66            self.log.error("Error saving old ticket changes: %s" % e) 
     67            addMessage("Tickets must be numbers") 
     68            return None 
    4969         
    50     def save_from_form (self, args, addMessage): 
     70    def notify_new_tickets(self, req, id, tickets, addMessage): 
     71        try: 
     72            tag = "[[Estimate(%s)]]" % id 
     73            tickets = [int(t.strip()) for t in tickets.split(',')] 
     74            for t in tickets: 
     75                ticket = Ticket (self.env, t) 
     76                if ticket['description'].find (tag) == -1: 
     77                    self.log.debug('Updating Ticket Description : %s'%t) 
     78                    ticket['description'] = ticket['description']+'\n----\n'+tag 
     79                    ticket.save_changes(req.authname, 'added estimate') 
     80            return True 
     81        except: 
     82            addMessage("Tickets must be numbers") 
     83            return None 
     84                   
     85         
     86    def save_from_form (self, req, addMessage): 
    5187        #try: 
     88 
     89            args = req.args 
    5290            tickets = args["tickets"] 
    5391            id = args["id"] 
     92            old_tickets = None 
    5493            if id == None or id == '' : 
     94                self.log.debug('Saving new estimate') 
    5595                sql = estimateInsert 
    5696                id = nextEstimateId () 
    5797            else: 
     98                self.log.debug('Saving edited estimate') 
     99                old_tickets = self.notify_old_tickets(req, id, addMessage, req.authname) 
    58100                sql = estimateUpdate 
    59  
     101            self.log.debug('Old Tickets to Update: %r' % old_tickets) 
    60102            estimate_args = [args['rate'], args['variability'], 
    61103                             args['communication'], tickets, 
     
    87129 
    88130            sql = removeLineItemsNotInListSql % ','.join(ids) 
    89             addMessage("Deleting NonExistant Estimate Rows: %r - %s" % (sql , id)) 
    90              
    91             result = dbhelper.execute_in_trans(saveEstimate, 
    92                                                (sql, [id]), 
    93                                                *saveLineItems) 
     131            #addMessage("Deleting NonExistant Estimate Rows: %r - %s" % (sql , id)) 
     132 
     133            sqlToRun = [saveEstimate, 
     134                        (sql, [id]),] 
     135            sqlToRun.extend(saveLineItems) 
     136            if old_tickets: 
     137                sqlToRun.extend(old_tickets) 
     138             
     139            result = dbhelper.execute_in_trans(*sqlToRun) 
    94140            #will be true or Exception 
    95141            if result == True: 
    96142                addMessage("Estimate Saved!") 
     143                if self.notify_new_tickets( req, id, tickets, addMessage): 
     144                    req.redirect(req.href.Estimate()+'?id=%s'%id) 
    97145            else: 
    98146                addMessage("Failed to save! %s" % result) 
     
    124172        def addMessage(s): 
    125173            messages.extend([s]); 
    126         addMessage("Post Args: %s"% req.args.items()) 
     174        #addMessage("Post Args: %s"% req.args.items()) 
    127175        if req.method == 'POST': 
    128             self.save_from_form(req.args, addMessage) 
     176            self.save_from_form(req, addMessage) 
    129177        data = {} 
    130178        data["estimate"]={ 
     
    140188         
    141189        if req.args.has_key('id') and req.args['id'].strip() != '': 
    142             self.load(req, addMessage, data) 
     190            self.load(int(req.args['id']), addMessage, data) 
    143191 
    144192 
  • estimatorplugin/0.11/setup.py

    r3013 r3039  
    44 
    55setup(name=PACKAGE, 
    6       version='0.0.1', 
     6      version='0.0.2', 
    77      packages=[PACKAGE], 
    88      url='http://www.trac-hacks.org/wiki/EstimatorPlugin',