Ejemplo n.º 1
0
 def getActiveTask(self, req, username=None):
     """ Returns a structure representing the info about the active task (identical to getLatestTask but does not return anything if the work has stopped). """
     if username:
         mgr = WorkLogManager(self.env, self.config, username)
     else:
         mgr = WorkLogManager(self.env, self.config, req.authname)
     return mgr.get_active_task()
Ejemplo n.º 2
0
 def getLatestTask(self, req, username=None):
     """ Returns a structure representing the info about the latest task. """
     if username:
         mgr = WorkLogManager(self.env, self.config, username)
     else:
         mgr = WorkLogManager(self.env, self.config, req.authname)
     return mgr.get_latest_task()
Ejemplo n.º 3
0
 def ticket_changed(self, ticket, comment, author, old_values):
     """Called when a ticket is modified.
     
     `old_values` is a dictionary containing the previous values of the
     fields that have changed.
     """
     if self.config.getbool('worklog', 'autostop') \
            and 'closed' == ticket['status'] \
            and old_values.has_key('status') \
            and 'closed' != old_values['status']:
         mgr = WorkLogManager(self.env, self.config)
         who, since = mgr.who_is_working_on(ticket.id)
         if who:
             mgr = WorkLogManager(self.env, self.config, who)
             mgr.stop_work()
Ejemplo n.º 4
0
    def get_navigation_items(self, req):
        match = re.match(r'/ticket/([0-9]+)$', req.path_info)
        if match:
            add_stylesheet(req, "worklog/worklogplugin.css")
            ticket = int(match.group(1))

            mgr = WorkLogManager(self.env, self.config, req.authname)
            task_js = ''
            if req.authname != 'anonymous':
                task = mgr.get_active_task()
                if task:
                    task_js = self.get_task_js(req, ticket, task)

            who, since = mgr.who_is_working_on(ticket)
            ticket_js = ''
            if who:
                # If who == req.authname then we will have some text from above.
                if who != req.authname:
                    ticket_js = self.get_ticket_js(who, since)
            else:
                ticket_js = self.get_ticket_js_noone()

            button_js = ''
            if req.authname != 'anonymous':
                if mgr.can_work_on(ticket):
                    # Display a "Work on Link" button.
                    button_js = self.get_button_js(req, ticket)
                elif task and task['ticket'] == ticket:
                    # We are currently working on this, so display the stop button...
                    button_js = self.get_button_js(req, ticket, True)

            yield 'mainnav', 'ticket-worklog-addon', self.get_javascript(
                task_js, ticket_js, button_js)
Ejemplo n.º 5
0
    def filter_stream(self, req, method, filename, stream, data):
        match = re.match(r'/ticket/([0-9]+)$', req.path_info)
        if match and req.perm.has_permission('WORK_LOG'):
            ticket = int(match.group(1))
            add_stylesheet(req, "worklog/worklogplugin.css")

            add_script(req, 'worklog/jqModal.js')
            add_stylesheet(req, 'worklog/jqModal.css')

            add_script(req, 'worklog/ui.datepicker.js')
            add_stylesheet(req, 'worklog/ui.datepicker.css')

            add_script(req, 'worklog/jquery.mousewheel.pack.js')
            add_script(req, 'worklog/jquery.timeentry.pack.js')

            add_script(req, 'worklog/tracWorklog.js')

            mgr = WorkLogManager(self.env, self.config, req.authname)
            task_markup = ''
            if req.authname != 'anonymous':
                task = mgr.get_active_task()
                if task:
                    task_markup = self.get_task_markup(req, ticket, task)

            who, since = mgr.who_is_working_on(ticket)
            ticket_markup = ''
            if who:
                # If who == req.authname then we will have some text from above.
                if who != req.authname:
                    ticket_markup = self.get_ticket_markup(who, since)
            else:
                ticket_markup = self.get_ticket_markup_noone()

            button_markup = ''
            if req.authname != 'anonymous':
                if mgr.can_work_on(ticket):
                    # Display a "Work on Link" button.
                    button_markup = self.get_button_markup(req, ticket)
                elif task and task['ticket'] == ticket:
                    # We are currently working on this, so display the stop button...
                    button_markup = self.get_button_markup(req, ticket, True)

            # User's current task information
            html = XML('''
              <fieldset class="workloginfo">
                <legend>Work Log</legend>
                %s
                <ul>
                  %s
                  %s
                </ul>
              </fieldset>
              ''' % (button_markup, task_markup, ticket_markup))
            stream |= Transformer('.//div[@id="ticket"]').before(html)
        return stream
Ejemplo n.º 6
0
    def process_request(self, req):
        req.perm.require('WORK_VIEW')

        messages = []

        def addMessage(s):
            messages.extend([s])

        # General protection (not strictly needed if Trac behaves itself)
        if not re.search('/worklog', req.path_info):
            return None

        add_stylesheet(req, "worklog/worklogplugin.css")

        # Specific pages:
        match = re.search('/worklog/users/(.*)', req.path_info)
        if match:
            mgr = WorkLogManager(self.env, self.config, match.group(1))
            if req.args.has_key('format') and req.args['format'] == 'csv':
                self.worklog_csv(req, mgr.get_work_log('user'))
                return None

            data = {
                "worklog": mgr.get_work_log('user'),
                "ticket_href": req.href.ticket(),
                "usermanual_href": req.href.wiki(user_manual_wiki_title),
                "usermanual_title": user_manual_title
            }
            return 'worklog_user.html', data, None

        match = re.search('/worklog/stop/([0-9]+)', req.path_info)
        if match:
            ticket = match.group(1)
            data = {
                'worklog_href': req.href.worklog(),
                'ticket_href': req.href.ticket(ticket),
                'ticket': ticket,
                'action': 'stop',
                'label': 'Stop Work'
            }
            xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest'
            if xhr:
                data['xhr'] = True
            return 'worklog_stop.html', data, None

        mgr = WorkLogManager(self.env, self.config, req.authname)
        if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log())
            return None

        # Not any specific page, so process POST actions here.
        if req.method == 'POST':
            if req.args.has_key('startwork') and req.args.has_key('ticket'):
                if not mgr.start_work(req.args['ticket']):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You are now working on ticket #%s.' %
                               (req.args['ticket'], ))

                req.redirect(req.args['source_url'])
                return None

            elif req.args.has_key('stopwork'):
                stoptime = None
                if req.args.has_key('stoptime') and req.args['stoptime']:
                    stoptime = int(req.args['stoptime'])

                comment = ''
                if req.args.has_key('comment'):
                    comment = req.args['comment']

                if not mgr.stop_work(stoptime, comment):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You have stopped working.')

                req.redirect(req.args['source_url'])
                return None

        # no POST, so they're just wanting a list of the worklog entries
        data = {
            "messages": messages,
            "worklog": mgr.get_work_log('summary'),
            "worklog_href": req.href.worklog(),
            "ticket_href": req.href.ticket(),
            "usermanual_href": req.href.wiki(user_manual_wiki_title),
            "usermanual_title": user_manual_title
        }
        return 'worklog.html', data, None
Ejemplo n.º 7
0
 def whoLastWorkedOn(self, req, ticket):
     """ Returns the username of the person last worked on the given ticket """
     mgr = WorkLogManager(self.env, self.config, req.authname)
     return mgr.who_last_worked_on(ticket)
Ejemplo n.º 8
0
 def whoIsWorkingOn(self, req, ticket):
     """ Returns the username of the person currently working on the given ticket """
     mgr = WorkLogManager(self.env, self.config, req.authname)
     (who, when) = mgr.who_is_working_on(ticket)
     return who
Ejemplo n.º 9
0
 def stopWork(self, req, comment='', stoptime=None):
     """ Stops work. Returns the string 'OK' on success or an explanation on error (requires authentication, stoptime is seconds since epoch) """
     mgr = WorkLogManager(self.env, self.config, req.authname)
     if mgr.stop_work(stoptime, comment):
         return 'OK'
     return mgr.get_explanation()
Ejemplo n.º 10
0
 def startWork(self, req, ticket):
     """ Start work on a ticket. Returns the string 'OK' on success or an explanation on error (requires authentication)"""
     mgr = WorkLogManager(self.env, self.config, req.authname)
     if mgr.start_work(ticket):
         return 'OK'
     return mgr.get_explanation()
Ejemplo n.º 11
0
    def process_request(self, req):
        messages = []

        def addMessage(s):
            messages.extend([s]);

        # General protection (not strictly needed if Trac behaves itself)
        if not re.search('/worklog', req.path_info):
            return None
        
        # Specific pages:
        match = re.search('/worklog/users/(.*)', req.path_info)
        if match:
          mgr = WorkLogManager(self.env, self.config, match.group(1))
          if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log('user'))
            return None
          
          req.hdf["worklog"] = {"worklog": mgr.get_work_log('user'),
                                "ticket_href": req.href.ticket(),
                                "usermanual_href":req.href.wiki(user_manual_wiki_title),
                                "usermanual_title":user_manual_title
                               }
          add_stylesheet(req, "worklog/worklogplugin.css")
          return 'worklog_user.cs', None

        mgr = WorkLogManager(self.env, self.config, req.authname)
        if req.args.has_key('format') and req.args['format'] == 'csv':
            self.worklog_csv(req, mgr.get_work_log())
            return None
        
        # Not any specific page, so process POST actions here.
        if req.method == 'POST':
            if req.args.has_key('startwork') and req.args.has_key('ticket'):
                if not mgr.start_work(req.args['ticket']):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You are now working on ticket #%s.' % (req.args['ticket'],))
                
                req.redirect(req.args['source_url'])
                return None
                
            elif req.args.has_key('stopwork'):
                stoptime = None
                if req.args.has_key('stoptime'):
                    stoptime = int(req.args['stoptime'])

                comment = ''
                if req.args.has_key('comment'):
                    comment = str(req.args['comment'])

                if not mgr.stop_work(stoptime, comment):
                    addMessage(mgr.get_explanation())
                else:
                    addMessage('You have stopped working.')
                
                req.redirect(req.args['source_url'])
                return None
        
        # no POST, so they're just wanting a list of the worklog entries
        req.hdf["worklog"] = {"messages": messages,
                              "worklog": mgr.get_work_log('summary'),
                              "href": req.href.worklog(),
                              "ticket_href": req.href.ticket(),
                              "usermanual_href": req.href.wiki(user_manual_wiki_title),
                              "usermanual_title": user_manual_title
                             }
        add_stylesheet(req, "worklog/worklogplugin.css")
        return 'worklog.cs', None