Andrew Kane пре 8 година
родитељ
комит
c4e9bed5ba

+ 2 - 2
app/assets/javascripts/blazer/queries.js

@@ -30,7 +30,7 @@ function runNext() {
 
 function runQueryHelper(query) {
   var xhr = $.ajax({
-    url: Routes.blazer_run_queries_path(),
+    url: Routes.run_queries_path(),
     method: "POST",
     data: query.data,
     dataType: "html"
@@ -89,7 +89,7 @@ function cancelQuery(query) {
   }
 
   // tell server
-  var path = Routes.blazer_cancel_queries_path()
+  var path = Routes.cancel_queries_path()
   var data = {run_id: query.run_id, data_source: query.data_source}
   if (navigator.sendBeacon) {
     navigator.sendBeacon(path, csrfProtect(data))

+ 26 - 1
app/assets/javascripts/blazer/routes.js.erb

@@ -1 +1,26 @@
-<%= JsRoutes.generate(include: /blazer/) %>
+<%#= JsRoutes.generate(engine: Blazer::Engine, prefix: Blazer::Engine.app.url_helpers.root_path) %>
+
+// temp fix
+var Routes = {
+  run_queries_path: function() {
+    return gon.root_path + "queries/run"
+  },
+  cancel_queries_path: function() {
+    return gon.root_path + "queries/cancel"
+  },
+  schema_queries_path: function(params) {
+    return gon.root_path + "queries/schema?data_source=" + params.data_source
+  },
+  tables_queries_path: function(params) {
+    return gon.root_path + "queries/tables?data_source=" + params.data_source
+  },
+  queries_path: function() {
+    return gon.root_path + "queries"
+  },
+  query_path: function(id) {
+    return gon.root_path + "queries/" + id
+  },
+  dashboard_path: function(id) {
+    return gon.root_path + "dashboards/" + id
+  }
+}

+ 7 - 0
app/controllers/blazer/base_controller.rb

@@ -19,6 +19,7 @@ module Blazer
     if Blazer.before_action
       before_action Blazer.before_action.to_sym
     end
+    before_action :set_js_routes
 
     layout "blazer/application"
 
@@ -101,5 +102,11 @@ module Blazer
       action = resource.persisted? ? :edit : :new
       render action, status: :unprocessable_entity
     end
+
+    def set_js_routes
+      gon.push(
+        root_path: root_path
+      )
+    end
   end
 end

+ 2 - 2
app/views/blazer/queries/_form.html.erb

@@ -79,7 +79,7 @@
     },
     computed: {
       dataSourcePath: function() {
-        return Routes.blazer_schema_queries_path({data_source: this.dataSource})
+        return Routes.schema_queries_path({data_source: this.dataSource})
       }
     },
     methods: {
@@ -116,7 +116,7 @@
         this.dataSource = dataSource
         var _this = this
 
-        $.getJSON(Routes.blazer_tables_queries_path({data_source: this.dataSource}), function(data) {
+        $.getJSON(Routes.tables_queries_path({data_source: this.dataSource}), function(data) {
           var newOptions = []
           for (var i = 0; i < data.length; i++) {
             newOptions.push({text: data[i], value: data[i]})

+ 3 - 3
app/views/blazer/queries/home.html.erb

@@ -86,7 +86,7 @@
       if (this.more) {
         var _this = this
 
-        $.getJSON(Routes.blazer_queries_path(), function (data) {
+        $.getJSON(Routes.queries_path(), function (data) {
           var i, j, newValues, val, size = 500;
 
           var newValues = []
@@ -138,9 +138,9 @@
     methods: {
       itemPath: function (item) {
         if (item.dashboard) {
-          return Routes.blazer_dashboard_path(item.to_param)
+          return Routes.dashboard_path(item.to_param)
         } else {
-          return Routes.blazer_query_path(item.to_param)
+          return Routes.query_path(item.to_param)
         }
       }
     }