parent
1490621af1
commit
97d4e9a1e6
@ -1,11 +0,0 @@ |
|||||||
module WorkPackages |
|
||||||
class RelationMapper < Yaks::Mapper |
|
||||||
link :self, '/api/v3/work_packages/{work_package_id}/relations' |
|
||||||
|
|
||||||
attributes :id |
|
||||||
|
|
||||||
def work_package_id |
|
||||||
1 |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,26 @@ |
|||||||
|
require 'roar/representer/json' |
||||||
|
require 'roar/decorator' |
||||||
|
require 'roar/representer/json/hal' |
||||||
|
|
||||||
|
module WorkPackages |
||||||
|
class UserRepresenter < Roar::Decorator |
||||||
|
include Roar::Representer::JSON |
||||||
|
include Roar::Representer::JSON::HAL |
||||||
|
include Roar::Representer::Feature::Hypermedia |
||||||
|
include Rails.application.routes.url_helpers |
||||||
|
|
||||||
|
property :login |
||||||
|
property :firstname |
||||||
|
property :lastname |
||||||
|
property :mail |
||||||
|
property :_type, exec_context: :decorator |
||||||
|
|
||||||
|
link :self do |
||||||
|
{ href: "http://localhost:3000/api/v3/users/#{represented.id}", title: "User." } |
||||||
|
end |
||||||
|
|
||||||
|
def _type |
||||||
|
"User" |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -1,90 +0,0 @@ |
|||||||
module WorkPackages |
|
||||||
class WorkPackageMapper < Yaks::Mapper |
|
||||||
def initialize(object, embedded) |
|
||||||
super(object) |
|
||||||
end |
|
||||||
|
|
||||||
link :self, '/api/v3/work_packages/{id}' |
|
||||||
link :createChildren, '/api/v3/work_packages?parent_id={id}', method: :post |
|
||||||
link :update, '/api/v3/work_packages/{id}', method: :patch |
|
||||||
link :delete, '/api/v3/work_packages/{id}', method: :delete |
|
||||||
link :project, '/api/v3/projects/{project_id}' |
|
||||||
link :author, '/api/v3/users/{author_id}' |
|
||||||
link :assignee, '/api/v3/users/{assigned_to_id}' |
|
||||||
link :responsible, '/api/v3/users/{responsible_id}' |
|
||||||
link :targetVersion, '/api/v3/versions/{fixed_version_id}' |
|
||||||
link :projectWorkPackages, '/api/v3/work_packages?filter=project_ideql{project_id}' |
|
||||||
link :descendants, '/api/v3/work_packages?filter=ancestors_idscontain{id}' |
|
||||||
link :children, '/api/v3/work_packages?filter=parent_ideql{id}' |
|
||||||
link :parent, '/api/v3/work_packages?filter=children_idscontain{id}' |
|
||||||
link :ancestors, '/api/v3/work_packages?filter=descendants_idscontain{id}' |
|
||||||
link :relations, '/api/v3/work_packages/{id}/relations' |
|
||||||
|
|
||||||
attributes :id, :subject, :description, :type, :dueDate, :status, :priority, :percentageDone, |
|
||||||
:estimatedTime, :startDate, :createdAt, :updatedAt, :customFields, :_type |
|
||||||
|
|
||||||
has_one :project, mapper: Projects::ProjectMapper |
|
||||||
has_one :author, mapper: Users::UserMapper |
|
||||||
has_one :assigned_to, mapper: Users::UserMapper, as: :assignee |
|
||||||
has_one :responsible, mapper: Users::UserMapper |
|
||||||
has_one :fixed_version, mapper: Versions::VersionMapper, as: :targetVersion |
|
||||||
has_one :parent, mapper: WorkPackages::WorkPackageMapper |
|
||||||
|
|
||||||
has_many :descendants, mapper: WorkPackages::WorkPackageMapper |
|
||||||
has_many :ancestors, mapper: WorkPackages::WorkPackageMapper |
|
||||||
has_many :children, mapper: WorkPackages::WorkPackageMapper |
|
||||||
has_many :relations, mapper: WorkPackages::RelationMapper |
|
||||||
|
|
||||||
def type |
|
||||||
object.type.name |
|
||||||
end |
|
||||||
|
|
||||||
def dueDate |
|
||||||
object.due_date.to_s |
|
||||||
end |
|
||||||
|
|
||||||
def status |
|
||||||
object.status.name |
|
||||||
end |
|
||||||
|
|
||||||
def priority |
|
||||||
object.priority.name |
|
||||||
end |
|
||||||
|
|
||||||
def percentageDone |
|
||||||
object.done_ratio |
|
||||||
end |
|
||||||
|
|
||||||
def estimatedTime |
|
||||||
{ unit: 'hours', value: object.estimated_hours } |
|
||||||
end |
|
||||||
|
|
||||||
def startDate |
|
||||||
object.start_date.to_s |
|
||||||
end |
|
||||||
|
|
||||||
def createdAt |
|
||||||
object.created_at.to_s |
|
||||||
end |
|
||||||
|
|
||||||
def updatedAt |
|
||||||
object.updated_at.to_s |
|
||||||
end |
|
||||||
|
|
||||||
def customFields |
|
||||||
fields = [ ] |
|
||||||
object.custom_field_values.each do |custom_value| |
|
||||||
fields << { name: custom_value.custom_field.name, format: custom_value.custom_field.field_format, value: custom_value.value } |
|
||||||
end |
|
||||||
fields |
|
||||||
end |
|
||||||
|
|
||||||
def _type |
|
||||||
"WorkPackage" |
|
||||||
end |
|
||||||
|
|
||||||
def relations |
|
||||||
[] |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,80 @@ |
|||||||
|
module WorkPackages |
||||||
|
class WorkPackageModel < Reform::Form |
||||||
|
include Composition |
||||||
|
|
||||||
|
model :work_package |
||||||
|
|
||||||
|
property :subject, on: :work_package |
||||||
|
property :description, on: :work_package |
||||||
|
property :due_date, on: :work_package |
||||||
|
property :percentage_done, as: :done_ratio, on: :work_package |
||||||
|
property :start_date, on: :work_package |
||||||
|
property :created_at, on: :work_package |
||||||
|
property :updated_at, on: :work_package |
||||||
|
property :author, on: :work_package |
||||||
|
|
||||||
|
def type |
||||||
|
work_package.type.name |
||||||
|
end |
||||||
|
|
||||||
|
def type=(value) |
||||||
|
type = Type.find(:first, conditions: ['name ilike ?', value]) |
||||||
|
work_package.type = type |
||||||
|
end |
||||||
|
|
||||||
|
def status |
||||||
|
work_package.status.name |
||||||
|
end |
||||||
|
|
||||||
|
def status=(value) |
||||||
|
status = Status.find(:first, conditions: ['name ilike ?', value]) |
||||||
|
work_package.status = status |
||||||
|
end |
||||||
|
|
||||||
|
def priority |
||||||
|
work_package.priority.name |
||||||
|
end |
||||||
|
|
||||||
|
def priority=(value) |
||||||
|
priority = IssuePriority.find(:first, conditions: ['name ilike ?', value]) |
||||||
|
work_package.priority = priority |
||||||
|
end |
||||||
|
|
||||||
|
def responsible_login |
||||||
|
work_package.responsible.try(:login) |
||||||
|
end |
||||||
|
|
||||||
|
def responsible_login=(value) |
||||||
|
responsible_user = User.find(:first, conditions: ['login ilike ?', value]) |
||||||
|
work_package.responsible = responsible_user |
||||||
|
end |
||||||
|
|
||||||
|
def responsible |
||||||
|
work_package.responsible |
||||||
|
end |
||||||
|
|
||||||
|
def assignee_login |
||||||
|
work_package.assigned_to.try(:login) |
||||||
|
end |
||||||
|
|
||||||
|
def assignee_login=(value) |
||||||
|
assignee_user = User.find(:first, conditions: ['login ilike ?', value]) |
||||||
|
work_package.assigned_to = assignee_user |
||||||
|
end |
||||||
|
|
||||||
|
def assignee |
||||||
|
work_package.assigned_to |
||||||
|
end |
||||||
|
|
||||||
|
def estimated_time |
||||||
|
{ units: 'hours', value: work_package.estimated_hours } |
||||||
|
end |
||||||
|
|
||||||
|
def estimated_time=(value) |
||||||
|
hours = ActiveSupport::JSON.decode(value)['value'] |
||||||
|
work_package.estimated_hours = hours |
||||||
|
end |
||||||
|
|
||||||
|
validates :subject, presence: true |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue