Class: Kennel::Models::Screen

Inherits:
Base
  • Object
show all
Includes:
OptionalValidations, TemplateVariables
Defined in:
lib/kennel/models/screen.rb

Constant Summary collapse

API_LIST_INCOMPLETE =
true
COPIED_WIDGET_VALUES =
[:board_id, :isShared].freeze
WIDGET_DEFAULTS =
{
  time: {},
  timeframe: "1h"
}.freeze

Constants inherited from Base

Base::LOCK, Base::READONLY_ATTRIBUTES, Base::REQUEST_DEFAULTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionalValidations

included

Methods included from TemplateVariables

included

Methods inherited from Base

defaults, inherited, #kennel_id, #name, settings, #to_json, #tracking_id, validate_setting_exists

Methods included from SubclassTracking

#recursive_subclasses, #subclasses

Constructor Details

#initialize(project, *args) ⇒ Screen

Returns a new instance of Screen.



25
26
27
28
# File 'lib/kennel/models/screen.rb', line 25

def initialize(project, *args)
  @project = project
  super(*args)
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



23
24
25
# File 'lib/kennel/models/screen.rb', line 23

def project
  @project
end

Class Method Details

.api_resourceObject



30
31
32
# File 'lib/kennel/models/screen.rb', line 30

def self.api_resource
  "screen"
end

Instance Method Details

#as_jsonObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kennel/models/screen.rb', line 34

def as_json
  return @json if @json
  @json = {
    id: id,
    board_title: "#{board_title}#{LOCK}",
    description: description,
    widgets: render_widgets,
    template_variables: render_template_variables
  }

  validate_json(@json) if validate

  @json
end

#diff(actual) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/kennel/models/screen.rb', line 49

def diff(actual)
  actual.delete(:disableCog)
  actual.delete(:disableEditing)
  actual.delete(:isIntegration)
  actual.delete(:isShared)
  actual.delete(:original_title)
  actual.delete(:read_only)
  actual.delete(:resource)
  actual.delete(:title)
  actual.delete(:title_edited)
  actual.delete(:created_by)
  actual.delete(:board_bgtype)
  actual.delete(:height)
  actual.delete(:width)
  actual.delete(:showGlobalTimeOnboarding)
  actual[:template_variables] ||= []
  (actual[:widgets] || []).each do |w|
    # api randomly returns time.live_span or timeframe or empty time hash
    if w.dig(:time, :live_span)
      w[:timeframe] = w[:time].delete(:live_span)
    end

    COPIED_WIDGET_VALUES.each { |v| w.delete v }
  end

  ignore_defaults as_json[:widgets], actual[:widgets], WIDGET_DEFAULTS
  ignore_request_defaults as_json, actual, :widgets, :tile_def

  super
end

#url(id) ⇒ Object



80
81
82
# File 'lib/kennel/models/screen.rb', line 80

def url(id)
  Utils.path_to_url "/screen/#{id}"
end