From 0d75a37451337d6e1aff0178e83e44099f7f3056 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 28 Feb 2012 20:05:18 +0600 Subject: [PATCH] [refs #194] show page beta version --- app/assets/javascripts/switcher.js | 54 ------------------- app/assets/javascripts/tracker.js | 21 ++++++++ app/controllers/issues_controller.rb | 16 +++--- app/models/issue.rb | 19 ++++++- app/views/issues/_create_sidebar.html.haml | 41 +++++++++++--- app/views/issues/_status.html.haml | 9 ++++ app/views/issues/edit.html.haml | 11 ---- app/views/issues/index.html.haml | 4 +- app/views/issues/show.html.haml | 50 +++++++---------- config/locales/issues.en.yml | 4 ++ config/locales/issues.ru.yml | 4 ++ config/routes.rb | 2 +- .../20120228094721_add_closed_at_to_issue.rb | 5 ++ .../20120228100121_add_closed_by_to_issue.rb | 6 +++ 14 files changed, 129 insertions(+), 117 deletions(-) delete mode 100644 app/assets/javascripts/switcher.js create mode 100644 app/views/issues/_status.html.haml delete mode 100644 app/views/issues/edit.html.haml create mode 100644 db/migrate/20120228094721_add_closed_at_to_issue.rb create mode 100644 db/migrate/20120228100121_add_closed_by_to_issue.rb diff --git a/app/assets/javascripts/switcher.js b/app/assets/javascripts/switcher.js deleted file mode 100644 index 4522e7687..000000000 --- a/app/assets/javascripts/switcher.js +++ /dev/null @@ -1,54 +0,0 @@ -function switchThis() { - var doc = document.getElementById("switcher"); - if (doc.className == "switcher") { - doc.className = "switcher-off"; - $("#open-comment").fadeOut(0); - $("#closed-comment").fadeIn("slow"); - } else { - doc.className = "switcher"; - $("#closed-comment").fadeOut(0); - $("#open-comment").fadeIn("slow"); - } -} - -function preload() { - if (document.images) { - var imgsrc = preload.arguments; - arr=new Array(imgsrc.length); - - for (var j=0; j @user_id}) ) - flash[:notice] = I18n.t("flash.issue.saved") - redirect_to [@project, @issue] - else - flash[:error] = I18n.t("flash.issue.save_error") - render :action => :new + if status = params[:issue][:status] + action = 'issues/_status' + @issue.set_close(current_user) if status == 'closed' + @issue.set_open if status == 'open' + status = 200 if @issue.save end + + render action, :status => (status || 500), :layout => false end def destroy diff --git a/app/models/issue.rb b/app/models/issue.rb index 3ce981df0..ba24d7010 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -5,6 +5,7 @@ class Issue < ActiveRecord::Base belongs_to :project belongs_to :user belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' + belongs_to :closer, :class_name => 'User', :foreign_key => 'closed_by' has_many :comments, :as => :commentable, :dependent => :destroy #, :finder_sql => proc { "comments.commentable_id = '#{self.id}' AND comments.commentable_type = '#{self.class.name}'"} has_many :subscribes, :as => :subscribeable, :dependent => :destroy #, :finder_sql => proc { "subscribes.subscribeable_id = '#{self.id}' AND subscribes.subscribeable_type = '#{self.class.name}'"} @@ -22,7 +23,7 @@ class Issue < ActiveRecord::Base after_update :deliver_issue_assign_notification after_update :subscribe_issue_assigned_user - attr_accessible :labelings_attributes, :title, :body, :project, :project_id + attr_accessible :labelings_attributes, :title, :body, :project, :project_id, :closed_at, :closed_by accepts_nested_attributes_for :labelings, :allow_destroy => true def assign_uname @@ -39,6 +40,21 @@ class Issue < ActiveRecord::Base end end + def closed? + closed_by && closed_at && status == 'closed' + end + + def set_close(closed_by) + self.closed_at = Time.now + self.closer = closed_by + self.status = 'closed' + end + + def set_open + self.closed_at = self.closed_by = nil + self.status = 'open' + end + protected def set_serial_id @@ -87,4 +103,5 @@ class Issue < ActiveRecord::Base end end end + end diff --git a/app/views/issues/_create_sidebar.html.haml b/app/views/issues/_create_sidebar.html.haml index bf01f9294..908d04f51 100644 --- a/app/views/issues/_create_sidebar.html.haml +++ b/app/views/issues/_create_sidebar.html.haml @@ -1,14 +1,39 @@ -content_for :sidebar do + - if @issue.persisted? + .bordered.nopadding + %h3=t('activerecord.attributes.issue.status') + #switcher.issue_status{:class => "#{@issue.closed? ? 'switcher-off' : 'switcher'} #{can?(:write, @issue.project) ? "switch_issue_status" : ''}"} + .swleft=t('layout.issues.status.open') + .swright=t('layout.issues.status.closed') + - if can? :write, @issue.project + =form_tag [@project, @issue], :id => 'update_issue_status', :method => :put do + =hidden_field_tag "issue_status", @issue.closed? ? 'closed' : 'open', :name => "issue[status]" + .bordered.nopadding %h3=t('layout.issues.executor') - =form_tag search_collaborators_project_issues_path(@project), :id => 'search_user', :method => :get do - =tracker_search_field(:search_user, t('layout.issues.search_user')) - #create_issue_users_list - =render 'issues/search_collaborators' + - if @issue.persisted? && @issue.user + .bordered.nopadding + .people.nopointer + .avatar=image_tag(@issue.user.avatar(25), :alt => 'avatar') + .name="#{@issue.user.uname} (#{@issue.user.name})" + =hidden_field_tag "user-0", @issue.user.id, :name => 'user_id' + .both + - else + =form_tag search_collaborators_project_issues_path(@project), :id => 'search_user', :method => :get do + =tracker_search_field(:search_user, t('layout.issues.search_user')) + #create_issue_users_list + =render 'issues/search_collaborators' .block %h3=t('layout.issues.labels') - =form_tag search_labels_project_issues_path(@project), :id => 'search_labels', :method => :get do - =tracker_search_field(:search_labels, t('layout.issues.search_labels')) - #create_issue_labels_list - =render 'issues/search_labels' \ No newline at end of file + - if @issue.new_record? + =form_tag search_labels_project_issues_path(@project), :id => 'search_labels', :method => :get do + =tracker_search_field(:search_labels, t('layout.issues.search_labels')) + #create_issue_labels_list + =render 'issues/search_labels' + - else + - (@issue.labels || []).each_with_index do |label| + .label.selected.nopointer + .labeltext.selected{:style => "background: ##{label.color};"} + =label.name + .both \ No newline at end of file diff --git a/app/views/issues/_status.html.haml b/app/views/issues/_status.html.haml new file mode 100644 index 000000000..970526d4d --- /dev/null +++ b/app/views/issues/_status.html.haml @@ -0,0 +1,9 @@ +#closed_issue_text + - if @issue.status == 'closed' && @issue.closed_at && @issue.closed_by + #closed-comment.comment-closed{:style => 'display: block;'} + .state=t('layout.issues.status.closed') + .text + .avatar=image_tag(@issue.closer.avatar(25), :alt => 'avatar') + .name="#{@issue.closer.uname} (#{@issue.closer.name}) #{t('layout.issues.at')} #{@issue.closed_at.to_s(:long)}" + .both + %br/ \ No newline at end of file diff --git a/app/views/issues/edit.html.haml b/app/views/issues/edit.html.haml deleted file mode 100644 index aa09ab66f..000000000 --- a/app/views/issues/edit.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first= link_to t("layout.issues.list"), project_issues_path(@project) - %li= link_to t("layout.issues.new"), new_project_issue_path(@project) - .content - %h2.title - = t("layout.issues.edit_header") - .inner - = form_for @issue, :url => project_issue_path(@project, @issue), :html => { :class => :form } do |f| - = render :partial => "form", :locals => {:f => f} diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index 461fde28a..c14a33bb2 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -4,9 +4,9 @@ #closed-switcher.blue-switcher =hidden_field_tag :issues_status, @status, :id => 'issues_status' .open - ="#{t('layout.issues.statuses.open')} (#{@issues.where(:status => 'open').count})" + ="#{t('layout.issues.statuses.open')} (#{@project.issues.where(:status => 'open').count})" #closed-tasks.closed - ="#{t('layout.issues.statuses.closed')} (#{@issues.where(:status => 'closed').count})" + ="#{t('layout.issues.statuses.closed')} (#{@project.issues.where(:status => 'closed').count})" #blue-switch-select.selected{:style => "margin-left: #{@status == 'open' ? '0' : '130'}px;"} .both .both diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index a8d1c3e6e..fca926f2c 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -1,32 +1,20 @@ -.block - .secondary-navigation - %ul.wat-cf - %li.first= link_to t("layout.issues.list"), project_issues_path(@project) - %li= link_to t("layout.issues.edit"), edit_project_issue_path(@project, @issue) if can? :edit, @issue - .content - .inner - %p - %b - = t("activerecord.attributes.issue.title") - \: - = @issue.title - %p - %b - = t("activerecord.attributes.issue.body") - \: - = @issue.body - %p - %b - = t('activerecord.attributes.issue.status') - \: - = @issue.status - %p - %b - = t('layout.issues.subscribe') - \: - - if @issue.subscribes.exists? :user_id => current_user.id - = link_to t('layout.issues.unsubscribe_btn'), project_issue_subscribe_path(@project, @issue, current_user.id), :method => :delete - - else - = link_to t('layout.issues.subscribe_btn'), project_issue_subscribes_path(@project, @issue), :method => :post +-render :partial => 'projects/submenu' +-render :partial => 'issues/create_sidebar' +-content_for :right_nopadding do + dummy +%h3=@issue.title +.activity + .top + .image + =image_tag(@issue.creator.avatar(42), :alt => 'avatar') if @issue.creator + .text + %span.name=link_to(@issue.creator.uname, user_path(@issue.creator)) if @issue.creator + %br/ + %span.date=@issue.created_at.to_s(:long) + %br/ + .both + .fulltext.view=@issue.body +.both +.hr -= render :partial => "comments/list", :locals => {:list => @issue.comments.order(:created_at), :project => @project, :commentable => @issue} +=render :partial => 'issues/status' diff --git a/config/locales/issues.en.yml b/config/locales/issues.en.yml index 37fb8e5fe..39a8dd365 100644 --- a/config/locales/issues.en.yml +++ b/config/locales/issues.en.yml @@ -27,6 +27,9 @@ en: open: Opened closed: Closed any: Any + status: + open: Открыто + closed: Closed subscribe: Subscribe subscribe_btn: Subscribe unsubscribe_btn: Unsubscribe @@ -44,6 +47,7 @@ en: search_labels: Search labels... choose_user_on_left: Choose executor on the left choose_labels_on_left: Choose labels on the left + at: at flash: issue: diff --git a/config/locales/issues.ru.yml b/config/locales/issues.ru.yml index 46c21d53c..827af86bc 100644 --- a/config/locales/issues.ru.yml +++ b/config/locales/issues.ru.yml @@ -27,6 +27,9 @@ ru: open: Открытые closed: Закрытые any: Все + status: + open: Открыто + closed: Закрыто subscribe: Подписка на уведомления subscribe_btn: Подписаться unsubscribe_btn: Отписаться @@ -44,6 +47,7 @@ ru: search_labels: Найти метки... choose_user_on_left: выберите исполнителя слева choose_labels_on_left: выберите метки слева + at: в flash: issue: diff --git a/config/routes.rb b/config/routes.rb index 22af526cc..421283a37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -116,7 +116,7 @@ Rosa::Application.routes.draw do match 'compare/*versions' => 'wiki#compare', :as => :compare_versions, :via => :get end end - resources :issues do + resources :issues, :except => :edit do resources :comments, :only => [:edit, :create, :update, :destroy] resources :subscribes, :only => [:create, :destroy] collection do diff --git a/db/migrate/20120228094721_add_closed_at_to_issue.rb b/db/migrate/20120228094721_add_closed_at_to_issue.rb new file mode 100644 index 000000000..91948e2af --- /dev/null +++ b/db/migrate/20120228094721_add_closed_at_to_issue.rb @@ -0,0 +1,5 @@ +class AddClosedAtToIssue < ActiveRecord::Migration + def change + add_column :issues, :closed_at, :datetime + end +end diff --git a/db/migrate/20120228100121_add_closed_by_to_issue.rb b/db/migrate/20120228100121_add_closed_by_to_issue.rb new file mode 100644 index 000000000..9da79b29b --- /dev/null +++ b/db/migrate/20120228100121_add_closed_by_to_issue.rb @@ -0,0 +1,6 @@ +class AddClosedByToIssue < ActiveRecord::Migration + def change + add_column :issues, :closed_by, :integer + + end +end