@@ -23,4 +23,29 @@ class AdminPanelController < ApplicationController |
||
| 23 | 23 |
def files |
| 24 | 24 |
@uploads = Upload.all |
| 25 | 25 |
end |
| 26 |
+ |
|
| 27 |
+ def site_config |
|
| 28 |
+ @config = Info.first |
|
| 29 |
+ end |
|
| 30 |
+ |
|
| 31 |
+ def site_config_update |
|
| 32 |
+ @config = Info.first |
|
| 33 |
+ respond_to do |format| |
|
| 34 |
+ if @config.update(info_params) |
|
| 35 |
+ format.html { redirect_to admin_config_path, notice: (t 'admin_panel.config_update_success') }
|
|
| 36 |
+ format.json { head :no_content }
|
|
| 37 |
+ else |
|
| 38 |
+ format.html { render action: 'site_config' }
|
|
| 39 |
+ format.json { render json: @upload.errors, status: :unprocessable_entity }
|
|
| 40 |
+ end |
|
| 41 |
+ end |
|
| 42 |
+ end |
|
| 43 |
+ |
|
| 44 |
+ private |
|
| 45 |
+ |
|
| 46 |
+ # Never trust parameters from the scary internet, only allow the white list through. |
|
| 47 |
+ def info_params |
|
| 48 |
+ params.require(:info).permit(:website_name, :tagline, :contact_email, :default_language) |
|
| 49 |
+ end |
|
| 50 |
+ |
|
| 26 | 51 |
end |
@@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base |
||
| 3 | 3 |
# For APIs, you may want to use :null_session instead. |
| 4 | 4 |
protect_from_forgery with: :exception |
| 5 | 5 |
|
| 6 |
- before_filter :set_locale |
|
| 6 |
+ before_filter :config_site |
|
| 7 | 7 |
|
| 8 | 8 |
before_filter :configure_permitted_parameters, if: :devise_controller? |
| 9 | 9 |
|
@@ -14,9 +14,10 @@ class ApplicationController < ActionController::Base |
||
| 14 | 14 |
|
| 15 | 15 |
private |
| 16 | 16 |
|
| 17 |
- def set_locale |
|
| 17 |
+ def config_site |
|
| 18 |
+ @config = Info.first |
|
| 18 | 19 |
#I18n.config.enforce_available_locales = false |
| 19 |
- I18n.default_locale = "pt-BR" |
|
| 20 |
+ I18n.default_locale = @config.default_language |
|
| 20 | 21 |
end |
| 21 | 22 |
|
| 22 | 23 |
end |
@@ -48,7 +48,7 @@ class BlogPostsController < ApplicationController |
||
| 48 | 48 |
format.html { redirect_to @blog_post, notice: 'Blog post was successfully updated.' }
|
| 49 | 49 |
format.json { head :no_content }
|
| 50 | 50 |
else |
| 51 |
- format.html { render action: 'edit' }
|
|
| 51 |
+ format.html { }
|
|
| 52 | 52 |
format.json { render json: @blog_post.errors, status: :unprocessable_entity }
|
| 53 | 53 |
end |
| 54 | 54 |
end |
@@ -0,0 +1,3 @@ |
||
| 1 |
+class Info < ActiveRecord::Base |
|
| 2 |
+ validates_presence_of :website_name, :default_language |
|
| 3 |
+end |
@@ -8,5 +8,7 @@ |
||
| 8 | 8 |
<%= link_to ('<i class="icon-file icon-white"></i> '+(t "admin_panel.files")).html_safe, admin_files_path %></li>
|
| 9 | 9 |
<% if current_page?(:action => 'users')%><li class="active"> <% else %><li><% end %> |
| 10 | 10 |
<%= link_to ('<i class="icon-user icon-white"></i> '+(t "admin_panel.users")).html_safe, admin_users_path %></li>
|
| 11 |
+ <% if current_page?(:action => 'site_config')%><li class="active"> <% else %><li><% end %> |
|
| 12 |
+ <%= link_to ('<i class="icon-cog icon-white"></i> '+(t "admin_panel.configurations")).html_safe, admin_config_path %></li>
|
|
| 11 | 13 |
</ul> |
| 12 | 14 |
</div> |
@@ -5,6 +5,7 @@ |
||
| 5 | 5 |
<h1><%= t "admin_panel.dashboard" %></h1> |
| 6 | 6 |
<p><%= t "admin_panel.welcome" %> <%= current_user.full_name%></p> |
| 7 | 7 |
</div> |
| 8 |
+ <%= bootstrap_flash %> |
|
| 8 | 9 |
<div class="well summary"> |
| 9 | 10 |
<ul> |
| 10 | 11 |
<li> |
@@ -4,6 +4,7 @@ |
||
| 4 | 4 |
<div class="page-header"> |
| 5 | 5 |
<h1><%= t "admin_panel.files" %> <%= link_to (t "admin_panel.upload_file"), new_upload_path, :class => 'btn btn-primary btn-mini' %></h1> |
| 6 | 6 |
</div> |
| 7 |
+ <%= bootstrap_flash %> |
|
| 7 | 8 |
<ul class="thumbnails"> |
| 8 | 9 |
<% @uploads.each do |upload| %> |
| 9 | 10 |
<li class="span3" style=""> |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 |
<div class="page-header"> |
| 5 | 5 |
<h1><%= t "admin_panel.posts" %> <%= link_to (t "admin_panel.new_blog_post"), new_blog_post_path, :class => 'btn btn-primary btn-mini' %></h1> |
| 6 | 6 |
</div> |
| 7 |
- |
|
| 7 |
+ <%= bootstrap_flash %> |
|
| 8 | 8 |
<% @posts.each do |post| %> |
| 9 | 9 |
<div class="media thumbnail" style="padding: 10px; padding-bottom: 5px;"> |
| 10 | 10 |
<span class="pull-left"> |
@@ -0,0 +1,26 @@ |
||
| 1 |
+<div class="row"> |
|
| 2 |
+ <%= render 'admin_panel/sidebar_nav' %> |
|
| 3 |
+ <div class="span9"> |
|
| 4 |
+ <div class="page-header"> |
|
| 5 |
+ <h1><%= t "admin_panel.configurations" %> </h1> |
|
| 6 |
+ </div> |
|
| 7 |
+ <%= bootstrap_flash %> |
|
| 8 |
+ <div class="media thumbnail" style="padding: 10px; padding-bottom: 5px;"> |
|
| 9 |
+ <%= simple_form_for(@config, :url => config_update_path, :method => 'POST', :html => { class: ''}) do |f| %>
|
|
| 10 |
+ <%= f.error_notification %> |
|
| 11 |
+ |
|
| 12 |
+ <div class="form-inputs"> |
|
| 13 |
+ <%= f.input :website_name, :label => (t 'admin_panel.website_name'), :input_html => {:class => 'input-large'} %>
|
|
| 14 |
+ <%= f.input :tagline, :label => (t 'admin_panel.tagline'), :input_html => { :class => 'input-xxlarge'} %>
|
|
| 15 |
+ <%= f.input :default_language, collection: ["en", "pt-BR"], prompt:"Select default language", :label => (t 'admin_panel.default_language'), hint: (t "admin_panel.language_hint") %> |
|
| 16 |
+ |
|
| 17 |
+ </div> |
|
| 18 |
+ |
|
| 19 |
+ <div class="form-actions" style="margin-left: -10px; margin-right: -10px; margin-bottom: -30px;"> |
|
| 20 |
+ <%= f.button :submit, (t 'admin_panel.update_config_btn'), :class => 'btn btn-success' %> |
|
| 21 |
+ </div> |
|
| 22 |
+ <% end %> |
|
| 23 |
+ </div> |
|
| 24 |
+ |
|
| 25 |
+ </div> |
|
| 26 |
+</div> |
@@ -4,6 +4,7 @@ |
||
| 4 | 4 |
<div class="page-header"> |
| 5 | 5 |
<h1><%= t "admin_panel.users" %></h1> |
| 6 | 6 |
</div> |
| 7 |
+ <%= bootstrap_flash %> |
|
| 7 | 8 |
<% @users.each do |user| %> |
| 8 | 9 |
<div class="media thumbnail" style="padding: 10px; padding-bottom: 5px;"> |
| 9 | 10 |
<span class="pull-left"> |
@@ -1 +1 @@ |
||
| 1 |
-<a class="brand" href="/">Website Template</a> |
|
| 1 |
+<a class="brand" href="/"><%= @config.website_name %></a> |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 |
<meta charset="utf-8"> |
| 5 | 5 |
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> |
| 6 | 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 |
- <title><%= content_for?(:title) ? yield(:title) : "RailsWebsiteTemplate" %></title> |
|
| 7 |
+ <title><%= content_for?(:title) ? yield(:title) : "Admin - " + @config.website_name %></title> |
|
| 8 | 8 |
<%= csrf_meta_tags %> |
| 9 | 9 |
|
| 10 | 10 |
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> |
@@ -55,7 +55,6 @@ |
||
| 55 | 55 |
</div> |
| 56 | 56 |
|
| 57 | 57 |
<div class="container top-container "> |
| 58 |
- <%= bootstrap_flash %> |
|
| 59 | 58 |
<%= yield %> |
| 60 | 59 |
|
| 61 | 60 |
<%= render 'layouts/footer' %> |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 |
<meta charset="utf-8"> |
| 5 | 5 |
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> |
| 6 | 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 |
- <title><%= content_for?(:title) ? yield(:title) : "RailsWebsiteTemplate" %></title> |
|
| 7 |
+ <title><%= content_for?(:title) ? yield(:title) : @config.website_name %></title> |
|
| 8 | 8 |
<%= csrf_meta_tags %> |
| 9 | 9 |
|
| 10 | 10 |
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 |
<div class="hero-unit"> |
| 2 |
- <h1>Website Name</h1> |
|
| 3 |
- <p>Tagline goes here</p> |
|
| 2 |
+ <h1><%= @config.website_name %></h1> |
|
| 3 |
+ <p><%= @config.tagline %></p> |
|
| 4 | 4 |
<p> |
| 5 | 5 |
<a class="btn btn-primary btn-large"> |
| 6 | 6 |
Learn more |
@@ -212,6 +212,12 @@ en: |
||
| 212 | 212 |
welcome: Welcome back |
| 213 | 213 |
logins: Logins |
| 214 | 214 |
last_login: Last Login |
| 215 |
+ configurations: Configurations |
|
| 216 |
+ language_hint: Wait a few seconds for changes to take effect |
|
| 217 |
+ website_name: Website Name |
|
| 218 |
+ tagline: Tagline |
|
| 219 |
+ default_language: Default Language |
|
| 220 |
+ update_config_btn: Update Config |
|
| 215 | 221 |
nav: |
| 216 | 222 |
admin_panel: Admin Panel |
| 217 | 223 |
account: Account |
@@ -214,6 +214,13 @@ pt-BR: |
||
| 214 | 214 |
welcome: Bem vindo |
| 215 | 215 |
logins: Acessos |
| 216 | 216 |
last_login: Último Acesso |
| 217 |
+ configurations: Configurações |
|
| 218 |
+ language_hint: Espere alguns segundos para as mudanças ocorrerem |
|
| 219 |
+ config_update_success: As configurações foram atualizadas com sucesso. |
|
| 220 |
+ website_name: Nome do Site |
|
| 221 |
+ tagline: Tagline |
|
| 222 |
+ default_language: Lingua padrão |
|
| 223 |
+ update_config_btn: Salvar Configurações |
|
| 217 | 224 |
nav: |
| 218 | 225 |
admin_panel: Painel de Controle |
| 219 | 226 |
account: Conta |
@@ -6,6 +6,8 @@ RailsWebsiteTemplate::Application.routes.draw do |
||
| 6 | 6 |
get "admin" => "admin_panel#index" |
| 7 | 7 |
get "admin/posts" => "admin_panel#posts", :as => :admin_posts |
| 8 | 8 |
get "admin/users" => "admin_panel#users", :as => :admin_users |
| 9 |
+ get "admin/config" => "admin_panel#site_config", :as => :admin_config |
|
| 10 |
+ post "admin/config/update" => "admin_panel#site_config_update", :as => :config_update |
|
| 9 | 11 |
|
| 10 | 12 |
post "upload" => "uploads#upload", :as => :post_upload |
| 11 | 13 |
get "blog" => "blog_posts#index", :as => :blog |
@@ -0,0 +1,13 @@ |
||
| 1 |
+class CreateInfos < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ create_table :infos do |t| |
|
| 4 |
+ t.string :website_name |
|
| 5 |
+ t.string :tagline |
|
| 6 |
+ t.string :logo |
|
| 7 |
+ t.string :contact_email |
|
| 8 |
+ t.string :default_language |
|
| 9 |
+ |
|
| 10 |
+ t.timestamps |
|
| 11 |
+ end |
|
| 12 |
+ end |
|
| 13 |
+end |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20140923061213) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20140924001609) do |
|
| 15 | 15 |
|
| 16 | 16 |
# These are extensions that must be enabled in order to support this database |
| 17 | 17 |
enable_extension "plpgsql" |
@@ -44,6 +44,16 @@ ActiveRecord::Schema.define(version: 20140923061213) do |
||
| 44 | 44 |
add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree |
| 45 | 45 |
add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree |
| 46 | 46 |
|
| 47 |
+ create_table "infos", force: true do |t| |
|
| 48 |
+ t.string "website_name" |
|
| 49 |
+ t.string "tagline" |
|
| 50 |
+ t.string "logo" |
|
| 51 |
+ t.string "contact_email" |
|
| 52 |
+ t.string "default_language" |
|
| 53 |
+ t.datetime "created_at" |
|
| 54 |
+ t.datetime "updated_at" |
|
| 55 |
+ end |
|
| 56 |
+ |
|
| 47 | 57 |
create_table "uploads", force: true do |t| |
| 48 | 58 |
t.string "title" |
| 49 | 59 |
t.string "file" |
@@ -0,0 +1,17 @@ |
||
| 1 |
+namespace :bootstrap do |
|
| 2 |
+ |
|
| 3 |
+ desc "Add the Admin user" |
|
| 4 |
+ task :admin => :environment do |
|
| 5 |
+ User.create( :first_name => 'admin', :email => 'admin@website.com', :password => '12345678', :admin => true ) |
|
| 6 |
+ puts "Admin user created. \n- Email: admin@website.com \n- Password: 12345678" |
|
| 7 |
+ end |
|
| 8 |
+ |
|
| 9 |
+ desc "Create website configuration" |
|
| 10 |
+ task :config => :environment do |
|
| 11 |
+ Info.create( :website_name => 'Website', :tagline => 'A Ruby on Rails app template', :default_language => 'en' ) |
|
| 12 |
+ puts "Website configured!" |
|
| 13 |
+ end |
|
| 14 |
+ |
|
| 15 |
+ desc "Run all bootstrapping tasks" |
|
| 16 |
+ task :all => [:admin, :config] |
|
| 17 |
+ end |
@@ -39,3 +39,15 @@ Other features are still under development: |
||
| 39 | 39 |
- [benjaminperet](http://benjaminperet.com) (Under Development) |
| 40 | 40 |
- [High Effects](http://higheffects.com.br) (Upgrade/Rewrite) |
| 41 | 41 |
|
| 42 |
+## Configurations |
|
| 43 |
+ |
|
| 44 |
+* Website Name |
|
| 45 |
+* Tagline |
|
| 46 |
+* Logo |
|
| 47 |
+* Contact Email |
|
| 48 |
+* Default Language |
|
| 49 |
+ |
|
| 50 |
+* Maintaince Mode (Boolean) |
|
| 51 |
+* Maintance Mode Message |
|
| 52 |
+ |
|
| 53 |
+* Modules |
@@ -0,0 +1,15 @@ |
||
| 1 |
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html |
|
| 2 |
+ |
|
| 3 |
+one: |
|
| 4 |
+ website_name: MyString |
|
| 5 |
+ tagline: MyString |
|
| 6 |
+ logo: MyString |
|
| 7 |
+ contact_email: MyString |
|
| 8 |
+ default_language: MyString |
|
| 9 |
+ |
|
| 10 |
+two: |
|
| 11 |
+ website_name: MyString |
|
| 12 |
+ tagline: MyString |
|
| 13 |
+ logo: MyString |
|
| 14 |
+ contact_email: MyString |
|
| 15 |
+ default_language: MyString |
@@ -0,0 +1,7 @@ |
||
| 1 |
+require 'test_helper' |
|
| 2 |
+ |
|
| 3 |
+class InfoTest < ActiveSupport::TestCase |
|
| 4 |
+ # test "the truth" do |
|
| 5 |
+ # assert true |
|
| 6 |
+ # end |
|
| 7 |
+end |