Class: Lesli::Items::TasksController

Inherits:
ApplicationLesliController show all
Defined in:
app/controllers/lesli/items/tasks_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#engine_path, #query

Instance Method Summary collapse

Methods inherited from ApplicationLesliController

#log

Methods included from CustomizationInterface

#set_customizer

Methods included from ResponderInterface

#respond_with_action, #respond_with_http, #respond_with_json, #respond_with_json_not_found, #respond_with_json_unauthorized, #respond_with_lesli, #respond_with_not_found, #respond_with_pagination, #respond_with_unauthorized, #stream_redirection

Methods included from RequesterInterface

#set_locale, #set_requester

Methods inherited from ApplicationController

#initialize

Constructor Details

This class inherits a constructor from Lesli::ApplicationController

Instance Method Details

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/lesli/items/tasks_controller.rb', line 49

def create
    task = task_class.new(task_params)

    task.user = current_user
    task. = current_user.
    task.taskable = @taskable if @taskable

    if task.save
        respond_with_lesli(:turbo => [
            stream_notification_success("Task created"),
            turbo_stream.prepend("#{scope_key}-lesli-items-tasks-list") do
                LesliView::Items::Task.new(task, scope_key).render_in(view_context)
            end
        ])
    else
        respond_with_lesli(
            :turbo => stream_notification_danger(task.errors.full_messages)
        )
    end
end

#indexObject



39
40
41
42
43
44
# File 'app/controllers/lesli/items/tasks_controller.rb', line 39

def index
    @tasks = task_class
        .where(account: current_user.)
        .order(created_at: :desc)
    respond_with_lesli(json: @tasks)
end

#showObject



46
47
# File 'app/controllers/lesli/items/tasks_controller.rb', line 46

def show
end

#updateObject



70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/lesli/items/tasks_controller.rb', line 70

def update
    @task.done = true
    @task.save
    respond_with_lesli(:turbo => [
        stream_notification_success("Task updated #{@taskable}"),
        turbo_stream.replace(helpers.dom_id(@task, scope_key)) do 
            LesliView::Items::Task.new(@task, scope_key).render_in(view_context)
        end
    ])
end