Class: LabelsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- LabelsController
- Defined in:
- app/controllers/labels_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #create_from_concept ⇒ Object
- #destroy ⇒ Object
- #duplicate ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #new_from_concept ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/labels_controller.rb', line 68 def create :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new(label_params) if @label.valid? if @label.save flash[:success] = I18n.t('txt.controllers.versioned_label.success') redirect_to label_path(published: 0, id: @label.origin) else flash.now[:error] = I18n.t('txt.controllers.versioned_label.error') render :new end else flash.now[:error] = I18n.t('txt.controllers.versioned_label.error') render :new end end |
#create_from_concept ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/controllers/labels_controller.rb', line 162 def create_from_concept :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new(label_params) @label.build_initial_change_note(current_user) if @label.save #TODO: idea for solving this #flash[:success] = I18n.t('txt.controllers.versioned_label.success') head :created else #TODO: idea for solving this #flash.now[:error] = I18n.t('txt.controllers.versioned_label.error') head :bad_request end end |
#destroy ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/labels_controller.rb', line 125 def destroy @new_label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :destroy, @new_label if @new_label.destroy published_label = Iqvoc::XLLabel.base_class.published.by_origin(@new_label.origin).first flash[:success] = I18n.t('txt.controllers.label_versions.delete') redirect_to published_label.present? ? label_path(id: published_label.origin) : dashboard_path else flash[:error] = I18n.t('txt.controllers.label_versions.delete_error') redirect_to label_path(published: 0, id: @new_label) end end |
#duplicate ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/labels_controller.rb', line 139 def duplicate :create, Iqvoc::XLLabel.base_class label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).published.first if Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last flash[:error] = t('txt.controllers.label.duplicate_error') redirect_to label_path(published: 1, id: label) end @new_label = label.duplicate(current_user) @new_label.build_notes end |
#edit ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/labels_controller.rb', line 87 def edit @label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :update, @label if params[:check_associations_in_editing_mode] @association_objects_in_editing_mode = @label.associated_objects_in_editing_mode end # @pref_labelings = PrefLabeling.by_label(@label).all(:include => {:owner => :pref_labels}).sort # @alt_labelings = AltLabeling.by_label(@label).all(:include => {:owner => :pref_labels}).sort if params[:full_consistency_check] @label.publishable? end @label.build_notes end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/labels_controller.rb', line 4 def index :read, Iqvoc::XLLabel.base_class search_string = search_string(params[:query], params[:mode]) scope = Iqvoc::XLLabel.base_class .editor_selectable .by_query_value(search_string) if params[:language] # NB: this is not the same as :lang, which is supplied via route scope = scope.by_language(params[:language]) end @labels = scope.order(Arel.sql("LENGTH(#{Iqvoc::XLLabel.base_class.table_name}.value)")).all respond_to do |format| format.html do redirect_to action: 'index', format: 'txt' end format.text do render content_type: 'text/plain', text: @labels.map { |label| "#{label.origin}: #{label.value}" }.join("\n") end format.json do response = [] # group labels to avoid duplicates # FIXME: filter in SQL directly @labels.group_by { |l| l.origin }.each { |origin, labels| response << (labels.first) } render json: response end end end |
#new ⇒ Object
61 62 63 64 65 66 |
# File 'app/controllers/labels_controller.rb', line 61 def new :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new @label.build_initial_change_note(current_user) @label.build_notes end |
#new_from_concept ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'app/controllers/labels_controller.rb', line 151 def new_from_concept :create, Iqvoc::XLLabel.base_class @label = Iqvoc::XLLabel.base_class.new respond_to do |format| format.html do render layout: false end end end |
#show ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/labels_controller.rb', line 38 def show scope = Iqvoc::XLLabel.base_class.by_origin(params[:id]).with_associations @published = params[:published] == '1' || !params[:published] if @published scope = scope.published @new_label_version = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last else scope = scope.unpublished end @label = scope.last! :read, @label respond_to do |format| format.html do @published ? render('show_published') : render('show_unpublished') end format.any(:rdf, :ttl, :nt) end end |
#update ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/labels_controller.rb', line 105 def update @label = Iqvoc::XLLabel.base_class.by_origin(params[:id]).unpublished.last! :update, @label # set to_review to false if someone edits a label label_params["to_review"] = "false" respond_to do |format| format.html do if @label.update(label_params) flash[:success] = I18n.t('txt.controllers.versioned_label.update_success') redirect_to label_path(published: 0, id: @label) else flash.now[:error] = I18n.t('txt.controllers.versioned_label.update_error') render action: :edit end end end end |