diff --git a/.gitignore b/.gitignore index 59dd548..0d8da22 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ # Ignore all logfiles, tempfiles, public assets, /log/*.log /tmp +public/system/* public/assets/* public/apidocs/* diff --git a/Gemfile b/Gemfile index 41541aa..9947167 100644 --- a/Gemfile +++ b/Gemfile @@ -80,6 +80,10 @@ gem 'turbolinks' #implementation of forms gem 'activeadmin', github: 'activeadmin' +# +# LOGO UPLOAD +# +gem 'dragonfly' # # EXPORTING PLANS diff --git a/Gemfile.lock b/Gemfile.lock index b4c911a..afb8242 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -116,6 +116,10 @@ devise_invitable (1.7.0) actionmailer (>= 4.0.0) devise (>= 4.0.0) + dragonfly (1.0.12) + addressable (~> 2.3) + multi_json (~> 1.0) + rack (>= 1.3.0) email_validator (1.6.0) activemodel erubis (2.7.0) @@ -343,6 +347,7 @@ contact_us (>= 1.2.0) devise devise_invitable + dragonfly email_validator exception_notification feedjira diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 45121e5..7caca1c 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -25,7 +25,7 @@ # POST /organisations.json def create @organisation = Organisation.new(params[:organisation]) - + @organisation.logo = param[:organisation][:logo] respond_to do |format| if @organisation.save format.html { redirect_to @organisation, notice: I18n.t("admin.org_created_message") } @@ -71,14 +71,17 @@ if user_signed_in? && current_user.is_org_admin? then @organisation = Organisation.find(params[:id]) @organisation.banner_text = params["org_banner_text"] - + @organisation.logo = params[:organisation][:logo] if params[:organisation][:logo] + assign_params = params[:organisation].dup + assign_params.delete(:logo) respond_to do |format| - if @organisation.update_attributes(params[:organisation]) + if @organisation.update_attributes(assign_params) format.html { redirect_to admin_show_organisation_path(params[:id]), notice: I18n.t("admin.org_updated_message") } format.json { head :no_content } else - format.html { render action: "edit" } + flash[:alert] = I18n.t("org_admin.org_logo_failed_message") + format.html { render action: "admin_edit" } format.json { render json: @organisation.errors, status: :unprocessable_entity } end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index a1eef16..71515c9 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,4 +1,5 @@ class Organisation < ActiveRecord::Base + extend Dragonfly::Model::Validations #associations between tables belongs_to :organisation_type has_many :guidance_groups @@ -19,11 +20,18 @@ accepts_nested_attributes_for :dmptemplates accepts_nested_attributes_for :token_permission_types - attr_accessible :abbreviation, :banner_text, :description, :domain, + attr_accessible :abbreviation, :banner_text, :logo, :remove_logo, :description, :domain, :logo_file_name, :name, :stylesheet_file_id, :target_url, :organisation_type_id, :wayfless_entity, :parent_id, :sort_name, :token_permission_type_ids + ## + # allow validations for logo upload + dragonfly_accessor :logo + validates_property :height, of: :logo, in: (0..100) + validates_property :format, of: :logo, in: ['jpeg', 'png', 'gif','jpg','bmp'] + validates_size_of :logo, maximum: 500.kilobytes + def to_s name end diff --git a/app/views/layouts/_dmponline_header.html.erb b/app/views/layouts/_dmponline_header.html.erb index 44a58af..b80c58b 100644 --- a/app/views/layouts/_dmponline_header.html.erb +++ b/app/views/layouts/_dmponline_header.html.erb @@ -3,7 +3,11 @@
@@ -20,4 +24,4 @@
- \ No newline at end of file + diff --git a/app/views/organisations/admin_edit.html.erb b/app/views/organisations/admin_edit.html.erb index 399be54..d1f918f 100644 --- a/app/views/organisations/admin_edit.html.erb +++ b/app/views/organisations/admin_edit.html.erb @@ -1,6 +1,13 @@ <%= stylesheet_link_tag "admin" %> <% javascript 'admin.js' %> +<% if @organisation.errors.any? %> + +<% end %>

<%= t('org_admin.org_details_label') %>

@@ -8,15 +15,7 @@
- - <%= form_for(@organisation, :url => admin_update_organisation_path(@organisation), :html => { :id => "edit_org_details", :method => :put}) do |f| %> - - <% if @organisation.logo_file_name.present? then%> -
- <%= image_tag("#{@organisation.logo_file_name}", class: "org_logo_admin_area" )%> -
- <%end%> - + <%= form_for(@organisation, :url => admin_update_organisation_path(@organisation), :html => { :multipart => true, :id => "edit_org_details", :method => :put}) do |f| %> @@ -39,6 +38,24 @@ + + <% if @organisation.logo.present? then%> + + + + + + + + + <%end%> + + + + + + +
<%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.url %>
<%= f.check_box :remove_logo %>   <%= t('org_admin.remove_logo') %>
<%= t('org_admin.new_org_logo') %><%= f.file_field :logo %>
<%= t('org_admin.org_desc') %> <%= f.text_area :description, { diff --git a/app/views/organisations/admin_show.html.erb b/app/views/organisations/admin_show.html.erb index 501fce5..e502a8a 100644 --- a/app/views/organisations/admin_show.html.erb +++ b/app/views/organisations/admin_show.html.erb @@ -13,13 +13,6 @@
- - <% if @organisation.logo_file_name.present? then%> -
- <%= image_tag("#{@organisation.logo_file_name}", class: "org_logo_admin_area" )%> -
- <%end%> - <% if @organisation.name.present? then%> @@ -34,6 +27,12 @@ <%end%> + <% if @organisation.logo.present? then%> + + + + + <%end%> <% if @organisation.description.present? then%> @@ -77,4 +76,4 @@
- \ No newline at end of file + diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb new file mode 100644 index 0000000..7e74f09 --- /dev/null +++ b/config/initializers/dragonfly.rb @@ -0,0 +1,26 @@ +require 'dragonfly' + +# Configure +Dragonfly.app.configure do + plugin :imagemagick + + secret "9188325fe2fc25afb4eff83fe9c172f8a324d056c359db4fac11d93ecd3e3865" + + url_format "/media/:job/:name" + + datastore :file, + root_path: Rails.root.join('public/system/dragonfly', Rails.env), + server_root: Rails.root.join('public') +end + +# Logger +Dragonfly.logger = Rails.logger + +# Mount as middleware +Rails.application.middleware.use Dragonfly::Middleware + +# Add model functionality +if defined?(ActiveRecord::Base) + ActiveRecord::Base.extend Dragonfly::Model + ActiveRecord::Base.extend Dragonfly::Model::Validations +end diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 6f75a06..c79e4ef 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -141,6 +141,10 @@ user_text_html: "Below is a list of users registered for your organisation. You can sort the data by each field." org_name: "Name" org_abbr: "Abbreviation" + org_logo_failed_message: "Logo Upload Failed. " + org_logo: "Logo" + new_org_logo: "Upload a new logo file" + remove_logo: "If you decide to use the default DCC logo, please check this box to remove your current logo." org_desc: "Description" org_banner_text: "Top banner text" org_target_url: "Website" @@ -924,4 +928,4 @@ org_not_funder: '{"Error":"Organisation specified is not a funder"}' org_multiple_templates: '{"Error":"Organisation has more than one template and template name unspecified or invalid"}' no_auth_for_endpoint: '{"Error":"You do not have authorisation to view this endpoint"}' - bad_resource: '{"Error":"You do not have authorisation to view this resource"}' \ No newline at end of file + bad_resource: '{"Error":"You do not have authorisation to view this resource"}' diff --git a/db/migrate/20160810193149_add_logouid_to_organisations.rb b/db/migrate/20160810193149_add_logouid_to_organisations.rb new file mode 100644 index 0000000..0e94076 --- /dev/null +++ b/db/migrate/20160810193149_add_logouid_to_organisations.rb @@ -0,0 +1,6 @@ +class AddLogouidToOrganisations < ActiveRecord::Migration + def change + add_column :organisations, :logo_uid, :string + add_column :organisations, :logo_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 99132ed..22e68cf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160719140055) do +ActiveRecord::Schema.define(version: 20160810193149) do create_table "answers", force: :cascade do |t| t.text "text", limit: 65535 @@ -86,9 +86,9 @@ t.datetime "updated_at" end - create_table "friendly_id_slugs", force: true do |t| - t.string "slug", limit: 191, null: false - t.integer "sluggable_id", null: false + create_table "friendly_id_slugs", force: :cascade do |t| + t.string "slug", limit: 255, null: false + t.integer "sluggable_id", limit: 4, null: false t.string "sluggable_type", limit: 40 t.datetime "created_at" end @@ -123,17 +123,18 @@ end create_table "languages", force: :cascade do |t| - t.string "abbreviation", limit: 255 - t.string "description", limit: 255 - t.string "name", limit: 255 + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 + t.boolean "default_language", limit: 1 end create_table "option_warnings", force: :cascade do |t| t.integer "organisation_id", limit: 4 t.integer "option_id", limit: 4 t.text "text", limit: 65535 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "options", force: :cascade do |t| @@ -175,6 +176,10 @@ t.string "sort_name", limit: 255 t.text "banner_text", limit: 65535 t.string "logo_file_name", limit: 255 + t.integer "region_id", limit: 4 + t.integer "language_id", limit: 4 + t.string "logo_uid", limit: 255 + t.string "logo_name", limit: 255 end create_table "phases", force: :cascade do |t| @@ -184,7 +189,7 @@ t.integer "dmptemplate_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 + t.string "slug", limit: 255 end add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id", using: :btree @@ -229,15 +234,15 @@ t.integer "dmptemplate_id", limit: 4 t.datetime "created_at" t.datetime "updated_at" - t.string "slug", limit: 191 - t.integer "organisation_id" - t.string "grant_number" - t.string "identifier" - t.text "description" - t.string "principal_investigator" - t.string "principal_investigator_identifier" - t.string "data_contact" - t.string "funder_name" + t.string "slug", limit: 255 + t.integer "organisation_id", limit: 4 + t.string "grant_number", limit: 255 + t.string "identifier", limit: 255 + t.text "description", limit: 65535 + t.string "principal_investigator", limit: 255 + t.string "principal_investigator_identifier", limit: 255 + t.string "data_contact", limit: 255 + t.string "funder_name", limit: 255 end add_index "projects", ["slug"], name: "index_projects_on_slug", unique: true, using: :btree @@ -271,8 +276,19 @@ add_index "questions_themes", ["question_id", "theme_id"], name: "index_questions_themes_on_question_id_and_theme_id", using: :btree - create_table "roles", force: true do |t| - t.string "name", limit: 191 + create_table "region_groups", force: :cascade do |t| + t.integer "super_region_id", limit: 4 + t.integer "region_id", limit: 4 + end + + create_table "regions", force: :cascade do |t| + t.string "abbreviation", limit: 255 + t.string "description", limit: 255 + t.string "name", limit: 255 + end + + create_table "roles", force: :cascade do |t| + t.string "name", limit: 255 t.datetime "created_at" t.datetime "updated_at" t.boolean "role_in_plans", limit: 1 @@ -299,8 +315,8 @@ t.text "value", limit: 65535 t.integer "target_id", limit: 4, null: false t.string "target_type", limit: 255, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end add_index "settings", ["target_type", "target_id", "var"], name: "index_settings_on_target_type_and_target_id_and_var", unique: true, using: :btree @@ -344,8 +360,8 @@ t.integer "user_id", limit: 4 t.integer "organisation_id", limit: 4 t.integer "user_role_type_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "user_role_types", force: :cascade do |t| @@ -377,8 +393,8 @@ t.string "shibboleth_id", limit: 255 t.integer "user_type_id", limit: 4 t.integer "user_status_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.string "encrypted_password", limit: 255, default: "" t.string "reset_password_token", limit: 255 t.datetime "reset_password_sent_at" @@ -402,6 +418,7 @@ t.string "api_token", limit: 255 t.integer "invited_by_id", limit: 4 t.string "invited_by_type", limit: 255 + t.integer "language_id", limit: 4 end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
<%= @organisation.abbreviation %>
<%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.thumb('100x100%').url %>
<%= t('org_admin.org_desc') %>