Embed cast custom value data in WP API response

* Update ng work-package-column-directive to render

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/1073/head
Alex Coles 11 years ago committed by Till Breuer
parent 2a8fb1ab0f
commit d14c2aa944
  1. 16
      app/assets/javascripts/angular/directives/work_packages/work-package-column-directive.js
  2. 4
      app/assets/javascripts/angular/helpers/components/custom-field-helper.js
  3. 4
      app/controllers/api/v3/work_packages_controller.rb
  4. 25
      app/models/work_package.rb

@ -51,8 +51,6 @@ angular.module('openproject.workPackages.directives')
var custom_field = scope.column.custom_field;
scope.displayText = WorkPackagesHelper.getFormattedCustomValue(scope.workPackage, custom_field) || '';
if (scope.column.meta_data.data_type === 'user') loadUserName();
} else {
// custom display types
if (scope.column.name === 'done_ratio') scope.displayType = 'progress_bar';
@ -68,20 +66,6 @@ angular.module('openproject.workPackages.directives')
}
}
function loadUserName() {
var userId = scope.displayText;
if(userId) {
scope.user = UserService.registerUserId(userId);
scope.$watch('user.name', function(userName) {
// triggered when user data is loaded
// TODO replace watcher as soon as data is loaded via a promise chain
scope.displayText = userName;
});
}
}
function getLinkFor(link_meta){
if (link_meta.model_type === 'work_package') {
return PathHelper.workPackagePath(scope.workPackage.id);

@ -54,10 +54,10 @@ angular.module('openproject.helpers')
case 'user':
if (users && users[value]) {
// try to look up users
return users[value].name;
return users.name;
} else {
// return user id
return value;
return value.name;
}
break;
case 'int':

@ -26,8 +26,6 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
module Api
module V3
@ -186,7 +184,7 @@ module Api
work_packages.map do |work_package|
custom_value = work_package.custom_values.find_by_custom_field_id($1)
if display
work_package.custom_value_display(custom_value)
work_package.get_cast_custom_value_with_meta(custom_value)
else
custom_field.cast_value custom_value.try(:value)
end

@ -713,6 +713,18 @@ class WorkPackage < ActiveRecord::Base
return allowed
end
def get_cast_custom_value_with_meta(custom_value, custom_field=nil)
return unless custom_value
custom_field ||= custom_value.custom_field
{
custom_field_id: custom_field.id,
field_format: custom_field.field_format, # TODO just return the cast value
value: custom_field.field_format == 'user' ? custom_field.cast_value(custom_value.value).as_json(methods: :name) : custom_field.cast_value(custom_value.value)
}
end
# Begin Custom Value Display Helper Methods
# 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.
@ -722,20 +734,9 @@ class WorkPackage < ActiveRecord::Base
def custom_values_display_data(field_names)
field_names.map do |field_name|
custom_value_display(custom_values.find_by_custom_field_id(field_name.to_s.gsub('cf_','')))
end
end
def custom_value_display(custom_value)
if !custom_value.nil?
{
custom_field_id: custom_value.custom_field.id,
field_format: custom_value.custom_field.field_format,
value: custom_value.value
}
get_cast_custom_value_with_meta(custom_values.find_by_custom_field_id(field_name.to_s.gsub('cf_','')))
end
end
# End Custom Value Display Helper Methods
protected

Loading…
Cancel
Save