Class: Lesli::Shared::DashboardsController

Inherits:
ApplicationLesliController show all
Defined in:
app/controllers/lesli/shared/dashboards_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#engine_path, #query

Instance Method Summary collapse

Methods included from Interfaces::Application::Logger

#get_user_agent, #log_account_activity, #log_account_requests, #log_requests, #log_user_requests

Methods included from Interfaces::Application::Requester

#set_locale, #set_path, #set_requester

Methods included from Interfaces::Application::Responder

#respond_with_action, #respond_with_error, #respond_with_http, #respond_with_not_found, #respond_with_pagination, #respond_with_successful, #respond_with_unauthorized

Methods included from Interfaces::Application::Customization

#set_customizer

Methods included from Interfaces::Application::Authorization

#authorize_privilege, #authorize_request

Methods inherited from ApplicationController

#initialize, #language

Constructor Details

This class inherits a constructor from Lesli::ApplicationController

Instance Method Details

#createJson

# Executing this controller’s action from javascript’s frontend

let data = {
    dashboard: {
        name: "Sales Dashboard",
        default: false,
        roles_id: 3,
        components_attributes: [
            {
                name: 'Projects Count',
                component_id: projects_component,
                layout: 4,
                index: 3,
                configuration: {}
            }, {
                name: 'New Customers Count',
                component_id: new_customers_component,
                layout: 4,
                index: 3,
                configuration: {}
            }
        ]
    }
};
this.http.post('127.0.0.1/help/dashboards', data);

Returns:

  • (Json)

    Json that contains wheter the creation of the dashboard was successful or not. If it is not successful, it returns an error message



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 105

def create
    dynamic_info = self.class.dynamic_info
    module_name = dynamic_info[:module_name]
    model = dynamic_info[:model]
    full_module_name = dynamic_info[:full_module_name].underscore

    dashboard = model.new(dashboard_params)
    dashboard["#{full_module_name}_account_id".to_sym] = current_user..id
    dashboard.user_creator = current_user

    if dashboard.save
        respond_with_successful(dashboard)
    else
        respond_with_error(dashboard.errors.full_messages.to_sentence)
    end
end

#destroyJson

Returns Json that contains wheter the dashboard was successfully deleted or not. If it it not successful, it returns an error message.

Examples:

# Executing this controller's action from javascript's frontend
let dashboard_id = 4;
this.http.delete(`127.0.0.1/help/dashboards/${dashboard_id}`);

Returns:

  • (Json)

    Json that contains wheter the dashboard was successfully deleted or not. If it it not successful, it returns an error message



181
182
183
184
185
186
187
188
189
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 181

def destroy
    return respond_with_not_found unless @dashboard

    if @dashboard.destroy
        respond_with_successful
    else
        respond_with_error(@dashboard.errors.full_messages.to_sentence)
    end
end

#editObject



63
64
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 63

def edit
end

#indexObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 37

def index
    respond_to do |format|
        format.html {}
        format.json do
            dynamic_info = self.class.dynamic_info
            model = dynamic_info[:model]

            dashboards = model.list(current_user, @query)
            respond_with_successful(dashboards)
        end
    end
end

#newObject



60
61
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 60

def new
end

#optionsObject



191
192
193
194
195
196
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 191

def options
    dynamic_info = self.class.dynamic_info
    model = dynamic_info[:module_model]

    respond_with_successful(model.options(current_user, @query))
end

#resource_componentObject



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 198

def resource_component
    dynamic_info = self.class.dynamic_info
    component_model = dynamic_info[:component_model]

    component_id = sanitize(params[:component_id].to_sym)

    # We verify if the method exists, and if it is in the available component list
    if component_model.respond_to?(component_id) && component_model.component_ids[component_id]
        respond_with_successful(component_model.public_send(component_id, current_user, @query))
    else
        respond_with_not_found()
    end
end

#showObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 50

def show
    respond_to do |format|
        format.html {}
        format.json do
            return respond_with_not_found unless @dashboard
            respond_with_successful(@dashboard.show)
        end
    end
end

#updateJson

# Executing this controller’s action from javascript’s frontend let dashboard_id = 4; let data =

dashboard: {
    name: "Sales Dashboard",
    default: false,
    roles_id: 3,
    components_attributes: [
        {
            name: 'Projects Count',
            component_id: projects_component,
            layout: 4,
            index: 3,
            configuration: {
        }, {
            name: 'New Customers Count',
            component_id: new_customers_component,
            layout: 4,
            index: 3,
            configuration: {}
        }
    ]
}

}; this.http.put(‘127.0.0.1/help/dashboards/${dashboard_id}`, data);

Returns:

  • (Json)

    Json that contains wheter the dashboard was successfully updated or not. If it it not successful, it returns an error message



162
163
164
165
166
167
168
169
170
# File 'app/controllers/lesli/shared/dashboards_controller.rb', line 162

def update
    return respond_with_not_found unless @dashboard

    if @dashboard.update(dashboard_params)
        respond_with_successful(@dashboard.show)
    else
        respond_with_error(@dashboard.errors.full_messages.to_sentence)
    end
end