[PATCH timesheet V2] Use the jqplot cube. 'plot' views has been dropped from cubicweb

Simon Chabot simon.chabot at logilab.fr
Thu Mar 5 16:45:40 CET 2020


# HG changeset patch
# User Simon Chabot <simon.chabot at logilab.fr>
# Date 1583399894 -3600
#      Thu Mar 05 10:18:14 2020 +0100
# Node ID 14d0557980497954f84e8f6d52c4c585f73c02e4
# Parent  b2e4994d271b7b2052ffce488059c50b7e5fbe00
# Available At https://hg.logilab.org/review/cubes/timesheet/
#              hg pull https://hg.logilab.org/review/cubes/timesheet/ -r 14d055798049
Use the jqplot cube. 'plot' views has been dropped from cubicweb

related: https://hg.logilab.org/master/cubicweb/rev/b01dd0ef43aa#l23.82

diff -r b2e4994d271b -r 14d055798049 cubicweb_timesheet/__pkginfo__.py
--- a/cubicweb_timesheet/__pkginfo__.py	Thu Mar 05 11:38:52 2020 +0100
+++ b/cubicweb_timesheet/__pkginfo__.py	Thu Mar 05 10:18:14 2020 +0100
@@ -22,5 +22,6 @@
 __depends__ = {'cubicweb': '>= 3.24.0',
                'cubicweb-calendar':  '>= 0.7.0',
                'cubicweb-workorder': '>= 0.9.0',
+               'cubicweb-jqplot': '>= 0.5.0',
                'cubicweb-rqlcontroller': None,
                }
diff -r b2e4994d271b -r 14d055798049 cubicweb_timesheet/migration/0.18.0_Any.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb_timesheet/migration/0.18.0_Any.py	Thu Mar 05 10:18:14 2020 +0100
@@ -0,0 +1,1 @@
+add_cube('jqplot')
diff -r b2e4994d271b -r 14d055798049 cubicweb_timesheet/views/primaries.py
--- a/cubicweb_timesheet/views/primaries.py	Thu Mar 05 11:38:52 2020 +0100
+++ b/cubicweb_timesheet/views/primaries.py	Thu Mar 05 10:18:14 2020 +0100
@@ -39,6 +39,30 @@
 # order #####################################################################
 
 
+class BaseGraphView(EntityView):
+    __regid__ = 'activity-graph'
+    title = _('activity-graph')
+
+    @property
+    def query(self):
+        raise NotImplementedError
+
+    def cell_call(self, row, col):
+        entity = self.cw_rset.get_entity(row, col)
+        rset = self._cw.execute(self.query, {'eid': entity.eid})
+        self.wview(
+            'jqplot.default',
+            rset,
+            series_options=None,
+            axes={
+                'xaxis': {
+                    'autoscale': True,
+                    'renderer': 'date',
+                },
+            },
+        )
+
+
 class OrderPrimaryView(tabs.TabsMixin, primary.PrimaryView):
     __select__ = is_instance('Order') & one_line_rset()
     tabs = [_('activity-overview'), _('activity-details'), _('activity-graph')]
@@ -85,16 +109,14 @@
         self.wview('generic-activitytable', rset, 'null')
 
 
-class OrderGraphView(EntityView):
+class OrderGraphView(BaseGraphView):
     __regid__ = 'activity-graph'
     title = _('activity-graph')
     __select__ = is_instance('Order')
 
-    def cell_call(self, row, col):
-        entity = self.cw_rset.get_entity(row, col)
-        rql = 'Any D,U WHERE O eid %(eid)s, O split_into W, A done_for W, A diem D, A duration U'
-        rset = self._cw.execute(rql, {'eid': entity.eid})
-        self.wview('plot', rset, 'null')
+    @property
+    def query(self):
+        return 'Any D,U WHERE O eid %(eid)s, O split_into W, A done_for W, A diem D, A duration U'
 
 # workorder ####################################################################
 
@@ -149,16 +171,14 @@
         self.wview('generic-activitytable', rset, 'null')
 
 
-class WorkOrderGraphView(EntityView):
+class WorkOrderGraphView(BaseGraphView):
     __regid__ = 'activity-graph'
     title = _('activity-graph')
     __select__ = is_instance('WorkOrder')
 
-    def cell_call(self, row, col):
-        entity = self.cw_rset.get_entity(row, col)
-        rql = 'Any D,U WHERE W eid %(eid)s, A done_for W, A diem D, A duration U'
-        rset = self._cw.execute(rql, {'eid': entity.eid})
-        self.wview('plot', rset, 'null')
+    @property
+    def query(self):
+        return 'Any D,U WHERE W eid %(eid)s, A done_for W, A diem D, A duration U'
 
 # resource #####################################################################
 
@@ -222,16 +242,14 @@
         self.wview('generic-activitytable', rset, 'null')
 
 
-class ResourceGraphView(EntityView):
+class ResourceGraphView(BaseGraphView):
     __regid__ = 'activity-graph'
+    title = _('activity-graph')
     __select__ = is_instance('Resource')
-    title = _('activity-graph')
 
-    def cell_call(self, row, col):
-        entity = self.cw_rset.get_entity(row, col)
-        rql = 'Any D,U WHERE R eid %(eid)s, A done_by R, A diem D, A duration U'
-        rset = self._cw.execute(rql, {'eid': entity.eid})
-        self.wview('plot', rset, 'null')
+    @property
+    def query(self):
+        return 'Any D,U WHERE R eid %(eid)s, A done_by R, A diem D, A duration U'
 
 
 class ResourceCalendarView(EntityView):



More information about the cubicweb-devel mailing list