easy_reports 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/easy_reports/dashboard/dashboard_content.css +2 -13
  3. data/app/controllers/easy_reports/databases_controller.rb +53 -0
  4. data/app/controllers/easy_reports/reports_controller.rb +11 -10
  5. data/app/forms/easy_reports/report_form.rb +22 -0
  6. data/app/helpers/easy_reports/databases_helper.rb +4 -0
  7. data/app/models/easy_reports/database.rb +11 -0
  8. data/app/models/easy_reports/report.rb +2 -0
  9. data/app/services/easy_reports/database_mediator.rb +11 -12
  10. data/app/views/easy_reports/dashboard/show.html.slim +8 -8
  11. data/app/views/easy_reports/{database_configs → databases}/_form.html.slim +6 -6
  12. data/app/views/easy_reports/databases/edit.html.slim +8 -0
  13. data/app/views/easy_reports/databases/index.html.slim +35 -0
  14. data/app/views/easy_reports/databases/new.html.slim +5 -0
  15. data/app/views/easy_reports/databases/show.html.slim +27 -0
  16. data/app/views/easy_reports/reports/_form.html.slim +15 -13
  17. data/app/views/layouts/easy_reports/application.html.slim +2 -2
  18. data/app/views/shared/_header.html.slim +3 -20
  19. data/config/initializers/simple_form.rb +145 -0
  20. data/config/initializers/simple_form_bootstrap.rb +45 -0
  21. data/config/locales/simple_form.en.yml +26 -0
  22. data/config/routes.rb +2 -2
  23. data/db/migrate/{20141213173509_create_easy_reports_database_configs.rb → 20141213173509_create_easy_reports_databases.rb} +3 -3
  24. data/db/migrate/20150131195101_add_config_id_to_reports.rb +5 -0
  25. data/easy_reports.gemspec +9 -5
  26. data/lib/easy_reports.rb +8 -5
  27. data/lib/easy_reports/version.rb +1 -1
  28. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  29. data/test/dummy/Gemfile.lock +5 -1
  30. data/test/dummy/db/migrate/{20141214161417_create_easy_reports_reports.easy_reports.rb → 20150131203555_create_easy_reports_reports.easy_reports.rb} +1 -1
  31. data/test/dummy/db/migrate/{20141214161418_create_easy_reports_database_configs.easy_reports.rb → 20150131203556_create_easy_reports_databases.easy_reports.rb} +4 -4
  32. data/test/dummy/db/migrate/20150131203557_add_config_id_to_reports.easy_reports.rb +6 -0
  33. data/test/dummy/db/schema.rb +4 -3
  34. metadata +58 -26
  35. data/app/assets/stylesheets/easy_reports/dashboard/sidebar.css +0 -10
  36. data/app/controllers/easy_reports/database_configs_controller.rb +0 -53
  37. data/app/helpers/easy_reports/database_configs_helper.rb +0 -4
  38. data/app/models/easy_reports/database_config.rb +0 -4
  39. data/app/views/easy_reports/database_configs/edit.html.slim +0 -8
  40. data/app/views/easy_reports/database_configs/index.html.slim +0 -35
  41. data/app/views/easy_reports/database_configs/new.html.slim +0 -5
  42. data/app/views/easy_reports/database_configs/show.html.slim +0 -27
  43. data/app/views/shared/_sidebar.html.slim +0 -90
  44. data/test/controllers/easy_reports/database_configs_controller_test.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d26f9e3ea77696746e0ec1af155e7128c26ea5cd
4
- data.tar.gz: 8654c7e4aaf941c29c194285474f22333adcb9db
3
+ metadata.gz: 746d45a01ec80bcf9507b683b27cb6211be5d688
4
+ data.tar.gz: 13c690001188fa46cf8153f4d0f48a7aa5812f9c
5
5
  SHA512:
6
- metadata.gz: 8c4b9547a315e013254e60516f6e549ae2126b6ec3734208ba430e59f2d9d770e64e817413bf87e2dc4b4586e3f882c024ac5712cd42c79b2b05e278326d1a2c
7
- data.tar.gz: c99a030ce9eec483dccdfd39c0ac609d9d1af385255299d43d515fe65f37e444d2135a65dcb1960d7b1d9f293430ed9865b7bd4600927eed794fda76c7d24309
6
+ metadata.gz: 9e5bc837d0399f510324485ad5e83ee39fa982452d0e2ab474770c82c27d59c5f9b8269d3621af1e712cee6ec92d0d1fb47be3e63a1838b5e8a750fedd6e90c8
7
+ data.tar.gz: 36263b604e022d66262232ac81ff1e5cea544fe2cbc4f46ebbda132e2b8a913811a277ce96925ed34e02e29701fa06deaae63df8b2371d3cb54e855647a6e4bc
@@ -1,9 +1,3 @@
1
- /*!
2
- * Start Bootstrap - SB Admin 2 Bootstrap Admin Theme (http://startbootstrap.com)
3
- * Code licensed under the Apache License v2.0.
4
- * For details, see http://www.apache.org/licenses/LICENSE-2.0.
5
- */
6
-
7
1
  body {
8
2
  background-color: #f8f8f8;
9
3
  }
@@ -18,13 +12,8 @@ body {
18
12
  background-color: #fff;
19
13
  }
20
14
 
21
- @media(min-width:768px) {
22
- #page-wrapper {
23
- position: inherit;
24
- margin: 0 0 0 250px;
25
- padding: 0 30px;
26
- border-left: 1px solid #e7e7e7;
27
- }
15
+ .navbar.navbar-default {
16
+ margin-bottom: 0;
28
17
  }
29
18
 
30
19
  .navbar-top-links {
@@ -0,0 +1,53 @@
1
+ require_dependency "easy_reports/application_controller"
2
+
3
+ module EasyReports
4
+ class DatabasesController < ApplicationController
5
+ before_action :set_database, only: [:show, :edit, :update, :destroy]
6
+
7
+ def index
8
+ @databases = Database.all
9
+ end
10
+
11
+ def show
12
+ end
13
+
14
+ def new
15
+ @database = Database.new
16
+ end
17
+
18
+ def edit
19
+ end
20
+
21
+ def create
22
+ @database = Database.new(database_params)
23
+
24
+ if @database.save
25
+ redirect_to @database, notice: 'Database was successfully created.'
26
+ else
27
+ render :new
28
+ end
29
+ end
30
+
31
+ def update
32
+ if @database.update(database_params)
33
+ redirect_to @database, notice: 'Database was successfully updated.'
34
+ else
35
+ render :edit
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @database.destroy
41
+ redirect_to databases_url, notice: 'Database was successfully destroyed.'
42
+ end
43
+
44
+ private
45
+ def set_database
46
+ @database = Database.find(params[:id])
47
+ end
48
+
49
+ def database_params
50
+ params.require(:database).permit(:adapter, :encoding, :pool, :username, :password, :host, :name, :port)
51
+ end
52
+ end
53
+ end
@@ -11,26 +11,27 @@ module EasyReports
11
11
  @table_list = database_mediator.tables
12
12
  end
13
13
 
14
- def show
15
- end
16
-
17
14
  def new
18
- @report = Report.new
19
- end
20
-
21
- def edit
15
+ @report_form = ReportForm.new
22
16
  end
23
17
 
24
18
  def create
25
- @report = Report.new(report_params)
19
+ @report_form = ReportForm.new(report_params)
26
20
 
27
- if @report.save
28
- redirect_to @report, notice: 'Report was successfully created.'
21
+ if @report_form.save
22
+ redirect_to @report_form, notice: 'Report was successfully created.'
29
23
  else
30
24
  render :new
31
25
  end
32
26
  end
33
27
 
28
+
29
+ def show
30
+ end
31
+
32
+ def edit
33
+ end
34
+
34
35
  def update
35
36
  if @report.update(report_params)
36
37
  redirect_to @report, notice: 'Report was successfully updated.'
@@ -0,0 +1,22 @@
1
+ module EasyReports
2
+ class ReportForm
3
+ include ActiveModel::Model
4
+
5
+ attr_accessor :report
6
+
7
+ delegate :database,
8
+ :title,
9
+ :description,
10
+ to: :report
11
+
12
+
13
+ def initialize
14
+ @report = Report.new
15
+ # @mediator = EasyReports::DatabaseMediator.new(params)
16
+ end
17
+
18
+ def database_list
19
+ EasyReports::Database.all
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module EasyReports
2
+ module DatabasesHelper
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module EasyReports
2
+ class Database < ActiveRecord::Base
3
+
4
+ has_many :reports
5
+
6
+ def to_s
7
+ name
8
+ end
9
+
10
+ end
11
+ end
@@ -1,4 +1,6 @@
1
1
  module EasyReports
2
2
  class Report < ActiveRecord::Base
3
+
4
+ belongs_to :database
3
5
  end
4
6
  end
@@ -2,35 +2,34 @@ module EasyReports
2
2
  class DatabaseMediator
3
3
  class DatabaseNotFoundError < StandardError; end
4
4
 
5
- attr_reader :db, :db_config
5
+ attr_reader :connection, :db
6
6
 
7
- delegate :adapter, :username, :password, :host, :port, :database_name,
8
- to: :db_config
7
+ delegate :adapter, :username, :password, :host, :port, :name,
8
+ to: :db
9
9
 
10
- def initialize
11
- @db_config = load_database_config
12
- @db = establish_connection
10
+ def initialize(database_id)
11
+ @db = set_database(database_id)
12
+ @connection = establish_connection
13
13
  rescue => e
14
14
  Rails.logger.info "#{e.message}"
15
15
  raise DatabaseNotFoundError
16
16
  end
17
17
 
18
18
  def tables
19
- db.tables
19
+ connection.tables
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def load_database_config
25
- EasyReports::DatabaseConfig.find(params[:db_id])
24
+ def set_database(id)
25
+ EasyReports::Database.find(id)
26
26
  end
27
27
 
28
28
  def establish_connection
29
29
  ::Sequel.connect(
30
- "#{adapter}://#{username}:#{password}@#{host}:#{port}/#{database_name}",
31
- :max_connections => db_config.pool,
30
+ "#{adapter}://#{username}:#{password}@#{host}:#{port}/#{name}",
31
+ :max_connections => db.pool,
32
32
  :logger => Logger.new('log/db.log'))
33
33
  end
34
-
35
34
  end
36
35
  end
@@ -1,4 +1,4 @@
1
- #page-wrapper style=("min-height: 200px;")
1
+ #page-wrapper style=("min-height: 200px;")
2
2
  .row
3
3
  .col-lg-12
4
4
  h1.page-header Dashboard
@@ -13,13 +13,13 @@
13
13
  i.fa.fa-comments.fa-5x
14
14
  .col-xs-9.text-right
15
15
  .huge 26
16
- div New Comments!
17
- a href="#"
18
- .panel-footer
19
- span.pull-left View Details
20
- span.pull-right
21
- i.fa.fa-arrow-circle-right
22
- .clearfix
16
+ div View Reports
17
+ = link_to new_report_path do
18
+ .panel-footer
19
+ span.pull-left Create report
20
+ span.pull-right
21
+ i.fa.fa-arrow-circle-right
22
+ .clearfix
23
23
  .col-lg-3.col-md-6
24
24
  .panel.panel-green
25
25
  .panel-heading
@@ -1,9 +1,9 @@
1
- = form_for @database_config do |f|
2
- - if @database_config.errors.any?
1
+ = form_for @database do |f|
2
+ - if @database.errors.any?
3
3
  #error_explanation
4
- h2 = "#{pluralize(@database_config.errors.count, "error")} prohibited this database_config from being saved:"
4
+ h2 = "#{pluralize(@database.errors.count, "error")} prohibited this database from being saved:"
5
5
  ul
6
- - @database_config.errors.full_messages.each do |message|
6
+ - @database.errors.full_messages.each do |message|
7
7
  li = message
8
8
 
9
9
  .field
@@ -28,6 +28,6 @@
28
28
  = f.label :port
29
29
  = f.text_field :port
30
30
  .field
31
- = f.label :database_name
32
- = f.text_field :database_name
31
+ = f.label :name
32
+ = f.text_field :name
33
33
  .actions = f.submit 'Save'
@@ -0,0 +1,8 @@
1
+ h1 Editing database config
2
+
3
+ == render 'form'
4
+
5
+ = link_to 'Show', @database
6
+ '|
7
+ = link_to 'Back', databases_path
8
+
@@ -0,0 +1,35 @@
1
+ h1 Listing databases
2
+
3
+ table
4
+ thead
5
+ tr
6
+ th Adapter
7
+ th Encoding
8
+ th Pool
9
+ th Username
10
+ th Password
11
+ th Host
12
+ th Port
13
+ th Name
14
+ th
15
+ th
16
+ th
17
+
18
+ tbody
19
+ - @databases.each do |database|
20
+ tr
21
+ td = database.adapter
22
+ td = database.encoding
23
+ td = database.pool
24
+ td = database.username
25
+ td = database.password
26
+ td = database.host
27
+ td = database.port
28
+ td = database.name
29
+ td = link_to 'Show', database
30
+ td = link_to 'Edit', edit_database_path(database)
31
+ td = link_to 'Destroy', database, data: {:confirm => 'Are you sure?'}, :method => :delete
32
+
33
+ br
34
+
35
+ = link_to 'New Database config', new_database_path
@@ -0,0 +1,5 @@
1
+ h1 New database_config
2
+
3
+ == render 'form'
4
+
5
+ = link_to 'Back', databases_path
@@ -0,0 +1,27 @@
1
+ p#notice = notice
2
+
3
+ p
4
+ strong Adapter:
5
+ = @database.adapter
6
+ p
7
+ strong Encoding:
8
+ = @database.encoding
9
+ p
10
+ strong Pool:
11
+ = @database.pool
12
+ p
13
+ strong Username:
14
+ = @database.username
15
+ p
16
+ strong Password:
17
+ = @database.password
18
+ p
19
+ strong Host:
20
+ = @database.host
21
+ p
22
+ strong Database:
23
+ = @database.name
24
+
25
+ = link_to 'Edit', edit_database_path(@database)
26
+ '|
27
+ = link_to 'Back', databases_path
@@ -1,17 +1,19 @@
1
- = form_for @report do |f|
2
- - if @report.errors.any?
1
+ = simple_form_for @report_form, url: reports_path, html: { multipart: true } do |f|
2
+ - if @report_form.errors.any?
3
3
  #error_explanation
4
- h2 = "#{pluralize(@report.errors.count, "error")} prohibited this report from being saved:"
4
+ h2 = "#{pluralize(@report_form.errors.count, "error")} prohibited this report from being saved:"
5
5
  ul
6
- - @report.errors.full_messages.each do |message|
6
+ - @report_form.errors.full_messages.each do |message|
7
7
  li = message
8
8
 
9
- .field
10
- select.selectpicker
11
- .field
12
- = f.label :title
13
- = f.text_field :title
14
- .field
15
- = f.label :description
16
- = f.text_area :description
17
- .actions = f.submit 'Save'
9
+ .form-inputs
10
+ /* = f.association :database, label: 'database config', input_html: { class: 'selectpicker' } */
11
+ = f.simple_fields_for :database, @report_form.database do |f_database|
12
+ = f_database.input :name, as: :select, collection: @report_form.database_list, label: 'Database config', input_html: { class: 'selectpicker' }
13
+ = f_database.input :name, as: :select, collection: @report_form.database_list, label: 'Database config', input_html: { class: 'selectpicker' }
14
+ /* = f.input :table_ids, label: 'table list', input_html: { class: 'selectpicker' } */
15
+ = f.input :title, label: 'title'
16
+ = f.input :description, as: :text, label: 'description'
17
+
18
+ .actions
19
+ = f.button :submit
@@ -7,6 +7,6 @@ html
7
7
  = csrf_meta_tags
8
8
  body
9
9
  = render 'shared/header'
10
- = render 'shared/sidebar'
11
- = yield
10
+ .container-fluid
11
+ = yield
12
12
 
@@ -2,21 +2,11 @@ nav.navbar.navbar-default
2
2
  .container-fluid
3
3
  /! Brand and toggle get grouped for better mobile display
4
4
  .navbar-header
5
- button.navbar-toggle.collapsed data-target="#bs-example-navbar-collapse-1" data-toggle="collapse" type="button"
6
- span.sr-only Toggle navigation
7
- span.icon-bar
8
- span.icon-bar
9
- span.icon-bar
10
- a.navbar-brand href="#" Easy Reports
5
+ = link_to 'Easy Reports', root_path, class: 'navbar-brand'
6
+
11
7
  /! Collect the nav links, forms, and other content for toggling
12
- #bs-example-navbar-collapse-1.collapse.navbar-collapse
8
+ #easy_reports_navbat.collapse.navbar-collapse
13
9
  ul.nav.navbar-nav
14
- li.active
15
- a href="#"
16
- | Link
17
- span.sr-only (current)
18
- li
19
- a href="#" Link
20
10
  li.dropdown
21
11
  a.dropdown-toggle aria-expanded="false" data-toggle="dropdown" href="#" role="button"
22
12
  | Dropdown
@@ -34,10 +24,6 @@ nav.navbar.navbar-default
34
24
  li.divider
35
25
  li
36
26
  a href="#" One more separated link
37
- form.navbar-form.navbar-left role="search"
38
- .form-group
39
- input.form-control placeholder="Search" type="text" /
40
- button.btn.btn-default type="submit" Submit
41
27
  ul.nav.navbar-nav.navbar-right
42
28
  li
43
29
  a href="#" Link
@@ -55,6 +41,3 @@ nav.navbar.navbar-default
55
41
  li.divider
56
42
  li
57
43
  a href="#" Separated link
58
- /! /.navbar-collapse
59
- /! /.container-fluid
60
-