tb_core 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/app/assets/javascripts/admin/application.js +2 -0
  4. data/app/assets/javascripts/admin/core/application.js +1 -8
  5. data/app/assets/javascripts/admin/core/dashboard.js +34 -3
  6. data/app/assets/javascripts/admin/core/date_picker.js +2 -2
  7. data/app/assets/javascripts/tb_core/configuration.js.erb +9 -0
  8. data/app/assets/javascripts/tb_core/console.js +12 -0
  9. data/app/assets/javascripts/tb_core/utility.js +32 -0
  10. data/app/assets/javascripts/tb_core.js.erb +6 -0
  11. data/app/assets/stylesheets/admin/core/application.css.scss +20 -0
  12. data/app/controllers/admin/application_controller.rb +3 -2
  13. data/app/controllers/admin/dashboard_controller.rb +16 -0
  14. data/app/controllers/admin/password_resets_controller.rb +3 -2
  15. data/app/controllers/admin/roles_controller.rb +1 -1
  16. data/app/controllers/admin/settings_controller.rb +6 -3
  17. data/app/controllers/admin/setup_controller.rb +2 -1
  18. data/app/controllers/admin/user_sessions_controller.rb +13 -2
  19. data/app/controllers/admin/users_controller.rb +1 -1
  20. data/app/controllers/password_resets_controller.rb +3 -2
  21. data/app/controllers/spud/application_controller.rb +5 -3
  22. data/app/controllers/user_sessions_controller.rb +1 -1
  23. data/app/helpers/admin/application_helper.rb +7 -0
  24. data/app/models/spud_user_session.rb +1 -0
  25. data/app/views/admin/dashboard/index.html.erb +11 -10
  26. data/config/routes.rb +1 -1
  27. data/lib/generators/spud/module_generator.rb +5 -8
  28. data/lib/generators/spud/setup_generator.rb +3 -7
  29. data/lib/generators/spud/templates/admin_controller.rb.erb +1 -1
  30. data/lib/generators/spud/templates/assets/admin/application.js +16 -0
  31. data/lib/generators/spud/templates/assets/admin/module.js.erb +19 -0
  32. data/lib/generators/spud/templates/assets/application.js +17 -0
  33. data/lib/generators/spud/templates/assets/module.js.erb +7 -3
  34. data/lib/generators/spud/templates/controller.rb.erb +1 -1
  35. data/lib/generators/spud/templates/views/admin/_form.html.erb +1 -1
  36. data/lib/generators/spud/templates/views/admin/index.html.erb +6 -0
  37. data/lib/generators/spud/templates/views/admin/show.html.erb +17 -0
  38. data/lib/generators/spud/templates/views/frontend/index.html.erb +5 -1
  39. data/lib/generators/spud/templates/views/frontend/show.html.erb +5 -1
  40. data/lib/spud_core/belongs_to_app.rb +1 -1
  41. data/lib/spud_core/version.rb +1 -1
  42. data/spec/controllers/admin/dashboard_controller_spec.rb +45 -0
  43. metadata +12 -7
  44. data/lib/generators/spud/templates/assets/admin.coffee.erb +0 -9
  45. data/lib/generators/spud/templates/assets/admin.js.erb +0 -14
  46. data/lib/generators/spud/templates/assets/module.coffee.erb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8475b9518168de94786cd9f214159943b6213c49
4
- data.tar.gz: bd3edd0b803176eff49892130070b5f28e785d23
3
+ metadata.gz: 71c34ea80001648010e043bef02b72692915420f
4
+ data.tar.gz: 3883316c2ffaa12dd1dd898f3b96a018b58441fd
5
5
  SHA512:
6
- metadata.gz: 71bb0da66f3555badb283e7fa90a3d1e68d2e41ad3f06ff62d2b07d3f5d3edda31ec93a3fa260e7afbd48379b28c4d6c22a83a6e39484237293a7d6ca5ca37de
7
- data.tar.gz: 05a4129bc69e3b7679948c57dcbabd0c4b193b774bc1f4aae548a8960b484467ca6d059142ab09db62a10d46e8a72a67bf66fd0674a9b16a2915bf6fda7565ca
6
+ metadata.gz: ce061063bbbe493d0371ce8a1f3eba01091a2ee8c4d35a77d47afa5e8431f6c40c39f2f93b4a4c7f442cf317951696a5640f80b7f90565e1f039c04c0064398a
7
+ data.tar.gz: 378b935cdabc307ec286995fc2b7f77a1dc18fe482a9c1790685a0bc12bccb07e976f57728e3cf3131c256d05ec9c3881471e0ab13751d6179c4618721b1f388
data/README.md CHANGED
@@ -47,7 +47,6 @@ The core engine provides various configuration options.
47
47
  - `admin_applications`: Array of custom admin modules. See section below for more info.
48
48
  - `site_name`: Controls the site name displayed in the dashboard and `tb_page_title` view helper.
49
49
  - `from_address`: Sender address used for password resets and other mailers.
50
- - `not_found_template`: ERB template used for 404 exceptions. Defaults to `layouts/not_found`.
51
50
  - `production_alert_domain`: When set, displays a prominent warning bar in the admin dashboard directing users to the production domain. You should only set this value in `config/environments/staging.rb`.
52
51
 
53
52
  Adding Apps to the Dashboard
@@ -60,12 +59,15 @@ The fastest way to add an app to the dashboard is via the geneator. The generato
60
59
  Admin apps are added via the `Spud::Core.config.admin_applications` array. We recommend you perform this action in either an initializer or within your `application.rb` file.
61
60
 
62
61
  Spud::Core.config.admin_applications += [{
62
+ # Required:
63
63
  :name => "Clients",
64
64
  :thumbnail => "spud/admin/clients.png",
65
- :url => "/admin/clients"
65
+ :url => "/admin/clients",
66
+ # Optional:
67
+ :badge => ->(user){ Client.where(:is_pending => true).count() }
66
68
  }]
67
69
 
68
- Build out your RESTful controller and views like you normally would in any Rails app. Extend your controller from `Admin::ApplicationController` in order to inherit the default admin behaviors, and look at the core admin controllers for example implementations.
70
+ Build out your RESTful controller and views like you normally would in any Rails app. Extend your controller from `Admin::ApplicationController` in order to inherit the default admin behaviors, and look at the core admin controllers for example implementations.
69
71
 
70
72
  Roles & Permissions
71
73
  -------------------
@@ -145,12 +147,12 @@ Create a file in your app at `app/views/admin/users/_show_additions.html.erb`.
145
147
  404 Handling
146
148
  ------------
147
149
 
148
- The base `Spud::ApplicationController` will automatically rescue from any `Spud::NotFoundError` errors by rendering out the template specified in `Spud::Core.not_found_template`. The default tempalte is `layouts/not_found.html`. To customize this view, create a template by that name in your own project.
150
+ The base `Spud::ApplicationController` will automatically rescue from any `Spud::NotFoundError` errors by rendering out the `layouts/not_found.html` template. To customize this view, create a template by that name in your own project.
149
151
 
150
152
  When building your own apps you may raise a `Spud::NotFoundError` at any time to halt further execution and cause the 404 page to render. For example:
151
153
 
152
154
  class CarsController
153
- before_filter :get_record
155
+ before_action :get_record
154
156
  # ... actions here
155
157
  def get_record
156
158
  @car = Car.where(:id => params[:id]).first
@@ -2,3 +2,5 @@
2
2
  PLACEHOLDER
3
3
  You should create a javascript file in your application at app/assets/javascripts/admin/application.js
4
4
  */
5
+
6
+ window.app = {admin: {}};
@@ -6,6 +6,7 @@
6
6
  //= require bootstrap/js/bootstrap
7
7
  //= require datepicker/js/bootstrap-datepicker
8
8
  //= require jquery-ui/js/jquery-ui-1.9.1.custom
9
+ //= require ../../tb_core
9
10
  //= require_self
10
11
  //= require_tree .
11
12
  //= require retina_tag
@@ -14,14 +15,6 @@ spud = {admin:{}};
14
15
 
15
16
  $(document).ready(function() {
16
17
 
17
- if(typeof(window.console) == 'undefined'){
18
- window.console = {
19
- log:function(){},
20
- warn:function(){},
21
- error:function(){}
22
- };
23
- }
24
-
25
18
  spud.admin.editor.init();
26
19
 
27
20
  $("#modal_window .modal-footer .form-submit").bind('click', function() {
@@ -1,9 +1,40 @@
1
1
  (function(){
2
2
 
3
3
  spud.admin.dashboard = {
4
- init:function(){
4
+ init:function(){
5
+ updateBadges();
6
+ setInterval(updateBadges, 30000);
7
+ }
8
+ };
9
+
10
+ var updateBadges = function updateBadges() {
11
+ var url = tb.util.urlFor('admin/badges');
12
+ $.ajax({
13
+ url: url
14
+ }).always(function(json) {
15
+ if(json && json.data) {
16
+ json.data.forEach(function(eachBadge) {
17
+ var id = "application_name_" + eachBadge.key;
18
+ updateBadge(id, eachBadge.badge_count);
19
+ });
20
+ }
21
+ });
22
+ };
5
23
 
6
- }
24
+ var updateBadge = function updateBadge(badge_id, count) {
25
+ var badgeIcon = $('#' + badge_id).find('.dash_icon_badge');
26
+ if(badgeIcon.length === 0) {
27
+ return;
28
+ }
29
+ else if (count === 0) {
30
+ badgeIcon.toggle(false);
31
+ }
32
+ else if (count > 999) {
33
+ badgeIcon.text("999+").toggle(true);
34
+ }
35
+ else {
36
+ badgeIcon.text(count).toggle(true);
37
+ }
7
38
  };
8
39
 
9
- })();
40
+ })();
@@ -12,10 +12,10 @@ spud.admin.date_picker = {};
12
12
  date = new Date(parseInt(dateComponents[0],10),parseInt(dateComponents[1],10) - 1,parseInt(dateComponents[2],10));
13
13
  }
14
14
  return date;
15
- }
15
+ };
16
16
 
17
17
  picker.init = function(selector) {
18
- selector = (typeof(selector) == 'undefined') ? '.spud_form_date_picker' : selector;
18
+ selector = (typeof(selector) == 'undefined') ? '.spud_form_date_picker, .tb-form-date-picker' : selector;
19
19
  $(selector).each(function() {
20
20
  var $this = $(this);
21
21
  var baseName = $this.attr('name');
@@ -0,0 +1,9 @@
1
+ (function(){
2
+
3
+ tb.config = {
4
+ env: '<%= Rails.env %>',
5
+ siteName: '<%= Spud::Core.config.site_name %>',
6
+ subUri: '<%= Rails.configuration.relative_url_root %>'
7
+ };
8
+
9
+ })();
@@ -0,0 +1,12 @@
1
+ (function(){
2
+
3
+ if(typeof(console) == 'undefined'){
4
+ var noop = function(){};
5
+ window.console = {
6
+ log: noop,
7
+ warn: noop,
8
+ error: noop
9
+ };
10
+ }
11
+
12
+ })();
@@ -0,0 +1,32 @@
1
+ (function(){
2
+
3
+ tb.util = {
4
+ domainWithPort: function(){
5
+ if(window.location.origin){
6
+ return window.location.origin;
7
+ }
8
+ else{
9
+ return location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
10
+ }
11
+ },
12
+
13
+ pathFor: function(){
14
+ var args = Array.prototype.slice.call(arguments, 0);
15
+ var parts = [''];
16
+ if(tb.config.subUri){
17
+ parts.push(tb.config.subUri);
18
+ }
19
+ return parts.concat(args).join('/');
20
+ },
21
+
22
+ urlFor: function(){
23
+ var args = Array.prototype.slice.call(arguments, 0);
24
+ var parts = [tb.util.domainWithPort()];
25
+ if(tb.config.subUri){
26
+ parts.push(tb.config.subUri);
27
+ }
28
+ return parts.concat(args).join('/');
29
+ }
30
+ };
31
+
32
+ })();
@@ -0,0 +1,6 @@
1
+ //= require_self
2
+ //= require_directory ./tb_core
3
+
4
+ (function(){
5
+ window.tb = {};
6
+ })();
@@ -377,3 +377,23 @@ form input.full-width {
377
377
  #modal_window .form-actions-no-modal{
378
378
  display: none;
379
379
  }
380
+
381
+ /* Admin Dashboard */
382
+ a .image_wrapper {
383
+ position: relative;
384
+ .dash_icon_badge {
385
+ display: none;
386
+ position: absolute;
387
+ right: -28px;
388
+ top: -28px;
389
+ width: 40px;
390
+ height: 40px;
391
+ background: #e55137;
392
+ -moz-border-radius: 70px;
393
+ -webkit-border-radius: 20px;
394
+ border-radius: 20px;
395
+ color: white;
396
+ line-height: 36px;
397
+ font-size: 15px;
398
+ }
399
+ }
@@ -1,7 +1,7 @@
1
1
  class Admin::ApplicationController < Spud::ApplicationController
2
2
 
3
- before_filter :require_admin_user
4
- before_filter :verify_site_mode
3
+ before_action :require_admin_user
4
+ before_action :verify_site_mode
5
5
  add_breadcrumb "Dashboard", :admin_root_path
6
6
  layout 'admin/detail'
7
7
  respond_to :html, :json, :xml, :js
@@ -24,6 +24,7 @@ private
24
24
  def require_admin_user
25
25
  if current_user.blank?
26
26
  flash[:notice] = "You must be logged in to access the requested page"
27
+ store_location
27
28
  redirect_to admin_login_path
28
29
  return false
29
30
  elsif !current_user.has_admin_rights?
@@ -8,6 +8,22 @@ class Admin::DashboardController < Admin::ApplicationController
8
8
  end
9
9
  end
10
10
 
11
+ def badges
12
+ data = []
13
+ @admin_applications = Spud::Core.admin_applications.select do |admin_application|
14
+ if current_user.can_view_app?(admin_application)
15
+ if admin_application[:badge]
16
+ begin
17
+ data << {:key => admin_application[:key], :badge_count => admin_application[:badge].call(current_user)}
18
+ rescue Exception => e
19
+ logger.error e
20
+ end
21
+ end
22
+ end
23
+ end
24
+ render :json => {:data => data}
25
+ end
26
+
11
27
  def switch
12
28
  if !params[:multisite_select].blank?
13
29
  if Spud::Core.multisite_config.select{|p| p[:site_id].to_i == params[:multisite_select].to_i}.blank? == false
@@ -1,7 +1,7 @@
1
1
  class Admin::PasswordResetsController < Admin::ApplicationController
2
2
 
3
- before_filter :load_user_using_perishable_token, :only => [:show, :update]
4
- skip_before_filter :require_user, :require_admin_user
3
+ before_action :load_user_using_perishable_token, :only => [:show, :update]
4
+ skip_before_action :require_user, :require_admin_user
5
5
  layout 'admin/login'
6
6
 
7
7
  def index
@@ -30,6 +30,7 @@ class Admin::PasswordResetsController < Admin::ApplicationController
30
30
  @user.password = params[:spud_user][:password]
31
31
  @user.password_confirmation = params[:spud_user][:password_confirmation]
32
32
  if @user.save
33
+ SpudUserSession.create(:login => @user.login, :password => params[:spud_user][:password])
33
34
  flash[:notice] = "Password successfully updated"
34
35
  redirect_to admin_login_path
35
36
  else
@@ -1,6 +1,6 @@
1
1
  class Admin::RolesController < Admin::ApplicationController
2
2
 
3
- before_filter :get_record, :only => [:show, :edit, :update, :destroy]
3
+ before_action :get_record, :only => [:show, :edit, :update, :destroy]
4
4
  respond_to :html, :json, :xml
5
5
  belongs_to_spud_app :users
6
6
  add_breadcrumb "Users", :admin_users_path
@@ -1,9 +1,9 @@
1
1
  class Admin::SettingsController < Admin::ApplicationController
2
2
 
3
- before_filter :require_user
4
- skip_before_filter :require_admin_user
3
+ before_action :require_user
4
+ skip_before_action :require_admin_user
5
5
 
6
- before_filter do |c|
6
+ before_action do |c|
7
7
  if current_user && current_user.has_admin_rights?
8
8
  add_breadcrumb "Settings", :admin_settings_path
9
9
  end
@@ -15,6 +15,9 @@ class Admin::SettingsController < Admin::ApplicationController
15
15
 
16
16
  def update
17
17
  if @current_user.update_attributes(user_params)
18
+ if user_params.include?(:password)
19
+ SpudUserSession.create(:login => @current_user.login, :password => user_params[:password])
20
+ end
18
21
  flash[:notice] = "User settings saved successfully."
19
22
  respond_with @current_user, :location => admin_settings_path
20
23
  else
@@ -1,6 +1,6 @@
1
1
  class Admin::SetupController < Admin::ApplicationController
2
2
 
3
- skip_before_filter :require_user, :require_admin_user
3
+ skip_before_action :require_user, :require_admin_user
4
4
 
5
5
  def new
6
6
  if SpudUser.count != 0
@@ -15,6 +15,7 @@ class Admin::SetupController < Admin::ApplicationController
15
15
  @spud_user = SpudUser.new(user_params)
16
16
  @spud_user.super_admin = true
17
17
  if @spud_user.save
18
+ SpudUserSession.create(:login => @spud_user.login, :password => user_params[:password])
18
19
  redirect_to admin_root_path
19
20
  else
20
21
  render 'new', :status => 422
@@ -1,6 +1,6 @@
1
1
  class Admin::UserSessionsController < Admin::ApplicationController
2
2
 
3
- skip_before_filter :require_admin_user
3
+ skip_before_action :require_admin_user
4
4
  layout 'admin/login'
5
5
 
6
6
  def new
@@ -17,7 +17,7 @@ class Admin::UserSessionsController < Admin::ApplicationController
17
17
  @user_session = SpudUserSession.new(params[:spud_user_session])
18
18
  if @user_session.save
19
19
  flash[:notice] = "Login successful!"
20
- redirect_to admin_root_path
20
+ redirect_to redirect_path_for_admin
21
21
  else
22
22
  render :action => :new
23
23
  end
@@ -36,4 +36,15 @@ class Admin::UserSessionsController < Admin::ApplicationController
36
36
  redirect_to admin_login_path
37
37
  end
38
38
 
39
+ private
40
+
41
+ def redirect_path_for_admin
42
+ back_or_default = back_or_default(admin_root_path)
43
+ if /\/admin\//.match(back_or_default)
44
+ return back_or_default
45
+ else
46
+ return admin_root_path
47
+ end
48
+ end
49
+
39
50
  end
@@ -3,7 +3,7 @@ class Admin::UsersController < Admin::ApplicationController
3
3
  layout false
4
4
  belongs_to_spud_app :users
5
5
  add_breadcrumb "Users", :admin_users_path
6
- before_filter :load_user, :only => [:edit, :update, :show, :destroy]
6
+ before_action :load_user, :only => [:edit, :update, :show, :destroy]
7
7
  respond_to :html
8
8
 
9
9
  def index
@@ -1,7 +1,7 @@
1
1
  class PasswordResetsController < ApplicationController
2
2
 
3
- before_filter :load_user_using_perishable_token, :only => [:show, :update]
4
- skip_before_filter :require_user
3
+ before_action :load_user_using_perishable_token, :only => [:show, :update]
4
+ skip_before_action :require_user
5
5
  respond_to :html
6
6
 
7
7
  def index
@@ -32,6 +32,7 @@ class PasswordResetsController < ApplicationController
32
32
  @user.password = params[:spud_user][:password]
33
33
  @user.password_confirmation = params[:spud_user][:password_confirmation]
34
34
  if @user.save()
35
+ SpudUserSession.create(:login => @user.login, :password => params[:spud_user][:password])
35
36
  flash[:notice] = "Password successfully updated"
36
37
  redirect_back_or_default(root_path)
37
38
  return
@@ -5,10 +5,10 @@ class Spud::ApplicationController < ActionController::Base
5
5
  around_filter :set_time_zone
6
6
 
7
7
  if Spud::Core.multisite_mode_enabled
8
- before_filter :multisite_caching
8
+ before_action :multisite_caching
9
9
  end
10
10
  include Spud::ApplicationHelper
11
- before_filter :set_mailer_default_url
11
+ before_action :set_mailer_default_url
12
12
 
13
13
  rescue_from Spud::NotFoundError, :with => :handle_not_found
14
14
 
@@ -51,7 +51,9 @@ private
51
51
  end
52
52
 
53
53
  def store_location
54
- session[:return_to] = request.url
54
+ if request.format.html? && !request.xhr?
55
+ session[:return_to] = request.url
56
+ end
55
57
  end
56
58
 
57
59
  def redirect_back_or_default(default)
@@ -1,6 +1,6 @@
1
1
  class UserSessionsController < ApplicationController
2
2
 
3
- skip_before_filter :require_user
3
+ skip_before_action :require_user
4
4
  respond_to :html
5
5
 
6
6
  def new
@@ -50,5 +50,12 @@ module Admin::ApplicationHelper
50
50
 
51
51
  end
52
52
 
53
+ def url_for_admin_dashboard_application(url)
54
+ if Rails.configuration.relative_url_root.blank?
55
+ return url
56
+ else
57
+ return [Rails.configuration.relative_url_root, url].join('/').gsub(/(\/+)/, '/')
58
+ end
59
+ end
53
60
 
54
61
  end
@@ -1,3 +1,4 @@
1
1
  class SpudUserSession < Authlogic::Session::Base
2
2
  generalize_credentials_error_messages true
3
+ self.last_request_at_threshold = 1.minutes
3
4
  end
@@ -1,14 +1,15 @@
1
-
2
1
  <div class="sortable">
3
- <%@admin_applications.each do |admin_application|%>
4
-
5
- <div class="admin_application" id="application_name_<%=admin_application[:name]%>"><a href="<%=admin_application[:url]%>">
6
- <div class="image_wrapper"><%=image_tag(admin_application[:thumbnail])%></div>
7
- <span class="application_name"><%=admin_application[:name]%></span>
8
- </a>
9
- </div>
10
-
11
- <%end%>
2
+ <% @admin_applications.each do |admin_application| %>
3
+ <div class="admin_application" id="application_name_<%= admin_application[:key] %>">
4
+ <%= link_to url_for_admin_dashboard_application(admin_application[:url]) do %>
5
+ <div class="image_wrapper">
6
+ <%= image_tag(admin_application[:thumbnail]) %>
7
+ <span class="dash_icon_badge" ></span>
8
+ </div>
9
+ <span class="application_name"><%= admin_application[:name] %></span>
10
+ <% end %>
11
+ </div>
12
+ <% end %>
12
13
  </div>
13
14
  <script type="text/javascript">
14
15
  $(document).ready(spud.admin.dashboard.init);
data/config/routes.rb CHANGED
@@ -4,8 +4,8 @@ Rails.application.routes.draw do
4
4
 
5
5
  get 'login' => 'user_sessions#new', :as => 'login'
6
6
  post 'login' => 'user_sessions#create'
7
+ get 'badges' => 'dashboard#badges'
7
8
  match 'logout' => 'user_sessions#destroy', :as => 'logout', :via => [:get, :post]
8
-
9
9
  resources :password_resets, :only => [:index, :create, :show, :update], :path => 'login/forgot'
10
10
 
11
11
  get 'settings' => 'settings#edit', :as => 'settings'
@@ -10,15 +10,12 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
10
10
  def create_module
11
11
  template "admin_controller.rb.erb", "app/controllers/admin/#{module_name_formatted}_controller.rb"
12
12
  template "controller.rb.erb", "app/controllers/#{module_name_formatted}_controller.rb"
13
-
14
- if defined?(CoffeeScript)
15
- template "assets/module.coffee.erb", "app/assets/javascripts/admin/#{module_name_formatted}.js.coffee"
16
- else
17
- template "assets/module.js.erb", "app/assets/javascripts/admin/#{module_name_formatted}.js"
18
- end
19
-
13
+
14
+ template "assets/module.js.erb", "app/assets/javascripts/#{module_name_formatted}.js"
15
+ template "assets/admin/module.js.erb", "app/assets/javascripts/admin/#{module_name_formatted}.js"
20
16
  create_file "app/assets/stylesheets/admin/#{module_name_formatted}.css.scss", "// Place #{module_name} module styles here\n\n"
21
17
  template "views/admin/index.html.erb", "app/views/admin/#{module_name_formatted}/index.html.erb"
18
+ template "views/admin/show.html.erb", "app/views/admin/#{module_name_formatted}/show.html.erb"
22
19
  template "views/admin/new.html.erb", "app/views/admin/#{module_name_formatted}/new.html.erb"
23
20
  template "views/admin/edit.html.erb", "app/views/admin/#{module_name_formatted}/edit.html.erb"
24
21
  template "views/admin/_form.html.erb", "app/views/admin/#{module_name_formatted}/_form.html.erb"
@@ -32,7 +29,7 @@ class Spud::ModuleGenerator < ::Rails::Generators::Base
32
29
  private
33
30
 
34
31
  def module_name_formatted
35
- module_name.pluralize.downcase.underscore
32
+ module_name.pluralize.underscore
36
33
  end
37
34
 
38
35
  def create_routes
@@ -8,18 +8,14 @@ class Spud::SetupGenerator < ::Rails::Generators::Base
8
8
  template 'assets/admin.css.scss', 'app/assets/stylesheets/admin/application.css.scss'
9
9
 
10
10
  update_base_stylesheet()
11
- update_base_javascript()
12
11
 
13
- if defined?(CoffeeScript)
14
- template 'assets/admin.coffee.erb', 'app/assets/javascripts/admin/application.js.coffee'
15
- else
16
- template 'assets/admin.js.erb', 'app/assets/javascripts/admin/application.js'
17
- end
12
+ template 'assets/application.js', 'app/assets/javascripts/application.js'
13
+ template 'assets/admin/application.js', 'app/assets/javascripts/admin/application.js'
18
14
 
19
15
  environment(spud_core_configs())
20
16
  rake('railties:install:migrations')
21
17
 
22
- if ask("Migrate the database? [Yn] ") == 'Y'
18
+ if ask("Migrate the database? [Yn] ").downcase == 'y'
23
19
  rake('db:migrate')
24
20
  end
25
21
  end
@@ -1,6 +1,6 @@
1
1
  class Admin::<%= module_name_formatted.camelize%>Controller < Admin::ApplicationController
2
2
 
3
- before_filter :load_<%= module_name_formatted.singularize %>, :only => [:show, :edit, :update, :destroy]
3
+ before_action :load_<%= module_name_formatted.singularize %>, :only => [:show, :edit, :update, :destroy]
4
4
  belongs_to_spud_app :<%= module_name_formatted %>
5
5
  add_breadcrumb "<%= module_name_formatted.humanize.titlecase %>", :admin_<%= module_name_formatted %>_path
6
6
 
@@ -0,0 +1,16 @@
1
+ //= require_self
2
+ //= require_tree
3
+
4
+ (function(){
5
+
6
+ window.app = {
7
+ admin: {
8
+ init: function(){
9
+
10
+ }
11
+ }
12
+ };
13
+
14
+ $(document).ready(app.admin.init);
15
+
16
+ })();
@@ -0,0 +1,19 @@
1
+ // <%= module_name.titleize %>
2
+
3
+ (function(){
4
+
5
+ app.admin.<%= module_name_formatted %> = {
6
+ index: function(){
7
+
8
+ },
9
+
10
+ show: function(){
11
+
12
+ },
13
+
14
+ edit: function(){
15
+
16
+ }
17
+ };
18
+
19
+ })();
@@ -0,0 +1,17 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require tb_core
4
+ //= require_self
5
+ //= require_directory .
6
+
7
+ (function(){
8
+
9
+ window.app = {
10
+ init: function(){
11
+ // global initializer
12
+ }
13
+ };
14
+
15
+ $(document).ready(app.init);
16
+
17
+ })();
@@ -1,9 +1,13 @@
1
- // Place module <%= module_name %> scripts here
1
+ // <%= module_name.titleize %>
2
2
 
3
3
  (function(){
4
4
 
5
- <%= application_name() %>.<%= module_name_formatted %> = {
6
- init: function(){
5
+ app.<%= module_name_formatted %> = {
6
+ index: function(){
7
+
8
+ },
9
+
10
+ show: function(){
7
11
 
8
12
  }
9
13
  };
@@ -1,7 +1,7 @@
1
1
  class <%=module_name_formatted.camelize%>Controller < ApplicationController
2
2
 
3
3
  respond_to :html, :json
4
- before_filter :load_<%=module_name_formatted.singularize%>, :only => [:show]
4
+ before_action :load_<%=module_name_formatted.singularize%>, :only => [:show]
5
5
 
6
6
  def index
7
7
  @<%=module_name_formatted%> = <%=module_name_formatted.singularize.camelize%>.paginate(:page => params[:page])
@@ -20,5 +20,5 @@
20
20
  <%% end %>
21
21
 
22
22
  <script>
23
- $(document).ready(<%= application_name %>.<%= module_name_formatted %>.init);
23
+ $(document).ready(app.admin.<%= module_name_formatted %>.edit);
24
24
  </script>
@@ -17,6 +17,7 @@
17
17
  <td><%%= <%=module_name_formatted.singularize%>.<%=attribute%> %></td>
18
18
  <%-end-%>
19
19
  <td align="right" width="150">
20
+ <%%= link_to 'Details', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-mini' %>
20
21
  <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-mini' %>
21
22
  <%%= link_to 'Delete', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :method => :delete, :data => {:confirm => 'Are you sure you want to delete this <%=module_name_formatted.singularize.humanize%>?'}, :class => 'btn btn-danger btn-mini' %>
22
23
  </td>
@@ -25,4 +26,9 @@
25
26
  </tbody>
26
27
  </table>
27
28
  <%%= will_paginate @<%=module_name_formatted%> %>
29
+
30
+ <script>
31
+ $(document).ready(app.admin.<%= module_name_formatted %>.index);
32
+ </script>
33
+
28
34
  <%% end %>
@@ -0,0 +1,17 @@
1
+ <%% content_for :data_controls do %>
2
+ <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(@<%=module_name_formatted.singularize%>), :class => 'btn' %>
3
+ <%% end %>
4
+
5
+ <ul>
6
+ <%- attribute_names.each do |attribute| -%>
7
+ <li><strong><%= attribute.humanize.titlecase %>:</strong> <%%= @<%= module_name_formatted.singularize %>.<%= attribute %> %></li>
8
+ <%- end -%>
9
+ </ul>
10
+
11
+ <div class="form-actions">
12
+ <%%= link_to "Back", admin_<%= module_name_formatted %>_path, :class => "btn" %>
13
+ </div>
14
+
15
+ <script>
16
+ $(document).ready(app.admin.<%= module_name_formatted %>.show);
17
+ </script>
@@ -19,4 +19,8 @@
19
19
  <%% end %>
20
20
  </tbody>
21
21
  </table>
22
- <%%=will_paginate @<%=module_name_formatted%>%>
22
+ <%%= will_paginate @<%=module_name_formatted%> %>
23
+
24
+ <script>
25
+ $(document).ready(app.<%= module_name_formatted %>.index);
26
+ </script>
@@ -5,4 +5,8 @@
5
5
  <p><strong><%=attribute_args[0].humanize.titlecase%></strong> <%%=@<%=module_name_formatted.singularize%>.<%=attribute_args[0]%> %></p>
6
6
  <%-end-%>
7
7
 
8
- <p><%%= link_to 'Back', <%=module_name_formatted.pluralize%>_path %></p>
8
+ <p><%%= link_to 'Back', <%=module_name_formatted.pluralize%>_path %></p>
9
+
10
+ <script>
11
+ $(document).ready(app.<%= module_name_formatted %>.show);
12
+ </script>
@@ -15,7 +15,7 @@ module Spud::BelongsToApp
15
15
  end
16
16
  end
17
17
  self.class_eval do
18
- before_filter do |controller|
18
+ before_action do |controller|
19
19
  @page_thumbnail = self.class.page_application[:thumbnail]
20
20
  @application_name = self.class.page_application[:name]
21
21
  @page_name = self.class.page_title
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Core
3
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
4
4
  end
5
5
  end
@@ -6,6 +6,11 @@ describe Admin::DashboardController do
6
6
  :name => 'Test App',
7
7
  :url => '/test/app',
8
8
  :permissions => ["admin.test_app.full_access"]
9
+ },
10
+ {
11
+ :name => "dash app",
12
+ :key => 'dash_app',
13
+ :badge => ->(user) { return 1 }
9
14
  }]
10
15
  end
11
16
 
@@ -114,4 +119,44 @@ describe Admin::DashboardController do
114
119
  end
115
120
  end
116
121
  end
122
+
123
+ describe :badges do
124
+ before(:each) do
125
+ request.accept = "application/json"
126
+ Spud::Core.configure do |config|
127
+ config.site_name = "Test Site"
128
+ config.multisite_mode_enabled = true
129
+ end
130
+ @user.super_admin = true
131
+ @user.save
132
+ end
133
+
134
+ it "should respond with a json content type" do
135
+ get :badges
136
+ response.content_type.should eq("application/json")
137
+ end
138
+
139
+ it "should contain data array in reponse" do
140
+ get :badges
141
+ json = JSON.parse(response.body)
142
+ assert json.has_key?("data")
143
+ end
144
+
145
+ it "should have badge count 1 for dash app" do
146
+ get :badges
147
+ json = JSON.parse(response.body)
148
+ data = json["data"]
149
+ assert data.size == 1
150
+ app_found = false
151
+ badge_count = 0
152
+ data.each do |app|
153
+ if app["key"] == "dash_app"
154
+ app_found = true
155
+ badge_count = app["badge_count"]
156
+ end
157
+ end
158
+ assert app_found && badge_count == 1
159
+ end
160
+
161
+ end
117
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.4'
33
+ version: 3.4.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.4'
40
+ version: 3.4.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: scrypt
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -328,6 +328,10 @@ files:
328
328
  - app/assets/javascripts/admin/core/roles.js
329
329
  - app/assets/javascripts/admin/core/split_pane.js
330
330
  - app/assets/javascripts/admin/core/users.js
331
+ - app/assets/javascripts/tb_core.js.erb
332
+ - app/assets/javascripts/tb_core/configuration.js.erb
333
+ - app/assets/javascripts/tb_core/console.js
334
+ - app/assets/javascripts/tb_core/utility.js
331
335
  - app/assets/libs/bootstrap/css/bootstrap-responsive.css
332
336
  - app/assets/libs/bootstrap/css/bootstrap.css.scss
333
337
  - app/assets/libs/bootstrap/img/glyphicons-halflings-white.png
@@ -430,16 +434,17 @@ files:
430
434
  - lib/generators/spud/setup_generator.rb
431
435
  - lib/generators/spud/templates/admin_controller.rb.erb
432
436
  - lib/generators/spud/templates/application_controller.rb
433
- - lib/generators/spud/templates/assets/admin.coffee.erb
434
437
  - lib/generators/spud/templates/assets/admin.css.scss
435
- - lib/generators/spud/templates/assets/admin.js.erb
436
- - lib/generators/spud/templates/assets/module.coffee.erb
438
+ - lib/generators/spud/templates/assets/admin/application.js
439
+ - lib/generators/spud/templates/assets/admin/module.js.erb
440
+ - lib/generators/spud/templates/assets/application.js
437
441
  - lib/generators/spud/templates/assets/module.js.erb
438
442
  - lib/generators/spud/templates/controller.rb.erb
439
443
  - lib/generators/spud/templates/views/admin/_form.html.erb
440
444
  - lib/generators/spud/templates/views/admin/edit.html.erb
441
445
  - lib/generators/spud/templates/views/admin/index.html.erb
442
446
  - lib/generators/spud/templates/views/admin/new.html.erb
447
+ - lib/generators/spud/templates/views/admin/show.html.erb
443
448
  - lib/generators/spud/templates/views/frontend/index.html.erb
444
449
  - lib/generators/spud/templates/views/frontend/show.html.erb
445
450
  - lib/generators/spud/templates/views/layouts/application.html.erb
@@ -1,9 +0,0 @@
1
- #= require_self
2
- #= require_tree
3
-
4
- window.<%= application_name() %> = {
5
- init: ()->
6
-
7
- }
8
-
9
- $(document).ready(<%= application_name() %>.init);
@@ -1,14 +0,0 @@
1
- //= require_self
2
- //= require_tree
3
-
4
- (function(){
5
-
6
- window.<%= application_name() %> = {
7
- init: function(){
8
-
9
- }
10
- };
11
-
12
- $(document).ready(<%= application_name() %>.init);
13
-
14
- })();
@@ -1,6 +0,0 @@
1
- # Place module <%= module_name %> scripts here
2
-
3
- <%= application_name() %>.<%= module_name_formatted %> = {
4
- init: ()->
5
-
6
- }