supercharts-bullet_train 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6753fdf7667abbfab39cfae072cc6700125ea7a728e551be8db5b34385e35de7
4
- data.tar.gz: 1d179f8527014cc41ddecc50f327ae71de2894e3a7b303b1f77521a5a9791506
3
+ metadata.gz: c1429840047519504e809947dd42379f44ed7f20217d329460bbde9d6e84bb3d
4
+ data.tar.gz: '0564496b17145084063209a2a9fc1ab4b13995335d92b4fde91127bafe6a45a6'
5
5
  SHA512:
6
- metadata.gz: bd24f82296ceaeb1bc8e62c2c7da8999668198a441b862b430c54d802cda5823093ccfbe73c2ccb817ce42dea96c7dfa0fe224cbaddc47638325da5f3dd92119
7
- data.tar.gz: 8d992be3d5b7648fd6f2f75f37b14b03956f89364549540b77de972a7b2bb81bf11e791e2e1ca2e98b6a59145aaf368b5be208ae21a7189cb36bbce85c11e4ba
6
+ metadata.gz: 5ec2707c55a76fd064424b1c85eead89f829d2f619eef6aa9004ef6efd3288ed414165f0ca254cf45f06f40650a59632840501cc1c57e4d14468b152f4c4d7aa
7
+ data.tar.gz: 2f439fcc3f94d76e8c02923941b04af5d3057c8076f0c8c855519b5069ce539910fba3b2d09ffa5cfe2fa8c08bafb8fced72cce8491f08e9fe446d09bc014933
data/.bt-link ADDED
File without changes
@@ -0,0 +1,42 @@
1
+ require 'csv'
2
+
3
+ class Account::Scaffolding::CompletelyConcrete::Charts::TangibleThingsController < Account::ApplicationController
4
+ account_load_and_authorize_resource :tangible_thing, through: :absolutely_abstract_creative_concept, through_association: :completely_concrete_tangible_things
5
+
6
+ # GET /account/scaffolding/absolutely_abstract/creative_concepts/:absolutely_abstract_creative_concept_id/completely_concrete/charts/tangible_things
7
+ def index
8
+ @timespan = params[:timespan]
9
+ case @timespan
10
+ when "ytd"
11
+ range = Time.now.beginning_of_year..Time.now
12
+ range_days = (range.max - range.min).seconds.in_days
13
+ if range_days > 4.months.in_days
14
+ @period = :month
15
+ elsif range_days > 1.month.in_days
16
+ @period = :week
17
+ else
18
+ @period = :day
19
+ end
20
+ data = @tangible_things.group_by_period(@period, :created_at, range: range, expand_range: true).count
21
+ else
22
+ @period = :day
23
+ data = @tangible_things.group_by_period(@period, :created_at, last: 30).count
24
+ end
25
+
26
+ @total = data.values.reduce(:+)
27
+
28
+ date_format = if @period == :day
29
+ "%e"
30
+ elsif @period == :week
31
+ "%b %e"
32
+ elsif @period == :month
33
+ "%b"
34
+ end
35
+
36
+ @csv = CSV.generate(" ", headers: %w[date value], write_headers: true, encoding: "UTF-8") do |csv|
37
+ data.each do |date, value|
38
+ csv.add_row [date.strftime(date_format), value]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -16,6 +16,7 @@ export default class extends SuperchartChartjsController {
16
16
 
17
17
  static defaultCssProperties = {
18
18
  '--animation-duration': 200, // milliseconds
19
+ '--axis-color': '#00000066'
19
20
  }
20
21
 
21
22
  connect() {
@@ -63,7 +64,7 @@ export default class extends SuperchartChartjsController {
63
64
 
64
65
  // You can set default options in this getter for all your charts.
65
66
  get defaultOptions() {
66
- const transparentWhite = '#ffffff66'
67
+ const axisColor = this.cssPropertyValue('--axis-color')
67
68
  return {
68
69
  maintainAspectRatio: false,
69
70
  animation: {
@@ -99,7 +100,7 @@ export default class extends SuperchartChartjsController {
99
100
  display: false,
100
101
  }
101
102
  },
102
- color: transparentWhite,
103
+ color: axisColor,
103
104
  borderColor: 'rgb(4, 123, 248)',
104
105
  fill: false,
105
106
  lineTension: 0.3,
@@ -122,20 +123,20 @@ export default class extends SuperchartChartjsController {
122
123
  scales: {
123
124
  x: {
124
125
  grid: {
125
- borderColor: transparentWhite
126
+ borderColor: axisColor
126
127
  },
127
128
  ticks: {
128
- color: transparentWhite,
129
- tickColor: transparentWhite
129
+ color: axisColor,
130
+ tickColor: axisColor
130
131
  }
131
132
  },
132
133
  y: {
133
134
  grid: {
134
- borderColor: transparentWhite,
135
- tickColor: transparentWhite
135
+ borderColor: axisColor,
136
+ tickColor: axisColor
136
137
  },
137
138
  ticks: {
138
- color: transparentWhite
139
+ color: axisColor
139
140
  }
140
141
  }
141
142
  }
@@ -0,0 +1,2 @@
1
+ <% absolutely_abstract_creative_concept ||= @absolutely_abstract_creative_concept || tangible_thing&.absolutely_abstract_creative_concept %>
2
+ <%= render 'account/scaffolding/absolutely_abstract/creative_concepts/breadcrumbs', creative_concept: absolutely_abstract_creative_concept %>
@@ -0,0 +1,50 @@
1
+ <%= turbo_frame_tag :charts_tangible_things do %>
2
+ <div class="bg-white dark:bg-sealBlue-400 p-8 rounded-md shadow"
3
+ data-controller="supercharts--filterable"
4
+ data-action="superchart:update-chart->supercharts--filterable#updateChart"
5
+ >
6
+ <%= turbo_frame_tag :charts_tangible_things_filters do %>
7
+ <div class="flex justify-start">
8
+ <div class="">
9
+ <h2 class="text-xs uppercase dark:text-white/50">
10
+ <% if @timespan == "1m" %>
11
+ Tangible Things last 31 days
12
+ <% elsif @timespan == "ytd" %>
13
+ Tangible Things since start of year
14
+ <% end %>
15
+ </h2>
16
+ <p class="font-semibold dark:text-white mt-2" style="font-size: 1.8rem;">
17
+ <%= @total %>
18
+ </p>
19
+ </div>
20
+ <div class="ml-auto">
21
+ <div
22
+ data-controller="supercharts--filters" data-supercharts--filters-event-name="superchart:update-chart"
23
+ >
24
+ <div class="flex items-center justify-center">
25
+ <div class="inline-flex space-x-1" role="group">
26
+ <%= render "shared/supercharts/filter_button", path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :charts, :tangible_things], timespan: "1m"), label: "1m", first: true %>
27
+ <%= render "shared/supercharts/filter_button", path: polymorphic_path([:account, @absolutely_abstract_creative_concept, :charts, :tangible_things], timespan: "ytd"), label: "ytd", last: true %>
28
+ </div>
29
+ </div>
30
+ <template data-supercharts--filters-target="data">
31
+ <%= @csv.lstrip.html_safe %>
32
+ </template>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <% end %>
37
+
38
+ <div
39
+ class="mt-4"
40
+ data-controller="superchart"
41
+ data-superchart-type-value="line"
42
+ data-superchart-label-value="Tangible Things per <%= @period.to_s.capitalize %>"
43
+ data-supercharts--filterable-target="chart"
44
+ data-action="update-chart->superchart#updateChart"
45
+ >
46
+ <canvas data-superchart-target="chartjsCanvas" style="height: 200px"></canvas>
47
+ <template data-superchart-target="csvData" data-supercharts--filterable-target="chartSourceData" />
48
+ </div>
49
+ </div>
50
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <%
2
+ first ||= false
3
+ last ||= false
4
+ label ||= "link"
5
+ path ||= ""
6
+ button_classes = "px-5 py-1.5 dark:text-white font-small text-xs leading-tight uppercase hover:bg-blue-800/50 hover:text-white focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out rounded-lg"
7
+ %>
8
+
9
+ <%= link_to label, path, class: [button_classes, "bg-gray-400 dark:bg-blue-800 text-white hover:bg-blue-400 dark:hover:bg-blue-800/100": current_page?(path)] %>
@@ -1,7 +1,7 @@
1
1
  module BulletTrain
2
2
  module Supercharts
3
3
  class Engine < ::Rails::Engine
4
- initializer "bullet_train.super_scaffolding.supercharts.templates.register_template_path" do |app|
4
+ initializer "bullet_train.super_scaffolding.templates.register_template_path" do |app|
5
5
  # Register the base path of this package with the Super Scaffolding engine.
6
6
  BulletTrain::SuperScaffolding.template_paths << File.expand_path('../../../..', __FILE__)
7
7
  BulletTrain::SuperScaffolding.scaffolders.merge!({
@@ -1,4 +1,5 @@
1
1
  require "scaffolding/supercharts_chart_transformer"
2
+ require "scaffolding/supercharts_routes_file_manipulator"
2
3
 
3
4
  module BulletTrain
4
5
  module Supercharts
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Supercharts
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require "bullet_train/supercharts/engine"
3
3
  require "scaffolding"
4
4
  require "scaffolding/transformer"
5
5
  require "scaffolding/block_manipulator"
6
+ require "scaffolding/routes_file_manipulator"
6
7
  require "bullet_train/supercharts/scaffolders/chart_scaffolder"
7
8
 
8
9
  module BulletTrain
@@ -4,11 +4,27 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
4
4
  def scaffold_supercharts
5
5
  super
6
6
 
7
+ # copy files over and do the appropriate string replace.
8
+ files = [
9
+ "./app/controllers/account/scaffolding/completely_concrete/charts/tangible_things_controller.rb",
10
+ "./app/views/account/scaffolding/completely_concrete/charts/tangible_things",
11
+ "./app/views/shared/supercharts",
12
+ ].compact
13
+
14
+ files.each do |name|
15
+ if File.directory?(resolve_template_path(name))
16
+ scaffold_directory(name)
17
+ else
18
+ scaffold_file(name)
19
+ end
20
+ end
21
+
7
22
  # add children to the show page of their parent.
8
23
  unless cli_options["skip-parent"] || parent == "None"
9
24
  lines_to_add = <<~RUBY
10
25
  <div class="mt-4">
11
- Insert #{child} chart here
26
+ <%= turbo_frame_tag :charts_tangible_things, src: polymorphic_path([:account, @creative_concept, :charts, :tangible_things], timespan: "1m") do %>
27
+ <% end %>
12
28
  </div>
13
29
  RUBY
14
30
  scaffold_add_line_to_file(
@@ -18,9 +34,81 @@ class Scaffolding::SuperchartsChartTransformer < Scaffolding::SuperchartsTransfo
18
34
  prepend: true
19
35
  )
20
36
  end
37
+
38
+ # apply routes.
39
+ unless cli_options["skip-routes"]
40
+ routes_namespace = cli_options["namespace"] || "account"
41
+
42
+ begin
43
+ routes_path = if routes_namespace == "account"
44
+ "config/routes.rb"
45
+ else
46
+ "config/routes/#{routes_namespace}.rb"
47
+ end
48
+ routes_manipulator = Scaffolding::SuperchartsRoutesFileManipulator.new(routes_path, child, parent, cli_options)
49
+ rescue Errno::ENOENT => _
50
+ puts "Creating '#{routes_path}'.".green
51
+
52
+ unless File.directory?("config/routes")
53
+ FileUtils.mkdir_p("config/routes")
54
+ end
55
+
56
+ File.write(routes_path, <<~RUBY)
57
+ collection_actions = [:index, :new, :create]
58
+
59
+ # 🚅 Don't remove this block, it will break Super Scaffolding.
60
+ begin do
61
+ namespace :#{routes_namespace} do
62
+ shallow do
63
+ resources :teams do
64
+ end
65
+ end
66
+ end
67
+ end
68
+ RUBY
69
+
70
+ retry
71
+ end
72
+
73
+ begin
74
+ routes_manipulator.apply([routes_namespace], prepend_namespace_to_child: "charts")
75
+ rescue StandardError => e
76
+ p e
77
+ add_additional_step :yellow, "We weren't able to automatically add your `#{routes_namespace}` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ ."
78
+ end
79
+
80
+ Scaffolding::FileManipulator.write("config/routes.rb", routes_manipulator.lines)
81
+ end
82
+
83
+ restart_server unless ENV["CI"].present?
21
84
  end
22
85
 
23
86
  def parent_show_file
24
87
  @target_show_file ||= "./app/views/account/scaffolding/absolutely_abstract/creative_concepts/show.html.erb"
25
88
  end
89
+
90
+ def transform_string(string)
91
+ [
92
+ "Scaffolding::CompletelyConcrete::Charts::TangibleThings",
93
+ "scaffolding/completely_concrete/charts/tangible_things",
94
+ ].each do |needle|
95
+ # TODO There might be more to do here?
96
+ # What method is this calling?
97
+ string = string.gsub(needle, encode_double_replacement_fix(replacement_for(needle)))
98
+ end
99
+
100
+ string = super(string)
101
+ decode_double_replacement_fix(string)
102
+ end
103
+
104
+ def replacement_for(string)
105
+ case string
106
+ when "Scaffolding::CompletelyConcrete::Charts::TangibleThings"
107
+ "Charts::" + child.pluralize
108
+ when "scaffolding/completely_concrete/charts/tangible_things"
109
+ "charts/" + child.underscore.pluralize
110
+ else
111
+ "🛑"
112
+ end
113
+ end
26
114
  end
@@ -0,0 +1,85 @@
1
+ class Scaffolding::SuperchartsRoutesFileManipulator < Scaffolding::RoutesFileManipulator
2
+
3
+ def apply(base_namespaces, prepend_namespace_to_child: nil)
4
+ child_namespaces, child_resource, parent_namespaces, parent_resource = divergent_parts
5
+
6
+ within = find_or_create_namespaces(base_namespaces)
7
+
8
+ # e.g. Project and Projects::Deliverable
9
+ if parent_namespaces.empty? && child_namespaces.one? && parent_resource == child_namespaces.first
10
+
11
+ # resources :projects do
12
+ # scope module: 'projects' do
13
+ # resources :deliverables, only: collection_actions
14
+ # end
15
+ # end
16
+
17
+ parent_within = find_or_convert_resource_block(parent_resource, within: within)
18
+
19
+ # add the new resource within that namespace.
20
+ line = "scope module: '#{parent_resource}' do"
21
+ # TODO you haven't tested this yet.
22
+ unless (scope_within = find(/#{line}/, parent_within))
23
+ scope_within = insert([line, "end"], parent_within)
24
+ end
25
+
26
+ find_or_create_resource([child_resource], options: "only: collection_actions", within: scope_within)
27
+
28
+ # namespace :projects do
29
+ # resources :deliverables, except: collection_actions
30
+ # end
31
+
32
+ # We want to see if there are any namespaces one level above the parent itself,
33
+ # because namespaces with the same name as the resource can exist on the same level.
34
+ parent_block_start = find_block_parent(parent_within)
35
+ namespace_line_within = find_or_create_namespaces(child_namespaces, parent_block_start)
36
+
37
+ if prepend_namespace_to_child.present?
38
+ namespace_line_within = find_or_create_namespaces([prepend_namespace_to_child], namespace_line_within)
39
+ end
40
+
41
+ find_or_create_resource([child_resource], options: "except: collection_actions", within: namespace_line_within)
42
+ unless find_namespaces(child_namespaces, within)[child_namespaces.last]
43
+ raise "tried to insert `namespace :#{child_namespaces.last}` but it seems we failed"
44
+ end
45
+
46
+ # e.g. Projects::Deliverable and Objective Under It, Abstract::Concept and Concrete::Thing
47
+ elsif parent_namespaces.any?
48
+
49
+ # namespace :projects do
50
+ # resources :deliverables
51
+ # end
52
+ top_parent_namespace = find_namespaces(parent_namespaces, within)[parent_namespaces.first]
53
+
54
+ find_or_create_resource(child_namespaces + [child_resource], within: top_parent_namespace)
55
+
56
+ # resources :projects_deliverables, path: 'projects/deliverables' do
57
+ # resources :objectives
58
+ # end
59
+ block_parent_within = find_block_parent(top_parent_namespace)
60
+ parent_namespaces_and_resource = (parent_namespaces + [parent_resource]).join("_")
61
+ parent_within = find_or_create_resource_block([parent_namespaces_and_resource], options: "path: '#{parent_namespaces_and_resource.tr("_", "/")}'", within: block_parent_within)
62
+
63
+ if prepend_namespace_to_child.present?
64
+ parent_within = find_or_create_namespaces([prepend_namespace_to_child], parent_within)
65
+ end
66
+
67
+ find_or_create_resource(child_namespaces + [child_resource], within: parent_within)
68
+ else
69
+
70
+ begin
71
+ within = find_or_convert_resource_block(parent_resource, within: within)
72
+ rescue
73
+ within = find_or_convert_resource_block(parent_resource, options: "except: collection_actions", within: within)
74
+ end
75
+
76
+ if prepend_namespace_to_child.present?
77
+ within = find_or_create_namespaces([prepend_namespace_to_child], within)
78
+ end
79
+
80
+ find_or_create_resource(child_namespaces + [child_resource], options: define_concerns, within: within)
81
+
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,8 @@
1
+ require "bullet_train/supercharts"
2
+
3
+ module Supercharts
4
+ module BulletTrain
5
+ # This file is loaded automatically by bundler
6
+ # It's required so we can keep the BulletTrain::Supercharts sub-module as the default structure (and inherit super scaffolding from BulletTrain)
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supercharts-bullet_train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pascal Laliberté
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - ".bt-link"
34
35
  - MIT-LICENSE
35
36
  - README.md
36
37
  - Rakefile
@@ -43,18 +44,24 @@ files:
43
44
  - app/assets/javascripts/supercharts-bullet-train.modern.mjs.map
44
45
  - app/assets/javascripts/supercharts-bullet-train.umd.js
45
46
  - app/assets/javascripts/supercharts-bullet-train.umd.js.map
47
+ - app/controllers/account/scaffolding/completely_concrete/charts/tangible_things_controller.rb
46
48
  - app/javascript/controllers/index.js
47
49
  - app/javascript/controllers/superchart_controller.js
48
50
  - app/javascript/controllers/supercharts/filterable_controller.js
49
51
  - app/javascript/controllers/supercharts/filters_controller.js
50
52
  - app/javascript/index.js
53
+ - app/views/account/scaffolding/completely_concrete/charts/tangible_things/_breadcrumbs.html.erb
54
+ - app/views/account/scaffolding/completely_concrete/charts/tangible_things/index.html.erb
55
+ - app/views/shared/supercharts/_filter_button.html.erb
51
56
  - config/routes.rb
52
57
  - lib/bullet_train/supercharts.rb
53
58
  - lib/bullet_train/supercharts/engine.rb
54
59
  - lib/bullet_train/supercharts/scaffolders/chart_scaffolder.rb
55
60
  - lib/bullet_train/supercharts/version.rb
56
61
  - lib/scaffolding/supercharts_chart_transformer.rb
62
+ - lib/scaffolding/supercharts_routes_file_manipulator.rb
57
63
  - lib/scaffolding/supercharts_transformer.rb
64
+ - lib/supercharts/bullet_train.rb
58
65
  - lib/tasks/bullet_train/supercharts_tasks.rake
59
66
  homepage: https://github.com/supercharts-dev/supercharts-bullet_train
60
67
  licenses: