Class: InnerPlan::Tasks::EditView

Inherits:
ApplicationView show all
Includes:
Phlex::Rails::Helpers::ContentTag, Phlex::Rails::Helpers::DOMID, Phlex::Rails::Helpers::Debug, Phlex::Rails::Helpers::FormWith, Phlex::Rails::Helpers::LinkTo, Phlex::Rails::Helpers::Routes
Defined in:
app/components/inner_plan/tasks/edit_view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task:, focus: nil) ⇒ EditView

Returns a new instance of EditView.



12
13
14
15
# File 'app/components/inner_plan/tasks/edit_view.rb', line 12

def initialize(task:, focus: nil)
  @task = task
  @focus = focus&.to_sym
end

Instance Attribute Details

#focusObject (readonly)

Returns the value of attribute focus.



10
11
12
# File 'app/components/inner_plan/tasks/edit_view.rb', line 10

def focus
  @focus
end

Instance Method Details

#templateObject



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/components/inner_plan/tasks/edit_view.rb', line 17

def template
  header(class: "mb-3") do
    render(InnerPlan::BreadcrumbsComponent.new) do |c|
      c.with_breadcrumb do
        link_to "Home",
                helpers.root_path,
                class: "text-reset",
                data: {
                  turbo_frame: :_top
                }
      end
      if @task.list.sub?
        c.with_breadcrumb do
          link_to @task.list.list.title, @task.list.list, class: "text-reset"
        end
        c.with_breadcrumb do
          link_to @task.list.title, helpers.group_path(@task.list), class: "text-reset"
        end
      else
        c.with_breadcrumb do
          link_to @task.list.title, @task.list, class: "text-reset"
        end
      end
      c.with_breadcrumb do
        link_to "Task ##{@task.id}", @task, class: "text-reset"
      end
      c.with_breadcrumb(active: true) { "Edit" }
    end
  end

  form_with model: @task do |f|
    div(class: "d-flex mb-4") do
      div(class: "text-end me-2 opacity-50") do
         :a,
                    style:
                      "display:block; margin-top: -0.1rem;margin-left:-0.6rem",
                    data: {
                      turbo: true,
                      turbo_stream: true
                    } do
          render(Phlex::Icons::Tabler::SquareRounded.new(width: 39, height: 39))
        end
      end
      div(class: "w-100") do
        plain f.text_field :title,
                          class: "form-control form-control-lg",
                          autofocus: (@focus == "title")
      end
    end

    InnerPlan.configuration.task_edit_view_rows.each do |row|
      render InnerPlan::Tasks::Form::RowComponent.new do |component|
        row.content.each do |item|
          component.with_column(span: item.options[:span]) do
            render(item.content.call(context: self, form: f))
          end
        end
      end
    end

    plain f.submit "Save changes", class: "btn btn-success btn-sm me-2"
    link_to "Cancel", @task, class: "btn btn-outline-secondary btn-sm"
  end
end