Class: InnerPlan::Lists::IndexView

Inherits:
ApplicationView show all
Includes:
Phlex::Rails::Helpers::DOMID, Phlex::Rails::Helpers::LinkTo, Phlex::Rails::Helpers::Routes
Defined in:
app/components/inner_plan/lists/index_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(lists:) ⇒ IndexView

Returns a new instance of IndexView.



7
8
9
# File 'app/components/inner_plan/lists/index_view.rb', line 7

def initialize(lists:)
  @lists = lists
end

Instance Method Details

#templateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/inner_plan/lists/index_view.rb', line 11

def template
  header(class: %(mb-4)) {
    div(class: %(row)) {
      div(class: %(col-6)) {
        h1(class: %(h2)) {
          plain %(Tasks)
          small(class: %(fs-6 text-body-tertiary ms-2)) {
            plain InnerPlan::Task.completed.count
            plain %(/)
            plain InnerPlan::Task.all.count
          }
        }
      }
      div(class: %(col-6 text-end)) {
        link_to('+ New list', helpers.new_list_path,
                              class: 'btn btn-success',
                              data: { turbo_frame: dom_id(InnerPlan::List.new, :form) })
      }
    }

    render(
      InnerPlan::ProgressBarSeparatorComponent.new(
        completed: InnerPlan::Task.completed.count,
        total: InnerPlan::Task.all.count
      )
    )
  }

  if @lists.none?
    div(class: %(text-center mt-5 pt-5)) {
      render(partial: 'inner_plan/shared/blankslate', formats: [:svg])

      h3(class: %(mt-5)) { %(Nothing here) }
      p(class: %(text-secondary)) {
        plain %( Looks like there are no tasks here yet. )
      }
    }
  end

  div(data_controller: %(lists)) {
    @lists.each do |list|
      render(InnerPlan::Lists::RowComponent.new(list, context: :lists_index))
    end
  }
end