Skip to content

Commit

Permalink
Merge branch 'release/0.3.14'
Browse files Browse the repository at this point in the history
* release/0.3.14:
  fix bug with states names
  #111 public and not public teams
  #290 fix styling of images
  Add state to tags
  #263 fix share buttons on event show
  Refactor admin index
  • Loading branch information
kalashnikovisme committed Aug 18, 2015
2 parents e6b3891 + c751906 commit 14100a4
Show file tree
Hide file tree
Showing 36 changed files with 149 additions and 234 deletions.
22 changes: 20 additions & 2 deletions app/assets/javascripts/ckeditor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ 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');

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);
}
};
});
};
6 changes: 5 additions & 1 deletion app/assets/stylesheets/web/events.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/admin/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create

def destroy
@tag = Tag.find params[:id]
@tag.destroy
@tag.remove
head :ok
end
end
5 changes: 4 additions & 1 deletion app/controllers/web/admin/activity_lines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/web/admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def choose_members
end

def choose_teams
@teams = Team.active.decorate
@teams = Team.active.visible.decorate
end
end
4 changes: 2 additions & 2 deletions app/controllers/web/admin/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/web/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/web/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/controllers/web/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/web/news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/controllers/web/users/account_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def index
@member_form = MemberForm.new @member
end
@authentications = current_user.authentications
@teams = Team.active.visible.decorate
end

def update
Expand Down
13 changes: 12 additions & 1 deletion app/helpers/web/admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ 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}"
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)
Expand All @@ -28,4 +30,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
13 changes: 13 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions app/scopes/activity_line_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions app/scopes/tag_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions app/views/web/admin/activity_lines/_activity_lines_list.html.haml
Original file line number Diff line number Diff line change
@@ -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'
33 changes: 1 addition & 32 deletions app/views/web/admin/activity_lines/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 1 addition & 16 deletions app/views/web/admin/articles/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 1 addition & 16 deletions app/views/web/admin/banners/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 1 addition & 16 deletions app/views/web/admin/comments/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions app/views/web/admin/default/_index.html.haml
Original file line number Diff line number Diff line change
@@ -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'
24 changes: 1 addition & 23 deletions app/views/web/admin/events/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 1 addition & 16 deletions app/views/web/admin/feedback/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 14100a4

Please sign in to comment.