Class: KManager::Overview::Dashboard

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/k_manager/overview/dashboard.rb

Overview

Generate dashboard information on the console

TODO: ConsoleDashboard and HtmlConsole dashboard = KManager::Overview::Dashboard.new(KManager.manager) dashboard.areas dashboard.resources dashboard.documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ Dashboard

Returns a new instance of Dashboard.



17
18
19
# File 'lib/k_manager/overview/dashboard.rb', line 17

def initialize(manager)
  @queries = KManager::Overview::Queries.new(manager)
end

Instance Attribute Details

#queriesObject (readonly)

Returns the value of attribute queries.



15
16
17
# File 'lib/k_manager/overview/dashboard.rb', line 15

def queries
  @queries
end

Instance Method Details

#areasObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/k_manager/overview/dashboard.rb', line 21

def areas
  data = queries.areas.map { |hash| KManager::Overview::Area.new(hash) }
  graph = {
    areas: {
      columns: [
        :name,
        :namespace,
        { resource_count: { display_method: ->(row) { blank_zero(row.resource_count) } } },
        { document_count: { display_method: ->(row) { blank_zero(row.document_count) } } }

      ]
    }
  }
  display(:areas, 'Areas', graph, data)
end

#documentsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/k_manager/overview/dashboard.rb', line 68

def documents
  data = grouped_documents(queries.documents).map { |hash| KManager::Overview::Document.new(hash) }

  graph = {
    resources: {
      columns: [
        { area:               { display_method: ->(row) { row.area_name } } },
        { area_ns:            { display_method: ->(row) { row.area_namespace } } },
        { resource_docs:      { display_method: ->(row) { resource_document_count(row) } } },
        { resource_id:        { display_method: ->(row) { blank_zero(row.resource_id) } } },
        # { key:                { display_method: -> (row) { row.resource_key } } },
        # { namespace:          { display_method: -> (row) { row.resource_namespace } } },
        # { status:             { display_method: -> (row) { row.resource_status } } },
        # { content_type:       { display_method: -> (row) { row.resource_content_type } } },
        # { content:            { display_method: -> (row) { row.resource_content } } },
        # { document_count:     { display_method: -> (row) { blank_zero(row.resource_document_count) } } },
        # { valid:              { display_method: -> (row) { row.resource_valid } } },
        # { error_count:        { display_method: -> (row) { blank_zero(row.resource_errors.length) } } },
        # { scheme:             { display_method: -> (row) { row.resource_scheme } } },
        # # { path:               { display_method: -> (row) { row.resource_path } } },
        # { exist:              { display_method: -> (row) { row.resource_exist } } },
        { document_id:        { display_method: ->(row) { blank_zero(row.document_id) } } },
        { state:              { display_method: ->(row) { document_state(row.document_state) } } },
        { data:               { display_method: ->(row) { row.document_data } } },
        { error_count:        { display_method: ->(row) { blank_zero(row.document_errors.length) } } },
        { key:                { display_method: ->(row) { row.document_key } } },
        { namespace:          { display_method: ->(row) { row.document_namespace } } },
        { tag:                { display_method: ->(row) { row.document_tag } } },
        { type:               { display_method: ->(row) { row.document_type } } },
        { relative_path:      { display_method: ->(row) { right(50, resource_path_location(row.resource_relative_path, row.document_location)) }, width: 50 } }
      ]
    }
  }

  display(:resources, 'Document List', graph, data)
end

#resourcesObject

rubocop:disable Metrics/AbcSize



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/k_manager/overview/dashboard.rb', line 38

def resources
  # sort and remove repeating area
  data = grouped_resources(queries.resources).map { |hash| KManager::Overview::Resource.new(hash) }
  graph = {
    resources: {
      columns: [
        { area:           { display_method: ->(row) { row.area_name } } },
        { area_ns:        { display_method: ->(row) { row.area_namespace } } },
        { resource_docs:  { display_method: ->(row) { resource_document_count(row) } } },
        { resource_id:    { display_method: ->(row) { blank_zero(row.id) } } },
        { key:            { display_method: ->(row) { row.key } } },
        { namespace:      { display_method: ->(row) { row.namespace } } },
        { status:         { display_method: ->(row) { row.status } } },
        { content_type:   { display_method: ->(row) { row.content_type } } },
        { content:        { display_method: ->(row) { format_content(row.content, row.content_type) }, width: 50 } },
        { document_count: { display_method: ->(row) { blank_zero(row.document_count) } } },
        { valid:          { display_method: ->(row) { row.valid } } },
        { error_count:    { display_method: ->(row) { blank_zero(row.errors.length) } } },
        { scheme:         { display_method: ->(row) { row.scheme } } },
        { root:           { display_method: ->(row) { row.scheme == :file ? '' : row.host } } },
        { relative_path:  { display_method: ->(row) { right(50, row.relative_path) }, width: 50 } },
        { exist:          { display_method: ->(row) { row.exist } } } # ,
        # { resource_path:  { display_method: ->(row) { row.path }, width: 100 } }
      ]
    }
  }

  display(:resources, 'Resource List', graph, data)
end