UMB-CS682-Team-02 / tracker

0 stars 1 forks source link

Make code use a local pygal-tooltips.js from the tracker not the one across the internet. #93

Open rouilj opened 6 months ago

rouilj commented 6 months ago

Add a copy of https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.js to the tracker and apply the inline patch to chart.py to use it.

Commit this so there is an original upstream version of the pygal-tooltip library in the history.

Then handle ticket #92.

Also edit chart.py to make ChartingAction look like:

class ChartingAction(Action):

    jsURL = None

    # set output image type. svg and data: are interactive
    output_type = "image/svg+xml"  # @image_type: image/svg+xml, image/png, data:

Then apply this patch:

@@ -32,6 +29,19 @@ class ChartingAction(Action):
     # image is to be embedded in a rendered html page rather than stand alone.
     embedded = False  # @embedded: 0, 1

+    def set_jsURL(self):
+        # original source_url:
+        #  "https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.js"
+        # Use our local copy of pygal-tooltips.js
+        try:
+            relative_jsURL = self.db.config.ext['CHART_JSURL']
+        except KeyError:
+            relative_jsURL = "pygal-tooltips.js"
+
+        if relative_jsURL:
+            self.jsURL = "%s@@file/%s" % (self.db.config['TRACKER_WEB'],
+                                          relative_jsURL)
+        
     def get_data_from_query(self, db, classname=None, filterspec=None,
                             group=None, search_text=None, **other):
         """Parse and summarize the query submitted into a data table.
@@ -382,6 +392,8 @@ class PieChartAction(ChartingAction):
     def handle(self):
         ''' Show chart for current query results
         '''
+        self.set_jsURL()
+
         db = self.db

         # 'arg' will contain all the data that we need to pass to
@@ -524,6 +536,8 @@ class BarChartAction(ChartingAction):
     def handle(self):
         ''' Show chart for current query results
         '''
+        self.set_jsURL()
+
         db = self.db

         # 'arg' will contain all the data that we need to pass to
@@ -661,6 +675,8 @@ class HorizontalBarChartAction(ChartingAction):
     def handle(self):
         ''' Show chart for current query results
         '''
+        self.set_jsURL()
+
         db = self.db

         # 'arg' will contain all the data that we need to pass to
@@ -789,6 +805,8 @@ class StackedBarChartAction(ChartingAction):
     def handle(self):
         ''' Show chart for current query results
         '''
+        self.set_jsURL()
+
         db = self.db

         # 'arg' will contain all the data that we need to pass to
@@ -920,6 +938,8 @@ class MultiBarChartAction(ChartingAction):
     def handle(self):
         ''' Show chart for current query results
         '''
+        self.set_jsURL()
+
         db = self.db

         # 'arg' will contain all the data that we need to pass to

This sets the url to get the js library from the tracker. It also allows the admin to see the relative path under @@file/ where the pygal-tooltips.js library can be retrieved using extensions/config.ini like:

[chart]
jsurl = jslibraries/pygal-tips.js
rouilj commented 5 months ago

What commit on mainline fixes this?