links user and version cf on wp table

pull/2276/head
Jens Ulferts 10 years ago
parent 132b733bf2
commit fa1d595d96
  1. 40
      app/assets/javascripts/angular/work_packages/helpers/work-packages-helper.js
  2. 25
      app/controllers/api/experimental/concerns/column_data.rb
  3. 44
      spec/controllers/api/experimental/concerns/column_data_spec.rb

@ -89,23 +89,43 @@ angular.module('openproject.workPackages.helpers')
}, },
getColumnDataId: function(object, column) { getColumnDataId: function(object, column) {
var id; var custom_field_id = column.name.match(/^cf_(\d+)$/);
if (custom_field_id) {
custom_field_id = parseInt(custom_field_id[1]);
return WorkPackagesHelper.getCFColumnDataId(object, custom_field_id);
}
else {
return WorkPackagesHelper.getStaticColumnDataId(object, column);
}
},
getCFColumnDataId: function(object, custom_field_id) {
var custom_value = _.find(object.custom_values, function(elem) {
return elem && (elem.custom_field_id === custom_field_id);
});
if(custom_value && custom_value.value) {
return custom_value.value.id;
}
else {
return null;
}
},
getStaticColumnDataId: function(object, column) {
switch (column.name) { switch (column.name) {
case 'parent': case 'parent':
id = object.parent_id; return object.parent_id;
break;
case 'project': case 'project':
id = object.project.identifier; return object.project.identifier;
break;
case 'subject': case 'subject':
id = object.id; return object.id;
break;
default: default:
id = (object[column.name]) ? object[column.name].id : null; return (object[column.name]) ? object[column.name].id : null;
} }
return id;
}, },
getFormattedColumnData: function(object, column) { getFormattedColumnData: function(object, column) {

@ -48,11 +48,23 @@ module Api::Experimental::Concerns::ColumnData
# link, datetime # link, datetime
{ {
data_type: column_data_type(column), data_type: column_data_type(column),
link: link_meta[column.name] || { display: false } link: link_meta(column)
} }
end end
def link_meta def link_meta(column)
link_meta = static_link_meta[column.name]
if link_meta
link_meta
elsif column.respond_to?(:custom_field)
linked_custom_field_meta(column)
else
{ display: false }
end
end
def static_link_meta
{ {
subject: { display: true, model_type: 'work_package' }, subject: { display: true, model_type: 'work_package' },
type: { display: false }, type: { display: false },
@ -66,6 +78,15 @@ module Api::Experimental::Concerns::ColumnData
} }
end end
def linked_custom_field_meta(column)
case column.custom_field.field_format
when 'user', 'version'
{ display: true, model_type: column.custom_field.field_format }
else
{ display: false }
end
end
def column_data_type(column) def column_data_type(column)
if column.is_a?(QueryCustomFieldColumn) if column.is_a?(QueryCustomFieldColumn)
column.custom_field.field_format column.custom_field.field_format

@ -28,9 +28,12 @@
require File.expand_path('../../../../../spec_helper', __FILE__) require File.expand_path('../../../../../spec_helper', __FILE__)
describe 'ColumnData', :type => :controller do describe 'ColumnData', type: :controller do
include Api::Experimental::Concerns::ColumnData include Api::Experimental::Concerns::ColumnData
let(:field_format) { 'user' }
let(:field) { double('field', id: 1, order_statement: '', field_format: field_format) }
describe '#column_data_type' do describe '#column_data_type' do
it 'should recognise custom field columns based on field format' do it 'should recognise custom field columns based on field format' do
field = double('field', id: 1, order_statement: '', field_format: 'user') field = double('field', id: 1, order_statement: '', field_format: 'user')
@ -49,4 +52,43 @@ describe 'ColumnData', :type => :controller do
xit 'should test the full gamut of types' xit 'should test the full gamut of types'
end end
describe '#link_meta' do
let(:cf_column) { ::QueryCustomFieldColumn.new(field) }
describe 'for version custom fields' do
let(:field_format) { 'version' }
it 'has display true' do
expect(link_meta(cf_column)[:display]).to be_truthy
end
it 'has the model_type set to "version"' do
expect(link_meta(cf_column)[:model_type]).to eql(field_format)
end
end
describe 'for user custom fields' do
let(:field_format) { 'user' }
it 'has display true' do
expect(link_meta(cf_column)[:display]).to be_truthy
end
it 'has the model_type set to "user"' do
expect(link_meta(cf_column)[:model_type]).to eql(field_format)
end
end
describe 'for int custom fields' do
let(:field_format) { 'int' }
it 'has display false' do
expect(link_meta(cf_column)[:display]).to be_falsey
end
it 'lacks a model_type' do
expect(link_meta(cf_column)[:model_type]).to be_nil
end
end
end
end end

Loading…
Cancel
Save