Re: [Planner Dev] Add "Assigned to" column to the tasks display



I couldn't figure out where the data for the wbs was entered, it didn't seem 
to be in the same file.  Is there some time we can chat on irc so I can get 
more information?

Here is a fixed up patch with the other formatting changes (minus the caching 
atm).

Chris



On Wednesday 21 July 2004 10:52 am, Richard Hult wrote:
> On ons, 2004-07-21 at 10:14 -0400, wrote:
> > > From: Richard Hult <richard imendio com>
> > > Date: 2004/07/21 Wed AM 04:02:44 EDT
> > > To: Planner Dev <planner-dev lists imendio com>
> > > Subject: Re: [Planner Dev] Add "Assigned to" column to the tasks
> > > display
> > >
> > > On mån, 2004-07-19 at 21:04 -0400, Chris Morgan wrote:
> > > > Just wanted to thank the developers of planner for an excellent and
> > > > very useful program.
> > > >
> > > > I wrote up this patch to add a column to the task view with the
> > > > resources a task is assigned to.  This seemed quite useful to have
> > > > and allows for knowing which tasks have no one assigned to at the
> > > > moment.  This is my first planner patch so please tell me what things
> > > > I need to clean up to get this into cvs.
> > >
> > > Hi,
> > >
> > > The patch looks like a useful addition! I have a few comments on the
> > > code, mostly style issues. We try to use a very consistent style to
> > > make the code easy to read and maintain:
> > >
> > > The indentation seems to be off in a few places, e.g.:
> > >
> > > +       gchar  *assigned_to;
> > > +       GList  *resources;
> > > +       MrpAssignment  *assignment;
> > > +       MrpResource    *resource;
> > >
> > > Those should be aligned.
> >
> > Of course, I'll take care of that and the rest of the formatting issues.
> >
> > > +       resources = mrp_task_get_assigned_resources(task);
> > > +
> > > +        for (l = resources; l; l = l->next) {
> > >
> > > Here as well.
> > >
> > > +               if(assigned_to)
> > > +               {
> > >
> > > The brace should be on the same line as the if, same with else
> > > (} else {).
> > >
> > > newstr = g_strdup_printf("%s, %s", assigned_to, name);
> > >
> > > We use spaces before "(".
> > >
> > > Other than that, the patch looks fine. I have one objection should,
> > > that is that we should really cache the string instead of building if
> > > in the data_func. data_func is run every time the cell is redrawn, like
> > > when you scroll or move the mouse over it.
> >
> > Are there other data functions in that code that cache their values
> > rather than retrieve them each time?  Is that the purpose for the task
> > tree view?
>
> The WBS stuff is cached, you could look at that (search for "wbs" in the
> same file).
>
> The purpose of the separate file with the task tree is mostly to be able
> to share that code between the task view and the gantt view.
>
> /Richard
? assigned_to_column_in_tasks.patch
? assigned_to_column_in_tasks2.patch
Index: src/planner-gantt-model.h
===================================================================
RCS file: /cvs/gnome/planner/src/planner-gantt-model.h,v
retrieving revision 1.5
diff -u -r1.5 planner-gantt-model.h
--- src/planner-gantt-model.h	29 Jun 2004 09:06:44 -0000	1.5
+++ src/planner-gantt-model.h	21 Jul 2004 23:03:43 -0000
@@ -59,6 +59,7 @@
 	COL_EDITABLE,
 	COL_TASK,
 	COL_COST,
+	COL_ASSIGNED_TO,
 	NUM_COLS
 };
 
Index: src/planner-task-tree.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-tree.c,v
retrieving revision 1.37
diff -u -r1.37 planner-task-tree.c
--- src/planner-task-tree.c	5 Jul 2004 09:13:48 -0000	1.37
+++ src/planner-task-tree.c	21 Jul 2004 23:03:49 -0000
@@ -47,6 +47,7 @@
 #include "planner-gantt-model.h"
 #include "planner-task-popup.h"
 #include "planner-task-cmd.h"
+#include "planner-gantt-row.h"
 
 #define WARN_TASK_DIALOGS 10
 #define MAX_TASK_DIALOGS 25
@@ -128,6 +129,11 @@
 							GtkTreeModel         *tree_model,
 							GtkTreeIter          *iter,
 							gpointer              data);
+static void        task_tree_assigned_to_data_func     (GtkTreeViewColumn    *tree_column,
+							GtkCellRenderer      *cell,
+							GtkTreeModel         *tree_model,
+							GtkTreeIter          *iter,
+							gpointer              data);
 static void        task_tree_work_data_func            (GtkTreeViewColumn    *tree_column,
 							GtkCellRenderer      *cell,
 							GtkTreeModel         *tree_model,
@@ -1523,6 +1529,63 @@
 }
 
 static void
+task_tree_assigned_to_data_func (GtkTreeViewColumn *tree_column,
+			  GtkCellRenderer   *cell,
+			  GtkTreeModel      *tree_model,
+			  GtkTreeIter       *iter,
+			  gpointer           data)
+{
+	gchar          *assigned_to;
+	GList          *resources;
+	GList          *l;
+	MrpAssignment  *assignment;
+	MrpResource    *resource;
+	MrpTask        *task;
+	const gchar    *name;
+
+	gtk_tree_model_get (tree_model, iter, 
+			    COL_TASK, &task,
+			    -1);
+
+	assigned_to = 0;
+	resources = mrp_task_get_assigned_resources(task);
+
+	for (l = resources; l; l = l->next) {
+		resource = l->data;
+
+		assignment = mrp_task_get_assignment (task, resource);
+
+		/* Try short name first. */
+		name = mrp_resource_get_short_name (resource);
+
+		if (!name || name[0] == 0) {
+			name = mrp_resource_get_name (resource);
+		}
+
+		if (!name || name[0] == 0) {
+			name = _("Unnamed");
+		}
+
+		/* separate names with commas */
+		if(assigned_to)	{
+			char *newstr;
+			newstr = g_strdup_printf ("%s, %s", assigned_to, name);
+			g_free (assigned_to);
+			assigned_to = newstr;
+		} else { /* g_strconcat() can't take a NULL string so we do special stuff when assigned_to is null */
+			assigned_to = g_strdup (name);
+		}
+	}
+	g_list_free (resources);
+
+	g_object_set (cell,
+		      "text", assigned_to,
+		      NULL);
+
+	g_free (assigned_to);
+}
+
+static void
 task_tree_work_data_func (GtkTreeViewColumn *tree_column,
 			  GtkCellRenderer   *cell,
 			  GtkTreeModel      *tree_model,
@@ -2395,6 +2458,25 @@
 							 NULL);
 		g_object_set_data (G_OBJECT (col),
 				   "data-func", task_tree_cost_data_func);
+		g_object_set_data (G_OBJECT (col),
+				   "user-data", tree);
+
+		gtk_tree_view_append_column (tree, col);
+		break;
+
+	case COL_ASSIGNED_TO:
+		cell = gtk_cell_renderer_text_new ();
+		col = gtk_tree_view_column_new_with_attributes (title,
+								cell,
+								NULL);
+		gtk_tree_view_column_set_resizable (col, TRUE);
+		gtk_tree_view_column_set_cell_data_func (col,
+							 cell,
+							 task_tree_assigned_to_data_func,
+							 tree,
+							 NULL);
+		g_object_set_data (G_OBJECT (col),
+				   "data-func", task_tree_assigned_to_data_func);
 		g_object_set_data (G_OBJECT (col),
 				   "user-data", tree);
 
Index: src/planner-task-view.c
===================================================================
RCS file: /cvs/gnome/planner/src/planner-task-view.c,v
retrieving revision 1.11
diff -u -r1.11 planner-task-view.c
--- src/planner-task-view.c	17 Jun 2004 16:30:38 -0000	1.11
+++ src/planner-task-view.c	21 Jul 2004 23:03:50 -0000
@@ -277,6 +277,7 @@
 						    COL_WORK,   _("Work"),
 						    COL_SLACK,  _("Slack"),
 						    COL_COST,   _("Cost"),
+						    COL_ASSIGNED_TO, _("Assigned to"),
 						    -1);
 
 		g_object_unref (model);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]