add edit function
This commit is contained in:
parent
a3edebce6a
commit
d7599f1ccf
|
@ -1,4 +1,5 @@
|
||||||
class Desktop::JournalPagesController < ApplicationController
|
class Desktop::JournalPagesController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@writing_journal = WritingJournal.where(create_user_id: current_user.id)
|
@writing_journal = WritingJournal.where(create_user_id: current_user.id)
|
||||||
@level_types = JournalLevelType.all
|
@level_types = JournalLevelType.all
|
||||||
|
@ -8,6 +9,9 @@ class Desktop::JournalPagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@writing_journal = WritingJournal.new
|
@writing_journal = WritingJournal.new
|
||||||
@level_types = JournalLevelType.all
|
@level_types = JournalLevelType.all
|
||||||
|
@ -20,6 +24,13 @@ class Desktop::JournalPagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@writing_journal= WritingJournal.find(params[:id])
|
||||||
|
@level_types = JournalLevelType.all
|
||||||
|
@author_types = JournalAuthorType.all
|
||||||
|
@paper_types= JournalPaperType.all
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { render :layout => false}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -43,12 +54,77 @@ class Desktop::JournalPagesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def update
|
||||||
|
if params[:commit].eql?"Save"
|
||||||
|
@writing_journal= WritingJournal.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
if not params[:writing_journal][:publication_date].nil?
|
||||||
if params[:commit].eql?"Edit"
|
params[:writing_journal][:publication_date] = \
|
||||||
params[:writing_journal][:update_user_id] = current_user.id
|
Date.new *(params[:writing_journal][:publication_date].split("/").map{|s| s.to_i})
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @writing_journal.update_attributes(params[:writing_journal])
|
||||||
|
format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully updated.'}
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { render action: "edit" }
|
||||||
|
format.json { render json: @user.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_file_type file
|
||||||
|
if not file.nil?
|
||||||
|
file_type = MIME::Types.type_for(file).first.to_s.split("/")[1]
|
||||||
|
|
||||||
|
case file_type
|
||||||
|
when "jpg", "jpeg"
|
||||||
|
type = "jpg"
|
||||||
|
when "text", "txt"
|
||||||
|
type = "txt"
|
||||||
|
when "pdf"
|
||||||
|
type = "pdf"
|
||||||
|
when "png"
|
||||||
|
type = "png"
|
||||||
|
else "readme"
|
||||||
|
end
|
||||||
|
|
||||||
|
file_type = "/assets/ft-icons/#{type}/#{type}-48_32.png"
|
||||||
|
else
|
||||||
|
file_type = ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_journals_json
|
||||||
|
publications = WritingJournal.where(create_user_id: current_user.id)
|
||||||
|
|
||||||
|
sort_publications= Hash.new
|
||||||
|
data = Array.new
|
||||||
|
|
||||||
|
publications.each do |publication|
|
||||||
|
if sort_publications[publication.journal_title].nil?
|
||||||
|
sort_publications[publication.journal_title] = Array.new
|
||||||
|
end
|
||||||
|
sort_publications[publication.journal_title] <<
|
||||||
|
{ title: publication.paper_title,
|
||||||
|
keywords: publication.keywords,
|
||||||
|
abstract: publication.abstract,
|
||||||
|
level: publication.journal_paper_type_id,
|
||||||
|
coauthors: publication.authors,
|
||||||
|
year: publication.year,
|
||||||
|
url_edit: edit_desktop_journal_page_path(publication),
|
||||||
|
files: publication.writing_journal_files.collect{|file|
|
||||||
|
{title: file.title, url: file.file.url, icon: check_file_type(file.file.url)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
sort_publications.each do |journal, papers|
|
||||||
|
data << {title: journal, papers: papers}
|
||||||
|
end
|
||||||
|
|
||||||
|
render json: JSON.pretty_generate(data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,29 +4,6 @@ class DesktopPublicationsController< ApplicationController
|
||||||
def journal_p
|
def journal_p
|
||||||
render "desktop/journal_p", :layout => false
|
render "desktop/journal_p", :layout => false
|
||||||
end
|
end
|
||||||
#
|
|
||||||
# def journal_p_list
|
|
||||||
# render "desktop/journal_pages/list", :layout => false
|
|
||||||
# end
|
|
||||||
|
|
||||||
# def journal_p_add
|
|
||||||
# @writing_journal = WritingJournal.new
|
|
||||||
# @level_types = JournalLevelType.all
|
|
||||||
#
|
|
||||||
# respond_to do |format|
|
|
||||||
# format.html { render "desktop/journal_pages/add", :layout => false}
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def journal_p_create
|
|
||||||
# @writing_journal = WritingJournal.all.first
|
|
||||||
# @level_types = JournalLevelType.all
|
|
||||||
# respond_to do |format|
|
|
||||||
# format.html { render "desktop/journal_pages/list", :layout => false}
|
|
||||||
# #format.js
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# end
|
|
||||||
|
|
||||||
def books
|
def books
|
||||||
render "desktop/books", :layout => false
|
render "desktop/books", :layout => false
|
||||||
|
@ -52,82 +29,31 @@ class DesktopPublicationsController< ApplicationController
|
||||||
render "desktop/seminar_pages/add", :layout => false
|
render "desktop/seminar_pages/add", :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_journal
|
# def create_journal
|
||||||
Journal.create(user_id: current_user.id, title: "Ice Cream Sandwich")
|
# Journal.create(user_id: current_user.id, title: "Ice Cream Sandwich")
|
||||||
b = Array.new
|
# b = Array.new
|
||||||
b << {"success"=>"true"}
|
# b << {"success"=>"true"}
|
||||||
render :json=>b.to_json
|
# render :json=>b.to_json
|
||||||
end
|
# end
|
||||||
|
#
|
||||||
def check_file_type file
|
#
|
||||||
if not file.nil?
|
# def delete_journal
|
||||||
file_type = MIME::Types.type_for(file).first.to_s.split("/")[1]
|
# @journals = Journal.find("")
|
||||||
|
# @journals.delete
|
||||||
case file_type
|
# b = Array.new
|
||||||
when "jpg", "jpeg"
|
# b << {"success"=>"true"}
|
||||||
type = "jpg"
|
# render :json=>b.to_json
|
||||||
when "text", "txt"
|
# end
|
||||||
type = "txt"
|
#
|
||||||
when "pdf"
|
# def update_journal
|
||||||
type = "pdf"
|
# @journal = Journal.find("4ff2d6ebbd98eb02b9000017")
|
||||||
when "png"
|
# @papers = @journal.papers
|
||||||
type = "png"
|
# @papers.each do |paper|
|
||||||
else "readme"
|
# paper.update_attributes(:user_id => current_user.id)
|
||||||
end
|
# end
|
||||||
|
# b = Array.new
|
||||||
file_type = "/assets/ft-icons/#{type}/#{type}-48_32.png"
|
#
|
||||||
else
|
# b << {"success"=>"true"}
|
||||||
file_type = ""
|
# render :json=>b.to_json
|
||||||
end
|
# end
|
||||||
end
|
|
||||||
|
|
||||||
def getjournals
|
|
||||||
publications = WritingJournal.where(create_user_id: current_user.id)
|
|
||||||
|
|
||||||
sort_publications= Hash.new
|
|
||||||
data = Array.new
|
|
||||||
|
|
||||||
publications.each do |publication|
|
|
||||||
if sort_publications[publication.journal_title].nil?
|
|
||||||
sort_publications[publication.journal_title] = Array.new
|
|
||||||
end
|
|
||||||
sort_publications[publication.journal_title] <<
|
|
||||||
{ title: publication.paper_title,
|
|
||||||
keywords: publication.keywords,
|
|
||||||
abstract: publication.abstract,
|
|
||||||
level: publication.journal_paper_type_id,
|
|
||||||
coauthors: publication.authors,
|
|
||||||
year: publication.year,
|
|
||||||
files: publication.writing_journal_files.collect{|file|
|
|
||||||
{title: file.title, url: file.file.url, icon: check_file_type(file.file.url)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
sort_publications.each do |journal, papers|
|
|
||||||
data << {title: journal, papers: papers}
|
|
||||||
end
|
|
||||||
|
|
||||||
render json: JSON.pretty_generate(data)
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete_journal
|
|
||||||
@journals = Journal.find("")
|
|
||||||
@journals.delete
|
|
||||||
b = Array.new
|
|
||||||
b << {"success"=>"true"}
|
|
||||||
render :json=>b.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_journal
|
|
||||||
@journal = Journal.find("4ff2d6ebbd98eb02b9000017")
|
|
||||||
@papers = @journal.papers
|
|
||||||
@papers.each do |paper|
|
|
||||||
paper.update_attributes(:user_id => current_user.id)
|
|
||||||
end
|
|
||||||
b = Array.new
|
|
||||||
|
|
||||||
b << {"success"=>"true"}
|
|
||||||
render :json=>b.to_json
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
<h1>Desktop::JournalPages#edit</h1>
|
<%= form_for @writing_journal, url: desktop_journal_page_path(@writing_journal) do |f| %>
|
||||||
<p>Find me in app/views/desktop/journal_pages/edit.html.erb</p>
|
<%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %>
|
||||||
|
<%end%>
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<%= form_for @writing_journal, url: desktop_journal_pages_path do |f| %>
|
<%= form_for @writing_journal, html: { multipart: true } , url: desktop_journal_pages_path do |f| %>
|
||||||
<%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %>
|
<%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
Orbit::Application.routes.draw do
|
Orbit::Application.routes.draw do
|
||||||
|
|
||||||
devise_for :users
|
devise_for :users
|
||||||
mount Resque::Server, :at => "/admin/resque"
|
mount Resque::Server, :at => "/admin/resque"
|
||||||
|
|
||||||
|
@ -151,8 +150,8 @@ Orbit::Application.routes.draw do
|
||||||
|
|
||||||
namespace :desktop do
|
namespace :desktop do
|
||||||
|
|
||||||
|
match '/journal_pages/get_journals_json' => 'journal_pages#get_journals_json' , via: :get
|
||||||
match "/" => "desktop#index"
|
match "/" => "desktop#index"
|
||||||
|
|
||||||
match '/desktop'=>'desktop#desktop'
|
match '/desktop'=>'desktop#desktop'
|
||||||
match '/app_manager'=>'desktop#app_manager'
|
match '/app_manager'=>'desktop#app_manager'
|
||||||
match '/sections'=>'desktop#sections'
|
match '/sections'=>'desktop#sections'
|
||||||
|
@ -167,16 +166,13 @@ Orbit::Application.routes.draw do
|
||||||
match '/newpositions/'=>'desktop#newpositions'
|
match '/newpositions/'=>'desktop#newpositions'
|
||||||
match '/connections/'=>'desktop#connections'
|
match '/connections/'=>'desktop#connections'
|
||||||
match '/widget_layout' => 'desktop#widget_layout'
|
match '/widget_layout' => 'desktop#widget_layout'
|
||||||
|
|
||||||
match '/temp_func/'=>'desktop#temp_func'
|
match '/temp_func/'=>'desktop#temp_func'
|
||||||
|
|
||||||
resources :journal_pages
|
resources :journal_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
# namespace :desktop_publications do
|
# namespace :desktop_publications do
|
||||||
match 'desktop_publications/journal_p'=>'desktop_publications#journal_p'
|
match 'desktop_publications/journal_p'=>'desktop_publications#journal_p'
|
||||||
# match 'desktop_publications/journal_p_list'=>'desktop_publications#journal_p_list'
|
|
||||||
# match 'desktop_publications/journal_p_add'=>'desktop_publications#journal_p_add'
|
|
||||||
# match 'desktop_publications/journal_p_create'=>'desktop_publications#journal_p_create' , :via => :post
|
|
||||||
match 'desktop_publications/books' => 'desktop_publications#books'
|
match 'desktop_publications/books' => 'desktop_publications#books'
|
||||||
match 'desktop_publications/books_list'=>'desktop_publications#books_list'
|
match 'desktop_publications/books_list'=>'desktop_publications#books_list'
|
||||||
match 'desktop_publications/books_add'=>'desktop_publications#books_add'
|
match 'desktop_publications/books_add'=>'desktop_publications#books_add'
|
||||||
|
@ -184,7 +180,6 @@ Orbit::Application.routes.draw do
|
||||||
match 'desktop_publications/seminar_p' => 'desktop_publications#seminar_p'
|
match 'desktop_publications/seminar_p' => 'desktop_publications#seminar_p'
|
||||||
match 'desktop_publications/seminar_p_list/'=>'desktop_publications#seminar_p_list'
|
match 'desktop_publications/seminar_p_list/'=>'desktop_publications#seminar_p_list'
|
||||||
match 'desktop_publications/seminar_p_add/'=>'desktop_publications#seminar_p_add'
|
match 'desktop_publications/seminar_p_add/'=>'desktop_publications#seminar_p_add'
|
||||||
match 'desktop_publications/getjournals' => 'desktop_publications#getjournals'
|
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# namespace :desktop_research do
|
# namespace :desktop_research do
|
||||||
|
|
|
@ -12,7 +12,7 @@ class WritingJournal
|
||||||
has_and_belongs_to_many :tags, :class_name => "PersonalJournalTag"
|
has_and_belongs_to_many :tags, :class_name => "PersonalJournalTag"
|
||||||
has_and_belongs_to_many :journal_author_types
|
has_and_belongs_to_many :journal_author_types
|
||||||
has_and_belongs_to_many :journal_level_types
|
has_and_belongs_to_many :journal_level_types
|
||||||
|
has_many :writing_journal_files, :autosave => true, :dependent => :destroy
|
||||||
belongs_to :journal_paper_type
|
belongs_to :journal_paper_type
|
||||||
|
|
||||||
field :year
|
field :year
|
||||||
|
@ -31,7 +31,6 @@ class WritingJournal
|
||||||
field :create_user_id, :type => BSON::ObjectId
|
field :create_user_id, :type => BSON::ObjectId
|
||||||
field :update_user_id, :type => BSON::ObjectId
|
field :update_user_id, :type => BSON::ObjectId
|
||||||
|
|
||||||
has_many :writing_journal_files, :autosave => true, :dependent => :destroy
|
|
||||||
|
|
||||||
accepts_nested_attributes_for :writing_journal_files, :allow_destroy => true
|
accepts_nested_attributes_for :writing_journal_files, :allow_destroy => true
|
||||||
after_save :save_writing_journal_files
|
after_save :save_writing_journal_files
|
||||||
|
|
Loading…
Reference in New Issue