Class: LesliBabel::LabelsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /labels



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/lesli_babel/labels_controller.rb', line 23

def create

    @label = Label.new(label_params)
    if @label.save
        respond_to do |format|
            format.html 
            format.turbo_stream do 
                respond_with_lesli(
                    :turbo => [
                        stream_notification_success('Label was successfully created.'),
                        stream_redirection(label_path(@label))
                    ]
                )
            end
        end
    else
        render :new, status: :unprocessable_entity
    end
end

#destroyObject

DELETE /labels/1



91
92
93
94
# File 'app/controllers/lesli_babel/labels_controller.rb', line 91

def destroy
    @label.destroy
    redirect_to labels_url, notice: "Label was successfully destroyed.", status: :see_other
end

#editObject



43
44
# File 'app/controllers/lesli_babel/labels_controller.rb', line 43

def edit
end

#indexObject

GET /labels



7
8
9
10
# File 'app/controllers/lesli_babel/labels_controller.rb', line 7

def index
    query[:pagination][:perPage] = 100
    @labels = respond_with_pagination(LabelService.new(current_user, query).index(params))
end

#newObject

GET /labels/new



18
19
20
# File 'app/controllers/lesli_babel/labels_controller.rb', line 18

def new
    @label = Label.new
end

#showObject

GET /labels/1



13
14
15
# File 'app/controllers/lesli_babel/labels_controller.rb', line 13

def show
    @label = @label.show
end

#updateObject

PATCH/PUT /labels/1



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
81
82
83
84
85
86
87
88
# File 'app/controllers/lesli_babel/labels_controller.rb', line 47

def update
    return respond_with_not_found unless @label.found?

    @label = @label.result

    # if status changed
    if @label["status"] != label_params["status"]

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

    end

    # if context changed
    if @label["context"] != label_params["context"]

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

    end

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

        # if translation changed
        if @label[locale] != label_params[locale]

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

    if @label.update(label_params)
        respond_with_lesli(
            :turbo => [
                stream_notification_success("Translation label updated successfully!"),
                turbo_stream.replace('lesli-babel-labels-form', partial: 'lesli_babel/labels/form')
            ]
        )
    else
        respond_with_lesli(:turbo => stream_notification_success("Error updating translation label"))
    end
end