bundler 対応、 unicorn 対応、 書籍登録周りの不具合修正
authorOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Sun, 18 Apr 2021 01:41:41 +0000 (10:41 +0900)
committerOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Sun, 18 Apr 2021 01:41:41 +0000 (10:41 +0900)
sinatra/Gemfile [new file with mode: 0644]
sinatra/app/controllers/web_gui.rb
sinatra/app/models/books_db.rb
sinatra/app/views/book_regist.haml
sinatra/app/views/scss/classes.scss
sinatra/start.rb
sinatra/unicorn.rb [new file with mode: 0644]
start.sh [new file with mode: 0755]
stop.sh [new file with mode: 0755]

diff --git a/sinatra/Gemfile b/sinatra/Gemfile
new file mode 100644 (file)
index 0000000..e8fd144
--- /dev/null
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+source "https://rubygems.org"
+
+git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
+
+# gem "rails"
+
+gem 'sinatra'
+gem 'rack-cache'
+gem 'haml'
+gem 'logger'
+gem 'activerecord'
+gem 'mysql2'
+gem 'rexml'
+gem 'bcrypt'
+gem 'httpclient'
+gem 'sass'
+gem 'scss'
+gem 'coffee-script'
+gem 'unicorn'
+# gem 'mini_racer'
index 94b7d7d..fac3cc9 100644 (file)
@@ -50,6 +50,9 @@ class WebGui < Sinatra::Base
     # @params [Hash] Upload用パラメータ
     # @return [Hash] Uploadデータ情報
     def getUploadData(upload_param)
+      if (upload_param == nil)
+        return nil
+      end
       upload_data = Hash.new
       file =  upload_param[:tempfile]
       upload_data[:mime_type] = upload_param[:type]
@@ -69,7 +72,7 @@ class WebGui < Sinatra::Base
     # 更新用の書籍情報を作成する。
     # @param [Hash] params Postで取得した全パラメータ
     # @return [Hash] 更新用書籍情報
-    def makeBookInfo(params)
+    def makeBookInfo(params, image_f)
       book_info = Hash.new
       params.each do |key, value|
         case key
@@ -77,7 +80,7 @@ class WebGui < Sinatra::Base
           # 対象キーは書籍情報ではないので飛す
           next
         end
-        if ((key == 'cover_uriD') && (image_f))
+        if ((key == 'cover_uri') && (image_f))
           # 登録するイメージがあるのでURIの登録は飛す
           next
         end
@@ -448,7 +451,7 @@ class WebGui < Sinatra::Base
     image_f = (params[:cover_base64] != nil)
 
     # 書籍の設定情報を選出
-    book_info = makeBookInfo(params)
+    book_info = makeBookInfo(params, image_f)
     
     begin
       isbn = book_info[:isbn]
@@ -499,7 +502,9 @@ class WebGui < Sinatra::Base
       user = UserAccount.getUser(id)
       @id = id
       @username = user.full_name
-      @book_info = BookManager.searchISBN(isbn, id)
+      if (isbn != nil && isbn.length > 0)
+        @book_info = BookManager.searchISBN(isbn, id)
+      end
       @is_admin = UserAccount.checkAdmin(id)
     rescue UserAccount::NotFoundInstanceError
       raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
@@ -508,6 +513,12 @@ class WebGui < Sinatra::Base
     rescue BookManager::FailedGetInstance
       raise WebError.new(status: 500, message: "ISBNによる書籍検索に失敗しました。", refs: "/book_regist")
     end
+    if (isbn == nil || isbn.length == 0)
+      @book_info = Hash.new
+      @warning = "ISBNを入力してください。"
+    elsif (@book_info[:title] == nil )
+      @warning = "ISBN探索にて対象の書籍が見付かりませんでした。"
+    end
     goPage :book_regist
   end
   
@@ -535,6 +546,8 @@ class WebGui < Sinatra::Base
       @book_info[:cover_base64] = base64
       @book_info[:mime_type] = mime_type
       @book_info[:cover_uri] = "data:" + mime_type + ";base64," + base64
+    else
+      @warning = "書影のファイルを指定してください"
     end
     goPage :book_regist
   end
index c4bc726..cae0e35 100644 (file)
@@ -286,7 +286,7 @@ class BookManager
     end
     parsons = getParsonsFromNDL(creators)
     book_hash = {
-      search_type: SEARCH_ON_OPENNDL,
+      search_type: SEARCH_ON_NDL,
       isbn: isbn,
       title: book.elements['dcterms:title'] != nil ? book.elements['dcterms:title'].text : nil,
       volume: book.elements['dcndl:volume/rdf:Description/rdf:value'] != nil ? book.elements['dcndl:volume/rdf:Description/rdf:value'].text.gsub(/[^\d]/, "").to_i : nil,
index 6572204..2bb7d57 100644 (file)
@@ -1,7 +1,8 @@
 - # encoding: utf-8
 - is_admin = @is_admin; id = @id; book_info = @book_info
 - update_f = @update_f; is_admin_books = @is_admin_books
-- if book_info[:title] != nil
+- warning = @warning
+- if book_info[:title] != nil && book_info[:title].length > 0
   - isbn_regist_f = true
 - else
   - isbn_regist_f = false
   - else
     新規に蔵書の情報を登録することができます。
     
-- if !isbn_regist_f
+- if update_f
   .message
     「ISBN探索」を押下すると、該当する本の情報が取得できます。
     (取得できない場合は、更新されません)
 
 .message
   「書影Upload」を押下すると、本の書影を登録できます。
-  
+
+- if warning
+  .warning
+    #{warning}
 
 %hr
 
@@ -31,8 +35,8 @@
         %label{ :for => 'isbn' }
           %span
             ISBN:
-        %input{ :name => 'isbn', :type => 'text', :class => 'input_text', :id => 'isbn', :value => book_info[:isbn], :readonly => isbn_regist_f, :required => isbn_regist_f}
-        %input{ :type => 'submit', :class => 'side_button', :value => 'ISBN探索', :formaction => '/book_search_isbn', :disabled => isbn_regist_f}
+        %input{ :name => 'isbn', :type => 'text', :class => 'input_text', :id => 'isbn', :value => book_info[:isbn], :readonly => update_f, :required => isbn_regist_f}
+        %input{ :type => 'submit', :class => 'side_button', :value => 'ISBN探索', :formaction => '/book_search_isbn', :disabled => update_f}
 
       .item
         %label{ :for => 'title' }
index 1f9b7a8..4637471 100644 (file)
     padding: 2px;
 }
 
+.warning {
+    margin-left: 10px;
+    margin-right: 10px;
+    font-family: 'Sawarabi Mincho';
+    font-size: 1em;
+    text-align: left;
+    padding: 2px;
+    color: #ee827c;
+}
+
 .formstyle {
     margin: 0, auto;
 
index e4dd42e..8ba7c4f 100644 (file)
@@ -2,6 +2,7 @@
 # 書籍管理サーバベース処理
 # @author OHASHI, Norikazu
 
+require 'bundler/setup'
 require 'sinatra/base'
 require_relative './app/controllers/web_gui'
 # require 'app/controllers/restful_api'
diff --git a/sinatra/unicorn.rb b/sinatra/unicorn.rb
new file mode 100644 (file)
index 0000000..d3eb6f5
--- /dev/null
@@ -0,0 +1,20 @@
+# coding: utf-8
+require 'fileutils'
+
+@dir = File.dirname(__FILE__)
+
+worker_processes 2 # CPUのコア数に揃える
+working_directory @dir
+
+timeout 300
+listen 8080
+
+@pid_path = File.join(@dir, "tmp/pids")
+FileUtils.mkdir_p(@pid_path)
+pid File.join(@pid_path, "unicorn.pid") #pidを保存するファイル
+
+@log_path = File.join(@dir, "log")
+FileUtils.mkdir_p(@log_path)
+# unicornは標準出力には何も吐かないのでログ出力を忘れずに
+stderr_path File.join(@log_path,"unicorn.stderr.log")
+stdout_path File.join(@log_path,"unicorn.stdout.log")
diff --git a/start.sh b/start.sh
new file mode 100755 (executable)
index 0000000..9b94269
--- /dev/null
+++ b/start.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -z $BOOK_SERVER_PATH ]
+then
+    BOOK_SERVER_PATH="."
+fi
+(cd $BOOK_SERVER_PATH; bundle exec unicorn -c unicorn.rb -D)
diff --git a/stop.sh b/stop.sh
new file mode 100755 (executable)
index 0000000..509dfa7
--- /dev/null
+++ b/stop.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -z $BOOK_SERVER_PATH ]
+then
+   BOOK_SERVER_PATH="."
+fi
+(cd $BOOK_SERVER_PATH; kill `cat tmp/pids/unicorn.pid`)