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 7d29877..02c57ef 100644 --- a/Gemfile +++ b/Gemfile @@ -56,12 +56,14 @@ # --------------------------------------------------------------------------------------------- # VIEWS +gem 'sass-rails' +gem 'less-rails' # WE SHOULD PROBABLY USE SASS OR LESS NOT BOTH gem 'jquery-rails' gem 'twitter-bootstrap-rails', '2.2.8' gem 'tinymce-rails' # WYSIWYG EDITOR gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE gem 'recaptcha' -#implementation of forms +gem 'dragonfly' # LOGO UPLOAD # --------------------------------------------------------------------------------------------- # EXPORTING @@ -91,9 +93,6 @@ group :development, :test do gem "byebug" - - gem 'sass-rails' - gem 'less-rails' # WE SHOULD PROBABLY USE SASS OR LESS NOT BOTH end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 78a29ed..39a0c98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,6 +112,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) erubis (2.7.0) eventmachine (1.2.0.1) execjs (2.7.0) @@ -324,6 +328,7 @@ contact_us (>= 1.2.0) devise devise_invitable + dragonfly feedjira friendly_id htmltoword 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/environments/development.rb b/config/environments/development.rb index 7abb30e..93edc60 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -26,7 +26,7 @@ # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. - config.assets.digest = true + config.assets.digest = false # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. 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 f423d90..0ee0ccd 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 9aae42a..44466b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,7 @@ # you'll amass, the slower it'll run and the greater likelihood for issues). # # 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 @@ -33,8 +31,8 @@ t.integer "user_id", limit: 4 t.integer "question_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" t.boolean "archived" t.integer "plan_id", limit: 4 t.integer "archived_by", limit: 4 @@ -87,7 +85,7 @@ end create_table "friendly_id_slugs", force: :cascade do |t| - t.string "slug", limit: 255, null: false + t.string "slug", limit: 191, null: false t.integer "sluggable_id", limit: 4, null: false t.string "sluggable_type", limit: 40 t.datetime "created_at" @@ -100,8 +98,8 @@ create_table "guidance_groups", force: :cascade do |t| t.string "name", limit: 255 t.integer "organisation_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "optional_subset" t.boolean "published" end @@ -142,8 +140,8 @@ t.string "text", limit: 255 t.integer "number", limit: 4 t.boolean "is_default" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" end create_table "org_token_permissions", force: :cascade do |t| @@ -178,6 +176,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| @@ -185,9 +185,9 @@ t.text "description", limit: 65535 t.integer "number", limit: 4 t.integer "dmptemplate_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "slug", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + t.string "slug", limit: 191 end add_index "phases", ["dmptemplate_id"], name: "index_phases_on_dmptemplate_id", using: :btree @@ -215,8 +215,8 @@ t.boolean "project_editor" t.integer "user_id", limit: 4 t.integer "project_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "project_administrator" end @@ -230,9 +230,9 @@ create_table "projects", force: :cascade do |t| t.string "title", limit: 255 t.integer "dmptemplate_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "slug", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + t.string "slug", limit: 191 t.integer "organisation_id", limit: 4 t.string "grant_number", limit: 255 t.string "identifier", limit: 255 @@ -286,9 +286,9 @@ end create_table "roles", force: :cascade do |t| - t.string "name", limit: 255 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.string "name", limit: 191 + t.datetime "created_at" + t.datetime "updated_at" t.boolean "role_in_plans" t.integer "resource_id", limit: 4 t.string "resource_type", limit: 255 @@ -303,18 +303,18 @@ t.integer "number", limit: 4 t.integer "version_id", limit: 4 t.integer "organisation_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "published" end create_table "settings", force: :cascade do |t| - t.string "var", limit: 255, null: false + t.string "var", limit: 191, null: false 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.string "target_type", limit: 191, 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 @@ -329,8 +329,8 @@ t.integer "question_id", limit: 4 t.integer "organisation_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" t.boolean "is_example" end @@ -386,7 +386,7 @@ create_table "users", force: :cascade do |t| t.string "firstname", limit: 255 t.string "surname", limit: 255 - t.string "email", limit: 255, default: "", null: false + t.string "email", limit: 191, default: "", null: false t.string "orcid_id", limit: 255 t.string "shibboleth_id", limit: 255 t.integer "user_type_id", limit: 4 @@ -394,7 +394,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "encrypted_password", limit: 255, default: "" - t.string "reset_password_token", limit: 255 + t.string "reset_password_token", limit: 191 t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", limit: 4, default: 0 @@ -402,14 +402,15 @@ t.datetime "last_sign_in_at" t.string "current_sign_in_ip", limit: 255 t.string "last_sign_in_ip", limit: 255 - t.string "confirmation_token", limit: 255 + t.string "confirmation_token", limit: 191 t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "invitation_token", limit: 255 + t.string "invitation_token", limit: 191 t.datetime "invitation_created_at" t.datetime "invitation_sent_at" t.datetime "invitation_accepted_at" t.string "other_organisation", limit: 255 + t.boolean "dmponline3" t.boolean "accept_terms" t.integer "organisation_id", limit: 4 t.string "api_token", limit: 255