update_at DATETIME NOT NULL);
CREATE TABLE book_collections (
+ id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
isbn VARCHAR(14) NOT NULL,
user_id INTEGER NOT NULL,
summary TEXT,
# 蔵書の登録
get '/book_regist' do
id = session[:userId]
+ session[:book_update_f] = false
if (id == nil)
raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
end
end
goPage :book_regist
end
+
+ # 蔵書の編集
+ get '/book_edit/:isbn' do
+ id = session[:userId]
+ session[:book_update_f] = true
+ isbn = params[:isbn]
+ if (id == nil)
+ raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ begin
+ user = UserAccount.getUser(id)
+ @id = id
+ @username = user.full_name
+ @book_info = BookManager.getBookCollect(isbn, id)
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
+ end
+ goPage :book_regist
+ end
- # 蔵書の登録 (POST)
+ # 蔵書の登録/編集 (POST)
# @post_param isbn [String] ISBN
# @post_param title [String] 書名
# @post_param volume [Integer] 巻数
# @raise [WebError] 蔵書情報編集失敗
post '/book_regist' do
id = session[:userId]
+ book_update_f = session[:book_update_f]
book_info = Hash.new
if (id == nil)
end
# 蔵書情報の更新
- BookManager.createBookCollect(isbn, id, params[:summary], params[:book_rank])
+ summary = params[:summary]; book_rank = params[:book_rank]
+ if (book_update_f)
+ BookManager.updateBookCollect(isbn, id, summary, book_rank)
+ else
+ BookManager.createBookCollect(isbn, id, summary, book_rank)
+ end
rescue BookManager::NotFoundInstanceError,
BookManager::AlreadyInstanceError
end
+ # 蔵書情報の取得
get '/book_info/:isbn' do
id = session[:userId]
isbn = params[:isbn]
goPage :book_info
end
+ #蔵書一覧の取得(トリガページ)
get '/book_list' do
+ session[:list_status] = {position: {start:0, step: 10},
+ find_status: nil}
+ redirect "/book_list/main"
+ end
+
+ #蔵書一覧の取得(表示件数変更ページ)
+ post '/book_list/change_step' do
+ step = params[:step].to_i
+ session[:list_status][:position][:step] = step
+ redirect "/book_list/main"
+ end
+
+ #蔵書一覧の取得(次ページ)
+ post '/book_list/next' do
+ step = session[:list_status][:position][:step]
+ session[:list_status][:position][:start] += step
+ redirect "/book_list/main"
+ end
+
+ #蔵書一覧の取得(前ページ)
+ post '/book_list/before' do
+ step = session[:list_status][:position][:step]
+ session[:list_status][:position][:start] -= step
+ redirect "/book_list/main"
+ end
+
+ #蔵書一覧の取得(検索後)
+ post '/book_list/find' do
+ find_status = session[:list_status][:find_status]
+ find_key = params[:kind].to_sym
+ find_value = params[:find_value]
+ if (find_status == nil)
+ find_status = {find_key => find_value}
+ else
+ find_status[find_key] = find_value
+ end
+ session[:list_status][:find_status] = find_status
+ redirect "/book_list/main"
+ end
+
+ #蔵書一覧の取得 (蔵書情報取得から)
+ get '/book_list/fromInfo' do
+ list_status = session[:list_status]
+ if (list_status == nil)
+ session[:list_status] = {position: {start:0, step: 10},
+ find_status: nil}
+ end
+ redirect "/book_list/main"
+ end
+ #蔵書一覧の取得(メインページ)
+ get '/book_list/main' do
id = session[:userId]
- list_status = session[:find_status]
+ list_status = session[:list_status]
if (id == nil)
raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
end
rescue UserAccount::NotFoundInstanceError
raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
end
- if (list_status == nil)
- position = {start: 0, step: 10}
- find_status = nil
- else
- position = list_status[:position]
- find_status = list_status[:find_status]
- end
+ position = list_status[:position]
+ find_status = list_status[:find_status]
books = BookManager.findBook(find_status)
- @book_list = BookManager.narrowBookOfId(id, books, position[:start], position[:step])
+ @book_list, @full_size = BookManager.narrowBookOfId(id, books, position[:start], position[:step])
@start = position[:start]
@step = position[:step]
if (@book_list == nil)
goPage :book_list
end
+ # 蔵書の削除
+ get '/book_delete/:isbn' do
+ id = session[:userId]
+ isbn = params[:isbn]
+ if (id == nil)
+ raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+ end
+ begin
+ user = UserAccount.getUser(id)
+ @id = id
+ @username = user.full_name
+ @book_info = BookManager.getBookCollect(isbn, id)
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
+ rescue BookManager::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "蔵書情報が見付かりません。", refs: "/user_home")
+ end
+ goPage :book_delete
+ end
+
+ # 蔵書の削除
+ get '/book_delete/result/:isbn' do
+ id = session[:userId]
+ isbn = params[:isbn]
+ begin
+ BookManager.deleteBookCollect(isbn, id)
+ rescue UserAccount::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "ユーザ情報が存在しません。")
+ rescue BookManager::NotFoundInstanceError
+ raise WebError.new(status: 404, message: "蔵書情報が見付かりません。", refs: "/user_home")
+ end
+ redirect '/user_home'
+ end
+
# ログアウトページ
get '/logout' do
# 最終ログイン情報登録
pubdate: book[:pubdate],
cover_uri: book[:cover_uri],
summary: book_collect[:summary],
- rank: book_collect[:rank]
+ book_rank: book_collect[:book_rank]
}
end
end
# 書籍情報の登録
- # @param [Hash] 書籍情報のハッシュ
+ # @param [Hash] book_info 書籍情報のハッシュ
def self.createBook(book_info)
isbn = book_info[:isbn]
if (Book.find_by(isbn: isbn) != nil)
end
columns.each do |key, value|
- if ((value == nil) || (value == ""))
+ if ((value == nil))
# 値がない、値が空文字の場合は対象としない。
next
end
if (find_keys == nil)
return books
end
-
find_keys.each do |key, value|
+
if (books == nil)
break
end
if (value =~ /^\/(.+)\/$/)
- books = books.with_regexp(key, value)
+ reg_value = value[1...-1]
+ books = books.with_regexp(key, reg_value)
else
books = books.where(key => value)
end
books.each do |book|
book_collect = BookCollection.find_by(user_id: user_id, isbn: book.isbn)
if (book_collect != nil)
- if (count >= start + step)
- break
- end
if ((count >= start) && (count < start + step))
narrow_book = createBookHash(book, book_collect)
narrow_books.push(narrow_book)
count += 1
end
end
- return narrow_books
+ return narrow_books, count
end
#蔵書情報の取得
# @param [String] isbn_str 取得対象のISBN
# @param [Integer] user_id 取得対象のユーザID
- # @param [Arrray<Book>] books 絞り込み対象の書籍情報一覧
# @return [Array<Hash>] 絞り込んだ書籍情報
def self.getBookCollect(isbn_str, user_id)
isbn = toIsbn(isbn_str)
# @param [String] isbn 登録するISBN
# @param [Integer] user_id 登録対象のユーザID
# @param [String] summary ユーザ毎の紹介分
- # @param [Integer] book_rank ユーザの評価
+ # @param [string] book_rank ユーザの評価
# @return [BookCollection] 蔵書情報
def self.createBookCollect(isbn, user_id, summary, book_rank)
if (BookCollection.find_by(isbn: isbn, user_id: user_id) != nil)
# 蔵書情報の変更
# @param [String] isbn_str 変更対象のISBN
# @param [Integer] user_id 変更対象のユーザID
- # @param [Hash] columns 変更するカラムと値のハッシュ
- def self.updateBookCollect(isbn_str, user_id, columns)
+ # @param [String] summary ユーザ毎の紹介分
+ # @param [string] book_rank ユーザの評価
+ def self.updateBookCollect(isbn_str, user_id, summary, book_rank)
isbn = toIsbn(isbn_str)
book_collect = BookCollection.find_by(isbn: isbn, user_id: user_id )
change_f = false
raise NotFoundInstanceError
end
- columns.each do |key, value|
- if ((value == nil) || (value == ""))
- # 値がない、値が空文字の場合は対象としない。
- next
- end
- if (value != book_collect.send(key))
+ if ((summary != nil) &&
+ (summary != book_collect.summary))
# 値が異なれば更新
- method = key.to_s + "="
- book_collect.send(method, value)
+ book_collect.summary = summary
change_f = true
- end
end
+ if ((book_rank != book_collect.book_rank))
+ # 値が異なれば更新
+ book_collect.book_rank = book_rank
+ change_f = true
+ end
+
# 更新内容の適用
if (change_f)
- user.update_at = DateTime.now
- if (user.save)
- raise DbAccessError
+ book_collect.update_at = DateTime.now
+ if (not book_collect.save)
+ raise DbAccesError
end
end
end
--- /dev/null
+- # encoding: utf-8
+- id = @id
+- username = @username
+- isbn = @book_info[:isbn]
+- title = @book_info[:title]
+- volume = @book_info[:volume]
+- if volume != nil
+ - title += ' : ' + volume.to_s + '巻'
+
+%h2
+ #{title} の削除
+
+.message
+ 「#{title}」を #{username} さんの蔵書から削除します。
+.message
+ よろしいですか?
+
+.buttons
+ %hr
+ %input{ :type => 'button', :class=>'push_button', :onclick => "location.href='/book_delete/result/#{isbn}'", :value => 'Ok'}
+ %input{ :type => 'button', :class=>'push_button', :onclick =>"location.href='/user_home'", :value => 'もどる' }
+
+
+
- # encoding: utf-8
-- admin_f = @admin_f
- id = @id
- book_info = @book_info
- when 5 then
.rank
★ ★ ★ ★ ★
+ .buttons
+ %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/book_edit/#{book_info[:isbn]}'", :value => '編集' }
+ %input{ :type => 'button', :class=>"push_button", :onclick =>"location.href='/book_list/fromInfo'", :value => '一覧へ' }
- # encoding: utf-8
- user_name = @username; book_list = @book_list
-- start = @start; step = @step; index = @start
-- if start + step > book_list.size
+- start = @start; step = @step; index = @start; full_size = @full_size
+- if start + step >= full_size
- next_step = 0
- else
- next_step = step
#{user_name} さんの蔵書一覧は以下となります。
.find_form
- %form{:action => "/book_find", :method => "post"}
+ %form{:action => "/book_list/find", :method => "post"}
%table
%tr
%th
%option{ :value => 'series' }
単行本シリーズ
%td
- %input{ :type => 'text', :name => 'find_value', :id => 'find_value', :size => 60}
+ %input{ :type => 'text', :name => 'find_value', :id => 'find_value', :size => 40}
%td
%input{ :type => 'submit', :class => 'side_button', :value => '検索'}
.seek_form
%form{:method => "post"}
- %input{ :type => 'submit', :class => 'side_button', :formaction => "/book_list/before/#{before_step}", :value => "《#{before_step}件戻る", :disabled => (before_step == 0) }
+ %input{ :type => 'submit', :class => 'side_button', :formaction => '/book_list/before', :value => "《#{before_step}件戻る", :disabled => (before_step == 0) }
%label{ :for => 'step' }
表示件数
%input{ :name => 'step', :type => 'text', :id => 'step', :size => 5, :value => step, :pattern => '[0-5]{1,4}'}
- %label{ :type => 'submit', :class => 'side_button', :formaction => '/book_list/chage_step', :value => '表示件数変更'}
- %input{ :type => 'submit', :class => 'side_button', :formaction => "/book_list/next/#{next_step}", :value => "#{next_step}件進む》", :disabled => (next_step == 0) }
+ %input{ :type => 'submit', :class => 'side_button', :formaction => '/book_list/change_step', :value => '表示件数変更'}
+ %input{ :type => 'submit', :class => 'side_button', :formaction => '/book_list/next', :value => "#{next_step}件進む》", :disabled => (next_step == 0) }
%input{ :type => 'hidden', :name => 'start', :value => start}
.book_list
%th.controll
操作
- book_list.each do |book|
- - book_id = index; index += 1
+ - index += 1
- isbn = book[:isbn]; publisher = book[:publisher]; pubdate = book[:pubdate]
- if book[:volume] != nil
- title = "#{book[:title]} : #{book[:volume]} 巻"
- author += "作画:#{book[:illustrator]} "
%tr
%td.number
- #{book_id}
+ #{index}
%td.title
%a{ :href => "/book_info/#{isbn}" }
#{title}
%span
出版日:
%input{ :name => 'pubdate', :type => 'text', :id => 'pubdate', :value => book_info[:pubdate], :oninput => 'validDateForm(this)'}
-
+
.item
- %label{ :for => 'cover_file' }
+ %label{ :for => 'cover_file'}
%span
書影:
+ %input{ :name => 'cover_file', :type => 'file', :id => 'cover_file', :accept => 'image/png, image/jpeg', :style => "display:none"}
+ %input{ :type => 'text', :id => 'file_name', :value => ''}
+ %input{ :type => 'submit', :class => 'side_button', :value => '書影Upload', :formaction => '/book_upload_cover' }
+ :javascript
+ var file = document.getElementById( 'cover_file' );
+ var text = document.getElementById( 'file_name' );
+
+ file.onchange = function()
+ {
+ text.value = this.value;
+ }
+
+ text.onclick = function()
+ {
+ file.click();
+ }
+
+ .item_center
- if book_info[:cover_uri] != nil
- %image{ :border => '1', :src => book_info[:cover_uri], :class => 'cover_image', :width => '128', :height => '182'}
+ %image{ :id => 'cover_image', :border => '1', :src => book_info[:cover_uri], :class => 'cover_image', :width => '128', :height => '182'}
%input{ :name => 'cover_uri', :type => 'hidden', :value => book_info[:cover_uri]}
- if book_info[:cover_base64] != nil
%input{ :name => 'cover_base64', :type => 'hidden', :value => book_info[:cover_base64]}
%input{ :name => 'mime_type', :type => 'hidden', :value => book_info[:mime_type]}
- %input{ :name => 'cover_file', :type => 'file', :id => 'cover_file', :accept => 'image/png, image/jpeg'}
- %input{ :type => 'submit', :class => 'side_button', :value => '書影Upload', :formaction => '/book_upload_cover' }
-
.item
%label{ :for => 'summary' }
%span
- # encoding: utf-8
%h1
- □■□■ 蔵書管理 Web v0.01 ■□■□
+ □■□■ 蔵書管理 Web v0.5 ■□■□
%h3
重ね買いを防ぐために…
@charset "utf-8";
+@mixin button_color {
+ background-color: #f08300;
+ color: #3e62ad;
+ border: 1px solid #000000;
+ &:hover {
+ background-color:#f6ad49;
+ color: #3e62ad;
+ }
+ &:disabled {
+ background-color: #e49e61;
+ color: #bbc8e6;
+ }
+}
+
body {
color:#444;
align-items: center;
text-align: center;
margin: 10px auto;
- max-width:50em;
+ max-width:52em;
}
h1 {
- font-size: 3em;
+ font-size: 2.5em;
+ font-family: serif
}
ul {
padding: 5px,20px;
width: 200px;
height: 25px;
- background-color: #f08300;
- color: #3e62ad;
- border: 1px solid #000000;
margin-left: 20px;
- &:hover {
- background-color:#f6ad49;
- color: #3e62ad;
- }
+ @include button_color;
+}
+
+input.side_button{
+ font-size: 0.7em;
+ padding: 2px,2px;
+ width: 80px;
+ height: 20px;
+ margin-left: 2px;
+ border-radius: 8px;
+ @include button_color;
}
#main1 {
background: #f8e58c;
align-items: center;
text-align: center;
- height: 30em;
+ height: 40em;
padding: 5px 0px;
overflow: auto;
}
.formstyle {
margin: 0, auto;
.params {
- height: 15em;
+ height: 27em;
overflow: auto;
margin-left: 20px;
text-align: left;
display: block;
.item {
+ margin: 2px auto;
label {
margin-right: 10px;
span {
width:220px;
display: inline-block;
+ vertical-align: top;
}
}
}
+ .item_center {
+ align-items: center;
+ text-align: center;
+ }
}
}
+.find_form, .book_list, seek_form {
+ display: inline-block;
+ align-items: center;
+ text-align: center;
+}
+
.buttons {
margin: 5px 0px;
position: absolute;