WIP - custom fields mainly displaying but needs to be reworked.

pull/1068/head
Richard 11 years ago
parent 099e99e880
commit a62b32ccb4
  1. 2
      app/assets/javascripts/angular/helpers/components/work-packages-helper.js
  2. 3
      app/controllers/api/v3/work_packages_controller.rb
  3. 10
      app/models/work_package.rb
  4. 2
      app/views/api/v3/work_packages/index.api.rabl

@ -30,7 +30,7 @@ angular.module('openproject.workPackages.helpers')
if (!object.custom_values) return null; if (!object.custom_values) return null;
var customValue = object.custom_values.filter(function(customValue){ var customValue = object.custom_values.filter(function(customValue){
return customValue.custom_field_id === customField.id; return customValue && customValue.custom_field_id === customField.id;
}).first(); }).first();
if(customValue) { if(customValue) {

@ -133,7 +133,8 @@ module Api
custom_field = CustomField.find($1) custom_field = CustomField.find($1)
work_packages.map do |work_package| work_packages.map do |work_package|
custom_value = work_package.custom_values.find_by_custom_field_id($1) custom_value = work_package.custom_values.find_by_custom_field_id($1)
custom_field.cast_value custom_value.try(:value) # custom_field.cast_value custom_value.try(:value)
work_package.custom_value_display(custom_value)
end end
else else
work_packages.map do |work_package| work_packages.map do |work_package|

@ -719,16 +719,16 @@ class WorkPackage < ActiveRecord::Base
# TODO RS: This probably isn't the right place for display helpers. It's convenient though to have # TODO RS: This probably isn't the right place for display helpers. It's convenient though to have
# the method on the model so that it can be used in the rabl template. # the method on the model so that it can be used in the rabl template.
def get_custom_value_display_data(custom_field) def get_custom_value_display_data(custom_field)
display_custom_value(custom_values.find_by_custom_field_id(custom_field.id)) custom_value_display(custom_values.find_by_custom_field_id(custom_field.id))
end end
def custom_values_display_data def custom_values_display_data(field_names)
custom_values.map do |custom_value| field_names.map do |field_name|
display_custom_value(custom_value) custom_value_display(custom_values.find_by_custom_field_id(field_name.to_s.gsub('cf_','')))
end end
end end
def display_custom_value(custom_value) def custom_value_display(custom_value)
if !custom_value.nil? if !custom_value.nil?
{ {
custom_field_id: custom_value.custom_field.id, custom_field_id: custom_value.custom_field.id,

@ -53,7 +53,7 @@ child @work_packages => :work_packages do
end end
node(:custom_values) do |wp| node(:custom_values) do |wp|
wp.custom_values_display_data wp.custom_values_display_data @custom_field_column_names
end end
end end

Loading…
Cancel
Save