diff --git a/.gitignore b/.gitignore
index 2b59cc6..df7a132 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@
# Ignore database configuration and token secrets
config/database.yml
config/secrets.yml
+config/branding.yml
# Ignore some of the initializers
config/initializers/recaptcha.rb
diff --git a/Gemfile b/Gemfile
index 017d396..0bd6fff 100644
--- a/Gemfile
+++ b/Gemfile
@@ -34,7 +34,7 @@
# ------------------------------------------------
# SUPER ADMIN SECTION
-gem "administrate", :github => 'thoughtbot/administrate', :branch =>'v0.4.0'
+gem "administrate", :github => 'thoughtbot/administrate', :branch =>'master' #:branch =>'v0.4.0'
# ------------------------------------------------
# USERS
diff --git a/Gemfile.lock b/Gemfile.lock
index 51506da..9784215 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,17 +1,17 @@
GIT
remote: git://github.com/thoughtbot/administrate.git
- revision: 5ee0c2ffe4de99ebf639befd63831c1083dc535f
- branch: v0.4.0
+ revision: 47a2f99e22be87119ef0e3a7af3956984df5842c
+ branch: master
specs:
administrate (0.4.0)
autoprefixer-rails (~> 6.0)
- bourbon (~> 4.2)
+ bourbon (>= 5.0.0.beta.6)
datetime_picker_rails (~> 0.0.7)
jquery-rails (~> 4.0)
- kaminari (~> 0.16)
+ kaminari (>= 1.0)
momentjs-rails (~> 2.8)
neat (~> 1.1)
- normalize-rails (~> 3.0)
+ normalize-rails (>= 3.0)
rails (>= 4.2, < 5.1)
sass-rails (~> 5.0)
selectize-rails (~> 0.6)
@@ -65,7 +65,7 @@
addressable (2.4.0)
ansi (1.5.0)
arel (6.0.3)
- autoprefixer-rails (6.7.6)
+ autoprefixer-rails (6.7.7.1)
execjs
bcrypt (3.1.11)
better_errors (2.1.1)
@@ -74,9 +74,9 @@
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
- bourbon (4.3.3)
- sass (~> 3.4)
- thor (~> 0.19)
+ bourbon (5.0.0.beta.7)
+ sass (~> 3.4.22)
+ thor (~> 0.19.1)
builder (3.2.2)
byebug (9.0.5)
capybara (2.9.1)
@@ -158,9 +158,18 @@
thor (>= 0.14, < 2.0)
json (1.8.3)
jwt (1.5.6)
- kaminari (0.17.0)
- actionpack (>= 3.0.0)
- activesupport (>= 3.0.0)
+ kaminari (1.0.1)
+ activesupport (>= 4.1.0)
+ kaminari-actionview (= 1.0.1)
+ kaminari-activerecord (= 1.0.1)
+ kaminari-core (= 1.0.1)
+ kaminari-actionview (1.0.1)
+ actionview
+ kaminari-core (= 1.0.1)
+ kaminari-activerecord (1.0.1)
+ activerecord
+ kaminari-core (= 1.0.1)
+ kaminari-core (1.0.1)
ledermann-rails-settings (2.4.2)
activerecord (>= 3.1)
less (2.6.0)
@@ -211,7 +220,7 @@
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
- normalize-rails (3.0.3)
+ normalize-rails (4.1.1)
oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb
index c60fbd3..498603b 100644
--- a/app/controllers/answers_controller.rb
+++ b/app/controllers/answers_controller.rb
@@ -36,6 +36,41 @@
@answer.update(params[:answer])
end
+ @section_id = @answer.question.section.id
+
+ # these are used for updating the status line
+ @username = @answer.user.name
+ @timestamp = ""
+
+ if @answer.text.present?
+ @timestamp = @answer.updated_at.iso8601
+ end
+
+
+ @nquestions = 0
+ @nanswers = 0
+ @n_section_questions = 0
+ @n_section_answers = 0
+
+ plan = Plan.find(plan_id)
+ plan.template.phases.each do |phase|
+ phase.sections.each do |section|
+ section.questions.each do |question|
+ @nquestions += 1
+ if section.id == @section_id
+ @n_section_questions += 1
+ end
+ question.answers = question.answers.to_a.select {|answer| answer.plan_id == plan.id}
+ if question.answers.present? && question.answers.first.text.present?
+ @nanswers += 1
+ if section.id == @section_id
+ @n_section_answers += 1
+ end
+ end
+ end
+ end
+ end
+
respond_to do |format|
# pass new lock_version back to the client or they'll never save again
@lock_version = @answer.lock_version
@@ -49,4 +84,5 @@
format.js {}
end
end
+
end
diff --git a/app/controllers/guidance_groups_controller.rb b/app/controllers/guidance_groups_controller.rb
index 585f32c..9d7706f 100644
--- a/app/controllers/guidance_groups_controller.rb
+++ b/app/controllers/guidance_groups_controller.rb
@@ -9,11 +9,11 @@
end
- # GET add new guidance groups
- def admin_new
+ # GET add new guidance groups
+ def admin_new
@guidance_group = GuidanceGroup.new
authorize @guidance_group
- end
+ end
# POST /guidance_groups
@@ -36,16 +36,17 @@
# GET /guidance_groups/1/edit
def admin_edit
- @guidance_group = GuidanceGroup.find(params[:id])
- authorize @guidance_group
+ @guidance_group = GuidanceGroup.find(params[:id])
+ authorize @guidance_group
end
# PUT /guidance_groups/1
def admin_update
- @guidance_group = GuidanceGroup.find(params[:id])
+ @guidance_group = GuidanceGroup.find(params[:id])
authorize @guidance_group
@guidance_group.org_id = current_user.org_id
+ @guidance_group.published = true unless params[:save_publish].nil?
if @guidance_group.update_attributes(params[:guidance_group])
redirect_to admin_index_guidance_path(params[:guidance_group]), notice: _('Guidance group was successfully updated.')
@@ -57,7 +58,7 @@
# PUT /guidance_groups/1
def admin_update_publish
- @guidance_group = GuidanceGroup.find(params[:id])
+ @guidance_group = GuidanceGroup.find(params[:id])
authorize @guidance_group
@guidance_group.org.id = current_user.org.id
@guidance_group.published = true
@@ -73,11 +74,11 @@
# DELETE /guidance_groups/1
# DELETE /guidance_groups/1.json
def admin_destroy
- @guidance_group = GuidanceGroup.find(params[:id])
+ @guidance_group = GuidanceGroup.find(params[:id])
authorize @guidance_group
@guidance_group.destroy
redirect_to admin_index_guidance_path, notice: _('Guidance group was successfully deleted.')
- end
+ end
end
\ No newline at end of file
diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb
index 674e0f6..123b334 100644
--- a/app/controllers/guidances_controller.rb
+++ b/app/controllers/guidances_controller.rb
@@ -13,7 +13,7 @@
##
# GET /guidances/1
def admin_show
- @guidance = Guidance.includes(:guidance_group, :question, :themes).find(params[:id])
+ @guidance = Guidance.includes(:guidance_group, :themes).find(params[:id])
authorize @guidance
end
@@ -21,36 +21,7 @@
@guidance = Guidance.new
authorize @guidance
- #@templates = Template.funders_and_own_templates(current_user.org_id)
- # Replacing weird accessor on Template
- @templates = (Org.funders.collect{|o| o.templates } + current_user.org.templates).flatten
-
- @phases = nil
- @templates.includes(:phases).each do |template|
- if @phases.nil? then
- @phases = template.phases.all.order('number')
- else
- @phases = @phases + template.phases.all.order('number')
- end
- end
- @sections = nil
- @phases.each do |phase|
- if @sections.nil? then
- @sections = phase.sections.all.order('number')
- else
- @sections = @sections + phase.sections.all.order('number')
- end
- end
- @questions = nil
- @sections.each do |section|
- if @questions.nil? then
- @questions = section.questions.all.order('number')
- else
- @questions = @questions + section.questions.all.order('number')
- end
- end
- @themes = Theme.all.order('title')
- @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
+ load_select_box_content
end
#setup variables for use in the dynamic updating
@@ -96,19 +67,19 @@
def admin_edit
@guidance = Guidance.includes(:themes, :guidance_group).find(params[:id])
authorize @guidance
- @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
- @themes = Theme.all.order('title')
+
+ load_select_box_content
end
##
# POST /guidances
def admin_create
- @guidance = Guidance.new(params[:guidance])
+ @guidance = Guidance.new(guidance_params)
authorize @guidance
@guidance.text = params["guidance-text"]
@guidance.question_id = params["question_id"]
if @guidance.published == true then
- @gg = GuidanceGroup.find(@guidance.guidance_group_ids).first
+ @gg = GuidanceGroup.find(@guidance.guidance_group_id)
if @gg.published == false || @gg.published.nil? then
@gg.published = true
@gg.save
@@ -118,7 +89,8 @@
if @guidance.save
redirect_to admin_show_guidance_path(@guidance), notice: _('Guidance was successfully created.')
else
- render action: "new"
+ load_select_box_content
+ render action: "admin_new"
end
end
@@ -133,7 +105,8 @@
if @guidance.update_attributes(params[:guidance])
redirect_to admin_show_guidance_path(params[:guidance]), notice: _('Guidance was successfully updated.')
else
- render action: "edit"
+ load_select_box_content
+ render action: "admin_edit"
end
end
@@ -147,4 +120,43 @@
redirect_to admin_index_guidance_path
end
+
+ private
+ def guidance_params
+ # The form on the page is weird. The text and template/section/question stuff is outside of the normal form params
+ params.require(:guidance).permit(:guidance_group_id, :theme_ids, :published)
+ end
+
+ def load_select_box_content
+ #@templates = Template.funders_and_own_templates(current_user.org_id)
+ # Replacing weird accessor on Template
+ @templates = (Org.funders.collect{|o| o.templates } + current_user.org.templates).flatten
+
+ @phases = nil
+ @templates.each do |template|
+ if @phases.nil? then
+ @phases = template.phases.all.order('number')
+ else
+ @phases = @phases + template.phases.all.order('number')
+ end
+ end
+ @sections = nil
+ @phases.each do |phase|
+ if @sections.nil? then
+ @sections = phase.sections.all.order('number')
+ else
+ @sections = @sections + phase.sections.all.order('number')
+ end
+ end
+ @questions = nil
+ @sections.each do |section|
+ if @questions.nil? then
+ @questions = section.questions.all.order('number')
+ else
+ @questions = @questions + section.questions.all.order('number')
+ end
+ end
+ @themes = Theme.all.order('title')
+ @guidance_groups = GuidanceGroup.where(org_id: current_user.org_id).order('name ASC')
+ end
end
\ No newline at end of file
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index 40f5e32..3653f4b 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -2,18 +2,19 @@
after_action :verify_authorized
respond_to :html
- ##
- # POST /notes
+ require "pp"
+
def create
@note = Note.new
user_id = params[:new_note][:user_id]
@note.user_id = user_id
-
answer_id = params[:new_note][:answer_id]
question_id = params[:new_note][:question_id]
plan_id = params[:new_note][:plan_id]
+
+ # create answer if we dont already have one
if answer_id.present?
- answer = Answer.find(@note.answer_id)
+ answer = Answer.find(answer_id)
else
answer = Answer.new
answer.plan_id = plan_id
@@ -23,49 +24,53 @@
end
@note.answer= answer
- @note.text = params["#{params[:new_note][:answer_id]}new_note_text"]
+ @note.text = params["#{question_id}new_note_text"]
authorize @note
@plan = answer.plan
- @phase = answer.question.section.phase
+ @notice = "Save failed."
+ @answer = answer
+ @question = Question.find(question_id)
if @note.save
- session[:question_id_notes] = answer.question_id
- redirect_to edit_plan_phase_path(@plan, @phase), status: :found, notice: _('Comment was successfully created.')
+ @status = true
+ @notice = _('Comment was successfully created.')
end
+ notes = answer.notes.all
+ @num_notes = notes.count
end
- ##
- # PUT /notes/1
+
+
def update
@note = Note.find(params[:note][:id])
authorize @note
@note.text = params["#{params[:note][:id]}_note_text"]
- @plan = Plan.find(@note.plan_id)
- @project = Project.find(@plan.project_id)
+ @answer = @note.answer
+ @question = @answer.question
+ @plan = @answer.plan
if @note.update_attributes(params[:note])
- session[:question_id_notes] = @note.question_id
- redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment was successfully updated.')
+ @notice = _('Comment was successfully saved.')
end
end
- ##
- # ARCHIVE /notes/1
+
+
def archive
@note = Note.find(params[:note][:id])
authorize @note
@note.archived = true
@note.archived_by = params[:note][:archived_by]
- @plan = Plan.find(@note.plan_id)
- @project = Project.find(@plan.project_id)
+ @answer = @note.answer
+ @question = @answer.question
+ @plan = @answer.plan
if @note.update_attributes(params[:note])
- session[:question_id_notes] = @note.question_id
- redirect_to edit_project_plan_path(@project, @plan), status: :found, notice: _('Comment has been removed.')
+ @notice = _('Comment removed.')
end
end
end
diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb
index afe9711..f1890ca 100644
--- a/app/controllers/phases_controller.rb
+++ b/app/controllers/phases_controller.rb
@@ -15,14 +15,22 @@
# the eager_load pulls in ALL answers
# need to restrict to just ones for this plan
+ # at the same time count the questions and answers for the status
+ @nquestions = 0
+ @nanswers = 0
+
@plan.template.phases.each do |phase|
- phase.sections do |section|
+ phase.sections.each do |section|
section.questions.each do |question|
+ @nquestions += 1
question.answers = question.answers.to_a.select {|answer| answer.plan_id == @plan.id}
+ if question.answers.present? && question.answers.first.text.present?
+ @nanswers += 1
+ end
end
end
end
-
+
# Now we need to get all the themed guidance for the plan.
# TODO: think this through again, there may be a better way to do this.
#
diff --git a/app/dashboards/guidance_group_dashboard.rb b/app/dashboards/guidance_group_dashboard.rb
index 5aee6df..a8a83cc 100644
--- a/app/dashboards/guidance_group_dashboard.rb
+++ b/app/dashboards/guidance_group_dashboard.rb
@@ -60,4 +60,8 @@
# def display_resource(guidance_group)
# "GuidanceGroup ##{guidance_group.id}"
# end
+
+ def display_resource(guidance_group)
+ guidance_group.name
+ end
end
diff --git a/app/dashboards/identifier_scheme_dashboard.rb b/app/dashboards/identifier_scheme_dashboard.rb
index 7c65ea8..7dc1dca 100644
--- a/app/dashboards/identifier_scheme_dashboard.rb
+++ b/app/dashboards/identifier_scheme_dashboard.rb
@@ -60,4 +60,9 @@
# def display_resource(identifier_scheme)
# "IdentifierScheme ##{identifier_scheme.id}"
# end
+
+ def display_resource(identifier_scheme)
+ identifier_scheme.description
+ end
+
end
diff --git a/app/dashboards/language_dashboard.rb b/app/dashboards/language_dashboard.rb
index b6f5a48..c888a7d 100644
--- a/app/dashboards/language_dashboard.rb
+++ b/app/dashboards/language_dashboard.rb
@@ -46,8 +46,8 @@
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
- :users,
- :orgs,
+ # :users,
+ # :orgs,
:abbreviation,
:description,
:name,
@@ -60,4 +60,9 @@
# def display_resource(language)
# "Language ##{language.id}"
# end
+
+ def display_resource(language)
+ language.abbreviation
+ end
+
end
diff --git a/app/dashboards/org_dashboard.rb b/app/dashboards/org_dashboard.rb
index 3bc1cf4..013748f 100644
--- a/app/dashboards/org_dashboard.rb
+++ b/app/dashboards/org_dashboard.rb
@@ -8,7 +8,6 @@
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
- organisation_type: Field::BelongsTo,
language: Field::BelongsTo,
guidance_groups: Field::HasMany,
templates: Field::HasMany,
@@ -47,7 +46,6 @@
:templates,
:contact_email,
:org_type,
- :organisation_type,
].freeze
# SHOW_PAGE_ATTRIBUTES
@@ -60,12 +58,10 @@
:templates,
:contact_email,
:org_type,
- :organisation_type,
-
- :id,
:users,
:suggested_answers,
:token_permission_types,
+ :id,
:target_url,
:wayfless_entity,
:created_at,
@@ -84,12 +80,11 @@
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
- :organisation_type,
:language,
:guidance_groups,
- :templates,
- :users,
- :suggested_answers,
+# :templates,
+# :users,
+# :suggested_answers,
:token_permission_types,
:name,
:abbreviation,
@@ -113,4 +108,8 @@
# def display_resource(org)
# "Org ##{org.id}"
# end
+
+ def display_resource(org)
+ org.name
+ end
end
diff --git a/app/dashboards/perm_dashboard.rb b/app/dashboards/perm_dashboard.rb
index 63ea695..dc9e20b 100644
--- a/app/dashboards/perm_dashboard.rb
+++ b/app/dashboards/perm_dashboard.rb
@@ -41,7 +41,7 @@
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
- :users,
+# :users,
:name,
].freeze
@@ -51,4 +51,9 @@
# def display_resource(perm)
# "Perm ##{perm.id}"
# end
+
+ def display_resource(perm)
+ perm.name
+ end
+
end
diff --git a/app/dashboards/token_permission_type_dashboard.rb b/app/dashboards/token_permission_type_dashboard.rb
index ce8d4ad..93deb0f 100644
--- a/app/dashboards/token_permission_type_dashboard.rb
+++ b/app/dashboards/token_permission_type_dashboard.rb
@@ -54,4 +54,8 @@
# def display_resource(token_permission_type)
# "TokenPermissionType ##{token_permission_type.id}"
# end
+ def display_resource(token_permission_type)
+ "#{token_permission_type.token_type}: #{token_permission_type.text_description}"
+ end
+
end
diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb
index bd685f7..d7339b5 100644
--- a/app/dashboards/user_dashboard.rb
+++ b/app/dashboards/user_dashboard.rb
@@ -8,6 +8,18 @@
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
+ invited_by: Field::Polymorphic,
+ perms: Field::HasMany,
+ language: Field::BelongsTo,
+ org: Field::BelongsTo,
+ answers: Field::HasMany,
+ notes: Field::HasMany,
+ exported_plans: Field::HasMany,
+ roles: Field::HasMany,
+ plans: Field::HasMany,
+ user_identifiers: Field::HasMany,
+ identifier_schemes: Field::HasMany,
+ setting_objects: Field::HasMany.with_options(class_name: "Settings::PlanList"),
id: Field::Number,
firstname: Field::String,
surname: Field::String,
@@ -36,18 +48,6 @@
dmponline3: Field::Boolean,
accept_terms: Field::Boolean,
api_token: Field::String,
- invited_by: Field::Polymorphic,
- perms: Field::HasMany,
- language: Field::BelongsTo,
- org: Field::BelongsTo,
- answers: Field::HasMany,
- notes: Field::HasMany,
- exported_plans: Field::HasMany,
- roles: Field::HasMany,
- plans: Field::HasMany,
- user_identifiers: Field::HasMany,
- identifier_schemes: Field::HasMany,
- setting_objects: Field::HasMany.with_options(class_name: "Settings::PlanList"),
}.freeze
# COLLECTION_ATTRIBUTES
@@ -73,7 +73,6 @@
:org,
:perms,
:confirmed_at,
-
:id,
:invited_by,
:language,
@@ -114,24 +113,24 @@
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
- :invited_by,
+# :invited_by,
:perms,
:language,
:org,
- :answers,
- :notes,
- :exported_plans,
- :roles,
- :plans,
+# :answers,
+# :notes,
+# :exported_plans,
+# :roles,
+# :plans,
:user_identifiers,
:identifier_schemes,
- :setting_objects,
+# :setting_objects,
:firstname,
:surname,
:email,
:orcid_id,
:shibboleth_id,
- :encrypted_password,
+# :encrypted_password,
:reset_password_token,
:reset_password_sent_at,
:remember_created_at,
@@ -159,4 +158,9 @@
# def display_resource(user)
# "User ##{user.id}"
# end
+
+ def display_resource(user)
+ "user.name (##{user.id})"
+ end
+
end
diff --git a/app/dashboards/user_identifier_dashboard.rb b/app/dashboards/user_identifier_dashboard.rb
index 181303e..fc6d73e 100644
--- a/app/dashboards/user_identifier_dashboard.rb
+++ b/app/dashboards/user_identifier_dashboard.rb
@@ -54,4 +54,9 @@
# def display_resource(user_identifier)
# "UserIdentifier ##{user_identifier.id}"
# end
+
+ def display_resource(user_identifier)
+ user_identifier.identifier
+ end
+
end
diff --git a/app/models/org.rb b/app/models/org.rb
index 2696852..61e6691 100644
--- a/app/models/org.rb
+++ b/app/models/org.rb
@@ -5,7 +5,7 @@
##
# Associations
- belongs_to :organisation_type # depricated, but cannot be removed until migration run
+# belongs_to :organisation_type # depricated, but cannot be removed until migration run
belongs_to :language
has_many :guidance_groups
has_many :templates
@@ -17,11 +17,11 @@
##
# Possibly needed for active_admin
# -relies on protected_attributes gem as syntax depricated in rails 4.2
- attr_accessible :abbreviation, :banner_text, :logo, :remove_logo,
- :logo_file_name, :name, :target_url,
- :organisation_type_id, :wayfless_entity, :parent_id, :sort_name,
- :token_permission_type_ids, :language_id, :contact_email,
- :language, :org_type, :region, :token_permission_types
+# attr_accessible :abbreviation, :banner_text, :logo, :remove_logo,
+# :logo_file_name, :name, :target_url,
+# :organisation_type_id, :wayfless_entity, :parent_id, :sort_name,
+# :token_permission_type_ids, :language_id, :contact_email,
+# :language, :org_type, :region, :token_permission_types
##
# Validators
@@ -47,7 +47,7 @@
column: 'org_type'
# Predefined queries for retrieving the managain organisation and funders
- scope :managing_orgs, -> { where(name: GlobalHelpers.constant("organisation_types.managing_organisation")) }
+ scope :managing_orgs, -> { where(abbreviation: Rails.configuration.branding[:organisation][:abbreviation]) }
scope :funders, -> { where(org_type: 2) }
scope :institutions, -> { where(org_type: 3) }
diff --git a/app/models/perm.rb b/app/models/perm.rb
index 0db316b..5efd21f 100644
--- a/app/models/perm.rb
+++ b/app/models/perm.rb
@@ -6,7 +6,7 @@
##
# Possibly needed for active_admin
# -relies on protected_attributes gem as syntax depricated in rails 4.2
- attr_accessible :name, :as => [:default, :admin]
+ #attr_accessible :name, :as => [:default, :admin]
validates :name, presence: true, uniqueness: true
diff --git a/app/models/user.rb b/app/models/user.rb
index 30f3699..ace73b5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -40,14 +40,14 @@
##
# Possibly needed for active_admin
# -relies on protected_attributes gem as syntax depricated in rails 4.2
- accepts_nested_attributes_for :roles
- attr_accessible :password_confirmation, :encrypted_password, :remember_me,
- :id, :email, :firstname, :last_login,:login_count, :orcid_id,
- :password, :shibboleth_id, :user_status_id, :surname,
- :user_type_id, :org_id, :skip_invitation, :other_organisation,
- :accept_terms, :role_ids, :dmponline3, :api_token,
- :organisation, :language, :language_id, :org, :perms,
- :confirmed_at, :org_id
+ #accepts_nested_attributes_for :roles
+ #attr_accessible :password_confirmation, :encrypted_password, :remember_me,
+ # :id, :email, :firstname, :last_login,:login_count, :orcid_id,
+ # :password, :shibboleth_id, :user_status_id, :surname,
+ # :user_type_id, :org_id, :skip_invitation, :other_organisation,
+ # :accept_terms, :role_ids, :dmponline3, :api_token,
+ # :organisation, :language, :language_id, :org, :perms,
+ # :confirmed_at, :org_id
validates :email, email: true, allow_nil: true, uniqueness: true
diff --git a/app/policies/note_policy.rb b/app/policies/note_policy.rb
index 8ffe95a..88a9e11 100644
--- a/app/policies/note_policy.rb
+++ b/app/policies/note_policy.rb
@@ -13,11 +13,11 @@
end
def update?
- Plan.find(@note.plan_id).readable_by?(@user.id)
+ Plan.find(@note.answer.plan_id).readable_by?(@user.id)
end
def archive?
- Plan.find(@note.plan_id).readable_by?(@user.id)
+ Plan.find(@note.answer.plan_id).readable_by?(@user.id)
end
end
diff --git a/app/views/admin/application/_collection.html.erb b/app/views/admin/application/_collection.html.erb
deleted file mode 100644
index ed64ea7..0000000
--- a/app/views/admin/application/_collection.html.erb
+++ /dev/null
@@ -1,83 +0,0 @@
-<%#
-# Collection
-
-This partial is used on the `index` and `show` pages
-to display a collection of resources in an HTML table.
-
-## Local variables:
-
-- `collection_presenter`:
- An instance of [Administrate::Page::Collection][1].
- The table presenter uses `ResourceDashboard::COLLECTION_ATTRIBUTES` to determine
- the columns displayed in the table
-- `resources`:
- An ActiveModel::Relation collection of resources to be displayed in the table.
- By default, the number of resources is limited by pagination
- or by a hard limit to prevent excessive page load times
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
-%>
-
-
-
-
- <% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
- |
- <%= link_to(sanitized_order_params.merge(
- collection_presenter.order_params_for(attr_name)
- )) do %>
- <%= t(
- "helpers.label.#{resource_name}.#{attr_name}",
- default: attr_name.to_s,
- ).titleize %>
-
- <% if collection_presenter.ordered_by?(attr_name) %>
-
- <%= svg_tag(
- "administrate/sort_arrow.svg",
- "sort_arrow",
- width: "13",
- height: "13"
- ) %>
-
- <% end %>
- <% end %>
- |
- <% end %>
- |
-
-
-
-
- <% resources.each do |resource| %>
-
- <% collection_presenter.attributes_for(resource).each do |attribute| %>
- |
- <%= render_field attribute %>
- |
- <% end %>
-
- <%= link_to(
- t("administrate.actions.edit"),
- [:edit, namespace, resource],
- class: "action-edit",
- ) %> |
-
- <%= link_to(
- t("administrate.actions.destroy"),
- [namespace, resource],
- class: "table__action--destroy",
- method: :delete,
- data: { confirm: t("administrate.actions.confirm") }
- ) %> |
-
- <% end %>
-
-
diff --git a/app/views/admin/application/_form.html.erb b/app/views/admin/application/_form.html.erb
deleted file mode 100644
index cf991d0..0000000
--- a/app/views/admin/application/_form.html.erb
+++ /dev/null
@@ -1,42 +0,0 @@
-<%#
-# Form Partial
-
-This partial is rendered on a resource's `new` and `edit` pages,
-and renders all form fields for a resource's editable attributes.
-
-## Local variables:
-
-- `page`:
- An instance of [Administrate::Page::Form][1].
- Contains helper methods to display a form,
- and knows which attributes should be displayed in the resource's form.
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
-%>
-
-<%= form_for([namespace, page.resource], html: { class: "form" }) do |f| %>
- <% if page.resource.errors.any? %>
-
-
- <%= pluralize(page.resource.errors.count, "error") %>
- prohibited this <%= page.resource_name %> from being saved:
-
-
-
- <% page.resource.errors.full_messages.each do |message| %>
- - <%= message %>
- <% end %>
-
-
- <% end %>
-
- <% page.attributes.each do |attribute| -%>
-
- <%= render_field attribute, f: f %>
-
- <% end -%>
-
-
- <%= f.submit %>
-
-<% end %>
diff --git a/app/views/admin/application/edit.html.erb b/app/views/admin/application/edit.html.erb
deleted file mode 100644
index 4fac99a..0000000
--- a/app/views/admin/application/edit.html.erb
+++ /dev/null
@@ -1,31 +0,0 @@
-<%#
-# Edit
-
-This view is the template for the edit page.
-
-It displays a header, and renders the `_form` partial to do the heavy lifting.
-
-## Local variables:
-
-- `page`:
- An instance of [Administrate::Page::Form][1].
- Contains helper methods to help display a form,
- and knows which attributes should be displayed in the resource's form.
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
-%>
-
-<% content_for(:title) { "Edit #{page.page_title}" } %>
-
-
-
-<%= render "form", page: page %>
diff --git a/app/views/admin/application/index.html.erb b/app/views/admin/application/index.html.erb
deleted file mode 100644
index 2dd2be7..0000000
--- a/app/views/admin/application/index.html.erb
+++ /dev/null
@@ -1,45 +0,0 @@
-<%#
-# Index
-
-This view is the template for the index page.
-It is responsible for rendering the search bar, header and pagination.
-It renders the `_table` partial to display details about the resources.
-
-## Local variables:
-
-- `page`:
- An instance of [Administrate::Page::Collection][1].
- Contains helper methods to help display a table,
- and knows which attributes should be displayed in the resource's table.
-- `resources`:
- An instance of `ActiveRecord::Relation` containing the resources
- that match the user's search criteria.
- By default, these resources are passed to the table partial to be displayed.
-- `search_term`:
- A string containing the term the user has searched for, if any.
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
-%>
-
-<% content_for(:title) do %>
- <%= display_resource_name(page.resource_name) %>
-<% end %>
-
-<% content_for(:search) do %>
- <%= render "search", search_term: search_term %>
-<% end %>
-
-
-
-<%= render "collection", collection_presenter: page, resources: resources %>
-
-<%= paginate resources %>
diff --git a/app/views/admin/application/new.html.erb b/app/views/admin/application/new.html.erb
deleted file mode 100644
index 7ff3f60..0000000
--- a/app/views/admin/application/new.html.erb
+++ /dev/null
@@ -1,27 +0,0 @@
-<%#
-# New
-
-This view is the template for the "new resource" page.
-It displays a header, and then renders the `_form` partial
-to do the heavy lifting.
-
-## Local variables:
-
-- `page`:
- An instance of [Administrate::Page::Form][1].
- Contains helper methods to help display a form,
- and knows which attributes should be displayed in the resource's form.
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
-%>
-
-<% content_for(:title) { "New #{page.resource_name.titleize}" } %>
-
-
-
-<%= render 'form', page: page %>
diff --git a/app/views/admin/application/show.html.erb b/app/views/admin/application/show.html.erb
deleted file mode 100644
index b4e453b..0000000
--- a/app/views/admin/application/show.html.erb
+++ /dev/null
@@ -1,44 +0,0 @@
-<%#
-# Show
-
-This view is the template for the show page.
-It renders the attributes of a resource,
-as well as a link to its edit page.
-
-## Local variables:
-
-- `page`:
- An instance of [Administrate::Page::Show][1].
- Contains methods for accessing the resource to be displayed on the page,
- as well as helpers for describing how each attribute of the resource
- should be displayed.
-
-[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
-%>
-
-<% content_for(:title) { page.page_title } %>
-
-
-
-
- <% page.attributes.each do |attribute| %>
- -
- <%= t(
- "helpers.label.#{resource_name}.#{attribute.name}",
- default: attribute.name.titleize,
- ) %>
-
-
- - <%= render_field attribute %>
- <% end %>
-
diff --git a/app/views/answers/update.js.erb b/app/views/answers/update.js.erb
index 781c176..3ddb49f 100644
--- a/app/views/answers/update.js.erb
+++ b/app/views/answers/update.js.erb
@@ -3,11 +3,9 @@
// On success this will be "" on error it will be the
// conflicting answer
-//$("#answer_notice").html("<%= raw @message %>");
-
-<%if @message %>
- $("#answer_notice-<%=@question.id%>").html(<%= @message %>) %>");
-<% end %>
+// go back from "Saving..." message to "Save" button
+$("#saving-<%=@question.id%>").hide();
+$("#saving-<%=@question.id%>").prev().show();
<% if @old_answer %>
$("#answer_notice_<%=@question.id%>").html("<%= escape_javascript(render partial: '/phases/answer', locals: { question: @question, answer: @old_answer}) %>");
@@ -20,3 +18,24 @@
// this it will fail forever.
$("#answer_lock_version-<%=@question.id%>").val(<%= @lock_version %>);
+
+// update the answer status
+
+var q_status = $("#<%=@question.id%>-status");
+var timestamp = "<%=@timestamp%>";
+
+if( timestamp != "") {
+ q_status.text("");
+ // TODO: i18n this
+ q_status.append( "Answered \" title=\"<%=@timestamp%>\"><%=@timestamp%> by <%=@username%>");
+ $('abbr.timeago').timeago();
+}
+
+
+// update plan progress bar
+$(".progress").html("<%= escape_javascript(render :partial => "/plans/progress", locals: {nquestions: @nquestions, nanswers: @nanswers}) %>");
+
+
+// update the section progress message
+//TODO: I18n this
+$("#<%=@section_id%>-status").html("(<%=@n_section_questions%> questions, <%=@n_section_answers%> answered)");
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index e8a3467..6afcffb 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -62,6 +62,8 @@
<%= render "layouts/header" %>
+
+
<% if notice %>
<%= notice %>
diff --git a/app/views/notes/archive.js.erb b/app/views/notes/archive.js.erb
new file mode 100644
index 0000000..f2687fa
--- /dev/null
+++ b/app/views/notes/archive.js.erb
@@ -0,0 +1,29 @@
+
+// remove all tinymce explicitly or re-init will not work later
+tinymce.remove(".tinymce");
+
+// render the list of notes and invisible view and edit sections
+<% listlabel = "#comment-question-area-#{@question.id}" %>
+$("<%=listlabel%>").html(
+ "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>"
+);
+
+// TODO: this duplicates what is in the .yml file
+// DRY it out!
+tinymce.init({
+ selector: ".tinymce",
+ statusbar: false,
+ menubar: false,
+ toolbar: "bold italic | bullist numlist | link | table",
+ plugins: [ "table", "link", "paste" ],
+ target_list: false,
+ autoresize_min_height: 130,
+ extended_valid_elements: [ "a[href|target=_blank]" ],
+ paste_auto_cleanup_on_paste : true,
+ paste_remove_styles: true,
+ paste_retain_style_properties: "none",
+ paste_convert_middot_lists: true,
+ paste_remove_styles_if_webkit: true,
+ paste_remove_spans: true,
+ paste_strip_class_attributes: "all"
+});
diff --git a/app/views/notes/create.js.erb b/app/views/notes/create.js.erb
new file mode 100644
index 0000000..4cd1b85
--- /dev/null
+++ b/app/views/notes/create.js.erb
@@ -0,0 +1,31 @@
+
+// rewrite the number of notes heading e.g. Notes(3)
+<% noteslabel = "#notes_number_#{@question.id}" %>
+$("<%=noteslabel%>").html("Notes (<%= @num_notes %>)");
+
+// need to remove the existing tinymce editor otherwise
+tinymce.remove(".tinymce");
+
+// render the list of notes and invisible view and edit sections
+<% listlabel = "#comment-question-area-#{@question.id}" %>
+$("<%=listlabel%>").html(
+ "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>"
+);
+
+tinymce.init({
+ selector: ".tinymce",
+ statusbar: false,
+ menubar: false,
+ toolbar: "bold italic | bullist numlist | link | table",
+ plugins: [ "table", "link", "paste" ],
+ target_list: false,
+ autoresize_min_height: 130,
+ extended_valid_elements: [ "a[href|target=_blank]" ],
+ paste_auto_cleanup_on_paste : true,
+ paste_remove_styles: true,
+ paste_retain_style_properties: "none",
+ paste_convert_middot_lists: true,
+ paste_remove_styles_if_webkit: true,
+ paste_remove_spans: true,
+ paste_strip_class_attributes: "all"
+});
diff --git a/app/views/notes/update.js.erb b/app/views/notes/update.js.erb
new file mode 100644
index 0000000..45c5eb5
--- /dev/null
+++ b/app/views/notes/update.js.erb
@@ -0,0 +1,27 @@
+
+// need to remove the existing tinymce editor otherwise
+tinymce.remove(".tinymce");
+
+// render the list of notes and invisible view and edit sections
+<% listlabel = "#comment-question-area-#{@question.id}" %>
+$("<%=listlabel%>").html(
+ "<%= escape_javascript( render partial: '/phases/note', locals: {question: @question, answer: @answer, plan: @plan } ) %>"
+);
+
+tinymce.init({
+ selector: ".tinymce",
+ statusbar: false,
+ menubar: false,
+ toolbar: "bold italic | bullist numlist | link | table",
+ plugins: [ "table", "link", "paste" ],
+ target_list: false,
+ autoresize_min_height: 130,
+ extended_valid_elements: [ "a[href|target=_blank]" ],
+ paste_auto_cleanup_on_paste : true,
+ paste_remove_styles: true,
+ paste_retain_style_properties: "none",
+ paste_convert_middot_lists: true,
+ paste_remove_styles_if_webkit: true,
+ paste_remove_spans: true,
+ paste_strip_class_attributes: "all"
+});
diff --git a/app/views/orgs/admin_show.html.erb b/app/views/orgs/admin_show.html.erb
index fe91c9c..fffd4ef 100644
--- a/app/views/orgs/admin_show.html.erb
+++ b/app/views/orgs/admin_show.html.erb
@@ -54,7 +54,7 @@
<% if @org.org_type != 0 then %>
| <%= _('Organisation type') %> |
- <%= @org.organisation_type %> |
+ <%= @org.type %> |
<% end %>
diff --git a/app/views/phases/_add_note.html.erb b/app/views/phases/_add_note.html.erb
index 190f89b..cc367af 100644
--- a/app/views/phases/_add_note.html.erb
+++ b/app/views/phases/_add_note.html.erb
@@ -1,25 +1,28 @@
-
<%
new_note = Note.new
- answerid = answer.id
+ questionid = question.id
%>
-<%= form_for :new_note,
- :url => {:controller => :notes, :action => :create },
- :html=>{:method=>:post, :id => "new_note_form_#{answerid}", :class => "add_note_form"} do |f| %>
- <%= f.hidden_field :user_id, :value => current_user.id %>
- <%= f.hidden_field :answer_id, :value => answerid %>
- <%= f.hidden_field :question_id, :value => question.id %>
- <%= f.hidden_field :plan_id, :value => plan_id %>
+<%= form_for( :new_note,
+ url: notes_path,
+ remote: true,
+ method: :post,
+ id: "new_note_form_#{questionid}",
+ class: "add_note_form") do |f| %>
+ <%= f.hidden_field :user_id, value: current_user.id %>
+ <%= f.hidden_field :question_id, value: questionid %>
+ <%= f.hidden_field :answer_id, value: answer.id %>
+ <%= f.hidden_field :plan_id, value: plan_id %>
- <%= text_area_tag("#{answerid}new_note_text".to_sym, "" , class: "tinymce") %>
+ <%= text_area_tag "#{questionid}new_note_text", nil, class: "tinymce" %>
+ <%= tinymce %>
- <%= f.submit _('Save'), :class => "btn btn-primary new_comment_submit_button" %>
+ <%= f.submit _('Save'), class: "btn btn-primary new_comment_submit_button" %>
-<%end%>
+<% end %>
diff --git a/app/views/phases/_answer_form.html.erb b/app/views/phases/_answer_form.html.erb
index 90880c5..16c60e0 100644
--- a/app/views/phases/_answer_form.html.erb
+++ b/app/views/phases/_answer_form.html.erb
@@ -104,10 +104,10 @@
<% end %>
- <% if answer.nil? || answer.created_at.nil? %>
+ <% if answer.nil? || !answer.text.present? %>
<%= _('Not answered yet') %>
<% else %>
- <%= _('Answered')%> <%= answer.created_at %><%= _(' by')%> <%= answer.user.name %>
+ <%= _('Answered')%> <%= answer.updated_at.iso8601 %><%= _(' by')%> <%= answer.user.name %>
<% end %>
@@ -130,9 +130,9 @@
<%else%>
@@ -142,9 +142,9 @@
<% if comments.count > 0 then%>
<% comments_label_with_count = "#{_('Notes')} (#{comments.count})"%>
- <%= comments_label_with_count %>
+ <%= comments_label_with_count %>
<%else%>
- <%= _('Share note') %>
+ <%= _('Share note') %>
<%end%>
<%end%>
@@ -202,7 +202,7 @@
diff --git a/app/views/phases/_archive_note.html.erb b/app/views/phases/_archive_note.html.erb
index 26e87e3..0e7b244 100644
--- a/app/views/phases/_archive_note.html.erb
+++ b/app/views/phases/_archive_note.html.erb
@@ -1,23 +1,21 @@
-<%= form_for(Note.new, :url => {:controller => :notes, :action => :archive } , :html => { :method => :put, :class => "archive_note_form", :id => "archive_note_form_#{note["id"]}"}) do |f| %>
- <%= f.hidden_field :id, :value => note["id"] %>
+<%= form_for(note,
+ url: archive_note_path(note),
+ remote: true,
+ class: "archive_note_form",
+ id: "archive_note_form_#{note.id}") do |f| %>
+
+ <%= f.hidden_field :id, :value => note.id %>
<%= f.hidden_field :archived_by, :value => current_user.id %>
- <%= render :partial => "view_note", locals: {note: note} %>
+ <%= render :partial => "/phases/view_note", locals: {note: note} %>
- <% if current_user.id == note["user_id"] then %>
- <%= _('helpers.notes.archive_own_note_question')%>
- <% button_label = _('helpers.notes.archive_own_comment_button_label') %>
- <% else%>
- <%= _('helpers.notes.archive_note_question')%>
- <% button_label = _('helpers.notes.archive_comment_button_label') %>
- <%end%>
+ <%= _('Are you sure you want to remove this note?')%>
-
-
- <%= hidden_field_tag :note_id, note["id"], :class => "comment_id" %>
- <%= f.submit button_label, :class => "btn btn-primary archive_comment_submit_button" %>
- <%= link_to _('Cancel'), "#", :class => "cancel_archive_comment btn cancel" %>
-
+
+
+ <%= f.submit _('Remove'), onclick: "archive_note(#{note.id}, #{question_id})", :class => "btn btn-primary archive_comment_submit_button" %>
+ <%= link_to _('Cancel'), "#", onclick: "cancel_archive_note(#{note.id})", :class => "cancel_archive_comment btn cancel" %>
+
-<%end%>
+<% end %>
diff --git a/app/views/phases/_edit_note.html.erb b/app/views/phases/_edit_note.html.erb
index cc482cc..b0a7bdf 100644
--- a/app/views/phases/_edit_note.html.erb
+++ b/app/views/phases/_edit_note.html.erb
@@ -1,15 +1,19 @@
-<%= form_for(Note.new, :url => {:controller => :notes, :action => :update } , :html => { :method => :put, :class => "edit_note_form", :id=> "edit_note_form_#{note["id"]}"}) do |f| %>
- <%= f.hidden_field :id, :value => note["id"] %>
+<%= form_for(note,
+ url: note_path(note),
+ remote: true,
+ method: :put,
+ class: "edit_note_form",
+ id: "edit_note_form_#{note.id}") do |f| %>
- <%= text_area_tag("#{note["id"]}_note_text".to_sym, note["text"] , class: "tinymce") %>
+ <%= f.hidden_field :id, :value => note.id %>
+
+ <%= text_area_tag("#{note.id}_note_text".to_sym, note.text , class: "tinymce") %>
- <%= hidden_field_tag :answer, note["answer_id"], :class => "answer_id" %>
- <%= hidden_field_tag :note_id, note["id"], :class => "note_id" %>
<%= f.submit _('Save'), :class => "btn btn-primary edit_note_submit_button" %>
diff --git a/app/views/phases/_list_notes.html.erb b/app/views/phases/_list_notes.html.erb
index bd2ae70..56a8b96 100644
--- a/app/views/phases/_list_notes.html.erb
+++ b/app/views/phases/_list_notes.html.erb
@@ -31,18 +31,16 @@
<%else%>
- <%= link_to _('View'),"#", :class => "dmp_table_link view_comment_button" %>
- <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %>
+ <%= link_to _('View'),"#question-form-#{question_id}", onclick: "view_note_button(#{note.id}, #{question_id})", :class => "dmp_table_link view_comment_button" %>
<% if current_user.id == note.user_id %>
- <%= link_to _('Edit'),"#", :class => "dmp_table_link edit_comment_button" %>
- <%= hidden_field_tag :note_id, note.id, :class => "comment_id" %>
- <%= link_to _('Remove'),"#", :class => "dmp_table_link archive_comment_button" %>
+ <%= link_to _('Edit'),"#question-form-#{question_id}", onclick: "edit_note(#{note.id}, #{question_id})", :class => "dmp_table_link edit_comment_button" %>
+ <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %>
<% end%>
<% if plan.administerable_by?(current_user.id) && current_user.id != note.user_id %>
<%= hidden_field_tag :note_id, note.id, :class => "comment_id" %>
- <%= link_to _('Remove'),"#", :class => "dmp_table_link archive_comment_button" %>
+ <%= link_to _('Remove'),"#question-form-#{question_id}", onclick: "archive_note(#{note.id}, #{question_id})", :class => "dmp_table_link archive_comment_button" %>
<% end%>
<%end%>
@@ -57,30 +55,30 @@
<% notes_not_archived = notes.select { |n| n.archived.nil? } %>
-<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %>
+<% latest_note = notes_not_archived.sort { |x,y| y.updated_at <=> x.updated_at }.first %>
<% if !latest_note.nil? then%>
<%end%>
-<%notes.each do |com|%>
+<%notes.each do |note|%>
-