[phase-14]add wiki-style description and preview

This commit is contained in:
Toru Takahashi 2018-06-15 23:21:40 +09:00 committed by TAKAHASHI,Toru
parent 3d77142a46
commit 0e0aa07131
6 changed files with 34 additions and 8 deletions

View File

@ -1,7 +1,8 @@
class GlossaryTermsController < ApplicationController class GlossaryTermsController < ApplicationController
before_action :find_term_from_id, only: [:show, :edit, :update, :destroy] before_action :find_term_from_id, only: [:show, :edit, :update, :destroy]
before_action :find_project_by_project_id, :authorize before_action :find_project_by_project_id, :authorize, except: [:preview]
before_action :find_attachments, only: [:preview]
def index def index
@glossary_terms = GlossaryTerm.where(project_id: @project.id) @glossary_terms = GlossaryTerm.where(project_id: @project.id)
@ -46,6 +47,16 @@ class GlossaryTermsController < ApplicationController
redirect_to project_glossary_terms_path redirect_to project_glossary_terms_path
end end
def preview
term = GlossaryTerm.find_by_id(params[:id])
if term
@attachments += term.attachments
@previewed = term
end
@text = params[:glossary_term][:description]
render partial: 'common/preview'
end
# Find the term whose id is the :id parameter # Find the term whose id is the :id parameter
def find_term_from_id def find_term_from_id
@term = GlossaryTerm.find(params[:id]) @term = GlossaryTerm.find(params[:id])

View File

@ -6,7 +6,7 @@
<p><%= form.text_field :datatype, size: 80 %></p> <p><%= form.text_field :datatype, size: 80 %></p>
<p><%= form.text_field :codename, size: 80 %></p> <p><%= form.text_field :codename, size: 80 %></p>
<p><%= form.select :category_id, GlossaryCategory.pluck(:name, :id), include_blank: true %></p> <p><%= form.select :category_id, GlossaryCategory.pluck(:name, :id), include_blank: true %></p>
<p><%= form.text_area :description, size: "80x10", required: false %></p> <p><%= form.text_area :description, rows: 10, class: 'wiki-edit', required: false %></p>
</div> </div>
<div class="box"> <div class="box">
@ -16,3 +16,4 @@
</p> </p>
</div> </div>
<%= wikitoolbar_for 'glossary_term_description' %>

View File

@ -1,7 +1,9 @@
<h2><%=l :label_glossary_term %> #<%= @term.id %></h2> <h2><%=l :label_glossary_term %> #<%= @term.id %></h2>
<%= labelled_form_for @term, url: project_glossary_term_path, html: {multipart: true} do |f| %> <%= labelled_form_for :glossary_term, @term, url: project_glossary_term_path, html: {multipart: true, id: 'term-form'} do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %> <%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_edit) %> <%= f.submit l(:button_edit) %>
<%= preview_link preview_project_glossary_term_path(@project, @term), 'term-form' %>
<% end %> <% end %>
<div id="preview" class="wiki" ></div>

View File

@ -1,7 +1,12 @@
<h2><%=l :label_glossary_term_new %></h2> <h2><%=l :label_glossary_term_new %></h2>
<%= labelled_form_for :glossary_term, @term, <%= labelled_form_for :glossary_term, @term,
url: project_glossary_terms_path, html: {multipart: true} do |f| %> url: project_glossary_terms_path, html: {multipart: true, id: 'term-form'} do |f| %>
<%= render partial: 'glossary_terms/form', locals: {form: f} %> <%= render partial: 'glossary_terms/form', locals: {form: f} %>
<%= f.submit l(:button_create) %> <%= f.submit l(:button_create) %>
<%= preview_link preview_project_glossary_terms_path(@project), 'term-form' %>
<% end %> <% end %>
<div id="preview" class="wiki"></div>

View File

@ -41,7 +41,7 @@
</tr> </tr>
<tr> <tr>
<th><%=l :field_description %></th> <th><%=l :field_description %></th>
<td><%= @term.description %></td> <td><div class="wiki"><%= textilizable @term, :description %></div></td>
</tr> </tr>
<tr> <tr>
<th><%=l :field_created_on %></th> <th><%=l :field_created_on %></th>

View File

@ -3,7 +3,14 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :projects do resources :projects do
resources :glossary_terms resources :glossary_terms do
member do
patch 'preview'
end
collection do
post 'preview'
end
end
resources :glossary_categories resources :glossary_categories
end end
end end