From 376623f2aae3ba6fff9722735835ecb1a27a3906 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 18:33:50 +0300 Subject: [PATCH 1/6] Refactor admin index --- .../web/admin/activity_lines_controller.rb | 5 ++- .../web/admin/comments_controller.rb | 4 +-- .../web/admin/events_controller.rb | 12 +++---- app/helpers/web/admin/application_helper.rb | 11 ++++++- app/scopes/activity_line_scopes.rb | 1 + .../_activity_lines_list.html.haml | 26 +++++++++++++++ .../web/admin/activity_lines/index.html.haml | 33 +------------------ app/views/web/admin/articles/index.html.haml | 17 +--------- app/views/web/admin/banners/index.html.haml | 17 +--------- app/views/web/admin/comments/index.html.haml | 17 +--------- app/views/web/admin/default/_index.html.haml | 16 +++++++++ app/views/web/admin/events/index.html.haml | 24 +------------- app/views/web/admin/feedback/index.html.haml | 17 +--------- app/views/web/admin/members/index.html.haml | 22 +------------ app/views/web/admin/news/index.html.haml | 17 +--------- .../web/admin/questionaries/index.html.haml | 17 +--------- app/views/web/admin/teams/index.html.haml | 17 +--------- app/views/web/admin/users/index.html.haml | 17 +--------- config/locales/ru/models.yml | 6 ++++ 19 files changed, 82 insertions(+), 214 deletions(-) create mode 100644 app/views/web/admin/activity_lines/_activity_lines_list.html.haml create mode 100644 app/views/web/admin/default/_index.html.haml diff --git a/app/controllers/web/admin/activity_lines_controller.rb b/app/controllers/web/admin/activity_lines_controller.rb index e7b2f266..1ca3da5b 100644 --- a/app/controllers/web/admin/activity_lines_controller.rb +++ b/app/controllers/web/admin/activity_lines_controller.rb @@ -2,7 +2,10 @@ class Web::Admin::ActivityLinesController < Web::Admin::ApplicationController before_filter :choose_members, only: [ :new, :edit ] def index - @activity_lines = Kaminari.paginate_array(ActivityLine.all.decorate).page params[:page] + @activity_lines = {} + @activity_lines[:active] = Kaminari.paginate_array(ActivityLine.active.decorate).page params[:page] + @activity_lines[:unviewed] = Kaminari.paginate_array(ActivityLine.unviewed.decorate).page params[:page] + @activity_lines[:removed] = Kaminari.paginate_array(ActivityLine.removed.decorate).page params[:page] end def new diff --git a/app/controllers/web/admin/comments_controller.rb b/app/controllers/web/admin/comments_controller.rb index 570c6df3..7aa32100 100644 --- a/app/controllers/web/admin/comments_controller.rb +++ b/app/controllers/web/admin/comments_controller.rb @@ -1,8 +1,8 @@ class Web::Admin::CommentsController < Web::Admin::ApplicationController def index @comments = {} - @comments[:unviewed] = Comment.unviewed.page params[:page] - @comments[:active] = Comment.active.page params[:page] + @comments[:unviewed] = Kaminari.paginate_array(Comment.unviewed.decorate).page params[:page] + @comments[:active] = Kaminari.paginate_array(Comment.active.decorate).page params[:page] end def new diff --git a/app/controllers/web/admin/events_controller.rb b/app/controllers/web/admin/events_controller.rb index 0b4a606f..f74d6187 100644 --- a/app/controllers/web/admin/events_controller.rb +++ b/app/controllers/web/admin/events_controller.rb @@ -4,12 +4,12 @@ class Web::Admin::EventsController < Web::Admin::ApplicationController before_filter :choose_members, only: [ :new, :edit ] def index - events = ::Event.presented - @future_events = Kaminari.paginate_array(events.future.decorate).page params[:page] - @current_events = Kaminari.paginate_array(events.current.decorate).page params[:page] - @past_events = Kaminari.paginate_array(events.past.decorate).page params[:page] - @unviewed_events = Kaminari.paginate_array(::Event.unviewed.decorate).page params[:page] - @declined_events = Kaminari.paginate_array(::Event.declined.decorate).page params[:page] + @events = {} + @events[:future] = Kaminari.paginate_array(::Event.presented.future.decorate).page params[:page] + @events[:current] = Kaminari.paginate_array(::Event.presented.current.decorate).page params[:page] + @events[:past] = Kaminari.paginate_array(::Event.presented.past.decorate).page params[:page] + @events[:unviewed] = Kaminari.paginate_array(::Event.unviewed.decorate).page params[:page] + @events[:declined] = Kaminari.paginate_array(::Event.declined.decorate).page params[:page] end def new diff --git a/app/helpers/web/admin/application_helper.rb b/app/helpers/web/admin/application_helper.rb index 4a86f57c..ed6377c9 100644 --- a/app/helpers/web/admin/application_helper.rb +++ b/app/helpers/web/admin/application_helper.rb @@ -9,7 +9,7 @@ def state_color(item) end def tab_title(model_class, tab, count) - "#{t("state_machines.#{model_class.name.downcase}.state.states.#{tab}").pluralize(:ru)} / #{count}" + "#{t("state_machines.#{model_class.name.underscore}.state.states.#{tab}").pluralize(:ru)} / #{count}" end def enumerize_locales_hash(model, attribute) @@ -28,4 +28,13 @@ def form_after_save? def object_updated_less_minute_ago?(object) ((DateTime.now - object.model.updated_at.to_datetime) * 24 * 60).to_i < 1 end + + def model_of(items) + items.transform_values.each { |i| return i.first.model.class if i.first } + end + + def to_path(constant) + constant = Team if constant.to_s.include? 'Team' + constant.name.underscore.gsub '/', '_' + end end diff --git a/app/scopes/activity_line_scopes.rb b/app/scopes/activity_line_scopes.rb index 56ff5d70..bc89b3bc 100644 --- a/app/scopes/activity_line_scopes.rb +++ b/app/scopes/activity_line_scopes.rb @@ -5,6 +5,7 @@ module ActivityLineScopes included do scope :removed, -> { where state: :removed } scope :active, -> { where state: :active } + scope :unviewed, -> { where state: :unviewed } scope :presented, -> { where.not(state: :removed).order('id ASC')} scope :central_programs, -> { where activity_type: :central_program } scope :local_projects, -> { where activity_type: :local_project } diff --git a/app/views/web/admin/activity_lines/_activity_lines_list.html.haml b/app/views/web/admin/activity_lines/_activity_lines_list.html.haml new file mode 100644 index 00000000..c3889ebc --- /dev/null +++ b/app/views/web/admin/activity_lines/_activity_lines_list.html.haml @@ -0,0 +1,26 @@ +- model_class = ActivityLine += paginate activity_lines, theme: 'twitter-bootstrap-3' +%table.table.table-condensed.table-hover + %thead + %tr + %th= model_class.human_attribute_name(:title) + %th= model_class.human_attribute_name(:description) + %th= model_class.human_attribute_name(:found_date) + %th= model_class.human_attribute_name(:head) + %th= t 'helpers.links.actions' + %tbody + - activity_lines.each do |activity_line| + %tr.link{ class: state_color(activity_line), data: { href: edit_admin_activity_line_path(activity_line) } } + %td= activity_line.full_title + %td= activity_line.short_body + %td=l activity_line.found_date, format: '%d %b %Y' + %td + - if activity_line.member.present? + = activity_line.member.decorate.short_name + %td.actions + = link_to edit_admin_activity_line_path(activity_line), class: 'btn btn-warning btn-xs' do + %span.glyphicon.glyphicon-pencil + = link_to admin_activity_line_path(activity_line), method: :delete, class: 'btn btn-xs btn-danger' do + %span.glyphicon.glyphicon-remove +%br += paginate activity_lines, theme: 'twitter-bootstrap-3' diff --git a/app/views/web/admin/activity_lines/index.html.haml b/app/views/web/admin/activity_lines/index.html.haml index 845fffed..24dad78f 100644 --- a/app/views/web/admin/activity_lines/index.html.haml +++ b/app/views/web/admin/activity_lines/index.html.haml @@ -1,32 +1 @@ -= paginate @activity_lines, theme: 'twitter-bootstrap-3' -- model_class = ActivityLine -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_activity_line_path, class: 'btn btn-primary' -%table.table.table-condensed.table-hover - %thead - %tr - %th= model_class.human_attribute_name(:title) - %th= model_class.human_attribute_name(:description) - %th= model_class.human_attribute_name(:found_date) - %th= model_class.human_attribute_name(:head) - %th= t 'helpers.links.actions' - %tbody - - @activity_lines.each do |activity_line| - %tr.link{ class: state_color(activity_line), data: { href: edit_admin_activity_line_path(activity_line) } } - %td= activity_line.full_title - %td= activity_line.short_body - %td=l activity_line.found_date, format: '%d %b %Y' - %td - - if activity_line.member.present? - = activity_line.member.decorate.short_name - %td.actions - = link_to edit_admin_activity_line_path(activity_line), class: 'btn btn-warning btn-xs' do - %span.glyphicon.glyphicon-pencil - = link_to admin_activity_line_path(activity_line), method: :delete, class: 'btn btn-xs btn-danger' do - %span.glyphicon.glyphicon-remove -= link_to t('.new', default: t('helpers.links.new')), new_admin_activity_line_path, class: 'btn btn-primary' -%br -= paginate @activity_lines, theme: 'twitter-bootstrap-3' += render 'web/admin/default/index', items: @activity_lines diff --git a/app/views/web/admin/articles/index.html.haml b/app/views/web/admin/articles/index.html.haml index 17f3c855..fe6feb05 100644 --- a/app/views/web/admin/articles/index.html.haml +++ b/app/views/web/admin/articles/index.html.haml @@ -1,16 +1 @@ -- model_class = Article -- tabs = [ :confirmed, :inactive, :unviewed ] -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - =t model_class.model_name.human.pluralize(:ru) - = link_to "#{t 'helpers.links.new'}", new_admin_article_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @articles[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'articles_list', articles: @articles[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_article_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @articles diff --git a/app/views/web/admin/banners/index.html.haml b/app/views/web/admin/banners/index.html.haml index f8b5a792..f4c9d41d 100644 --- a/app/views/web/admin/banners/index.html.haml +++ b/app/views/web/admin/banners/index.html.haml @@ -1,16 +1 @@ -- model_class = Banner -- tabs = @banners.keys -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - =t model_class.model_name.human.pluralize(:ru) - = link_to "#{t 'helpers.links.new'}", new_admin_banner_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @banners[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'banners_list', banners: @banners[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_banner_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @banners diff --git a/app/views/web/admin/comments/index.html.haml b/app/views/web/admin/comments/index.html.haml index 9f84956a..7ee5f0ca 100644 --- a/app/views/web/admin/comments/index.html.haml +++ b/app/views/web/admin/comments/index.html.haml @@ -1,16 +1 @@ -- model_class = Comment -- title model_class.model_name.human.pluralize(:ru), :admin -- tabs = @comments.keys -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_comment_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @comments[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'comments_list', comments: @comments[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_comment_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @comments diff --git a/app/views/web/admin/default/_index.html.haml b/app/views/web/admin/default/_index.html.haml new file mode 100644 index 00000000..cf293c36 --- /dev/null +++ b/app/views/web/admin/default/_index.html.haml @@ -0,0 +1,16 @@ +- model_class = model_of items +- tabs = items.keys +- title model_class.model_name.human.pluralize(:ru), :admin +.page-header + %h1 + =t model_class.model_name.human.pluralize(:ru) + = link_to "#{t 'helpers.links.new'}", send("new_admin_#{to_path(model_class)}_path"), class: 'btn btn-primary' +#tabs + %ul.nav.nav-tabs{ role: :tablist } + - tabs.each do |tab| + %li + = link_to tab_title(model_class, tab, items[tab].total_count), "##{tab}" + - tabs.each do |tab| + %div{ id: tab } + = render "#{to_path(model_class).pluralize(:en)}_list", to_path(model_class).pluralize(:en).to_sym => items[tab] += link_to t('.new', default: t('helpers.links.new')), send("new_admin_#{to_path(model_class)}_path"), class: 'btn btn-primary' diff --git a/app/views/web/admin/events/index.html.haml b/app/views/web/admin/events/index.html.haml index 71061211..11378bca 100644 --- a/app/views/web/admin/events/index.html.haml +++ b/app/views/web/admin/events/index.html.haml @@ -1,23 +1 @@ -- model_class = Event -- tabs = [ :future, :unviewed, :current, :past, :declined ] -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_event_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to t("scopes.event.#{tab}"), "##{tab}" - #unviewed - = render 'events_list', events: @unviewed_events - #future - = render 'events_list', events: @future_events - #current - = render 'events_list', events: @current_events - #past - = render 'events_list', events: @past_events - #declined - = render 'events_list', events: @declined_events -= link_to t('.new', default: t('helpers.links.new')), new_admin_event_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @events diff --git a/app/views/web/admin/feedback/index.html.haml b/app/views/web/admin/feedback/index.html.haml index 0c6ab8d6..6652849b 100644 --- a/app/views/web/admin/feedback/index.html.haml +++ b/app/views/web/admin/feedback/index.html.haml @@ -1,16 +1 @@ -- model_class = Feedback -- title model_class.model_name.human.pluralize(:ru), :admin -- tabs = [ :unviewed, :fixing, :done, :declined ] -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_feedback_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @feedback[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'feedback_list', feedback: @feedback[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_feedback_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @feedback diff --git a/app/views/web/admin/members/index.html.haml b/app/views/web/admin/members/index.html.haml index a4087c3e..836ce5e0 100644 --- a/app/views/web/admin/members/index.html.haml +++ b/app/views/web/admin/members/index.html.haml @@ -1,21 +1 @@ -- model_class = Member -- tabs = [ :confirmed, :unviewed, :declined, :unavailable ] -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_member_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to t("state_machines.member.state.states.#{tab}").pluralize(:ru), "##{tab}" - #unviewed - = render 'members_list', members: @unviewed_members - #confirmed - = render 'members_list', members: @confirmed_members - #declined - = render 'members_list', members: @declined_members - #unavailable - = render 'members_list', members: @unavailable_members -= link_to t('.new', default: t('helpers.links.new')), new_admin_member_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @members diff --git a/app/views/web/admin/news/index.html.haml b/app/views/web/admin/news/index.html.haml index 2e094128..5e1fcc33 100644 --- a/app/views/web/admin/news/index.html.haml +++ b/app/views/web/admin/news/index.html.haml @@ -1,16 +1 @@ -- model_class = News -- title model_class.model_name.human.pluralize(:ru), :admin -- tabs = @news.keys -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_news_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @news[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'news_list', news: @news[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_news_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @news diff --git a/app/views/web/admin/questionaries/index.html.haml b/app/views/web/admin/questionaries/index.html.haml index c3ae5fe6..9babef35 100644 --- a/app/views/web/admin/questionaries/index.html.haml +++ b/app/views/web/admin/questionaries/index.html.haml @@ -1,16 +1 @@ -- model_class = Questionary -- title model_class.model_name.human.pluralize(:ru), :admin -- tabs = @questionaries.keys -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_questionary_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @questionaries[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'questionaries_list', questionaries: @questionaries[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_questionary_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @questionaries diff --git a/app/views/web/admin/teams/index.html.haml b/app/views/web/admin/teams/index.html.haml index f2a4b6c9..d211a9b5 100644 --- a/app/views/web/admin/teams/index.html.haml +++ b/app/views/web/admin/teams/index.html.haml @@ -1,16 +1 @@ -- model_class = Team -- tabs = @teams.keys -- title model_class.model_name.human.pluralize(:ru), :admin -.page-header - %h1 - =t model_class.model_name.human.pluralize(:ru) - = link_to "#{t 'helpers.links.new'}", new_admin_team_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @teams[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'teams_list', teams: @teams[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_team_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @teams diff --git a/app/views/web/admin/users/index.html.haml b/app/views/web/admin/users/index.html.haml index 4917124d..88813210 100644 --- a/app/views/web/admin/users/index.html.haml +++ b/app/views/web/admin/users/index.html.haml @@ -1,16 +1 @@ -- model_class = User -- title model_class.model_name.human.pluralize(:ru), :admin -- tabs = @users.keys -.page-header - %h1 - = model_class.model_name.human.pluralize(:ru) - = link_to t('.new', default: t('helpers.links.new')), new_admin_user_path, class: 'btn btn-primary' -#tabs - %ul.nav.nav-tabs{ role: :tablist } - - tabs.each do |tab| - %li - = link_to tab_title(model_class, tab, @users[tab].total_count), "##{tab}" - - tabs.each do |tab| - %div{ id: tab } - = render 'users_list', users: @users[tab] -= link_to t('.new', default: t('helpers.links.new')), new_admin_user_path, class: 'btn btn-primary' += render 'web/admin/default/index', items: @users diff --git a/config/locales/ru/models.yml b/config/locales/ru/models.yml index 844abccd..617b3c50 100644 --- a/config/locales/ru/models.yml +++ b/config/locales/ru/models.yml @@ -196,6 +196,12 @@ ru: unviewed: Непросмотренные active: Активные removed: Удалённые + activity_line: + state: + states: + removed: Удалённые + active: Активные + unviewed: Непросмотренные errors: models: member: From 60f57717e6c9a3350a9188d7c323b2e2acc68b0e Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 18:56:33 +0300 Subject: [PATCH 2/6] #263 fix share buttons on event show --- app/assets/stylesheets/web/events.scss | 6 +++++- app/views/web/events/show.html.haml | 3 +++ config/locales/ru/helpers.yml | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/web/events.scss b/app/assets/stylesheets/web/events.scss index e4d21304..07c5c553 100644 --- a/app/assets/stylesheets/web/events.scss +++ b/app/assets/stylesheets/web/events.scss @@ -130,7 +130,11 @@ $slopy-height: 140px; } .share { margin-top: 30px; - margin-left: 40px; + margin-left: 12%; + span { + font-size: 26px; + margin-left: 2px; + } } } .event-content.container { diff --git a/app/views/web/events/show.html.haml b/app/views/web/events/show.html.haml index 573d81e8..4a8f47b2 100644 --- a/app/views/web/events/show.html.haml +++ b/app/views/web/events/show.html.haml @@ -53,6 +53,9 @@ %a.join-button.mic-press-button{ href: new_session_path } = t('.attend') .share + %span + = t('helpers.share') + %br = render 'layouts/web/shared/social_sharing', counter: false .more-lead-info.container .row.large-collapse diff --git a/config/locales/ru/helpers.yml b/config/locales/ru/helpers.yml index 3ab6e133..85d23648 100644 --- a/config/locales/ru/helpers.yml +++ b/config/locales/ru/helpers.yml @@ -15,6 +15,7 @@ ru: cancel: Отмена view_all: посмотреть всех contacts: Контакты + share: Поделиться actions: update: Редактировать create: Создать From 39e1af54d9780b900490a3a748bd3f27cb8ad03a Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 19:16:52 +0300 Subject: [PATCH 3/6] Add state to tags --- app/controllers/api/admin/tags_controller.rb | 2 +- app/controllers/web/articles_controller.rb | 6 +++--- app/controllers/web/members_controller.rb | 4 ++-- app/controllers/web/news_controller.rb | 8 ++++---- app/models/tag.rb | 13 +++++++++++++ app/models/team.rb | 3 --- app/scopes/tag_scopes.rb | 2 ++ app/views/web/admin/tags/_list.html.haml | 2 +- db/migrate/20150818160544_add_state_to_tags.rb | 5 +++++ db/schema.rb | 3 ++- 10 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20150818160544_add_state_to_tags.rb diff --git a/app/controllers/api/admin/tags_controller.rb b/app/controllers/api/admin/tags_controller.rb index ec5dc728..4f4a4cfc 100644 --- a/app/controllers/api/admin/tags_controller.rb +++ b/app/controllers/api/admin/tags_controller.rb @@ -24,7 +24,7 @@ def create def destroy @tag = Tag.find params[:id] - @tag.destroy + @tag.remove head :ok end end diff --git a/app/controllers/web/articles_controller.rb b/app/controllers/web/articles_controller.rb index 2fdf027d..ee042628 100644 --- a/app/controllers/web/articles_controller.rb +++ b/app/controllers/web/articles_controller.rb @@ -5,9 +5,9 @@ def show @article = Article.find(params[:id]).decorate @article.increase_views @topic_articles = Article.broadcasted.same_articles(@article).last 3 - @strings = @article.tags.string - @not_strings = @article.tags.events + @article.tags.activity_lines + @article.tags.teams - @members = @article.tags.members.map &:target + @strings = @article.tags.active.string + @not_strings = @article.tags.active.events + @article.tags.active.activity_lines + @article.tags.active.teams + @members = @article.tags.active.members.map &:target @popular_articles = ArticleDecorator.decorate_collection Article.broadcasted.popular.first 3 end end diff --git a/app/controllers/web/members_controller.rb b/app/controllers/web/members_controller.rb index ca1002bc..0136fc21 100644 --- a/app/controllers/web/members_controller.rb +++ b/app/controllers/web/members_controller.rb @@ -51,8 +51,8 @@ def show @children = MemberDecorator.decorate_collection member.children.shuffle @parent = MemberDecorator.decorate member.parent @registrations = ::Event::RegistrationDecorator.decorate_collection member.registrations.reverse - @news = NewsDecorator.decorate_collection member.tags.news.map &:record - @articles = member.tags.articles.map &:record + @news = NewsDecorator.decorate_collection member.tags.active.news.map &:record + @articles = member.tags.active.articles.map &:record @attribute_accesses = member.attribute_accesses end end diff --git a/app/controllers/web/news_controller.rb b/app/controllers/web/news_controller.rb index 520b961c..75cc1163 100644 --- a/app/controllers/web/news_controller.rb +++ b/app/controllers/web/news_controller.rb @@ -13,13 +13,13 @@ def show topic_news_tags = @news.tags.last 2 @topic_news = [] topic_news_tags.each do |tag| - news_tag = Tag.where(target_type: tag.target_type, record_type: 'News').where.not(record_id: @news.id).where.not(record_id: @topic_news.map(&:id)).last + news_tag = Tag.active.where(target_type: tag.target_type, record_type: 'News').where.not(record_id: @news.id).where.not(record_id: @topic_news.map(&:id)).last @topic_news << NewsDecorator.decorate(news_tag.record) if news_tag end @last_news = NewsDecorator.decorate_collection News.published.first 3 - @members = @news.tags.members.map &:target - @strings = @news.tags.string - @not_strings = @news.tags.events + @news.tags.activity_lines + @news.tags.teams + @members = @news.tags.active.members.map &:target + @strings = @news.tags.active.string + @not_strings = @news.tags.active.events + @news.tags.active.activity_lines + @news.tags.active.teams @news.increase_views @previous_news = News.published.previous @news.id @next_news = News.published.next @news.id diff --git a/app/models/tag.rb b/app/models/tag.rb index 29e1728d..ee470be7 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -12,4 +12,17 @@ class Tag < ActiveRecord::Base enumerize :tag_type, in: [ :string, :link ] include TagScopes + + state_machine :state, initial: :active do + state :active + state :removed + + event :activate do + transition removed: :active + end + + event :remove do + transition active: :remove + end + end end diff --git a/app/models/team.rb b/app/models/team.rb index c961a4ff..d4a3f7f7 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -47,7 +47,4 @@ def is_primary? #FIXME tags association include Concerns::TagsHelper - def tags - Tag.where(target_type: 'Team', target_id: id) - end end diff --git a/app/scopes/tag_scopes.rb b/app/scopes/tag_scopes.rb index 3bc33fd6..1a1a2936 100644 --- a/app/scopes/tag_scopes.rb +++ b/app/scopes/tag_scopes.rb @@ -10,5 +10,7 @@ module TagScopes scope :teams, -> { where target_type: 'Team' } scope :news, -> { where record_type: 'News' } scope :articles, -> { where record_type: 'Article' } + scope :active, -> { where state: :active } + scope :removed, -> { where state: :removed } end end diff --git a/app/views/web/admin/tags/_list.html.haml b/app/views/web/admin/tags/_list.html.haml index 65302634..6c155322 100644 --- a/app/views/web/admin/tags/_list.html.haml +++ b/app/views/web/admin/tags/_list.html.haml @@ -1,5 +1,5 @@ %ul.list-group - - record.tags.each do |tag| + - record.tags.active.each do |tag| %li.list-group-item = link_to api_admin_tag_path(tag), method: :delete, remote: true, class: 'badge tag_destroy' do X diff --git a/db/migrate/20150818160544_add_state_to_tags.rb b/db/migrate/20150818160544_add_state_to_tags.rb new file mode 100644 index 00000000..9aa4595f --- /dev/null +++ b/db/migrate/20150818160544_add_state_to_tags.rb @@ -0,0 +1,5 @@ +class AddStateToTags < ActiveRecord::Migration + def change + add_column :tags, :state, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 28fbbcf3..e73b015a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150811224909) do +ActiveRecord::Schema.define(version: 20150818160544) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -203,6 +203,7 @@ t.string "target_type" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "state" end add_index "tags", ["record_type", "record_id"], name: "index_tags_on_record_type_and_record_id", using: :btree From e4c552b9fe371a0896f112970be292c11f20cb72 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 22:55:44 +0300 Subject: [PATCH 4/6] #290 fix styling of images --- app/assets/javascripts/ckeditor/config.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/ckeditor/config.js b/app/assets/javascripts/ckeditor/config.js index b8d9b8ef..9f58a43b 100644 --- a/app/assets/javascripts/ckeditor/config.js +++ b/app/assets/javascripts/ckeditor/config.js @@ -6,7 +6,7 @@ CKEDITOR.editorConfig = function (config) { config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; config.filebrowserImageUploadUrl = "/ckeditor/pictures"; config.filebrowserUploadUrl = "/ckeditor/attachment_files"; - config.language = 'ru'; + config.language = 'ru'; config.extraPlugins = 'youtube,oembed'; var csrf_token = $('meta[name=csrf-token]').attr('content'), csrf_param = $('meta[name=csrf-param]').attr('content'); @@ -14,4 +14,22 @@ CKEDITOR.editorConfig = function (config) { if (csrf_param !== undefined && csrf_token !== undefined) { config.filebrowserImageUploadUrl += "?" + csrf_param + "=" + encodeURIComponent(csrf_token) } -} + CKEDITOR.on('dialogDefinition', function(ev) { + var dialogName = ev.data.name; + var dialogDefinition = ev.data.definition; + + var uploadTab = dialogDefinition.getContents('Upload'); + var uploadButton = uploadTab.get('uploadButton'); + uploadButton['filebrowser']['onSelect'] = function( fileUrl, errorMessage ) { + if (dialogName == 'image') { + var infoTab = dialogDefinition.getContents( 'info' ); + var dialog = CKEDITOR.dialog.getCurrent(); + + setTimeout(function() { + dialog.setValueOf('info', 'txtWidth', ''); + dialog.setValueOf('info', 'txtHeight', ''); + }, 100); + } + }; + }); +}; From 5bd28b454acdb525482addb06b07b2d83b8c76de Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 23:06:56 +0300 Subject: [PATCH 5/6] #111 public and not public teams --- app/controllers/web/admin/application_controller.rb | 2 +- app/controllers/web/users/account_controller.rb | 1 + app/views/web/users/account/index.html.haml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/web/admin/application_controller.rb b/app/controllers/web/admin/application_controller.rb index 66dd31f1..54b855f3 100644 --- a/app/controllers/web/admin/application_controller.rb +++ b/app/controllers/web/admin/application_controller.rb @@ -13,6 +13,6 @@ def choose_members end def choose_teams - @teams = Team.active.decorate + @teams = Team.active.visible.decorate end end diff --git a/app/controllers/web/users/account_controller.rb b/app/controllers/web/users/account_controller.rb index 84ebd205..5c10627d 100644 --- a/app/controllers/web/users/account_controller.rb +++ b/app/controllers/web/users/account_controller.rb @@ -8,6 +8,7 @@ def index @member_form = MemberForm.new @member end @authentications = current_user.authentications + @teams = Team.active.visible.decorate end def update diff --git a/app/views/web/users/account/index.html.haml b/app/views/web/users/account/index.html.haml index adc8446c..7d7d80db 100644 --- a/app/views/web/users/account/index.html.haml +++ b/app/views/web/users/account/index.html.haml @@ -25,7 +25,7 @@ = image_tag @member_form.model.avatar if @member_form.model.avatar.present? = f.input :avatar, as: :file, label: false, input_html: { style: 'display: none' } = f.input :avatar, label: false, as: :jasny_file_preview_upload_foundation - = f.association :teams, input_html: { class: :select2 } + = f.association :teams, input_html: { class: :select2 }, collection: teams_hash(@teams) -#= f.hint t('.my_position_in_mic') -#= f.simple_fields_for :positions do |ff| = render 'position_fields', f: ff From c751906504586225e8c6a6411913486b3c8e8ee2 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 18 Aug 2015 23:10:07 +0300 Subject: [PATCH 6/6] fix bug with states names --- app/helpers/web/admin/application_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/helpers/web/admin/application_helper.rb b/app/helpers/web/admin/application_helper.rb index ed6377c9..b5cafe95 100644 --- a/app/helpers/web/admin/application_helper.rb +++ b/app/helpers/web/admin/application_helper.rb @@ -9,7 +9,9 @@ def state_color(item) end def tab_title(model_class, tab, count) - "#{t("state_machines.#{model_class.name.underscore}.state.states.#{tab}").pluralize(:ru)} / #{count}" + model = model_class.name.underscore + model = :team if model.include? 'team' + "#{t("state_machines.#{model}.state.states.#{tab}").pluralize(:ru)} / #{count}" end def enumerize_locales_hash(model, attribute)