tb_core 1.4.3.1 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -54
- data/app/assets/javascripts/admin/core/application.js +8 -4
- data/app/assets/javascripts/admin/core/dashboard.js +2 -3
- data/app/assets/javascripts/admin/core/date_picker.js +2 -2
- data/app/assets/javascripts/admin/core/editor.js +2 -2
- data/app/assets/javascripts/admin/core/modal.js +1 -1
- data/app/assets/javascripts/admin/core/users.js +5 -5
- data/app/assets/javascripts/tb_core.js +8 -0
- data/app/assets/libs/sortable/sortable.js +152 -91
- data/app/controllers/admin/application_controller.rb +1 -2
- data/app/controllers/admin/dashboard_controller.rb +2 -2
- data/app/controllers/admin/settings_controller.rb +2 -2
- data/app/controllers/admin/users_controller.rb +4 -7
- data/app/controllers/concerns/tb_core/error_handling.rb +16 -7
- data/app/controllers/concerns/tb_core/user_authentication.rb +5 -5
- data/app/controllers/tb_core/application_controller.rb +1 -1
- data/app/controllers/user_sessions_controller.rb +2 -2
- data/app/helpers/tb_core/application_helper.rb +4 -36
- data/app/mailers/tb_core_mailer.rb +3 -3
- data/app/models/concerns/tb_core/user_model.rb +131 -0
- data/app/models/spud/spud_user_model.rb +6 -138
- data/app/models/spud_permission.rb +4 -4
- data/app/models/spud_role.rb +1 -1
- data/app/models/spud_user.rb +2 -1
- data/app/views/admin/dashboard/index.html.erb +1 -1
- data/app/views/admin/settings/_form.html.erb +1 -1
- data/app/views/admin/settings/edit.html.erb +1 -1
- data/app/views/admin/setup/new.html.erb +1 -1
- data/app/views/admin/users/_form.html.erb +1 -1
- data/app/views/admin/users/index.html.erb +2 -2
- data/app/views/admin/users/show.html.erb +1 -1
- data/app/views/layouts/admin/application.html.erb +6 -6
- data/app/views/layouts/admin/login.html.erb +1 -1
- data/app/views/tb_core_mailer/forgot_password_notification.html.erb +2 -2
- data/app/views/tb_core_mailer/user_credentials.html.erb +2 -2
- data/app/views/user_sessions/_form.html.erb +1 -1
- data/app/views/user_sessions/new.html.erb +1 -1
- data/lib/generators/spud/module_generator.rb +7 -7
- data/lib/generators/spud/setup_generator.rb +6 -7
- data/lib/generators/spud/templates/assets/admin/application.js +1 -1
- data/lib/generators/spud/templates/assets/application.js +3 -4
- data/lib/generators/spud/templates/controller_spec.rb.erb +5 -5
- data/lib/generators/spud/templates/views/admin/_form.html.erb +1 -1
- data/lib/generators/spud/templates/views/admin/index.html.erb +1 -1
- data/lib/generators/spud/templates/views/admin/show.html.erb +1 -1
- data/lib/generators/spud/templates/views/frontend/index.html.erb +1 -1
- data/lib/generators/spud/templates/views/frontend/show.html.erb +1 -1
- data/lib/tb_core.rb +3 -5
- data/lib/tb_core/belongs_to_app.rb +47 -46
- data/lib/tb_core/catch_all_route.rb +3 -0
- data/lib/tb_core/configuration.rb +28 -0
- data/lib/tb_core/engine.rb +61 -0
- data/lib/tb_core/errors.rb +50 -0
- data/lib/tb_core/responder.rb +0 -26
- data/lib/{spud_core → tb_core}/searchable.rb +4 -1
- data/lib/tb_core/spud_core.rb +23 -0
- data/lib/{spud_core → tb_core}/test_files.rb +0 -0
- data/lib/tb_core/test_helper.rb +3 -3
- data/lib/tb_core/version.rb +3 -0
- data/spec/controllers/admin/application_controller_spec.rb +5 -5
- data/spec/controllers/admin/dashboard_controller_spec.rb +5 -5
- data/spec/controllers/admin/password_reset_controller_spec.rb +1 -1
- data/spec/controllers/admin/settings_controller_spec.rb +1 -1
- data/spec/controllers/admin/setup_controller_spec.rb +2 -2
- data/spec/controllers/admin/user_sessions_controller_spec.rb +2 -2
- data/spec/controllers/admin/users_controller_spec.rb +17 -17
- data/spec/dummy/app/assets/javascripts/admin/application.js +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/factories/spud_admin_permission_factories.rb +2 -2
- data/spec/factories/spud_role_factories.rb +2 -2
- data/spec/factories/spud_user_factories.rb +6 -6
- data/spec/helpers/spud/admin/application_helper_spec.rb +1 -1
- data/spec/helpers/tb_core/application_helper_spec.rb +0 -35
- data/spec/lib/spud_core/configuration_spec.rb +2 -2
- data/spec/lib/tb_core/belongs_to_app_spec.rb +4 -3
- data/spec/models/spud_role_spec.rb +2 -2
- data/spec/models/spud_user_spec.rb +13 -13
- data/spec/rails_helper.rb +1 -1
- metadata +59 -67
- data/app/assets/javascripts/tb_core.js.erb +0 -9
- data/app/assets/javascripts/tb_core/configuration.js.erb +0 -9
- data/app/assets/javascripts/tb_core/console.js +0 -12
- data/app/assets/javascripts/tb_core/remote.js +0 -237
- data/app/assets/javascripts/tb_core/utility.js +0 -55
- data/app/controllers/concerns/tb_core/sortable_params.rb +0 -80
- data/app/controllers/spud/application_controller.rb +0 -10
- data/lib/generators/spud/templates/assets/bootstrap.js +0 -14
- data/lib/spud_core/catch_all_route.rb +0 -3
- data/lib/spud_core/configuration.rb +0 -56
- data/lib/spud_core/engine.rb +0 -76
- data/lib/spud_core/errors.rb +0 -47
- data/lib/spud_core/version.rb +0 -5
- data/lib/tb_core/table_header.rb +0 -92
- data/spec/controllers/tb_core/sortable_params_spec.rb +0 -64
data/lib/spud_core/engine.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'responders'
|
2
|
-
require 'jquery-rails'
|
3
|
-
require 'authlogic'
|
4
|
-
require 'bootstrap-sass'
|
5
|
-
require 'autoprefixer-rails'
|
6
|
-
require 'will_paginate'
|
7
|
-
require 'will_paginate-bootstrap'
|
8
|
-
require 'breadcrumbs_on_rails'
|
9
|
-
require 'rails-ujs'
|
10
|
-
|
11
|
-
# this should eventually replace the Spud::Core namespace
|
12
|
-
module TbCore
|
13
|
-
end
|
14
|
-
|
15
|
-
module Spud
|
16
|
-
module Core
|
17
|
-
class Engine < ::Rails::Engine
|
18
|
-
require "#{root}/lib/spud_core/errors"
|
19
|
-
require "#{root}/lib/spud_core/searchable"
|
20
|
-
require "#{root}/lib/tb_core/form_builder"
|
21
|
-
require "#{root}/lib/tb_core/table_header"
|
22
|
-
|
23
|
-
engine_name :tb_core
|
24
|
-
config.autoload_paths << "#{root}/lib"
|
25
|
-
|
26
|
-
initializer 'tb_core.controller_overrides' do |config|
|
27
|
-
ActionController::Base.class_eval do
|
28
|
-
include TbCore::BelongsToApp
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
initializer 'tb_core.model_overrides' do |config|
|
33
|
-
ActiveRecord::Base.class_eval do
|
34
|
-
include Spud::Searchable
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
initializer 'tb_core.admin', after: :admin do |config|
|
39
|
-
# Translate Hash configured permissions into SpudPermission objects
|
40
|
-
Spud::Core.permissions.collect! do |p|
|
41
|
-
if p.class == Hash
|
42
|
-
p = SpudPermission.new(p[:tag], p[:name], p[:apps])
|
43
|
-
end
|
44
|
-
p
|
45
|
-
end
|
46
|
-
# Append Users admin module
|
47
|
-
Spud::Core.config.admin_applications.unshift(name: 'Users',
|
48
|
-
thumbnail: 'admin/users_thumb.png',
|
49
|
-
url: '/admin/users',
|
50
|
-
order: 100)
|
51
|
-
# Create default permissions for modules
|
52
|
-
Spud::Core.admin_applications.each do |admin_application|
|
53
|
-
admin_application[:key] ||= admin_application[:name].gsub(' ', '_').downcase.to_sym
|
54
|
-
tag = "admin.#{admin_application[:key]}.full_access"
|
55
|
-
name = "#{admin_application[:name]} admin"
|
56
|
-
apps = [admin_application[:key]]
|
57
|
-
Spud::Core.permissions.push(SpudPermission.new(tag, name, apps))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
initializer 'tb_core.catch_all_route' do |config|
|
62
|
-
# Handle 404 errors if Spud::Cms is not installed
|
63
|
-
if !defined?(Spud::Cms)
|
64
|
-
config.routes_reloader.paths << File.expand_path('../catch_all_route.rb', __FILE__)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
initializer 'tb_core.assets' do
|
69
|
-
Rails.application.config.assets.precompile += ['admin/users_thumb.png', 'admin/module_icon.png']
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
TbCore::Engine = Spud::Core::Engine
|
data/lib/spud_core/errors.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
class Spud::RequestError < StandardError
|
2
|
-
attr_accessor :request_url, :item, :template
|
3
|
-
attr_reader :code, :title
|
4
|
-
|
5
|
-
# For compatability reasons, this method accepts multiple styles of inputs
|
6
|
-
# Going forward the expected input will be:
|
7
|
-
#
|
8
|
-
# * item: The item that could not be found. String. (default = page)
|
9
|
-
# * template (named): ERB template you wish to render
|
10
|
-
#
|
11
|
-
def initialize(item_or_opts='page', opts={})
|
12
|
-
if item_or_opts.is_a?(Hash)
|
13
|
-
@item = item_or_opts[:item]
|
14
|
-
@template = item_or_opts[:template]
|
15
|
-
else
|
16
|
-
@item = item_or_opts
|
17
|
-
@template = opts[:template]
|
18
|
-
end
|
19
|
-
@template ||= 'layouts/error_page'
|
20
|
-
@title = I18n.t(:title, scope: [:tb_core, :errors, @i18n])
|
21
|
-
super(I18n.t(:message, scope: [:tb_core, :errors, @i18n], item: @item))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Spud::AccessDeniedError < Spud::RequestError
|
26
|
-
def initialize(item_or_opts='page', opts={})
|
27
|
-
@code = 403
|
28
|
-
@i18n = 'access_denied'
|
29
|
-
super(item_or_opts, opts)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class Spud::NotFoundError < Spud::RequestError
|
34
|
-
def initialize(item_or_opts='page', opts={})
|
35
|
-
@code = 404
|
36
|
-
@i18n = 'not_found'
|
37
|
-
super(item_or_opts, opts)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Spud::UnauthorizedError < Spud::RequestError
|
42
|
-
def initialize(item_or_opts='page', opts={})
|
43
|
-
@code = 401
|
44
|
-
@i18n = 'unauthorized'
|
45
|
-
super(item_or_opts, opts)
|
46
|
-
end
|
47
|
-
end
|
data/lib/spud_core/version.rb
DELETED
data/lib/tb_core/table_header.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
module TbCore
|
2
|
-
class TableHeader
|
3
|
-
attr_reader :context
|
4
|
-
attr_accessor :header_html
|
5
|
-
|
6
|
-
# Forward view helper methods to the view context
|
7
|
-
delegate :concat, :content_tag, :link_to, to: :context
|
8
|
-
|
9
|
-
def initialize(path_helper:, model: nil, params: {}, context:)
|
10
|
-
@path_helper = path_helper
|
11
|
-
@model = model
|
12
|
-
@params = params
|
13
|
-
@context = context
|
14
|
-
end
|
15
|
-
|
16
|
-
def capture(block)
|
17
|
-
@html = context.capture do
|
18
|
-
block.call(self)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def sortable(attribute, label: nil)
|
23
|
-
content_tag :th, class: classes_for_attribute(attribute) do
|
24
|
-
concat(link_to_for_attribute(attribute, label))
|
25
|
-
concat(sort_arrow_for_attribute(attribute))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def header(attribute, label: nil)
|
30
|
-
label ||= translated_attribute(attribute)
|
31
|
-
content_tag :th, label
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_row
|
35
|
-
content_tag(:tr, @html)
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_html
|
39
|
-
content_tag :thead, to_row, class: 'tb-table-header'
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def translated_attribute(attribute)
|
45
|
-
if @model
|
46
|
-
@model.human_attribute_name(attribute)
|
47
|
-
else
|
48
|
-
context.t(attribute)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def current_direction
|
53
|
-
@params[:dir] || 'asc'
|
54
|
-
end
|
55
|
-
|
56
|
-
def inverted_direction
|
57
|
-
current_direction == 'asc' ? 'desc' : 'asc'
|
58
|
-
end
|
59
|
-
|
60
|
-
def determine_direction(attribute)
|
61
|
-
if @params[:sort].nil? || @params[:sort] != attribute.to_s
|
62
|
-
'asc'
|
63
|
-
else
|
64
|
-
inverted_direction
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def classes_for_attribute(attribute)
|
69
|
-
classes = ['sortable']
|
70
|
-
if @params[:sort] == attribute.to_s
|
71
|
-
classes << 'sortable-active'
|
72
|
-
classes << "sortable-#{current_direction}"
|
73
|
-
end
|
74
|
-
classes.join(' ')
|
75
|
-
end
|
76
|
-
|
77
|
-
def link_to_for_attribute(attribute, label)
|
78
|
-
label ||= translated_attribute(attribute)
|
79
|
-
path = context.send(
|
80
|
-
@path_helper,
|
81
|
-
@params.merge(sort: attribute, dir: determine_direction(attribute))
|
82
|
-
)
|
83
|
-
link_to(label, path)
|
84
|
-
end
|
85
|
-
|
86
|
-
def sort_arrow_for_attribute(attribute)
|
87
|
-
return '' unless @params[:sort] == attribute.to_s
|
88
|
-
arrow_class = current_direction == 'asc' ? 'up' : 'down'
|
89
|
-
content_tag(:span, '', class: "glyphicon glyphicon-arrow-#{arrow_class}")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
|
3
|
-
describe TbCore::SortableParams, type: :controller do
|
4
|
-
controller do
|
5
|
-
include TbCore::SortableParams
|
6
|
-
sortable_by :first_name, :last_name, :email,
|
7
|
-
display_name: [:first_name, :last_name],
|
8
|
-
birth_date: 'user_birthdays.date :dir',
|
9
|
-
special: proc { |dir| "some_other_tables.whatever #{dir}" },
|
10
|
-
default: :last_name
|
11
|
-
|
12
|
-
def index; end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#sort_direction' do
|
16
|
-
it 'returns asc' do
|
17
|
-
expect(controller.sort_direction).to eq(:asc)
|
18
|
-
end
|
19
|
-
it 'returns desc' do
|
20
|
-
controller.params[:dir] = 'desc'
|
21
|
-
expect(controller.sort_direction).to eq(:desc)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#sort_attribute' do
|
26
|
-
it 'returns the default' do
|
27
|
-
expect(controller.sort_attribute).to eq(:last_name)
|
28
|
-
end
|
29
|
-
it 'returns the param' do
|
30
|
-
controller.params[:sort] = 'email'
|
31
|
-
expect(controller.sort_attribute).to eq(:email)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#sortable_query' do
|
36
|
-
it 'returns the value as a hash' do
|
37
|
-
controller.params[:sort] = 'email'
|
38
|
-
expect(controller.sortable_query).to eq(email: :asc)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns a multi value hash' do
|
42
|
-
controller.params[:sort] = 'display_name'
|
43
|
-
controller.params[:dir] = 'desc'
|
44
|
-
expect(controller.sortable_query).to eq(first_name: :desc, last_name: :desc)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns a string with substitution' do
|
48
|
-
controller.params[:sort] = 'birth_date'
|
49
|
-
controller.params[:dir] = 'desc'
|
50
|
-
expect(controller.sortable_query).to eq('user_birthdays.date desc')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns a string by calling a proc' do
|
54
|
-
controller.params[:sort] = 'special'
|
55
|
-
controller.params[:dir] = 'desc'
|
56
|
-
expect(controller.sortable_query).to eq('some_other_tables.whatever desc')
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'returns nothing' do
|
60
|
-
controller.params[:sort] = 'not_allowed'
|
61
|
-
expect(controller.sortable_query).to eq(nil)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|