diff --git a/app/models/project.rb b/app/models/project.rb index 9479bd2..cb74ba4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -3,9 +3,10 @@ class Project < ActiveRecord::Base def self.status_keys {upcoming: 0, active: 1, backlog: 2, completed: 3} end + enum status: self.status_keys - +# HTML def requirements check_date_overdue_output requirements_completed?, requirements_due end @@ -22,17 +23,41 @@ class Project < ActiveRecord::Base check_date_overdue_output qalaunch_completed?, qalaunch_due end + # JSON + def requirements_json + check_date_overdue_output requirements_completed?, requirements_due, json: true + end + + def design_json + check_date_overdue_output design_completed?, design_due, json:true + end + + def devops_json + check_date_overdue_output devops_completed?, devops_due, json:true + end + + def qalaunch_json + check_date_overdue_output qalaunch_completed?, qalaunch_due, json:true + end private - def check_date_overdue_output completed, due - if completed - "".html_safe - elsif Date.today > due - "Overdue".html_safe + def check_date_overdue_output completed, due, options = {} + if completed + if options[:json] + "completed" else - due + "".html_safe end + elsif Date.today > due + if options[:json] + "overdue" + else + "Overdue".html_safe + end + else + due end + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e4dd4c2..cdfdd3a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,7 +13,7 @@
-

Roadmap +

<%= link_to "Roadmap", root_path %>

diff --git a/app/views/projects/index.json.jbuilder b/app/views/projects/index.json.jbuilder index 33c4403..a789842 100644 --- a/app/views/projects/index.json.jbuilder +++ b/app/views/projects/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@projects) do |project| - json.extract! project, :id, :title, :status, :requirements, :design, :devops, :qalaunch + json.extract! project, :id, :title, :status, :requirements_json, :design_json, :devops_json, :qalaunch_json json.url project_url(project, format: :json) end