Commit 05335a3c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Create milestones in the group

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1328e4b5
class Groups::MilestonesController < Groups::ApplicationController class Groups::MilestonesController < Groups::ApplicationController
before_action :authorize_group_milestone!, only: :update before_action :authorize_group_milestone!, only: :update
before_action :group
def index def index
project_milestones = case params[:state] project_milestones =
when 'all'; state case params[:state]
when 'closed'; state('closed') when 'all'; state
else state('active') when 'closed'; state('closed')
end else state('active')
end
@group_milestones = Milestones::GroupService.new(project_milestones).execute @group_milestones = Milestones::GroupService.new(project_milestones).execute
@group_milestones = Kaminari.paginate_array(@group_milestones).page(params[:page]).per(PER_PAGE) @group_milestones = Kaminari.paginate_array(@group_milestones).page(params[:page]).per(PER_PAGE)
end end
def new
@group_milestone = OpenStruct.new(title: nil, description: nil)
end
def create
project_ids = params[:milestone][:project_ids]
title = milestone_params[:title]
@group.projects.where(id: project_ids).each do |project|
Milestones::CreateService.new(project, current_user, milestone_params).execute
end
redirect_to group_milestone_path(@group, title.parameterize, title: title)
end
def show def show
project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC") project_milestones = Milestone.where(project_id: group.projects).order("due_date ASC")
@group_milestone = Milestones::GroupService.new(project_milestones).milestone(title) @group_milestone = Milestones::GroupService.new(project_milestones).milestone(title)
...@@ -51,4 +69,12 @@ class Groups::MilestonesController < Groups::ApplicationController ...@@ -51,4 +69,12 @@ class Groups::MilestonesController < Groups::ApplicationController
def authorize_group_milestone! def authorize_group_milestone!
return render_404 unless can?(current_user, :admin_group, group) return render_404 unless can?(current_user, :admin_group, group)
end end
def milestone_params
params.require(:milestone).permit(
:title,
:description,
:due_date
)
end
end end
...@@ -3,9 +3,15 @@ ...@@ -3,9 +3,15 @@
= render 'shared/milestones_filter' = render 'shared/milestones_filter'
.gray-content-block .gray-content-block
Only milestones from .pull-right
%strong #{@group.name} %span.pull-right.hidden-xs
group are listed here. = link_to new_group_milestone_path(@group), class: "btn btn-new" do
New Milestone
.oneline
Only milestones from
%strong #{@group.name}
group are listed here.
.milestones .milestones
%ul.content-list %ul.content-list
- if @group_milestones.blank? - if @group_milestones.blank?
......
%h3.page-title
New Milestone
%p.light
This will create milestone in every selected project
%hr
= form_for @group_milestone, as: :milestone, url: group_milestones_path(@group), html: { class: 'form-horizontal milestone-form gfm-form js-requires-input' } do |f|
.row
.col-md-6
.form-group
= f.label :title, "Title", class: "control-label"
.col-sm-10
= f.text_field :title, maxlength: 255, class: "form-control js-quick-submit", required: true
%p.hint Required
.form-group.milestone-description
= f.label :description, "Description", class: "control-label"
.col-sm-10
= render layout: 'projects/md_preview', locals: { preview_class: "md-preview" } do
= render 'projects/zen', f: f, attr: :description, classes: 'description form-control js-quick-submit'
= render 'projects/notes/hints'
.clearfix
.error-alert
.form-group
= f.label :projects, "Projects", class: "control-label"
.col-sm-10
= f.collection_select :project_ids, @group.projects, :id, :name,
{ selected: @group.projects.map(&:id) }, multiple: true, class: 'select2'
.col-md-6
.form-group
= f.label :due_date, "Due Date", class: "control-label"
.col-sm-10= f.hidden_field :due_date
.col-sm-10
.datepicker
.form-actions
= f.submit 'Create Milestone', class: "btn-create btn"
= link_to "Cancel", group_milestones_path(@group), class: "btn btn-cancel"
:javascript
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
onSelect: function(dateText, inst) { $("#milestone_due_date").val(dateText) }
}).datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $('#milestone_due_date').val()));
...@@ -368,7 +368,7 @@ Gitlab::Application.routes.draw do ...@@ -368,7 +368,7 @@ Gitlab::Application.routes.draw do
end end
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
resources :milestones, only: [:index, :show, :update] resources :milestones, only: [:index, :show, :update, :new, :create]
end end
end end
......
...@@ -153,6 +153,13 @@ Feature: Groups ...@@ -153,6 +153,13 @@ Feature: Groups
Then I should see group milestone with descriptions and expiry date Then I should see group milestone with descriptions and expiry date
And I should see group milestone with all issues and MRs assigned to that milestone And I should see group milestone with all issues and MRs assigned to that milestone
Scenario: Create multiple milestones with one form
Given I visit group "Owned" milestones page
And I click new milestone button
And I fill milestone name
When I press create mileston button
Then milestone in each project should be created
# Group projects in settings # Group projects in settings
Scenario: I should see all projects in the project list in settings Scenario: I should see all projects in the project list in settings
Given Group "Owned" has archived project Given Group "Owned" has archived project
...@@ -169,4 +176,4 @@ Feature: Groups ...@@ -169,4 +176,4 @@ Feature: Groups
When I visit group "Owned" page When I visit group "Owned" page
Then I should see group "Owned" Then I should see group "Owned"
Then I should see project "Public-project" Then I should see project "Public-project"
...@@ -255,6 +255,28 @@ class Spinach::Features::Groups < Spinach::FeatureSteps ...@@ -255,6 +255,28 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
expect(page).to have_xpath("//span[@class='label label-warning']", text: 'archived') expect(page).to have_xpath("//span[@class='label label-warning']", text: 'archived')
end end
step 'I fill milestone name' do
fill_in 'milestone_title', with: 'v2.9.0'
end
step 'I click new milestone button' do
click_link "New Milestone"
end
step 'I press create mileston button' do
click_button "Create Milestone"
end
step 'milestone in each project should be created' do
group = Group.find_by(name: 'Owned')
expect(page).to have_content "Milestone v2.9.0"
expect(group.projects).to be_present
group.projects.each do |project|
expect(page).to have_content project.name
end
end
protected protected
def assigned_to_me(key) def assigned_to_me(key)
......
...@@ -31,6 +31,10 @@ module SharedPaths ...@@ -31,6 +31,10 @@ module SharedPaths
visit merge_requests_group_path(Group.find_by(name: "Owned")) visit merge_requests_group_path(Group.find_by(name: "Owned"))
end end
step 'I visit group "Owned" milestones page' do
visit group_milestones_path(Group.find_by(name: "Owned"))
end
step 'I visit group "Owned" members page' do step 'I visit group "Owned" members page' do
visit group_group_members_path(Group.find_by(name: "Owned")) visit group_group_members_path(Group.find_by(name: "Owned"))
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment