From 4244dcb3e69f8cbf164eb25efd2fce4129fe71b2 Mon Sep 17 00:00:00 2001 From: ArtOfCode- <hello@artofcode.co.uk> Date: Fri, 31 Jul 2020 13:22:41 +0100 Subject: [PATCH] Address review comments --- app/controllers/pinned_links_controller.rb | 10 ++--- app/controllers/posts_controller.rb | 2 +- app/views/categories/_form.html.erb | 4 +- app/views/pinned_links/_form.html.erb | 52 ++++++++++++++++++++++ app/views/pinned_links/edit.html.erb | 52 +--------------------- app/views/pinned_links/index.html.erb | 18 +++++--- app/views/pinned_links/new.html.erb | 52 +--------------------- 7 files changed, 73 insertions(+), 117 deletions(-) create mode 100644 app/views/pinned_links/_form.html.erb diff --git a/app/controllers/pinned_links_controller.rb b/app/controllers/pinned_links_controller.rb index 127e8dffd..64b7139ff 100644 --- a/app/controllers/pinned_links_controller.rb +++ b/app/controllers/pinned_links_controller.rb @@ -33,10 +33,9 @@ class PinnedLinksController < ApplicationController attr = @link.attributes.map { |k, v| "#{k}: #{v}" }.join(' ') AuditLog.moderator_audit(event_type: 'pinned_link_create', related: @link, user: current_user, - comment: "<<PinnedLink #{attr}>>") + comment: "<<PinnedLink #{attr}>>") - flash[:success] = 'Your pinned link has been created. Due to caching, it may take some time, '\ - 'until it is shown.' + flash[:success] = 'Your pinned link has been created. Due to caching, it may take some time until it is shown.' redirect_to pinned_links_path end @@ -58,10 +57,9 @@ class PinnedLinksController < ApplicationController @link.update data.merge(post: post, community: community) after = @link.attributes.map { |k, v| "#{k}: #{v}" }.join(' ') AuditLog.moderator_audit(event_type: 'pinned_link_update', related: @link, user: current_user, - comment: "from <<PinnedLink #{before}>>\nto <<PinnedLink #{after}>>") + comment: "from <<PinnedLink #{before}>>\nto <<PinnedLink #{after}>>") - flash[:success] = 'The pinned link has been updated. Due to caching, it may take some time, ' \ - 'until it is shown.' + flash[:success] = 'The pinned link has been updated. Due to caching, it may take some time until it is shown.' redirect_to pinned_links_path end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a1d8c434c..381789634 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -178,7 +178,7 @@ class PostsController < ApplicationController attr = @link.attributes.map { |k, v| "#{k}: #{v}" }.join(' ') AuditLog.moderator_audit(event_type: 'pinned_link_create', related: @link, user: current_user, comment: "<<PinnedLink #{attr}>>\n(using moderator tools on post)") - flash[:success] = 'Post has been featured. Due to caching it may take some time, until the changes apply.' + flash[:success] = 'Post has been featured. Due to caching, it may take some time until the changes apply.' render json: { success: true } end diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index 8941ae888..097316ac3 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -93,7 +93,7 @@ <div class="form-group"> <%= f.label :asking_guidance_override, class: 'form-element' %> <span class="form-caption"> - This field overrides the default asking guidance and is shown, when a new post is created. Leave blank to use site-default. + This field overrides the default asking guidance and is shown when a new post is created. Leave blank to use site-default. </span> <%= f.text_area :asking_guidance_override, class: 'form-element' %> </div> @@ -101,7 +101,7 @@ <div class="form-group"> <%= f.label :answering_guidance_override, class: 'form-element' %> <span class="form-caption"> - This field overrides the default answering guidance and is shown, when a new answer is created. Leave blank to use site-default. + This field overrides the default answering guidance and is shown when a new answer is created. Leave blank to use site-default. </span> <%= f.text_area :answering_guidance_override, class: 'form-element' %> </div> diff --git a/app/views/pinned_links/_form.html.erb b/app/views/pinned_links/_form.html.erb new file mode 100644 index 000000000..1452dde02 --- /dev/null +++ b/app/views/pinned_links/_form.html.erb @@ -0,0 +1,52 @@ +<%= form_for @link, url: url do |f| %> + <div class="form-group has-padding-1"> + <%= f.label :label, "Shown label", class: "form-element" %> + <div class="form-caption">What is shown in the sidebar. This will be ignored when a post is set.</div> + <%= f.text_area :label, class: "form-element" %> + </div> + + <div class="form-group has-padding-1"> + <%= f.label :link, "Target link", class: "form-element" %> + <div class="form-caption">What the label is linked to in the sidebar. This will be ignored when a post is set.</div> + <%= f.text_field :link, class: "form-element" %> + </div> + + <% if current_user.is_global_moderator %> + <div class="form-group has-padding-1"> + <%= f.label :community, "Community", class: "form-element" %> + <div class="form-caption">Which sidebar this is shown in the sidebar. Global if blank.</div> + <% communities = Community.all %> + <% ocs = communities.map { |c| [c.name, c.id] } %> + <%= f.select :community, options_for_select(ocs, selected: @link.community&.id), + { include_blank: true }, class: 'form-element' %> + </div> + <% end %> + + <div class="form-group has-padding-1"> + <%= f.label :post_id, "ID of target post", class: "form-element" %> + <div class="form-caption">You can link to a post within this community. Will override label and link.</div> + <%= f.number_field :post_id, class: "form-element" %> + </div> + + <div class="form-group has-padding-1"> + <%= f.label :active, "Active?", class: "form-element" %> + <%= f.select :active, options_for_select([['yes', true], ['no', false]], selected: @link.active), + {}, class: 'form-element' %> + </div> + + <div class="form-group has-padding-1"> + <%= f.label :shown_before, "End date", class: "form-element" %> + <div class="form-caption">Link will show until this date. Will be shown in the sidebar.</div> + <%= f.date_field :shown_before, class: "form-element" %> + </div> + + <div class="form-group has-padding-1"> + <%= f.label :shown_after, "Start date", class: "form-element" %> + <div class="form-caption">Used to display in the sidebar when the event starts. Does not affect visibility - the event + will show immediately.</div> + <%= f.date_field :shown_after, class: "form-element" %> + </div> + + <%= f.submit "Update", class: "button is-filled" %> + <%= link_to "Cancel", pinned_links_path(global: params[:global]), class: "button" %> +<% end %> \ No newline at end of file diff --git a/app/views/pinned_links/edit.html.erb b/app/views/pinned_links/edit.html.erb index 8c43add89..eafe82cc7 100644 --- a/app/views/pinned_links/edit.html.erb +++ b/app/views/pinned_links/edit.html.erb @@ -11,54 +11,4 @@ </div> <% end %> -<%= form_for @link, url: update_pinned_link_path(global: params[:global]) do |f| %> - <div class="form-group has-padding-1"> - <%= f.label :label, "Shown label", class: "form-element" %> - <div class="form-caption">What is shown in the sidebar. This will be ignored, when a post is set.</div> - <%= f.text_area :label, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :link, "Target link", class: "form-element" %> - <div class="form-caption">What the label is linked to in the sidebar. This will be ignored, when a post is set.</div> - <%= f.text_field :link, class: "form-element" %> - </div> - - <% if current_user.is_global_moderator %> - <div class="form-group has-padding-1"> - <%= f.label :community, "Community", class: "form-element" %> - <div class="form-caption">Which sidebar this is shown in the sidebar. Global if blank.</div> - <% communities = Community.all %> - <% ocs = communities.map { |c| [c.name, c.id] } %> - <%= f.select :community, options_for_select(ocs, selected: @link.community&.id), - { include_blank: true }, class: 'form-element' %> - </div> - <% end %> - - <div class="form-group has-padding-1"> - <%= f.label :post_id, "ID of target post", class: "form-element" %> - <div class="form-caption">You can link to a post of this community. Will override label and link.</div> - <%= f.number_field :post_id, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :active, "Active?", class: "form-element" %> - <%= f.select :active, options_for_select([['yes', true], ['no', false]], selected: @link.active), - {}, class: 'form-element' %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :shown_before, "Shown before", class: "form-element" %> - <div class="form-caption">Link will expire showing on that date. Will be shown in the sidebar as meta data.</div> - <%= f.date_field :shown_before, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :shown_after, "Begin of Event", class: "form-element" %> - <div class="form-caption">Use only, when shown before is set. Use, when your event spans more than one day. Will indicate, whether the event already started or ended in the sidebar. Does not affect visibility.</div> - <%= f.date_field :shown_after, class: "form-element" %> - </div> - - <%= f.submit "Update", class: "button is-filled" %> - <%= link_to "Cancel", pinned_links_path(global: params[:global]), class: "button" %> -<% end %> +<%= render 'form', url: update_pinned_link_path(global: params[:global]) %> diff --git a/app/views/pinned_links/index.html.erb b/app/views/pinned_links/index.html.erb index 8a99075c8..f95ebe133 100644 --- a/app/views/pinned_links/index.html.erb +++ b/app/views/pinned_links/index.html.erb @@ -5,17 +5,23 @@ <% if current_user.is_global_moderator %> <div class="grid--cell"> <div class="button-list is-gutterless"> - <%= link_to "current community", "?global=0&filter="+(params[:filter]||'active'), class: "button is-muted is-outlined #{(params[:global]=='0' || params[:global].nil?) ? 'is-active' : ''}" %> - <%= link_to "global", "?global=1&filter="+(params[:filter]||'active'), class: "button is-muted is-outlined #{(params[:global]=='1') ? 'is-active' : ''}" %> - <%= link_to "everywhere", "?global=2&filter="+(params[:filter]||'active'), class: "button is-muted is-outlined #{(params[:global]=='2') ? 'is-active' : ''}" %> + <%= link_to "current community", query_url(global: '0', filter: params[:filter] || 'active'), + class: "button is-muted is-outlined #{(params[:global] == '0' || params[:global].nil?) ? 'is-active' : ''}" %> + <%= link_to "global", query_url(global: '1', filter: params[:filter] || 'active'), + class: "button is-muted is-outlined #{(params[:global] == '1') ? 'is-active' : ''}" %> + <%= link_to "everywhere", query_url(global: '2', filter: params[:filter] || 'active'), + class: "button is-muted is-outlined #{(params[:global] == '2') ? 'is-active' : ''}" %> </div> </div> <% end %> <div class="grid--cell"> <div class="button-list is-gutterless"> - <%= link_to "active", "?global="+(params[:global]||'0')+"&filter=active", class: "button is-muted is-outlined #{(params[:filter]=='active' || params[:filter].nil?) ? 'is-active' : ''}" %> - <%= link_to "inactive", "?global="+(params[:global]||'0')+"&filter=inactive", class: "button is-muted is-outlined #{(params[:filter]=='inactive') ? 'is-active' : ''}" %> - <%= link_to "all", "?global="+(params[:global]||'0')+"&filter=all", class: "button is-muted is-outlined #{(params[:filter]=='all') ? 'is-active' : ''}" %> + <%= link_to "active", query_url(global: params[:global] || '0', filter: 'active'), + class: "button is-muted is-outlined #{(params[:filter] == 'active' || params[:filter].nil?) ? 'is-active' : ''}" %> + <%= link_to "inactive", query_url(global: params[:global] || '0', filter: 'inactive'), + class: "button is-muted is-outlined #{(params[:filter] == 'inactive') ? 'is-active' : ''}" %> + <%= link_to "all", query_url(global: params[:global] || '0', filter: 'all'), + class: "button is-muted is-outlined #{(params[:filter] == 'all') ? 'is-active' : ''}" %> </div> </div> <div class="grid--cell is-flexible"> diff --git a/app/views/pinned_links/new.html.erb b/app/views/pinned_links/new.html.erb index 9cdd5babd..e719f8c89 100644 --- a/app/views/pinned_links/new.html.erb +++ b/app/views/pinned_links/new.html.erb @@ -11,54 +11,4 @@ </div> <% end %> -<%= form_for @link, url: create_pinned_link_path do |f| %> - <div class="form-group has-padding-1"> - <%= f.label :label, "Shown label", class: "form-element" %> - <div class="form-caption">What is shown in the sidebar. This will be ignored, when a post is set.</div> - <%= f.text_area :label, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :link, "Target link", class: "form-element" %> - <div class="form-caption">What the label is linked to in the sidebar. This will be ignored, when a post is set.</div> - <%= f.text_field :link, class: "form-element" %> - </div> - - <% if current_user.is_global_moderator %> - <div class="form-group has-padding-1"> - <%= f.label :community, "Community", class: "form-element" %> - <div class="form-caption">Which sidebar this is shown in the sidebar. Global if blank.</div> - <% communities = Community.all %> - <% ocs = communities.map { |c| [c.name, c.id] } %> - <%= f.select :community, options_for_select(ocs, selected: @link.community&.id), - { include_blank: true }, class: 'form-element' %> - </div> - <% end %> - - <div class="form-group has-padding-1"> - <%= f.label :post_id, "ID of target post", class: "form-element" %> - <div class="form-caption">You can link to a post of this community. Will override label and link.</div> - <%= f.number_field :post_id, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :active, "Active?", class: "form-element" %> - <%= f.select :active, options_for_select([['yes', true], ['no', false]], selected: @link.active), - {}, class: 'form-element' %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :shown_before, "Shown before", class: "form-element" %> - <div class="form-caption">Link will expire showing on that date. Will be shown in the sidebar as meta data.</div> - <%= f.date_field :shown_before, class: "form-element" %> - </div> - - <div class="form-group has-padding-1"> - <%= f.label :shown_after, "Begin of Event", class: "form-element" %> - <div class="form-caption">Use only, when shown before is set. Use, when your event spans more than one day. Will indicate, whether the event already started or ended in the sidebar. Does not affect visibility.</div> - <%= f.date_field :shown_after, class: "form-element" %> - </div> - - <%= f.submit "Create", class: "button is-filled" %> - <%= link_to "Cancel", pinned_links_path(global: params[:global]), class: "button" %> -<% end %> +<%= render 'form', url: create_pinned_link_path %> \ No newline at end of file -- GitLab