diff --git a/app/controllers/admin/course_editions_controller.rb b/app/controllers/admin/course_editions_controller.rb index 99e9f890efce6486ccccb1dbbdec107446dcb1b1..79a60f48d12e8704934c63e8531995ad82c33c09 100644 --- a/app/controllers/admin/course_editions_controller.rb +++ b/app/controllers/admin/course_editions_controller.rb @@ -329,7 +329,7 @@ module Admin def course_edition_params_with_tags params.require(:course_edition).permit( - course_edition_params_keys + [tags: %i[id name category tag_name configuration _destroy]] + course_edition_params_keys + [tags: %i[id name _destroy]] ) end diff --git a/app/controllers/concerns/tag_updateable.rb b/app/controllers/concerns/tag_updateable.rb index a2eb9f47183438fc36756b6085910288f4ba5d84..cb5e38e571591fac27a16fd37fee086252a878bd 100644 --- a/app/controllers/concerns/tag_updateable.rb +++ b/app/controllers/concerns/tag_updateable.rb @@ -9,35 +9,22 @@ module TagUpdateable tags_params = params_with_tags[:tags] || {} tags_params.each do |id, tag_params| current = Tagging.where(taggable: taggable).find_by(tag_id: id) - name = (tag_params[:name].presence || configure_name(tag_params)) if tag_params[:_destroy].to_s == '1' # Ignore if this currently does not exist current&.destroy elsif tag_params[:id].nil? # New tag current&.destroy - tag = Tag.find_by(name: name.downcase) || Tag.create(name: name.downcase) + tag = Tag.find_by(name: tag_params[:name].downcase) || Tag.create(name: tag_params[:name].downcase) taggable.tags << tag elsif tag_params[:id] != id # Modified tag failed << id if current.nil? # Record failure if not found current&.destroy - taggable.tags.create(name: name.downcase) + taggable.tags.create(name: tag_params[:name].downcase) end end failed end - def configure_name(tag_params) - if tag_params[:category].blank? - tag_params[:tag_name] - elsif tag_params[:configuration] == '0' - "#{tag_params[:category]}:#{tag_params[:tag_name]}" - elsif tag_params[:configuration] == '1' - "#{tag_params[:category]}::#{tag_params[:tag_name]}" - else - "#{tag_params[:category]}:::#{tag_params[:tag_name]}" - end - end - # @param [ActionController::Parameters] params_with_tags the params that includes tags in the :tags property # @param [Object] taggable the object that is taggable # @return [Array] the failed ids diff --git a/app/models/tag.rb b/app/models/tag.rb index bda4482371330f0c6b08566c6cbeda9a1e9f38dd..ffbede84f66dc2f0b7463fdb780e096c098e1a30 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,7 +1,6 @@ class Tag < ApplicationRecord has_many :taggings, dependent: :destroy has_many :taggables, through: :taggings - attr_accessor :category, :tag_name, :configuration # Touch the thing that was tagged such that elasticsearch is informed of the change after_update do diff --git a/app/models/tagging.rb b/app/models/tagging.rb index b8af007576b14d6b372d61a440a3583964d6319e..3706d6cf26f7f5dda67a80bd46e6c053a931d595 100644 --- a/app/models/tagging.rb +++ b/app/models/tagging.rb @@ -1,16 +1,6 @@ class Tagging < ApplicationRecord belongs_to :tag belongs_to :taggable, polymorphic: true - validate :category_mentioned_has_different_setting - - def category_mentioned_has_different_setting - taggable.tags.each do |my_tag| - if my_tag.name.include?(':') && (my_tag.name.split(':').first == tag.name.split(':').first && my_tag.name.count(':') != tag.name.count(':')) - errors.add(:category, "#{tag.name.split(':').first} that you try to add already exists with different setting in this course edition") - break - end - end - end after_destroy do tag.destroy_if_unassociated diff --git a/app/views/admin/application/_tag_fields.html.erb b/app/views/admin/application/_tag_fields.html.erb index bc25add6b9528e084f731b629774152f003f0efd..90530bd3015638aa4666ac8bfc3872c9bb00bbda 100644 --- a/app/views/admin/application/_tag_fields.html.erb +++ b/app/views/admin/application/_tag_fields.html.erb @@ -1,9 +1,16 @@ <div class="nested-fields list-group-item"> - <div class="row"> - <%= f.hidden_field :id, value: f.object.id %> - <div class="col-xs-9"><%= f.object.name.split(':').last %></div> - <div class="text-center col-xs-1"> - <%= cocoon_remove_link f %> - </div> - </div> + <div class="panel panel-default"> + <table class="table table-striped"> + <tbody> + <tr> + <%= f.hidden_field :id, value: f.object.id %> + <td class="col-xs-2"><strong><%= Tag.human_attribute_name :name %></strong></td> + <td class="col-xs-9"><%= f.object.name %></td> + <td rowspan="4" class="text-center col-xs-1"> + <%= cocoon_remove_link f %> + </td> + </tr> + </tbody> + </table> + </div> </div> diff --git a/app/views/admin/application/_tag_fields_new.html.erb b/app/views/admin/application/_tag_fields_new.html.erb index 9dc0f9639cd96a96e6d971a6d79c28dc132abc2d..f0c3b51974aefdf109f8f645ed13a0b7c5a149a5 100644 --- a/app/views/admin/application/_tag_fields_new.html.erb +++ b/app/views/admin/application/_tag_fields_new.html.erb @@ -3,29 +3,19 @@ <table class="table table-striped"> <tbody> <tr> - <td class="col-xs-2"><strong><%= Tag.human_attribute_name :category %></strong></td> - <td class="col-xs-9" id="category-field"><%= f.text_field :category, hide_label: true %></td> - </tr> - <tr> - <td class="col-xs-2"><strong><%= Tag.human_attribute_name :tag_name %></strong></td> - <td class="col-xs-9"><%= f.text_field :tag_name, required: true, hide_label: true %></td> + <td class="col-xs-2"><strong><%= Tag.human_attribute_name :name %></strong></td> + <td class="col-xs-9"><%= f.text_field :name, hide_label: true, list: 'tag-list' %> + <datalist id="tag-list"> + <% Tag.all.each do |tag| %> + <option value="<%= tag.name %>"></option> + <% end %> + </datalist> + </td> <td rowspan="4" class="text-center col-xs-1"> <%= cocoon_remove_link f %> </td> </tr> - <tr> - <td class="col-xs-2"><strong><%= Tag.human_attribute_name :configuration %></strong> <small><%= t("admin.themes.tags.applicable_category") %></small></td> - <td class="col-xs-9"> - <%= f.select :configuration, - [[t("admin.themes.tags.one_configuration"), 0], - [t("admin.themes.tags.one_or_more_configuration"), 1], - [t("admin.themes.tags.none_or_more_configuration"), 2]], - hide_label: true - %> - </td> - </tr> </tbody> </table> </div> </div> - diff --git a/app/views/admin/course_editions/edit/_project_tags.html.erb b/app/views/admin/course_editions/edit/_project_tags.html.erb index 56f30adb415e512389889617b20764d376d32dfe..c5e63c68b330c9ba9518f26ed858995f088dfe55 100644 --- a/app/views/admin/course_editions/edit/_project_tags.html.erb +++ b/app/views/admin/course_editions/edit/_project_tags.html.erb @@ -1,8 +1,8 @@ <%# -<!-- Partial for modifying the project tags.--> + Partial for modifying the project tags. -<!-- Required parameters:--> -<!-- * f: the form modifying course_edition--> + Required parameters: + * f: the form modifying course_edition %> <div class="panel panel-default"> @@ -12,61 +12,35 @@ <%= popover t('admin.course_editions.tags.explanation') %> </h3> </div> - <% grouped_tags = @course_edition.tags.group_by do |tag| - num_columns = tag.name.split(':').count - 1 - conf = case num_columns - when 1 - t("admin.themes.tags.one_configuration") - when 2 - t("admin.themes.tags.one_or_more_configuration") - when 3 - t("admin.themes.tags.none_or_more_configuration") - else - "" - end - name_before_colon = tag.name.include?(':') ? tag.name.split(':').first : '' - [name_before_colon, conf] - end - %> - <% grouped_tags.each do |group, tags| %> - <div class="panel panel-default"> - <% if group.first != '' %> - <div class="panel-heading"> - <h3 class="panel-title" id="tags"> - <%= glyphicon :tags %> <%= group.first.capitalize %> - <small><%= group.last %></small> - </h3> - </div> + <div class="list-group cocoon"> + + <%= f.fields_for :tags do |f_tags| %> + <% @course_edition.tags.sort_by_name.each do |tag| %> + <%= f_tags.fields_for tag.id.to_s, tag do |f_tag| %> + <%= render 'admin/application/tag_fields', f: f_tag %> + <% end %> <% end %> - <div class="list-group cocoon"> - <%= f.fields_for :tags do |f_tags| %> - <% tags.each do |tag| %> - <%= f_tags.fields_for tag.id.to_s, tag do |f_tag| %> - <%= render 'admin/application/tag_fields', f: f_tag %> - <% end %> - <% end %> - <% @override_tags&.each do |tag| %> - <%= f_tags.fields_for (tag.id + 1000000).to_s, tag do |f_tag| %> - <%= render 'admin/application/tag_fields_new', f: f_tag %> - <% end %> - <% end %> + + <% @override_tags&.each do |tag| %> + <%= f_tags.fields_for (tag.id + 1000000).to_s, tag do |f_tag| %> + <%= render 'admin/application/tag_fields_new', f: f_tag %> <% end %> - </div> - </div> - <% end %> - <%= f.fields_for :tags do |f_tags| %> - <a class="list-group-item list-group-item--button add_fields" data-association-insertion-node="this" - data-association="tag" data-associations="tags" id="tag_add" - data-association-insertion-template=" - <%= CGI.escapeHTML(render_association('new_tags', - f_tags, - Tag.new, - 'f', - { wrapper: 'inline' }, - 'admin/application/tag_fields_new').to_str).html_safe %> - " href="#"> - <%= glyphicon_text('plus-sign', "Add #{Tag.model_name.human}") %> - </a> - <% end %> -</div> + <% end %> + + <a class="list-group-item list-group-item--button add_fields" data-association-insertion-node="this" + data-association="tag" data-associations="tags" id="tag_add" + data-association-insertion-template=" + <%= CGI.escapeHTML(render_association('new_tags', + f_tags, + Tag.new, + 'f', + { wrapper: 'inline' }, + 'admin/application/tag_fields_new').to_str).html_safe %> + " href="#"> + <%= glyphicon_text('plus-sign', "Add #{Tag.model_name.human}") %> + </a> + <% end %> + + </div> +</div> \ No newline at end of file diff --git a/app/views/admin/course_editions/show/_project_tags.html.erb b/app/views/admin/course_editions/show/_project_tags.html.erb index 9f35a6d7ab0618fc965ae89fcacfa909b55b6095..257d4b5c7540df3b2328cbfb035a9f53420cfd6c 100644 --- a/app/views/admin/course_editions/show/_project_tags.html.erb +++ b/app/views/admin/course_editions/show/_project_tags.html.erb @@ -5,46 +5,21 @@ <%= popover t('admin.course_editions.tags.explanation') %> </h3> </div> - - <% grouped_tags = @course_edition.tags.group_by do |tag| - num_columns = tag.name.split(':').count - 1 - conf = case num_columns - when 1 - t("admin.themes.tags.one_configuration") - when 2 - t("admin.themes.tags.one_or_more_configuration") - when 3 - t("admin.themes.tags.none_or_more_configuration") - else - "" - end - name_before_colon = tag.name.include?(':') ? tag.name.split(':').first : '' - [name_before_colon, conf] - end %> - <div class="list-group"> - <% grouped_tags.each do |group_name, tags| %> - <% unless tags.empty? %> - <div class="list-group-item"> - <strong><%= group_name.first.capitalize %></strong> - <small><%= group_name.last %></small> - <% tags.each do |tag| %> - <div data-item id="tag-<%= tag.id %>"> - <div class="pull-left"> - <a class="btn" data-item-display="true" data-item-name="true"><%= glyphicon :tag %> <%= tag.name.split(':').last %></a> - </div> - <div class="pull-right"> - <% if can? :destroy, tag %> - <%= link_to tag_delete_admin_course_edition_path(@course_edition.course, @course_edition, tag), class: 'btn', method: :delete, data: { confirm: "Are you sure you want to remove tag #{tag.name}?", remote: true } do %> - <%= glyphicon 'trash' %> - <% end %> - <% end %> - </div> - <div class="clear"></div> - </div> + <% @course_edition.tags.sort_by_name.each do |tag| %> + <div class="list-group-item" data-item id="tag-<%= tag.id %>"> + <div class="pull-left"> + <a class="btn" data-item-display="true" data-item-name="true"><%= glyphicon :tag %> <%= tag.name %></a> + </div> + <div class="pull-right"> + <% if can? :destroy, tag %> + <%= link_to tag_delete_admin_course_edition_path(@course_edition.course, @course_edition, tag), class: 'btn', method: :delete, data: { confirm: "Are you sure you want to remove tag #{tag.name}?", remote: true } do %> + <%= glyphicon 'trash' %> <% end %> + <% end %> </div> - <% end %> + <div class="clear"></div> + </div> <% end %> <% if can? :update, @course_edition %> <li class="list-group-item" id="new-tag" data-item> @@ -55,4 +30,4 @@ </li> <% end %> </div> -</div> +</div> \ No newline at end of file diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 42553f7e536b989ead051c9639aee4309c7a70d1..3152345cce2a098fb57e3e579bf146ec7497f768 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -167,10 +167,6 @@ will be assigned to all members of the group on the 'students' sheet automatical tags: label: Tags explanation: Tags affect searches by students and are used for auto completion. Add relevant keywords, courses, etc. as tags to improve searchability. You can also add tags that don't exist yet by typing. - one_configuration: exactly one must be selected - one_or_more_configuration: one or more must be selected - none_or_more_configuration: zero or more may be selected - applicable_category: "Applicable only for category tags" thesis_projects: associated_users: label: Associated Users diff --git a/config/locales/views/nl.yml b/config/locales/views/nl.yml index 48d7b6885802d5c2de30d37fbad50bd13f92b0d8..30fedb64cd30da3ac98b6603801b3e55e5e59400 100644 --- a/config/locales/views/nl.yml +++ b/config/locales/views/nl.yml @@ -174,10 +174,6 @@ worden dan automatisch toegekend aan alle leden van de groep op de 'students' sh tags: label: Labels explanation: Labels hebben effect op zoekopdrachten bij studenten en worden gebruikt voor automatisch aanvullen van zoektermen. Voeg relevante kernwoorden, vakken, etc. toe als labels om vindbaarheid te verbeteren. U kunt ook nieuwe labels maken door deze in te typen. - one_configuration: precies één moet worden geselecteerd - one_or_more_configuration: tenminste één moet worden geselecteerd - none_or_more_configuration: nul of meer mogen worden geselecteerd - applicable_category: "Toepasbaar alleen voor categorielabels" thesis_projects: associated_users: label: Gekoppelde Gebruikers