From 734390b055f2c44b9fef2be70cd1088f4b208c79 Mon Sep 17 00:00:00 2001 From: kousukeuo Date: Tue, 29 Jan 2019 20:57:56 +0900 Subject: [PATCH 1/6] =?UTF-8?q?hot=E3=82=AD=E3=83=BC=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=80=81=E3=81=99=E3=81=B9=E3=81=A6=E3=81=AE=E3=82=AD?= =?UTF-8?q?=E3=83=BC=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/templates_controller.rb | 16 ++++++++++++++++ app/views/templates/_form.html.erb | 4 +++- app/views/templates/index.html.erb | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index ec77d799..afcb1bf4 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,4 +1,5 @@ class TemplatesController < ApplicationController + autocomplete :category, :name, full: true before_action :logged_in_user def index @@ -6,8 +7,23 @@ def index @user = User.find(current_user.id) @my_templates_unreleased=@user.templates.where(scope: 0) @my_templates_released=@user.templates.where(scope: 1).order('likes_count DESC') + + @category_name = [] + @categories = Category.all + @categories.each do |category| + @category_name.push(category.name) + end + @category_name = @category_name.each_with_object(Hash.new(0)){|v,o| o[v]+=1} + @category_name = @category_name.sort do |a, b| + b[1] <=> a[1] + end + @category_name = @category_name.to_h.first(3).to_h + @categories = @categories.select(:name).distinct + end + + def new @template=Template.new @category=Category.new diff --git a/app/views/templates/_form.html.erb b/app/views/templates/_form.html.erb index ba8f1d00..5bcd8569 100644 --- a/app/views/templates/_form.html.erb +++ b/app/views/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for @template do |f| %> +<%= form_for @template , html: {autocomplete: "off"} do |f| %>
<%= f.label :title, "アシスタント名" ,class: 'font-weight-bold'%> <%= f.text_field :title, class: 'form-control'%> @@ -28,6 +28,8 @@ <%= i.text_field :name ,class: 'form-control'%> <% end %> + <%= autocomplete_field_tag 'category[name]', nil, autocomplete_category_name_templates_path %> + <% =begin%> <%= f.collection_select(:category_id, Category.all, :id, :name, {}, {:class => "custom-select"}) %> diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index 5be009ca..81cd68f4 100644 --- a/app/views/templates/index.html.erb +++ b/app/views/templates/index.html.erb @@ -1,8 +1,25 @@
+

Hot キーワード

+
+ <% @category_name.each do |key,value| %> + <%= link_to "#{key}", templates_path({"utf8"=>"✓", "select"=>"category", "search"=>"#{key}", "button"=>""}) , class: 'mr-4',style:'font-size: 1.5rem;'%> + <%end%> +
+ + +
+ <% @categories.each do |category| %> + <%= link_to "#{category.name}", templates_path({"utf8"=>"✓", "select"=>"category", "search"=>"#{category.name}", "button"=>""}) , class: 'mr-4',style:'font-size: 1.5rem;'%> + <%end%> +

すべてのアシスタント

+ +
From 0fd73a89579d4bf27fcfa4e9b7af6dcb2f26a99e Mon Sep 17 00:00:00 2001 From: kousukeuo Date: Wed, 30 Jan 2019 02:09:34 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E3=82=A2=E3=82=B7=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=AE=E6=96=B0=E8=A6=8F=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=AE=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=81=E3=82=AB=E3=83=86?= =?UTF-8?q?=E3=82=B4=E3=83=AA=E3=81=AE=E5=85=A5=E5=8A=9B=E3=82=A2=E3=82=B7?= =?UTF-8?q?=E3=82=B9=E3=83=88=E6=A9=9F=E8=83=BD+=E6=A4=9C=E7=B4=A2?= =?UTF-8?q?=E3=81=AE=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=81=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E3=82=A2=E3=82=B7=E3=82=B9=E3=83=88=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- Gemfile.lock | 3 ++ app/assets/javascripts/application.js | 3 +- app/assets/stylesheets/application.scss | 23 ++++++++++++ app/controllers/templates_controller.rb | 14 ++++++-- app/views/templates/_form.html.erb | 18 +++++++--- app/views/templates/index.html.erb | 47 +++++++++++++++++++++++-- config/routes.rb | 4 +++ 8 files changed, 103 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 2ea468a2..c4a8e752 100644 --- a/Gemfile +++ b/Gemfile @@ -43,7 +43,7 @@ gem "activestorage", ">= 5.2.1.1" #bootstrapを追加 gem 'bootstrap', '~> 4.1.1' gem 'jquery-rails' - +gem 'jquery-ui-rails' #iconを追加 gem "font-awesome-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 53059e34..48a8ba17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -271,6 +271,8 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (6.0.1) + railties (>= 3.2.16) json (1.8.6) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) @@ -432,6 +434,7 @@ DEPENDENCIES foreman jbuilder (~> 2.5) jquery-rails + jquery-ui-rails listen (>= 3.0.5, < 3.2) mini_magick (= 4.7.0) pg (>= 0.18, < 2.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0044d3e1..3a126a85 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,4 +17,5 @@ //= require jquery3 //= require popper //= require bootstrap-sprockets -//= require cocoon \ No newline at end of file +//= require cocoon +//= require jquery-ui \ No newline at end of file diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5b21494b..8a22ea81 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -235,4 +235,27 @@ p.kaiwa-text:last-child { .table { background-color: white; +} + +ul.ui-autocomplete { + position: absolute; + list-style: none; + margin: 0; + padding: 0; + border: solid 1px #999; + cursor: default; + li { + background-color: #FFF; + border-top: solid 1px #DDD; + margin: 0; + padding: 2px 15px; + a { + color: #000; + display: block; + padding: 3px; + } + a.ui-state-hover, a.ui-state-active { + background-color: #FFFCB2; + } + } } \ No newline at end of file diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index afcb1bf4..5a81d166 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,5 +1,4 @@ class TemplatesController < ApplicationController - autocomplete :category, :name, full: true before_action :logged_in_user def index @@ -27,7 +26,6 @@ def index def new @template=Template.new @category=Category.new - @submit='作成' end def show @@ -93,6 +91,18 @@ def release end end + def category_auto_complete + categories = Category.select(:name).where("name like '%" + params[:term] + "%'").order(:name) + categories = categories.map(&:name) + render json: categories.to_json + end + + def template_auto_complete + templates = Template.where(scope: 1).select(:title).where("title like '%" + params[:term] + "%'").order(:title) + templates = templates.map(&:title) + render json: templates.to_json + end + private def template_params diff --git a/app/views/templates/_form.html.erb b/app/views/templates/_form.html.erb index 5bcd8569..32cb64f7 100644 --- a/app/views/templates/_form.html.erb +++ b/app/views/templates/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for @template , html: {autocomplete: "off"} do |f| %> +<%= form_for @template do |f| %>
<%= f.label :title, "アシスタント名" ,class: 'font-weight-bold'%> <%= f.text_field :title, class: 'form-control'%> @@ -25,11 +25,9 @@
<%= fields_for @category do |i| %> <%= i.label :name, "カテゴリ" ,class: 'font-weight-bold'%> - <%= i.text_field :name ,class: 'form-control'%> + <%= i.text_field :name ,class: 'form-control' , id: :category_name%> <% end %> - <%= autocomplete_field_tag 'category[name]', nil, autocomplete_category_name_templates_path %> - <% =begin%> <%= f.collection_select(:category_id, Category.all, :id, :name, {}, {:class => "custom-select"}) %> @@ -54,10 +52,22 @@ <% end %> \ No newline at end of file diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index 81cd68f4..c37ecd4a 100644 --- a/app/views/templates/index.html.erb +++ b/app/views/templates/index.html.erb @@ -26,10 +26,10 @@ <%= form_tag(templates_path, :method => 'get') do %>
- <%= select_tag :select, options_for_select([["タイトル", 'title'], ["カテゴリ", 'category']]) , class:"custom-select" %> + <%= select_tag :select, options_for_select([["タイトル", 'title'], ["カテゴリ", 'category']]) , class:"custom-select" ,id:"select_key"%>
- <%= text_field_tag :search ,'',:class => 'form-control',:placeholder =>'アシスタントを検索' %> + <%= text_field_tag :search ,'',:class => 'form-control',:placeholder =>'アシスタントを検索' ,:id=>'template_or_category_name'%>
<%= button_tag '検索', class: 'btn btn-primary' %> @@ -126,4 +126,45 @@
-
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2b117282..70a52d61 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,10 @@ member do get 'release' end + collection do + get 'category_auto_complete' + get 'template_auto_complete' + end end resources :likes, only: [:create, :destroy] get 'login' => 'sessions#new' From c001dacc84969f0c4cecc8fc0d121fc893d73083 Mon Sep 17 00:00:00 2001 From: kousukeuo Date: Wed, 30 Jan 2019 02:12:17 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E3=82=AD=E3=83=BC=E3=83=AF=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E3=82=AB=E3=83=86=E3=82=B4=E3=83=AA=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/templates/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index c37ecd4a..886178d6 100644 --- a/app/views/templates/index.html.erb +++ b/app/views/templates/index.html.erb @@ -1,7 +1,7 @@
-

Hot キーワード

+

Hot カテゴリ

<% @category_name.each do |key,value| %> <%= link_to "#{key}", templates_path({"utf8"=>"✓", "select"=>"category", "search"=>"#{key}", "button"=>""}) , class: 'mr-4',style:'font-size: 1.5rem;'%> From d216b3b94327637a02a6b854162e5cb1ec09a044 Mon Sep 17 00:00:00 2001 From: kousukeuo Date: Wed, 30 Jan 2019 13:21:18 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/templates/show.html.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/views/templates/show.html.erb b/app/views/templates/show.html.erb index ea9d87ea..b69ff943 100644 --- a/app/views/templates/show.html.erb +++ b/app/views/templates/show.html.erb @@ -27,6 +27,16 @@

<%= link_to "公開する", release_template_path(@template.id), data:{confirm: "本当にこのアシスタントを公開しますか?\n一度公開されると戻せません。"}%>

+ <%= form_for(@document) do |f| %> +
+ <%= f.hidden_field :title,value:'テスト' %> +
+ + <%= f.hidden_field :template_id, :value => @template.id %> +
+ <%= f.submit "このボタンでアシスタントをテストします。公開はされません", class: "btn btn-primary" %> +
+ <% end %> <% else %>
- + +
@@ -183,11 +184,16 @@ export default { tab1: true, tab2: false, record_flag: false, - chrome: false + chrome: false, + test_flag: false }; }, mounted: function() { + let test = this.getParams().test; + if (test == 1) { + this.test_flag = true; + } let path = location.pathname.split("/"); let documentNumber = path[2]; axios @@ -294,6 +300,18 @@ export default { resolve(); }); }, + getParams: function() { + var vars = {}; + var param = location.search.substring(1).split("&"); + for (var i = 0; i < param.length; i++) { + var keySearch = param[i].search(/=/); + var key = ""; + if (keySearch != -1) key = param[i].slice(0, keySearch); + var val = param[i].slice(param[i].indexOf("=", 0) + 1); + if (key != "") vars[key] = decodeURI(val); + } + return vars; + }, addAnswerToNote: function() { this.note += ` Q${this.count + 1}` + this.questions[this.count].qtext + "\n"; @@ -552,6 +570,18 @@ export default { } else if (agent.indexOf("firefox") > -1) { } else { } + }, + endTest: function() { + let path = location.pathname.split("/"); + let documentNumber = path[2]; + var form = document.createElement("form"); + + form.method = "POST"; + form.action = `/documents/${documentNumber}/test`; + + document.body.appendChild(form); + + form.submit(); } } }; diff --git a/app/views/templates/show.html.erb b/app/views/templates/show.html.erb index b69ff943..5ef4003b 100644 --- a/app/views/templates/show.html.erb +++ b/app/views/templates/show.html.erb @@ -30,6 +30,7 @@ <%= form_for(@document) do |f| %>
<%= f.hidden_field :title,value:'テスト' %> + <%= hidden_field_tag 'test', true %>
<%= f.hidden_field :template_id, :value => @template.id %> diff --git a/config/routes.rb b/config/routes.rb index 70a52d61..fdb7081f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,13 @@ resources :users post '/users/new', to: 'users#create' resources :sessions, :only => [:new,:create] - resources :documents, :only => [:index,:new,:show,:create,:update,:destroy] + + resources :documents do + member do + post 'test' + end + end + resources :templates do member do get 'release'