Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added licence, attribution, topic tags, and tag line to projects. #298

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def update
do_authorize_instance

respond_to do |format|
if @project.update_attributes(project_params)
if @project.update_custom_attrs(project_params) && @project.update_attributes(project_params)
format.html { redirect_to @project, notice: 'Project was successfully updated.' }
format.json { respond_show }
else
Expand Down Expand Up @@ -185,7 +185,7 @@ def filter
private

def project_params
params.require(:project).permit(:description, :image, :name, :notes, :urn)
params.require(:project).permit(:description, :image, :name, :notes, :urn, :tag_line, :topic_tags, :licence_spec, :attribution_cite)
end

def access_request_params
Expand Down
58 changes: 53 additions & 5 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class Project < ActiveRecord::Base
# ensures that creator_id, updater_id, deleter_id are set
include UserChange

# for updating notes field, which stores JSON
include ModifyNotes

# relationships
belongs_to :creator, class_name: 'User', foreign_key: :creator_id, inverse_of: :created_projects
belongs_to :updater, class_name: 'User', foreign_key: :updater_id, inverse_of: :updated_projects
Expand All @@ -17,7 +20,29 @@ class Project < ActiveRecord::Base

accepts_nested_attributes_for :permissions

#plugins
# store notes as json in a text column
serialize :notes, JSON

# attributes that are not backed by db fields
attr_accessor :tag_line, :topic_tags

def tag_line
if !self.notes.blank? && self.notes.include?('tag_line')
self.notes['tag_line']
else
''
end
end

def topic_tags
if !self.notes.blank? && self.notes.include?('topic_tags')
self.notes['topic_tags']
else
''
end
end

# plugins
has_attached_file :image,
styles: {span4: '300x300#', span3: '220x220#', span2: '140x140#', span1: '60x60#', spanhalf: '30x30#'},
default_url: '/images/project/project_:style.png'
Expand All @@ -35,19 +60,38 @@ class Project < ActiveRecord::Base
#validates :urn, uniqueness: {case_sensitive: false}, allow_blank: true, allow_nil: true
validates_format_of :urn, with: /\Aurn:[a-z0-9][a-z0-9-]{0,31}:[a-z0-9()+,\-.:=@;$_!*'%\/?#]+\z/, message: 'urn %{value} is not valid, must be in format urn:<name>:<path>', allow_blank: true, allow_nil: true
validates_attachment_content_type :image, content_type: /\Aimage\/(jpg|jpeg|pjpeg|png|x-png|gif)\z/, message: 'file type %{value} is not allowed (only jpeg/png/gif images)'

# make sure the project has a permission entry for the creator after it is created
after_create :create_owner_permission

def description_html
CustomRender.render_markdown(self, :description)
end

def update_custom_attrs(hash)
has_tag_line = hash.include?('tag_line')
content_tag_line = hash['tag_line']
has_topic_tags = hash.include?('topic_tags')
content_topic_tags = hash['topic_tags']

if self.notes.blank?
self.notes = {}
end

if has_tag_line
self.notes['tag_line'] = content_tag_line
end
if has_topic_tags
self.notes['topic_tags'] = content_topic_tags
end
true
end

# Define filter api settings
def self.filter_settings
{
valid_fields: [:id, :name, :description, :created_at, :creator_id],
render_fields: [:id, :name, :description, :creator_id],
valid_fields: [:id, :name, :description, :licence_spec, :attribution_cite, :created_at, :creator_id],
render_fields: [:id, :name, :description, :licence_spec, :attribution_cite, :creator_id],
text_fields: [:name, :description],
custom_fields: lambda { |item, user|

Expand All @@ -57,9 +101,13 @@ def self.filter_settings

project_hash = {}
project_hash[:site_ids] = fresh_project.nil? ? nil : fresh_project.sites.pluck(:id).flatten

project_hash[:description_html]= fresh_project.description_html

unless fresh_project.notes.blank?
project_hash[:tag_line] = fresh_project.notes['tag_line'] if fresh_project.notes.include?('tag_line')
project_hash[:topic_tags]= fresh_project.notes['topic_tags'] if fresh_project.notes.include?('topic_tags')
end

[item, project_hash]
},
controller: :projects,
Expand Down
3 changes: 3 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Site < ActiveRecord::Base
acts_as_paranoid
validates_as_paranoid

# store notes as json in a text column
serialize :notes, JSON

# association validations
validates :creator, existence: true

Expand Down
6 changes: 5 additions & 1 deletion app/views/projects/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
= field_set_tag do
= f.error_notification
= f.input :name, required: true, label: 'Project Name'
= f.input :description, input_html: {rows: '3'}
= f.input :tag_line, label: 'Project Tag Line', hint: 'Summarise your project in a few words'
= f.input :description, input_html: {rows: '4'}
= render partial: 'shared/image_upload', locals: { f: f, model_instance: project, model_name: 'project' }
= f.input :topic_tags, label: 'Project Topics', hint: 'Enter descriptive labels, separated by commas'
= f.input :licence_spec, label: 'Project Licence', input_html: {rows: '5'}, placeholder: 'Enter the licence name, year, and copyright holder\'s name and a url to the licence.', hint: ('Need help choosing a licence? Try ' + link_to('Creative Commons', 'https://creativecommons.org/choose/') + ' or ' + link_to('ANDS', 'http://www.ands.org.au/working-with-data/enabling-data-reuse/licensing-for-reuse') + '.').html_safe
= f.input :attribution_cite, label: 'Attribution/Citation Suggestion', input_html: {rows: '5' }, placeholder: 'Enter the text you would like to be used when anyone refers to this project or the data it contains.'
= f.button :submit_cancel, 'Submit', class: 'btn-default'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddLicenseAndAttributionToProjects < ActiveRecord::Migration
def change
add_column :projects, :licence_spec, :text
add_column :projects, :attribution_cite, :text
end
end
Loading