binda 0.0.6 → 0.0.7
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 +4 -4
- data/README.md +4 -2
- data/Rakefile +2 -1
- data/app/assets/javascripts/binda/dist/binda.bundle.js +75 -75
- data/app/assets/stylesheets/binda/settings/common.scss +4 -0
- data/app/controllers/binda/application_controller.rb +1 -1
- data/app/controllers/binda/boards_controller.rb +73 -0
- data/app/controllers/binda/components_controller.rb +18 -44
- data/app/controllers/binda/field_groups_controller.rb +36 -24
- data/app/controllers/binda/field_settings_controller.rb +5 -5
- data/app/controllers/binda/manage/users_controller.rb +2 -9
- data/app/controllers/binda/structures_controller.rb +6 -13
- data/app/controllers/concerns/binda/default_helpers.rb +226 -0
- data/app/controllers/concerns/binda/fieldable_helpers.rb +44 -0
- data/app/helpers/binda/boards_helper.rb +13 -0
- data/app/helpers/binda/components_helper.rb +0 -5
- data/app/helpers/binda/field_settings_helper.rb +1 -1
- data/app/models/binda/asset.rb +0 -8
- data/app/models/binda/binda.rb +7 -0
- data/app/models/binda/binding.rb +4 -4
- data/app/models/binda/board.rb +41 -0
- data/app/models/binda/category.rb +7 -3
- data/app/models/binda/checkbox.rb +1 -3
- data/app/models/binda/choice.rb +31 -1
- data/app/models/binda/component.rb +7 -22
- data/app/models/binda/field_group.rb +13 -7
- data/app/models/binda/field_setting.rb +40 -29
- data/app/models/binda/gallery.rb +0 -7
- data/app/models/binda/radio.rb +1 -1
- data/app/models/binda/repeater.rb +13 -20
- data/app/models/binda/selection.rb +17 -0
- data/app/models/binda/string.rb +4 -0
- data/app/models/binda/structure.rb +65 -7
- data/app/models/concerns/binda/{component_model_helper.rb → fieldable_associations.rb} +102 -31
- data/app/views/binda/boards/edit.html.erb +7 -0
- data/app/views/binda/components/edit.html.erb +4 -1
- data/app/views/binda/components/index.html.erb +2 -0
- data/app/views/binda/components/new.html.erb +1 -1
- data/app/views/binda/field_groups/_form_body.html.erb +8 -8
- data/app/views/binda/field_groups/_form_item.html.erb +3 -3
- data/app/views/binda/field_groups/_form_item_choice.erb +11 -8
- data/app/views/binda/field_groups/_form_section.html.erb +5 -5
- data/app/views/binda/field_groups/_form_section_repeater.html.erb +3 -3
- data/app/views/binda/field_groups/edit.html.erb +1 -1
- data/app/views/binda/field_groups/new.html.erb +1 -1
- data/app/views/binda/{components → fieldable}/_form_body.html.erb +9 -9
- data/app/views/binda/{components → fieldable}/_form_item_asset.html.erb +0 -0
- data/app/views/binda/{components → fieldable}/_form_item_date.html.erb +0 -0
- data/app/views/binda/{components → fieldable}/_form_item_gallery.html.erb +0 -0
- data/app/views/binda/{components → fieldable}/_form_item_new_repeater.html.erb +5 -5
- data/app/views/binda/{components → fieldable}/_form_item_repeater.html.erb +8 -9
- data/app/views/binda/fieldable/_form_item_selections.html.erb +99 -0
- data/app/views/binda/fieldable/_form_item_string.html.erb +19 -0
- data/app/views/binda/{components → fieldable}/_form_item_text.html.erb +2 -11
- data/app/views/binda/fieldable/_form_section.html.erb +52 -0
- data/app/views/binda/fieldable/_form_section_repeater.html.erb +48 -0
- data/app/views/binda/fieldable/_form_sidebar.html.erb +35 -0
- data/app/views/binda/structures/_form_body.html.erb +6 -0
- data/app/views/binda/structures/_form_section.html.erb +1 -1
- data/app/views/binda/structures/edit.html.erb +3 -0
- data/app/views/binda/structures/index.html.erb +2 -0
- data/app/views/layouts/binda/_flash.html.erb +3 -3
- data/app/views/layouts/binda/_sidebar.html.erb +20 -15
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +18 -21
- data/db/migrate/1_create_binda_tables.rb +12 -6
- data/lib/binda/engine.rb +5 -1
- data/lib/binda/version.rb +1 -1
- data/lib/generators/binda/install/install_generator.rb +9 -0
- data/lib/generators/binda/setup/setup_generator.rb +50 -7
- data/lib/tasks/binda.rake +78 -24
- metadata +100 -31
- data/app/controllers/binda/settings_controller.rb +0 -75
- data/app/controllers/concerns/binda/component_controller_helper.rb +0 -16
- data/app/helpers/binda/settings_helper.rb +0 -13
- data/app/models/binda/select.rb +0 -7
- data/app/models/binda/setting.rb +0 -42
- data/app/views/binda/components/_form_item_selectable.html.erb +0 -72
- data/app/views/binda/components/_form_section.html.erb +0 -42
- data/app/views/binda/components/_form_section_repeater.html.erb +0 -41
- data/app/views/binda/components/_form_sidebar.html.erb +0 -34
- data/app/views/binda/settings/_dashboard_form.html.erb +0 -51
- data/app/views/binda/settings/_form.html.erb +0 -52
- data/app/views/binda/settings/dashboard.html.erb +0 -9
- data/app/views/binda/settings/edit.html.erb +0 -8
- data/app/views/binda/settings/index.html.erb +0 -34
- data/app/views/binda/settings/new.html.erb +0 -8
@@ -0,0 +1,35 @@
|
|
1
|
+
<h4><%= "#{ t :setting }".pluralize.capitalize %></h4>
|
2
|
+
|
3
|
+
<% if @structure.has_categories %>
|
4
|
+
|
5
|
+
<% if @structure.categories.any? %>
|
6
|
+
<h5><%= t(:category).capitalize %></h5>
|
7
|
+
<%= f.association :categories, as: :radio_buttons, collection: @structure.categories ,checked: @instance.category_ids, include_blank: false %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% if @instance.slug.nil? %>
|
11
|
+
<h5>
|
12
|
+
<%= t( :hint_create_parent_before_child, arg1: "#{ t :category }", arg2: "#{ t :instance }" ).capitalize %>
|
13
|
+
</h5>
|
14
|
+
<% else %>
|
15
|
+
<a class="main-header--link btn btn-default" href="<%= new_structure_category_path( @structure ) %>">
|
16
|
+
<%= "#{ t :new }".capitalize %> <%= t :category %>
|
17
|
+
</a>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<hr>
|
23
|
+
|
24
|
+
<% if @instance.respond_to? :publish_state %>
|
25
|
+
<h5><%= t(:publish_settings).capitalize %></h5>
|
26
|
+
<%= f.input :publish_state, as: :radio_buttons, collection: [ 'draft', 'published' ], checked: f.object.publish_state %>
|
27
|
+
<hr>
|
28
|
+
<% end %>
|
29
|
+
|
30
|
+
<%= f.button :submit, 'Save changes', class: 'btn btn-primary' %>
|
31
|
+
|
32
|
+
|
33
|
+
<% unless @instance.new_record? || @instance.structure.instance_type == 'board' %>
|
34
|
+
<a class="form-body--delete btn btn-default" href="<%= url_for([@structure, @instance]) %>" data-method="delete" data-confirm="This operation will delete this <%= @structure.name %> and there is no coming back. Are you ok with that?">Delete <%= @structure.name.capitalize %> <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
35
|
+
<% end %>
|
@@ -40,10 +40,16 @@
|
|
40
40
|
<div class="form-section--narrow-container row">
|
41
41
|
<div class="col-sm-12">
|
42
42
|
<h4><%= "#{ t :publish }".capitalize %></h4>
|
43
|
+
<h5><%= "#{ t :structure_instance_type }".capitalize %></h5>
|
44
|
+
<%= f.input :instance_type, as: :radio_buttons, collection: ['component','board'] %>
|
43
45
|
<h5><%= "#{ t :structure_has_categories }".capitalize %></h5>
|
44
46
|
<%= f.input :has_categories, as: :radio_buttons %>
|
45
47
|
<hr>
|
46
48
|
<%= f.button :submit, 'Save changes', class: 'btn btn-primary' %>
|
49
|
+
|
50
|
+
<% unless @structure.new_record? %>
|
51
|
+
<a class="form-body--delete btn btn-default" href="<%= url_for([@structure]) %>" data-method="delete" data-confirm="This operation will delete this structure and there is no coming back. Are you ok with that?">Delete Structure <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
52
|
+
<% end %>
|
47
53
|
</div>
|
48
54
|
</div>
|
49
55
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<%# - - - - - - - - - - - - %>
|
5
5
|
<%# FORM ITEM %>
|
6
6
|
<%# - - - - - - - - - - - - %>
|
7
|
-
<%= f.simple_fields_for :field_groups, f.object.field_groups.order( :position ) do |ff| %>
|
7
|
+
<%= f.simple_fields_for :field_groups, f.object.field_groups.order( :position, :name ) do |ff| %>
|
8
8
|
|
9
9
|
<div class="form-item">
|
10
10
|
|
@@ -1,4 +1,7 @@
|
|
1
1
|
<% content_for :header do %>
|
2
|
+
<div class="main-header--buttons">
|
3
|
+
<%= link_to 'New Structure', new_structure_path, class: 'main-header--link btn btn-primary' %>
|
4
|
+
</div>
|
2
5
|
<h3>Editing Structure</h3>
|
3
6
|
<a href="<%= structures_path %>" class="main-header--back"><span class="glyphicon glyphicon-list"></span> Back to list</a>
|
4
7
|
<% end %>
|
@@ -3,8 +3,8 @@
|
|
3
3
|
<div class="alert alert-success col-sm-12">
|
4
4
|
<%= notice if notice.is_a? String %>
|
5
5
|
<% if notice.is_a? Hash %>
|
6
|
-
<% notice.each do |key, message| %>
|
7
|
-
<p><%= key.humanize.capitalize %> <%= message.to_sentence %></p>
|
6
|
+
<% notice.each do |key, message| %>
|
7
|
+
<p><%= key.split('.').map{|k| k.humanize.capitalize }.join(': ') %> <%= message.to_sentence %></p>
|
8
8
|
<% end %>
|
9
9
|
<% end %>
|
10
10
|
</div>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<%= alert if alert.is_a? String %>
|
18
18
|
<% if alert.is_a? Hash %>
|
19
19
|
<% alert.each do |key, message| %>
|
20
|
-
<p><%= key.humanize.capitalize %> <%= message.to_sentence %></p>
|
20
|
+
<p><%= key.split('.').map{|k| k.humanize.capitalize }.join(': ') %> <%= message.to_sentence %></p>
|
21
21
|
<% end %>
|
22
22
|
<% end %>
|
23
23
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%
|
2
|
-
# If this partial is run from Devise
|
2
|
+
# If this partial is run from Devise controller
|
3
3
|
# keep in mind to add "binda." to path helpers
|
4
4
|
#
|
5
5
|
# https://github.com/plataformatec/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine#path-helpers
|
@@ -11,22 +11,27 @@
|
|
11
11
|
<li class = "main-sidebar--brand">
|
12
12
|
<h3><%= link_to get_website_name, '/' %></h3>
|
13
13
|
</li>
|
14
|
-
<li>
|
15
|
-
<a href="<%= dashboard_path %>">
|
16
|
-
<span class="glyphicon glyphicon-home" aria-hidden="true"></span> Dashboard
|
17
|
-
</a>
|
18
|
-
</li>
|
19
14
|
<% Binda::Structure.all.order(:position).each_with_index do |structure, index| %>
|
20
|
-
|
21
|
-
<
|
22
|
-
<
|
23
|
-
|
24
|
-
|
25
|
-
<a class="main-sidebar--sub-link" href="<%= structure_categories_path( structure.slug ) %>">
|
26
|
-
<span class="glyphicon glyphicon-tags" aria-hidden="true"></span> <%= structure.name.humanize %> <%= t(:category).capitalize.pluralize %>
|
15
|
+
<% if structure.instance_type == 'component' %>
|
16
|
+
<li class="main-sidebar--structure <%= 'main-sidebar--first-structure' if index == 0 %>">
|
17
|
+
<a href="<%= structure_components_path( structure ) %>">
|
18
|
+
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
|
19
|
+
<%= structure.name.humanize.pluralize %>
|
27
20
|
</a>
|
28
|
-
|
29
|
-
|
21
|
+
<% if structure.has_categories %>
|
22
|
+
<a class="main-sidebar--sub-link" href="<%= structure_categories_path( structure.slug ) %>">
|
23
|
+
<span class="glyphicon glyphicon-tags" aria-hidden="true"></span> <%= structure.name.humanize %> <%= t(:category).capitalize.pluralize %>
|
24
|
+
</a>
|
25
|
+
<% end %>
|
26
|
+
</li>
|
27
|
+
<% else %>
|
28
|
+
<li class="main-sidebar--structure <%= 'main-sidebar--first-structure' if index == 0 %>">
|
29
|
+
<a href="<%= structure_board_path( structure, structure.board ) %>">
|
30
|
+
<span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>
|
31
|
+
<%= structure.name.humanize %>
|
32
|
+
</a>
|
33
|
+
</li>
|
34
|
+
<% end %>
|
30
35
|
<% end %>
|
31
36
|
<% if current_user.is_superadmin %>
|
32
37
|
<li>
|
data/config/locales/en.yml
CHANGED
@@ -14,6 +14,7 @@ en:
|
|
14
14
|
create: create
|
15
15
|
delete: delete
|
16
16
|
setting: setting
|
17
|
+
board: board
|
17
18
|
back_to_index: back to list
|
18
19
|
back_to: back to
|
19
20
|
slug_disable_hint: 'Editing slug is not possible. If you want a specific slug create a new item and a slug will be extracted from the title.'
|
@@ -42,3 +43,6 @@ en:
|
|
42
43
|
default_choice: default choice
|
43
44
|
default_choice_description: if you have added/removed any choice you need to click save to update the list of choices
|
44
45
|
allow_null: allow null?
|
46
|
+
instance: instance
|
47
|
+
structure_instance_type: 'This structure is for:'
|
48
|
+
null_is_not_allowed: You need to select at least one choice
|
data/config/routes.rb
CHANGED
@@ -4,10 +4,10 @@ Binda::Engine.routes.draw do
|
|
4
4
|
# ----
|
5
5
|
# https://github.com/plataformatec/devise/wiki/How-To:-Require-authentication-for-all-components
|
6
6
|
# authenticated :user, class_name: "Binda::User", module: :devise do
|
7
|
-
# root to: '
|
7
|
+
# root to: 'boards#dashboard', as: :authenticated_root
|
8
8
|
# end
|
9
9
|
# root to: 'users/sessions#new'
|
10
|
-
root to: '
|
10
|
+
root to: 'boards#dashboard'
|
11
11
|
|
12
12
|
# DEVISE
|
13
13
|
# ------
|
@@ -31,38 +31,35 @@ Binda::Engine.routes.draw do
|
|
31
31
|
|
32
32
|
# ADMINISTRATION PANEL
|
33
33
|
# --------------------
|
34
|
-
get 'dashboard', to: '
|
35
|
-
post 'dashboard', to: 'settings#update_dashboard'
|
36
|
-
resources :settings
|
34
|
+
get 'dashboard', to: 'boards#dashboard', as: :dashboard
|
37
35
|
|
38
36
|
post 'structures/sort'
|
39
37
|
resources :structures do
|
40
|
-
|
41
|
-
resources :categories
|
42
|
-
|
43
|
-
post 'components/sort'
|
44
|
-
resources :components do
|
45
|
-
post 'sort_repeaters'
|
46
|
-
post 'new_repeater'
|
47
|
-
end
|
48
|
-
|
49
38
|
post 'field_groups/sort'
|
50
39
|
post 'field_groups/add_child'
|
51
40
|
resources :field_groups do
|
52
|
-
|
53
41
|
post 'field_settings/add_child'
|
54
42
|
post 'field_settings/sort'
|
55
43
|
resources :field_settings
|
56
|
-
|
57
44
|
end
|
45
|
+
resources :boards do
|
46
|
+
post 'sort_repeaters'
|
47
|
+
post 'new_repeater'
|
48
|
+
end
|
49
|
+
post 'components/sort'
|
50
|
+
resources :components do
|
51
|
+
post 'sort_repeaters'
|
52
|
+
post 'new_repeater'
|
53
|
+
end
|
54
|
+
resources :categories
|
58
55
|
end
|
59
56
|
|
60
57
|
resources :choices, only: [:destroy]
|
61
58
|
|
62
|
-
resources :texts
|
63
|
-
resources :bindings
|
64
|
-
resources :assets
|
65
|
-
resources :repeaters
|
66
|
-
resources :dates
|
59
|
+
# resources :texts
|
60
|
+
# resources :bindings
|
61
|
+
# resources :assets
|
62
|
+
resources :repeaters, only: [:destroy]
|
63
|
+
# resources :dates
|
67
64
|
|
68
65
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class CreateBindaTables < ActiveRecord::Migration[5.0]
|
2
2
|
def change
|
3
3
|
|
4
|
-
create_table :
|
4
|
+
create_table :binda_boards do |t|
|
5
5
|
t.string :name, null: false
|
6
6
|
t.string :slug
|
7
7
|
t.index :slug, unique: true
|
8
|
-
t.text :content
|
9
8
|
t.integer :position
|
10
|
-
t.
|
9
|
+
t.belongs_to :structure
|
11
10
|
end
|
12
11
|
|
13
12
|
create_table :binda_components do |t|
|
@@ -26,6 +25,7 @@ class CreateBindaTables < ActiveRecord::Migration[5.0]
|
|
26
25
|
t.integer :position
|
27
26
|
t.boolean :has_categories, default: true
|
28
27
|
t.index :slug, unique: true
|
28
|
+
t.string :instance_type, null: false, default: 'component'
|
29
29
|
t.timestamps
|
30
30
|
end
|
31
31
|
|
@@ -52,7 +52,7 @@ class CreateBindaTables < ActiveRecord::Migration[5.0]
|
|
52
52
|
t.belongs_to :field_group
|
53
53
|
t.string :ancestry
|
54
54
|
t.index :ancestry
|
55
|
-
t.boolean :allow_null
|
55
|
+
t.boolean :allow_null, default: false
|
56
56
|
t.references :default_choice, index: true
|
57
57
|
t.timestamps
|
58
58
|
end
|
@@ -69,6 +69,7 @@ class CreateBindaTables < ActiveRecord::Migration[5.0]
|
|
69
69
|
t.integer :position
|
70
70
|
t.belongs_to :field_setting
|
71
71
|
t.references :fieldable, polymorphic: true, index: true
|
72
|
+
t.string :type
|
72
73
|
t.timestamps
|
73
74
|
end
|
74
75
|
|
@@ -97,11 +98,16 @@ class CreateBindaTables < ActiveRecord::Migration[5.0]
|
|
97
98
|
t.string :label
|
98
99
|
t.string :value
|
99
100
|
t.belongs_to :field_setting
|
100
|
-
t.references :selectable, polymorphic: true, index: true
|
101
101
|
t.timestamps
|
102
102
|
end
|
103
103
|
|
104
|
-
create_table :
|
104
|
+
create_table :binda_choices_selections do |t|
|
105
|
+
t.belongs_to :choice, index: true
|
106
|
+
t.belongs_to :selection, index: true
|
107
|
+
t.timestamps
|
108
|
+
end
|
109
|
+
|
110
|
+
create_table :binda_selections do |t|
|
105
111
|
t.belongs_to :field_setting
|
106
112
|
t.references :fieldable, polymorphic: true, index: true
|
107
113
|
t.string :type
|
data/lib/binda/engine.rb
CHANGED
@@ -6,12 +6,16 @@ require 'coffee-rails'
|
|
6
6
|
require 'colorize'
|
7
7
|
require 'friendly_id'
|
8
8
|
require 'aasm'
|
9
|
-
require 'ffaker'
|
10
9
|
require 'simple_form'
|
11
10
|
require 'tinymce-rails'
|
12
11
|
require 'carrierwave'
|
13
12
|
require 'mini_magick'
|
14
13
|
require 'ancestry'
|
14
|
+
require 'kaminari'
|
15
|
+
# require 'bullet'
|
16
|
+
# require 'rails-perftest'
|
17
|
+
# require 'ruby-prof'
|
18
|
+
# require 'test-unit'
|
15
19
|
|
16
20
|
module Binda
|
17
21
|
class Engine < ::Rails::Engine
|
data/lib/binda/version.rb
CHANGED
@@ -20,6 +20,15 @@ module Binda
|
|
20
20
|
route "mount Binda::Engine => '/admin_panel'"
|
21
21
|
end
|
22
22
|
|
23
|
+
def add_helpers
|
24
|
+
ac_path = Rails.root.join('app', 'controllers', 'application_controller.rb' )
|
25
|
+
unless File.readlines(ac_path).grep(/::Binda::DefaultHelpers/).size > 0
|
26
|
+
inject_into_file ac_path, after: "ActionController::Base" do
|
27
|
+
"\n include ::Binda::DefaultHelpers"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
23
32
|
def copy_migrations
|
24
33
|
return if Rails.env.production?
|
25
34
|
|
@@ -2,6 +2,13 @@ require 'colorize'
|
|
2
2
|
require 'securerandom'
|
3
3
|
|
4
4
|
module Binda
|
5
|
+
# Setup initial settings for the application.
|
6
|
+
#
|
7
|
+
# This is setup is mandatory as sets the initial super admin user and
|
8
|
+
# the default dashboard where are stored the main application settings.
|
9
|
+
# It is useful also when Binda has been already installed once but the
|
10
|
+
# database has been reset. Runnin `rails g binda:setup` will populate
|
11
|
+
# the application database with new default settings.
|
5
12
|
class SetupGenerator < Rails::Generators::Base
|
6
13
|
source_root File.expand_path('../templates', __FILE__)
|
7
14
|
|
@@ -13,27 +20,63 @@ module Binda
|
|
13
20
|
puts
|
14
21
|
puts "We need few details. Don't worry you can modify them later. \n\n"
|
15
22
|
|
23
|
+
dashboard_structure = ::Binda::Structure.find_or_create_by( name: 'dashboard', slug: 'dashboard', instance_type: 'board' )
|
24
|
+
@dashboard = dashboard_structure.board
|
25
|
+
|
26
|
+
# By default each structure has a field group which will be used to store the default field settings
|
27
|
+
field_settings = dashboard_structure.field_groups.first.field_settings
|
28
|
+
|
29
|
+
|
16
30
|
# MAINTENANCE MODE
|
17
|
-
|
31
|
+
puts "Setting up maintenance mode"
|
32
|
+
|
33
|
+
# Use radio field_type untill truefalse isn't available
|
34
|
+
unless field_settings.find_by(slug: 'maintenance-mode').present?
|
35
|
+
maintenance_mode = field_settings.create!( name: 'Maintenance Mode', field_type: 'radio' )
|
36
|
+
# make sure slug works
|
37
|
+
maintenance_mode.update_attributes( slug: 'maintenance-mode' )
|
38
|
+
disabled = maintenance_mode.choices.create!( label: 'disabled', value: 'false' )
|
39
|
+
active = maintenance_mode.choices.create!( label: 'active', value: 'true' )
|
40
|
+
@dashboard.radios.find_or_create_by!( field_setting_id: maintenance_mode.id )
|
41
|
+
end
|
42
|
+
puts "The maintenance-mode option has been set up."
|
43
|
+
puts
|
44
|
+
|
18
45
|
|
19
46
|
# WEBSITE NAME
|
20
|
-
|
21
|
-
|
47
|
+
puts "Setting up website name"
|
48
|
+
|
49
|
+
website_name_obj = field_settings.find_by(slug: 'website-name')
|
50
|
+
unless website_name_obj.present?
|
51
|
+
website_name_obj = field_settings.create!( name: 'Website Name', field_type: 'string' )
|
52
|
+
# make sure slug works
|
53
|
+
website_name_obj.update_attribute( 'slug', 'website-name' )
|
54
|
+
end
|
55
|
+
website_name = ask("How would you like to name your website? ['MySite']\n").presence || 'MySite'
|
56
|
+
@dashboard.strings.find_or_create_by( field_setting_id: website_name_obj.id ).update_attribute('content', website_name )
|
22
57
|
|
23
58
|
# WEBSITE CONTENT
|
24
|
-
|
25
|
-
|
59
|
+
puts "Setting up website description"
|
60
|
+
|
61
|
+
website_description_obj = field_settings.find_by(slug: 'website-description')
|
62
|
+
unless website_description_obj.present?
|
63
|
+
website_description_obj = field_settings.find_or_create_by( name: 'Website Description', field_type: 'text' )
|
64
|
+
# make sure slug works
|
65
|
+
website_description_obj.update_attribute( 'slug', 'website-description' )
|
66
|
+
end
|
67
|
+
website_description = ask("What is your website about? ['A website about the world']\n").presence || 'A website about the world'
|
68
|
+
@dashboard.texts.find_or_create_by!( field_setting_id: website_description_obj.id ).update_attribute( 'content', website_description )
|
26
69
|
end
|
27
70
|
|
28
71
|
def create_credentials
|
29
|
-
rake '
|
72
|
+
rake 'binda:create_superadmin_user'
|
30
73
|
end
|
31
74
|
|
32
75
|
def feedback
|
33
76
|
puts
|
34
77
|
puts "============================================================================="
|
35
78
|
puts
|
36
|
-
puts " Binda CMS has been succesfully installed! "
|
79
|
+
puts " Binda CMS has been succesfully installed! "
|
37
80
|
puts
|
38
81
|
puts "============================================================================="
|
39
82
|
puts
|
data/lib/tasks/binda.rake
CHANGED
@@ -1,25 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
namespace :binda do
|
4
|
+
|
5
|
+
desc "Create super admin user"
|
6
|
+
task :create_superadmin_user => :environment do
|
7
|
+
STDOUT.puts "What is your email? [mail@domain.com]"
|
8
|
+
username = STDIN.gets.strip
|
9
|
+
username = 'mail@domain.com' if username.blank?
|
10
|
+
STDOUT.puts "What is your password? [password]"
|
11
|
+
password = STDIN.gets.strip
|
12
|
+
password = 'password' if password.blank?
|
13
|
+
Binda::User.create!( email: username, password: password, password_confirmation: password, is_superadmin: true )
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Update Binda to v0.0.7"
|
17
|
+
task :upgrade_to_v007 => :environment do
|
18
|
+
|
19
|
+
# Make sure Binda hasn't been upgraded already
|
20
|
+
check_structure = Binda::Structure.where(slug: 'dashboard').any?
|
21
|
+
check_field_settings = Binda::FieldSetting.where(slug: ['maintenance-mode', 'website-name', 'website-description']).length == 3
|
22
|
+
if check_structure && check_field_settings
|
23
|
+
puts "It seems you have already upgraded to v0.0.7".colorize(:red)
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
if Binda::Structure.where(slug: 'dashboard').any?
|
28
|
+
puts "A Binda::Structure with `slug = 'dashboard'` has been detected in your database.".colorize(:red)
|
29
|
+
puts "In order to upgrade Binda, the structure's name and slug will be set to 'dashboard-backup'".colorize(:red)
|
30
|
+
Binda::Structure.where(slug: 'dashboard').update_all(name: 'dashboard-backup')
|
31
|
+
end
|
32
|
+
# DASHBOARD
|
33
|
+
dashboard_structure = Binda::Structure.create( name: 'dashboard', slug: 'dashboard', instance_type: 'board' )
|
34
|
+
unless dashboard_structure.board.nil?
|
35
|
+
@dashboard = dashboard_structure.board
|
36
|
+
else
|
37
|
+
@dashboard = dashboard_structure.create_board( name: 'dashboard' )
|
38
|
+
end
|
39
|
+
# By default each structure has a field group which will be used to store the default field settings
|
40
|
+
field_settings = dashboard_structure.field_groups.first.field_settings
|
41
|
+
|
42
|
+
# MAINTENANCE MODE
|
43
|
+
puts "Setting up maintenance mode"
|
44
|
+
unless Binda::FieldSetting.where(slug: 'maintenance-mode').any?
|
45
|
+
maintenance_mode = field_settings.create( name: 'Maintenance Mode', field_type: 'radio')
|
46
|
+
maintenance_mode.update_attributes( slug: 'maintenance-mode' )
|
47
|
+
active = maintenance_mode.choices.create( label: 'active', value: 'true' )
|
48
|
+
disabled = maintenance_mode.choices.create( label: 'disabled', value: 'false' )
|
49
|
+
@dashboard.radios.find_or_create_by( field_setting_id: maintenance_mode.id ).choices << disabled
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# WEBSITE NAME
|
54
|
+
puts "Setting up website name"
|
55
|
+
unless Binda::FieldSetting.where(slug: 'website-name').any?
|
56
|
+
website_name = field_settings.create( name: 'Website Name', field_type: 'string' )
|
57
|
+
website_name.update_attributes( slug: 'website-name' )
|
58
|
+
old_name_record = Binda::Board.where(slug: 'website-name')
|
59
|
+
if old_name_record.any?
|
60
|
+
@dashboard.texts.find_or_create_by( field_setting_id: website_name.id ).update_attributes(content: old_name_record.first.content )
|
61
|
+
else
|
62
|
+
@dashboard.texts.find_or_create_by( field_setting_id: website_name.id ).update_attributes(content: 'MySite' )
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# WEBSITE CONTENT
|
67
|
+
puts "Setting up website description"
|
68
|
+
unless Binda::FieldSetting.where(slug: 'website-description').any?
|
69
|
+
website_description = field_settings.create( name: 'Website Description', field_type: 'string' )
|
70
|
+
website_description.update_attributes( slug: 'website-description' )
|
71
|
+
old_description_record = Binda::Board.where(slug: 'website-name')
|
72
|
+
if old_description_record.any?
|
73
|
+
@dashboard.texts.find_or_create_by( field_setting_id: website_description.id ).update_attributes( content: old_description_record.first.content )
|
74
|
+
else
|
75
|
+
@dashboard.texts.find_or_create_by( field_setting_id: website_description.id ).update_attributes( content: 'A website about the world' )
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
25
79
|
end
|