From edc877438723b40190f4c9d51bb10ba01a4ef986 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sun, 19 Feb 2012 02:47:57 +0400 Subject: [PATCH] [issue #203] Some layout changes & presenters. * Fixed bugs in layout * Fixed typos * Fixed bugs in JS * Added universal partial _feed_message.html.haml * Added presenters * Added CommitAsMessage presenter, that prepares Grit::Commit to be shown as message. --- app/assets/javascripts/all.js | 14 +++- app/assets/javascripts/cusel-init.js | 16 ++-- app/assets/stylesheets/custom.scss | 73 +++++++++++++++++++ app/assets/stylesheets/main.scss | 12 +-- app/models/project.rb | 12 +++ app/presenters/application_presenter.rb | 25 +++++++ .../commit_as_message_presenter.rb | 59 +++++++++++++++ app/views/layouts/application.html.haml | 2 +- app/views/projects/show.html.haml | 23 +++++- app/views/shared/_feed_message.html.haml | 19 +++++ config/application.rb | 2 + config/locales/layout/messages.ru.yml | 5 ++ 12 files changed, 240 insertions(+), 22 deletions(-) create mode 100644 app/presenters/application_presenter.rb create mode 100644 app/presenters/git_presenters/commit_as_message_presenter.rb create mode 100644 app/views/shared/_feed_message.html.haml create mode 100644 config/locales/layout/messages.ru.yml diff --git a/app/assets/javascripts/all.js b/app/assets/javascripts/all.js index f8b00c3e4..a3f22da76 100644 --- a/app/assets/javascripts/all.js +++ b/app/assets/javascripts/all.js @@ -25,6 +25,14 @@ $(document).ready(function(){ e.preventDefault(); }); + $('.data-expander').live('click', function(e) { + var $button = $(e.target); + var id = "#content-" + $button.attr('id'); + var $slider = $(id); + $slider.slideToggle("slow", function(){ + $button.toggleClass('expanded collapsed'); + }); + }); }); $(document).click(function(e) { @@ -36,9 +44,9 @@ $(document).click(function(e) { function showActivity(elem) { $("#activity-bottom"+elem).slideToggle("slow"); var img = $("#expand" + elem).attr("src"); - if (img == "assets/expand-gray.png") { - $("#expand" + elem).attr("src","assets/expand-gray2.png"); + if (img == "/assets/expand-gray.png") { + $("#expand" + elem).attr("src","/assets/expand-gray2.png"); } else { - $("#expand" + elem).attr("src","assets/expand-gray.png"); + $("#expand" + elem).attr("src","/assets/expand-gray.png"); } } diff --git a/app/assets/javascripts/cusel-init.js b/app/assets/javascripts/cusel-init.js index 04a7f7093..9ba553380 100644 --- a/app/assets/javascripts/cusel-init.js +++ b/app/assets/javascripts/cusel-init.js @@ -1,11 +1,11 @@ jQuery(document).ready(function(){ -var params = { - changedEl: ".lineForm select", - visRows: 999999, - scrollArrows: false - } - - cuSel(params); +//var params = { +// changedEl: ".lineForm select", +// visRows: 999999, +// scrollArrows: false +// } +// +// cuSel(params); -}); \ No newline at end of file +}); diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss index 57d493edf..bdfde51d3 100644 --- a/app/assets/stylesheets/custom.scss +++ b/app/assets/stylesheets/custom.scss @@ -12,3 +12,76 @@ header menu ul li a { padding: 15px 8px 15px 8px; } +div.description-top div.name { + width: 300px; + padding: 0; +} + +div.description-top div.name input { + width: 100%; + height: 100%; +} + +article div.activity { + border: 1px solid #D6D6D6; + border-radius: 5px 5px 5px 5px; + color: #333333; + margin-top: 15px; + padding: 6px; +} + +article div.activity .top div.image { + position: absolute; + float: left; + width: 40px; + height: 40px; + margin-left: 2px; + margin-top: 2px; +} + +article div.activity .top div.text { + float: left; + font-size: 12px; + padding-left: 10px; +} + +article div.activity .top div.text.imaged { + margin-left: 44px; +} + +article div.activity .top div.text .name { + font-weight: 700; +} + +article div.activity .top div.text .date { + font-size: 11px; +} + +article div.activity .top div.text { + font-size: 12px; +} + +article div.activity .fulltext { + font-size: 12px; + padding-top: 10px; +} + +article div.activity .fulltext.hidden { + display: none; +} + +div.activity .data-expander { + margin-left: 10px; + display: inline-block; + width: 12px; +} + +div.activity .data-expander.collapsed { + background: #FFF image-url('expand-gray.png') no-repeat; + background-position: 0 2px; +} + +div.activity .data-expander.expanded { + background: #FFF image-url('expand-gray2.png') no-repeat; + background-position: 0 2px; +} diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss index 546de2797..6647b52ac 100644 --- a/app/assets/stylesheets/main.scss +++ b/app/assets/stylesheets/main.scss @@ -1220,7 +1220,7 @@ h3.bmargin10 { padding-top: 9px; } -div.desription-top { +div.description-top { background: #dcecfa; font-size: 12px; color: #575756; @@ -1230,13 +1230,13 @@ div.desription-top { margin-bottom: 20px; } -div.desription-top div.img { +div.description-top div.img { float: left; padding-left: 10px; margin-top: 14px; } -div.desription-top div.name { +div.description-top div.name { float: left; margin-top: 5px; margin-left: 10px; @@ -1250,19 +1250,19 @@ div.desription-top div.name { padding-top: 5px; } -div.desription-top div.role { +div.description-top div.role { float: left; margin-top: 11px; margin-left: 10px; font-size: 11px; } -div.desription-top div.fork { +div.description-top div.fork { float: right; margin-top: 5px; margin-right: 10px; } -div.desription-top div.fork p { +div.description-top div.fork p { float: right; margin-top: 5px; margin-right: 2px; diff --git a/app/models/project.rb b/app/models/project.rb index 68bdc9f62..b3b8ed47a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -84,6 +84,18 @@ class Project < ActiveRecord::Base self.git_repository.branches end + def last_active_branch + @last_active_branch ||= branches.inject do |r, c| + r_last = r.commit.committed_date || r.commit.authored_date unless r.nil? + c_last = c.commit.committed_date || c.commit.authored_date + if r.nil? or r_last < c_last + r = c + end + r + end + @last_active_branch + end + def versions tags.map(&:name) + branches.map{|b| "latest_#{b.name}"} end diff --git a/app/presenters/application_presenter.rb b/app/presenters/application_presenter.rb new file mode 100644 index 000000000..72e9937cb --- /dev/null +++ b/app/presenters/application_presenter.rb @@ -0,0 +1,25 @@ +class ApplicationPresenter + include Rails.application.routes.url_helpers + include ActionView::Helpers::UrlHelper + + def initialize(*args) + end + + # TODO it needs to be refactored! + class << self + def present(*args, &block) + block.call(self.new(*args)) + end + + def present_collection(collection, &block) + res = collection.map {|e| self.new(*e)} + if block.present? + res = res.inject('') do |akk, presenter| + akk << block.call(presenter) + akk + end + end + return res + end + end +end diff --git a/app/presenters/git_presenters/commit_as_message_presenter.rb b/app/presenters/git_presenters/commit_as_message_presenter.rb new file mode 100644 index 000000000..561b1f131 --- /dev/null +++ b/app/presenters/git_presenters/commit_as_message_presenter.rb @@ -0,0 +1,59 @@ +class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter + attr_accessor :commit, :options + attr_reader :header, :image, :date, :caption, :content, :expandable + + def initialize(commit, opts = {}) + @commit = commit + @optons = opts#[:branch] if opts[:branch] + prepare_message + end + + def header + @header ||= if options[:branch].present? + I18n.t("layout.messages.commits.header_with_branch", + :committer => committer_link, :commit => '', :branch => options[:branch].name) + elsif options[:project].present? + I18n.t("layout.messages.commits.header_with_project", + :committer => committer_link, :commit => '', :project => options[:project].name) + end.html_safe + end + + def image + @image ||= "https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest(committer.email.downcase)}?s=40&r=pg" + end + + def date + @date ||= I18n.l(@commit.committed_date || @commit.authored_date, :format => :long) + end + + def expandable? + true + end + + def content? + !content.blank? + end + + protected + + def committer + @committer ||= User.where(:email => @commit.committer.email).first || @commit.committer + end + + def committer_link + @committer_link ||= if committer.is_a? User + link_to committer.uname, user_path(c) + else + mail_to committer.email, committer.name + end + end + + def prepare_message + (@caption, @content) = @commit.message.split("\n\n", 2) + if @caption.length > 72 + @content = '...' + @caption[69..-1] + @content + @caption = @caption[0..68] + '...' + end + @content = @content.gsub("\n", "
").html_safe + end +end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index ceb8e6189..a55b2f9a1 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -9,7 +9,7 @@ = csrf_meta_tag %body - .wrap + .wrap{:class => content_for?(:sidebar) ? 'columns' : ''} %header .left .middle diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 30af680c4..ebb1c8c95 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -1,4 +1,19 @@ -.block += render :partial => 'submenu' += render :partial => 'repo_block', :locals => {:project => @project} + +.description + %h3= t("layout.projects.about_subheader") + %p + = @project.description + = link_to t('layout.read_more'), '#' + +%h3= t("layout.projects.last_commit") +- GitPresenters::CommitAsMessagePresenter.present(@project.last_active_branch.commit, + :branch => @project.last_active_branch) do |presenter| + = render :partial => 'shared/feed_message', :locals => {:presenter => presenter, + :item_no => 1} + +-#.block .secondary-navigation %ul.wat-cf %li.first= link_to t("layout.projects.list"), projects_path @@ -38,8 +53,8 @@ = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), project_path(@project), :method => "delete", :class => "button", :confirm => t("layout.projects.confirm_delete") if can? :destroy, @project = link_to "Fork", fork_project_path(@project), :class => "button", :method => "post", :confirm => t("layout.confirm") if can? :fork, @project -%a{ :name => "build_lists"} -.block +-#%a{ :name => "build_lists"} +-#.block .secondary-navigation %ul.wat-cf %li.first.active= link_to t("layout.build_lists.current"), project_path(@project) + "#build_lists" @@ -48,4 +63,4 @@ .content = render :partial => "build_lists/build_lists", :object => @current_build_lists -- content_for :sidebar, render('sidebar') +-# content_for :sidebar, render('sidebar') diff --git a/app/views/shared/_feed_message.html.haml b/app/views/shared/_feed_message.html.haml new file mode 100644 index 000000000..451f6aacc --- /dev/null +++ b/app/views/shared/_feed_message.html.haml @@ -0,0 +1,19 @@ +.activity + .top + .image + %img{:alt => "avatar", :src => presenter.image} + .text.imaged + %span.name= presenter.header + %br/ + %span.date= presenter.date + %br/ + %span.subject + = presenter.caption + - if presenter.expandable? and presenter.content? + %span.data-expander.collapsed{:id => "expand#{item_no}"}   + -#%img#expand1.activity-full{:alt => "expand", :onclick => "showActivity(4)", :src => "/assets/expand-gray.png"}/ + .both + - if presenter.content? + .fulltext{:class => presenter.expandable? ? "hidden" : '', + :id => presenter.expandable? ? "content-expand#{item_no}" : ''} + = presenter.content diff --git a/config/application.rb b/config/application.rb index 7729c9f09..5e1c3504d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,6 +24,7 @@ module Rosa # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += %W(#{config.root}/app/presenters) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. @@ -38,6 +39,7 @@ module Rosa # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] config.i18n.default_locale = :en config.action_view.javascript_expansions[:defaults] = %w() diff --git a/config/locales/layout/messages.ru.yml b/config/locales/layout/messages.ru.yml new file mode 100644 index 000000000..6b66b06eb --- /dev/null +++ b/config/locales/layout/messages.ru.yml @@ -0,0 +1,5 @@ +ru: + layout: + messages: + commits: + header_with_branch: "%{committer} добавил коммит %{commit} в ветку %{branch}"