diff --git a/.gitignore b/.gitignore index 960fdd4..ee170d8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,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 1da4a0b..eaed3ba 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -1,20 +1,23 @@ class Organisation < ActiveRecord::Base include GlobalHelpers - #associations between tables - belongs_to :organisation_type - has_many :guidance_groups - has_many :dmptemplates - has_many :sections - has_many :users, through: :user_org_roles - has_many :option_warnings - has_many :suggested_answers - has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions" - has_many :user_org_roles + extend Dragonfly::Model::Validations - belongs_to :parent, :class_name => 'Organisation' + #associations between tables + belongs_to :organisation_type + has_many :guidance_groups + has_many :dmptemplates + has_many :sections + has_many :users, through: :user_org_roles + has_many :option_warnings + has_many :suggested_answers + has_and_belongs_to_many :token_permission_types, join_table: "org_token_permissions" - has_one :language + has_many :user_org_roles + + belongs_to :parent, :class_name => 'Organisation' + + has_one :language has_many :children, :class_name => 'Organisation', :foreign_key => 'parent_id' @@ -22,11 +25,20 @@ accepts_nested_attributes_for :dmptemplates accepts_nested_attributes_for :token_permission_types - attr_accessible :abbreviation, :banner_text, :description, :domain, - :logo_file_name, :name, :stylesheet_file_id, :target_url, + 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, :language_id + # 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 ## # returns the name of the organisation diff --git a/app/views/layouts/_dmponline_header.html.erb b/app/views/layouts/_dmponline_header.html.erb index b02f3dd..b80c58b 100644 --- a/app/views/layouts/_dmponline_header.html.erb +++ b/app/views/layouts/_dmponline_header.html.erb @@ -1,23 +1,27 @@ - - -
-
- -
-
-
- <%= render "layouts/dmponline_org_branding" %> -
- - - - - -
-
\ No newline at end of file + + +
+
+ +
+
+
+ <%= render "layouts/dmponline_org_branding" %> +
+ + + + + +
+
diff --git a/app/views/organisations/admin_edit.html.erb b/app/views/organisations/admin_edit.html.erb index 109a94f..c03379c 100644 --- a/app/views/organisations/admin_edit.html.erb +++ b/app/views/organisations/admin_edit.html.erb @@ -1,98 +1,99 @@ -<%= stylesheet_link_tag "admin" %> -<% javascript 'admin.js' %> - -

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

- -
- -
- - <%= 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 %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%= t('org_admin.org_name') %><%= f.text_field :name, - :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.name_help_text') %>
<%= t('org_admin.org_abbr') %> -
- <%= f.text_field :abbreviation, - :as => :string, - :class => 'text_field' %> -
-
- <%= link_to(image_tag('help_button.png'), '#', :class => 'org_abbr_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html')) %> -
-
-
<%= t('org_admin.org_desc') %><%= f.text_area :description, { - :rows => 5, - :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title' => t('org_admin.desc_help_text_html')} %>
<%= t('org_admin.org_banner_text') %> - <%= text_area_tag("org_banner_text", @organisation.banner_text, class: "tinymce") %> -
<%= t('org_admin.org_target_url') %><%= f.text_field :target_url, - :as => :string, - :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.target_url_help_text') %>
<%= t('org_admin.org_default_language') %> -
- <%= collection_select(:@organisation, - :language_id, Language.all.order("name"), - :id, :name, {selected: Language.where(default_language: true).first.id}, - {:class => "typeahead org_sign_up"}) %> -
-
- <%= link_to(image_tag('help_button.png'), '#', :class => 'org_abbr_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.org_default_language_help_text')) %> -
-
-
<%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
- -
-
- - - -
- <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> - <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn btn-primary' %> -
- -
- <% end %> -
-
- -<%= tinymce :content_css => asset_path('application.css') %> +<%= stylesheet_link_tag "admin" %> +<% javascript 'admin.js' %> + +<% if @organisation.errors.any? %> + +<% end %> +

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

+ +
+ +
+ <%= form_for(@organisation, :url => admin_update_organisation_path(@organisation), :html => { :multipart => true, :id => "edit_org_details", :method => :put}) do |f| %> + + + + + + + + + + + + + <% if @organisation.logo.present? then%> + + + + + + + + + <%end%> + + + + + + + + + + + + + + + + + + + + + + + +
<%= t('org_admin.org_name') %><%= f.text_field :name, + :as => :string, + :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.name_help_text') %>
<%= t('org_admin.org_abbr') %>
+ <%= f.text_field :abbreviation, + :as => :string, + :class => 'text_field' %> +
+
+ <%= link_to( image_tag('help_button.png'), '#', :class => 'org_abbr_popover', :rel => "popover", 'data-html' => "true", 'data-content' => t('org_admin.templates.desc_help_text_html'))%> +
+
+
<%= 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, { + :rows => 5, + :class => 'text_area has-tooltip', 'data-toggle' => "tooltip", 'data-html' => "true", 'title'=> t('org_admin.desc_help_text_html')} %>
<%= t('org_admin.org_banner_text') %> + <%= text_area_tag("org_banner_text", @organisation.banner_text, class: "tinymce") %> +
<%= t('org_admin.org_target_url') %><%= f.text_field :target_url, + :as => :string, + :class => 'text_field has-tooltip', 'data-toggle' => "tooltip", 'title' => t('org_admin.target_url_help_text') %>
<%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
+ +
+
+ + + +
+ <%= f.submit t('helpers.submit.save'), :class => 'btn btn-primary' %> + <%= link_to t('helpers.submit.cancel'), :back, :class => 'btn btn-primary' %> +
+ +
+ <%end%> +
+
+ +<%= tinymce :content_css => asset_path('application.css') %> + diff --git a/app/views/organisations/admin_show.html.erb b/app/views/organisations/admin_show.html.erb index cd6b834..c412b82 100644 --- a/app/views/organisations/admin_show.html.erb +++ b/app/views/organisations/admin_show.html.erb @@ -1,80 +1,80 @@ -<%= stylesheet_link_tag "admin" %> - -

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

-<%= t('org_admin.org_text')%> -
-
- -
- -
- - - <% if @organisation.logo_file_name.present? then%> -
- <%= image_tag("#{@organisation.logo_file_name}", class: "org_logo_admin_area" )%> -
- <%end%> - - - - <% if @organisation.name.present? then%> - - - - - <%end%> - <% if @organisation.abbreviation.present? then%> - - - - - <%end%> - <% if @organisation.description.present? then%> - - - - - <%end%> - <% if @organisation.banner_text.present? then%> - - - - - <%end%> - <% if @organisation.target_url.present? then%> - - - - - <%end%> - <% if @organisation.organisation_type_id.present? then%> - - - - - <%end%> - <% if @organisation.parent_id.present? then%> - - - - - <%end%> - - - - -
<%= t('org_admin.org_name') %><%= @organisation.name %>
<%= t('org_admin.org_abbr') %><%= @organisation.abbreviation %>
<%= t('org_admin.org_desc') %><%= raw @organisation.description %>
<%= t('org_admin.org_banner_text') %><%= raw @organisation.banner_text %>
<%= t('org_admin.org_target_url') %><%= @organisation.target_url %>
<%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
<%= t('org_admin.parent_org') %><%= @organisation.parent.name %>
<%= t('org_admin.last_updated') %><%= l @organisation.updated_at.to_date, :formats => :short %>
- -
-
-
- <%= link_to t("helpers.submit.edit"), admin_edit_organisation_path(current_user.organisation), :class => 'btn btn-primary'%> -
-
-
-
\ No newline at end of file +<%= stylesheet_link_tag "admin" %> + +

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

+<%= t('org_admin.org_text')%> +
+
+ +
+ +
+ + + + <% if @organisation.name.present? then%> + + + + + <%end%> + <% if @organisation.abbreviation.present? then%> + + + + + <%end%> + <% if @organisation.logo.present? then%> + + + + + <%end%> + <% if @organisation.description.present? then%> + + + + + <%end%> + <% if @organisation.banner_text.present? then%> + + + + + <%end%> + <% if @organisation.target_url.present? then%> + + + + + <%end%> + <% if @organisation.organisation_type_id.present? then%> + + + + + <%end%> + <% if @organisation.parent_id.present? then%> + + + + + <%end%> + + + + +
<%= t('org_admin.org_name') %><%= @organisation.name %>
<%= t('org_admin.org_abbr') %><%= @organisation.abbreviation %>
<%= t('org_admin.org_logo') %><%= image_tag @organisation.logo.thumb('100x100%').url %>
<%= t('org_admin.org_desc') %><%= raw @organisation.description %>
<%= t('org_admin.org_banner_text') %><%= raw @organisation.banner_text %>
<%= t('org_admin.org_target_url') %><%= @organisation.target_url %>
<%= t('org_admin.org_type') %><%= @organisation.organisation_type.name %>
<%= t('org_admin.parent_org') %><%= @organisation.parent.name %>
<%= t('org_admin.last_updated') %><%= l @organisation.updated_at.to_date, :formats => :short %>
+ +
+
+
+ <%= link_to t("helpers.submit.edit"), admin_edit_organisation_path(current_user.organisation), :class => 'btn btn-primary'%> +
+
+
+
+>>>>>>> d191694e1cedc43d310c37ca7ceae733e677fb03 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 c3c1b1b..8cd2188 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -149,6 +149,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" 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 518755e..22e68cf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160805105941) do +ActiveRecord::Schema.define(version: 20160810193149) do + create_table "answers", force: :cascade do |t| t.text "text", limit: 65535 t.integer "plan_id", limit: 4 @@ -177,6 +178,8 @@ 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|