Class: LesliBabel::StringsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lesli_babel/strings_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /strings



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/lesli_babel/strings_controller.rb', line 30

def create

    if String.find_by(
        label: string_params[:label],
        bucket_id: string_params[:bucket_id]
    )
        return respond_with_error("Duplicated string")
    end
    
    string = String.new(string_params)
    if string.save
        #String.log_activity_create(current_user, string)
        respond_with_successful(string)
    else
        respond_with_error("Error on create translation string", string.errors)
    end
end

#destroyObject

DELETE /strings/1



97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/lesli_babel/strings_controller.rb', line 97

def destroy
    return respond_with_not_found unless @string

    if @string.destroy
        respond_with_successful

        String.log_activity_destroy(current_user, @string)
    else
        respond_with_error(@string.errors.full_messages.to_sentence)
    end
end

#editObject

GET /strings/1/edit



26
27
# File 'app/controllers/lesli_babel/strings_controller.rb', line 26

def edit
end

#indexObject

GET /strings



7
8
9
10
11
12
13
14
# File 'app/controllers/lesli_babel/strings_controller.rb', line 7

def index
    respond_to do |format|
        format.html { }
        format.json { 
            respond_with_pagination(StringService.new(current_user, query).index(params))
        }
    end
end

#localesObject

return a list of the locales available



118
119
120
# File 'app/controllers/lesli_babel/strings_controller.rb', line 118

def locales
    respond_with_successful(Rails.application.config.lesli.dig(:configuration, :locales))
end

#newObject

GET /strings/new



21
22
23
# File 'app/controllers/lesli_babel/strings_controller.rb', line 21

def new
    @string = String.new
end

#relevantObject



113
114
115
# File 'app/controllers/lesli_babel/strings_controller.rb', line 113

def relevant
    respond_with_pagination(String.relevant(current_user, @query, params))
end

#showObject

GET /strings/1



17
18
# File 'app/controllers/lesli_babel/strings_controller.rb', line 17

def show
end

#statsObject



109
110
111
# File 'app/controllers/lesli_babel/strings_controller.rb', line 109

def stats
    respond_with_successful(StringService.new(current_user, query).stats())
end

#updateObject

PATCH/PUT /strings/1



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/lesli_babel/strings_controller.rb', line 49

def update
    return respond_with_not_found unless @string

    # We store the original attributes
    old_attributes = @string.attributes

    # if status changed
    if @string["status"] != string_params["status"]

        # saved update date
        @string["last_update_status"] = Time.now

    end

    # if context changed
    if @string["context"] != string_params["context"]

        # saved update date
        @string["last_update_context"] = Time.now

    end

    Lesli.config.locales.keys.each do |locale|

        # if translation changed
        if @string[locale] != string_params[locale]

            # saved update date
            @string["last_update_#{locale}"] = Time.now

        end

    end

    if @string.update(string_params)

        # We store the new attributes and compare the activities
        new_attributes = @string.attributes
        #String.log_activity_update(current_user, @string, old_attributes, new_attributes)

        respond_with_successful(@string)
    else
        respond_with_error(@string.errors.full_sentence)
    end

end