Module: Timebox

Extended by:
ActiveSupport::Concern
Includes:
AtomicInternalId, CacheMarkdownField, FromUnion, Gitlab::SQL::Pattern, IidRoutes, Referable, StripAttribute
Included in:
Milestone
Defined in:
app/models/concerns/timebox.rb

Defined Under Namespace

Classes: TimeboxStruct

Constant Summary collapse

None =

Represents a “No Timebox” state used for filtering Issues and Merge Requests that have no timeboxes assigned.

TimeboxStruct.new('No Timebox', 'No Timebox', 0)
Any =
TimeboxStruct.new('Any Timebox', '', -1)
Upcoming =
TimeboxStruct.new('Upcoming', '#upcoming', -2)
Started =
TimeboxStruct.new('Started', '#started', -3)

Constants included from Gitlab::SQL::Pattern

Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_WORD

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Instance Method Summary collapse

Methods included from StripAttribute

#strip_attributes

Methods included from Referable

#referable_inspect, #to_reference_base

Methods included from IidRoutes

#to_param

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #local_version, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #updated_cached_html_for

Methods included from AtomicInternalId

#internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage

Instance Method Details

#group_timebox?Boolean

Returns:

  • (Boolean)

168
169
170
# File 'app/models/concerns/timebox.rb', line 168

def group_timebox?
  group_id.present?
end

#merge_requests_enabled?Boolean

Returns:

  • (Boolean)

188
189
190
191
192
193
194
195
196
# File 'app/models/concerns/timebox.rb', line 188

def merge_requests_enabled?
  if group_timebox?
    # Assume that groups have at least one project with merge requests enabled.
    # Otherwise, we would need to load all of the projects from the database.
    true
  elsif project_timebox?
    project&.merge_requests_enabled?
  end
end

#project_timebox?Boolean

Returns:

  • (Boolean)

172
173
174
# File 'app/models/concerns/timebox.rb', line 172

def project_timebox?
  project_id.present?
end

156
157
158
# File 'app/models/concerns/timebox.rb', line 156

def reference_link_text(from = nil)
  self.class.reference_prefix + self.title
end

#resource_parentObject


180
181
182
# File 'app/models/concerns/timebox.rb', line 180

def resource_parent
  group || project
end

#safe_titleObject


176
177
178
# File 'app/models/concerns/timebox.rb', line 176

def safe_title
  title.to_slug.normalize.to_s
end

#timebox_nameObject


164
165
166
# File 'app/models/concerns/timebox.rb', line 164

def timebox_name
  model_name.singular
end

#title=(value) ⇒ Object


160
161
162
# File 'app/models/concerns/timebox.rb', line 160

def title=(value)
  write_attribute(:title, sanitize_title(value)) if value.present?
end

#to_ability_nameObject


184
185
186
# File 'app/models/concerns/timebox.rb', line 184

def to_ability_name
  model_name.singular
end

#to_reference(from = nil, format: :name, full: false) ⇒ Object

Returns the String necessary to reference a Timebox in Markdown. Group timeboxes only support name references, and do not support cross-project references.

format - Symbol format to use (default: :iid, optional: :name)

Examples:

Milestone.first.to_reference                           # => "%1"
Iteration.first.to_reference(format: :name)            # => "*iteration:\"goal\""
Milestone.first.to_reference(cross_namespace_project)  # => "gitlab-org/gitlab-foss%1"
Iteration.first.to_reference(same_namespace_project)   # => "gitlab-foss*iteration:1"

145
146
147
148
149
150
151
152
153
154
# File 'app/models/concerns/timebox.rb', line 145

def to_reference(from = nil, format: :name, full: false)
  format_reference = timebox_format_reference(format)
  reference = "#{self.class.reference_prefix}#{format_reference}"

  if project
    "#{project.to_reference_base(from, full: full)}#{reference}"
  else
    reference
  end
end

#weight_available?Boolean

Returns:

  • (Boolean)

198
199
200
# File 'app/models/concerns/timebox.rb', line 198

def weight_available?
  resource_parent&.feature_available?(:issue_weights)
end