Skip to content

Commit

Permalink
Merge pull request opf#15187 from opf/chore/rename-delay-to-lag
Browse files Browse the repository at this point in the history
Rename delay to lag
  • Loading branch information
ulferts authored Apr 9, 2024
2 parents 3d7cab0 + f7ba774 commit c82a5e8
Show file tree
Hide file tree
Showing 49 changed files with 446 additions and 231 deletions.
2 changes: 1 addition & 1 deletion app/contracts/relations/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
module Relations
class BaseContract < ::ModelContract
attribute :relation_type
attribute :delay
attribute :lag
attribute :description
attribute :from
attribute :to
Expand Down
15 changes: 4 additions & 11 deletions app/models/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ class Relation < ApplicationRecord
scope :of_work_package,
->(work_package) { where(from: work_package).or(where(to: work_package)) }

scope :follows_with_delay,
-> { follows.where("delay > 0") }
scope :follows_with_lag,
-> { follows.where("lag > 0") }

validates :delay, numericality: { allow_nil: true }
validates :lag, numericality: { allow_nil: true }

validates :to, uniqueness: { scope: :from }

Expand Down Expand Up @@ -138,21 +138,14 @@ def successor_soonest_start
if follows? && (to.start_date || to.due_date)
days = WorkPackages::Shared::Days.for(from)
relation_start_date = (to.due_date || to.start_date) + 1.day
days.soonest_working_day(relation_start_date, delay:)
days.soonest_working_day(relation_start_date, lag:)
end
end

def <=>(other)
TYPES[relation_type][:order] <=> TYPES[other.relation_type][:order]
end

# delay is an attribute of Relation but its getter is masked by delayed_job's #delay method
# here we overwrite dj's delay method with the one reading the attribute
# since we don't plan to use dj with Relation objects, this should be fine
def delay
self[:delay]
end

TYPES.each_key do |type|
define_method :"#{type}?" do
canonical_type == self.class.canonical_type(type)
Expand Down
20 changes: 10 additions & 10 deletions app/models/work_package/scheduling_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ def schedule_automatically?

# TODO: move into work package contract (possibly a module included into the contract)
# Calculates the minimum date that
# will not violate the precedes relations (max(finish date, start date) + relation delay)
# will not violate the precedes relations (max(finish date, start date) + relation lag)
# of this work package or its ancestors
# e.g.
# AP(due_date: 2017/07/25)-precedes(delay: 0)-A
# |
# parent
# |
# BP(due_date: 2017/07/22)-precedes(delay: 2)-B
# |
# parent
# |
# CP(due_date: 2017/07/25)-precedes(delay: 2)-C
# AP(due_date: 2017/07/25)-precedes(lag: 0)-A
# |
# parent
# |
# BP(due_date: 2017/07/22)-precedes(lag: 2)-B
# |
# parent
# |
# CP(due_date: 2017/07/25)-precedes(lag: 2)-C
#
# Then soonest_start for:
# C is 2017/07/28
Expand Down
4 changes: 2 additions & 2 deletions app/services/relations/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def update_relation(model, attributes)

def set_defaults(model)
if Relation::TYPE_FOLLOWS == model.relation_type
model.delay ||= 0
model.lag ||= 0
else
model.delay = nil
model.lag = nil
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/services/work_packages/shared/all_days.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def due_date(start_date, duration)
start_date + duration - 1
end

def soonest_working_day(date, delay: nil)
delay ||= 0
date + delay.days if date
def soonest_working_day(date, lag: nil)
lag ||= 0
date + lag.days if date
end

def working?(_date)
Expand Down
8 changes: 4 additions & 4 deletions app/services/work_packages/shared/working_days.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def due_date(start_date, duration)
due_date
end

def soonest_working_day(date, delay: nil)
def soonest_working_day(date, lag: nil)
return unless date

delay ||= 0
lag ||= 0

while delay > 0
delay -= 1 if working?(date)
while lag > 0
lag -= 1 if working?(date)
date += 1
end

Expand Down
2 changes: 1 addition & 1 deletion app/workers/work_packages/apply_working_days_change_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def changed_non_working_dates(previous_non_working_days)

def applicable_predecessor(excluded)
WorkPackage
.where(id: Relation.follows_with_delay.select(:to_id))
.where(id: Relation.follows_with_lag.select(:to_id))
.where.not(id: excluded)
end

Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
oauth_client:
client: "Client ID"
relation:
delay: "Delay"
lag: "Lag"
from: "Work package"
to: "Related work package"
status:
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20240408132459_rename_delay_to_lag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class RenameDelayToLag < ActiveRecord::Migration[7.1]
def change
rename_column :relations, :delay, :lag

# TODO remove after 14.0
add_column :relations, :delay, :virtual, type: :integer, as: 'lag', stored: true
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ example:
href: "/api/v3/work_packages/3857"
_type: WorkPackage
type: follows
delay: 3
lag: 3
description: let it rest for 3 days
schema:
_type: Schema
Expand Down Expand Up @@ -64,8 +64,8 @@ example:
name: To work package
type: WorkPackage
writable: false
delay:
name: Delay
lag:
name: lag
type: Integer
writable: true
validationErrors:
Expand Down
6 changes: 3 additions & 3 deletions docs/api/apiv3/components/schemas/relation_model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ properties:
description:
type: string
description: Short text further describing the relation
delay*:
lag*:
type: integer
description: The delay in days between closing of `from` and start of `to`
description: The lag in days between closing of `from` and start of `to`
minimum: 0
_links:
type: object
Expand Down Expand Up @@ -131,4 +131,4 @@ example:
type: precedes
reverseType: follows
description: We can't bend the steel before it's been delivered!
delay: 0
lag: 0
4 changes: 2 additions & 2 deletions docs/api/apiv3/components/schemas/relation_schema_model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ example:
name: To work package
type: WorkPackage
writable: false
delay:
name: Delay
lag:
name: Lag
type: Integer
writable: true
2 changes: 1 addition & 1 deletion docs/api/apiv3/components/schemas/relations_model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ example:
type: precedes
reverseType: follows
description: We can't bend the steel before it's been delivered!
delay: 0
lag: 0
4 changes: 2 additions & 2 deletions docs/api/apiv3/paths/custom_action_execute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ post:
value:
_embedded:
details:
attribute: delay
attribute: lag
_type: Error
errorIdentifier: urn:openproject-org:api:v3:errors:PropertyConstraintViolation
message: Delay must be a number greater than or equal to 0
message: Lag must be a number greater than or equal to 0
description: Returned if the custom action was not executed successfully e.g.
when a constraint on a work package property was violated.
headers: {}
Expand Down
8 changes: 4 additions & 4 deletions docs/api/apiv3/paths/relation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ get:
href: "/api/v3/relations/1"
method: PATCH
_type: Relation
delay: 0
lag: 0
description: We can't bend the steel before it's been delivered!
id: 1
name: precedes
Expand Down Expand Up @@ -157,7 +157,7 @@ patch:
href: "/api/v3/relations/1"
method: PATCH
_type: Relation
delay: 0
lag: 0
description: We can't bend the steel before it's been delivered!
id: 1
name: precedes
Expand Down Expand Up @@ -199,10 +199,10 @@ patch:
value:
_embedded:
details:
attribute: delay
attribute: lag
_type: Error
errorIdentifier: urn:openproject-org:api:v3:errors:PropertyConstraintViolation
message: Delay must be a number greater than or equal to 0
message: Lag must be a number greater than or equal to 0
description: |-
Returned if:
Expand Down
6 changes: 3 additions & 3 deletions docs/api/apiv3/paths/relation_form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ post:
to:
href: "/api/v3/work_packages/3857"
_type: WorkPackage
delay: 3
lag: 3
description: let it rest for 3 days
type: follows
schema:
_links:
self:
href: "/api/v3/relations/schema"
_type: Schema
delay:
name: Delay
lag:
name: Lag
type: Integer
writable: true
description:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/apiv3/paths/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ get:
href: "/api/v3/relations/1"
method: PATCH
_type: Relation
delay: 0
lag: 0
description: We can't bend the steel before it's been delivered!
id: 1
name: precedes
Expand Down
4 changes: 2 additions & 2 deletions docs/api/apiv3/paths/relations_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ get:
self:
href: "/api/v3/relations/schema"
_type: Schema
delay:
name: Delay
lag:
name: Lag
type: Integer
writable: true
description:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/apiv3/paths/relations_schema_{type}.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ get:
self:
href: "/api/v3/relations/schema"
_type: Schema
delay:
name: Delay
lag:
name: Lag
type: Integer
writable: true
description:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/apiv3/paths/work_package_relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ post:
value:
_embedded:
details:
attribute: delay
attribute: lag
_type: Error
errorIdentifier: urn:openproject-org:api:v3:errors:PropertyConstraintViolation
message: Delay must be a number greater than or equal to 0
message: Lag must be a number greater than or equal to 0
description: |-
Returned if:
Expand Down
4 changes: 2 additions & 2 deletions docs/api/apiv3/tags/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: |-
| type |
| reverseType |
| description |
| delay |
| lag |
+--------------+
```
Expand Down Expand Up @@ -44,7 +44,7 @@ description: |-
| type | Which kind of relation (blocks, precedes, etc.) | String | in: relates, duplicates, duplicated, blocks, blocked, precedes, follows, includes, partof, requires, required | READ / WRITE |
| reverseType | The kind of relation from the other WP's perspective | String | in: relates, duplicates, duplicated, blocks, blocked, precedes, follows, includes, partof, requires, required | READ |
| description | Short text further describing the relation | String | | READ / WRITE |
| delay* | The delay in days between closing of `from` and start of `to` | Integer | x >= 0 | READ / WRITE |
| lag* | The number of days between closing of `from` and start of `to`| Integer | x >= 0 | READ / WRITE |
\* Only applicable for some relation types such as "follows". You can check using the relation by schema
endpoint at `/api/v3/relations/schema/{type}`.
Expand Down
Loading

0 comments on commit c82a5e8

Please sign in to comment.