Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Commit

Permalink
Add ability to create new issues in the new issue editor (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarib committed Apr 15, 2014
1 parent 4fdcf44 commit 6dbd0b1
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/issueEditor.js
Expand Up @@ -17,7 +17,7 @@

HDO.markdownEditor();

this.form = $('form.edit_issue');
this.form = $('form.edit_issue, form.new_issue');
this.saveButton = this.root.find('button[name=save]');
this.editorSelect = this.root.find('select#issue_editor_id');
this.categorySelect = this.root.find('select#issue_category_ids');
Expand Down
36 changes: 28 additions & 8 deletions app/controllers/admin/new_issues_controller.rb
@@ -1,23 +1,32 @@
class Admin::NewIssuesController < AdminController
before_filter :fetch_issue, only: [:edit, :update]
before_filter :fetch_sections, only: [:edit, :update]
before_filter :fetch_sections, only: [:new, :create, :edit, :update]
before_filter :authorize_edit

def edit
def new
@issue = Issue.new(status: 'in_progress')
render 'edit'
end

def update
logger.info "updating issue: #{params.to_json}"
ok = Hdo::IssueUpdater.new(@issue, params, current_user).update
def create
@issue = Issue.new(params[:issue])
@issue.last_updated_by = current_user

if ok
PageCache.expire_issue(@issue)
render json: { location: edit_next_admin_issue_path(@issue) }
if @issue.save
save_issue
else
render text: @issue.errors.full_messages.to_sentence, status: :unprocessable_entity
end
end

def edit
end

def update
logger.info "updating issue: #{params.to_json}"
save_issue
end

def promises
# xhr_only?
json = params[:ids].split(',').map do |id|
Expand Down Expand Up @@ -59,4 +68,15 @@ def fetch_sections
}
end

def save_issue
ok = Hdo::IssueUpdater.new(@issue, params, current_user).update

if ok
PageCache.expire_issue(@issue)
render json: { location: edit_next_admin_issue_path(@issue) }
else
render text: @issue.errors.full_messages.to_sentence, status: :unprocessable_entity
end
end

end
2 changes: 1 addition & 1 deletion app/views/admin/issues/_issue_index_table.html.erb
@@ -1,6 +1,6 @@
<div class="row-fluid">
<div class="pull-right">
<%= link_to t('app.issues.edit.new'), new_admin_issue_path, class: 'btn btn-primary' %>
<%= link_to t('app.issues.edit.new'), new_next_admin_issues_path, class: 'btn btn-primary' %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/new_issues/_intro.html.erb
Expand Up @@ -36,7 +36,7 @@

<%=
form.select :status,
options_for_select(Issue::STATUSES.map { |s| [t("app.issues.status.#{s}"), s] }),
options_for_select(Issue::STATUSES.map { |s| [t("app.issues.status.#{s}"), s] }, selected: @issue.status),
class: 'input-small'
%>

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/new_issues/edit.html.erb
Expand Up @@ -94,8 +94,8 @@
$(function() {
issueEditor = HDO.issueEditor.create({
root: "#issue-editor",
url: "<%= edit_next_admin_issue_path(@issue) %>",
id: <%= @issue.id %>
url: "<%= @issue.new_record? ? create_next_admin_issues_path : edit_next_admin_issue_path(@issue) %>",
id: <%= @issue.id || -1 %>
});

issueEditor.init();
Expand Down
10 changes: 6 additions & 4 deletions config/routes.rb
Expand Up @@ -14,17 +14,19 @@
resources :issues do
member do
# new
get 'edit/next' => 'new_issues#edit', as: :edit_next
put 'edit/next' => 'new_issues#update'
get 'edit/next' => 'new_issues#edit', as: :edit_next
put 'edit/next' => 'new_issues#update'

# old
get 'edit/:step' => 'issues#edit', as: :edit_step
get 'votes/search' => "issues#votes_search", as: :vote_search
end

collection do
get 'promises/:ids' => 'new_issues#promises'
get 'propositions/:ids' => 'new_issues#propositions'
post 'next' => 'new_issues#create', as: :create_next
get 'new/next' => 'new_issues#new', as: :new_next
get 'promises/:ids' => 'new_issues#promises'
get 'propositions/:ids' => 'new_issues#propositions'
end
end

Expand Down

0 comments on commit 6dbd0b1

Please sign in to comment.