Module: Lesli::Interfaces::Controllers::Activities

Defined in:
app/controllers/lesli/interfaces/controllers/activities.rb

Instance Method Summary collapse

Instance Method Details

#createJson

Returns Json that contains wheter the creation of the activity was successful or not. If it is not successful, it returs an error message.

Examples:

# Executing this controller's activity from javascript's frontend
let ticket_id = 1;
let data = {
    ticket_activity: {
        description: "Created",
        category: "action_create"
    }
};
this.http.post(`127.0.0.1/help/tickets/${ticket_id}/activities`, data);

Returns:

  • (Json)

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



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/lesli/interfaces/controllers/activities.rb', line 102

def create
    activity_model = activity_model() # If there is a custom activity model, it must be returned in this method
    cloud_object_model = activity_model.cloud_object_model

    set_cloud_object
    new_activity_params = activity_params.merge(
        user_creator: current_user,
        cloud_object: @cloud_object
    )

    activity = activity_model.new(new_activity_params)
    if activity.save
        if block_given?
            yield(cloud_object, activity)
        else
            # Returning the 200 HTTP response
            respond_with_successful(activity)
        end
    else
        respond_with_error(activity.errors.full_messages)
    end
end

#indexJson

Returns Json that contains a list of all activities related to a cloud_object.

Examples:

# Executing this controller's activity from javascript's frontend
let ticket_id = 1;
this.http.get(`127.0.0.1/help/tickets/${ticket_id}/activities`);

Returns:

  • (Json)

    Json that contains a list of all activities related to a cloud_object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/lesli/interfaces/controllers/activities.rb', line 45

def index
    activity_model = activity_model() # If there is a custom activity model, it must be returned in this method
    cloud_object_model = activity_model.cloud_object_model
    translations_module = activity_model.name.split("::")[0].gsub("Cloud", "").underscore
    
    @activities = activity_model.index(
        current_user,
        params["#{cloud_object_model.name.demodulize.underscore}_id".to_sym],
        @query
    )

    if block_given?
        yield(@activities)
    else
        respond_with_successful(@activities)
    end
end

#showJSON

Returns The json information about the selected activity.

Examples:

# Executing this controller's action from javascript's frontend
let ticket_id = 1;
let activity_id = 5;
this.http.get(`127.0.0.1/help/tickets/${ticket_id}/activities/${activity_id}`);

Returns:

  • (JSON)

    The json information about the selected activity



72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/lesli/interfaces/controllers/activities.rb', line 72

def show
    set_activity
    return respond_with_not_found unless @activity

    if block_given?
        yield(@activity)
    else
        return respond_with_successful(@activity)
    end
end