From a3a1e4b92e7742473f3f58f6808e5e91b80b3784 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 3 May 2012 21:30:12 +0800 Subject: [PATCH] controller change, views working and db for paper and journals --- app/assets/javascripts/orbitdesktop.js | 156 ++++++++++++++++-- app/controllers/desktop_controller.rb | 12 +- .../desktop_publications_controller.rb | 30 ++++ app/controllers/otheraccounts_controller.rb | 6 +- app/models/desktop.rb | 2 +- app/models/journal.rb | 19 +++ app/models/paper.rb | 14 ++ app/models/user/user.rb | 1 + app/views/desktop/journal_p.html.erb | 36 ++-- app/views/desktop/journal_pages/list.html.erb | 85 ++-------- config/routes.rb | 10 +- 11 files changed, 248 insertions(+), 123 deletions(-) create mode 100644 app/controllers/desktop_publications_controller.rb create mode 100644 app/models/journal.rb create mode 100644 app/models/paper.rb diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 8ad2694d..b4b3ce23 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -794,9 +794,8 @@ var orbitDesktop = function(dom){ saveaccount("","",type,what); } }) - break; + break; } - }) var $conlist = $('.s_form'), @@ -812,19 +811,19 @@ var orbitDesktop = function(dom){ } var saveaccount = function(usernm,pwd,type,what){ - $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:type,dowhat:what},function(result){ - if(what!="delete"){ - if(result[0].success=="true") - o.notify(type+" account connected!!","success",2); - else - o.notify(type+" account connection failed!!","imp",2); - }else{ - if(result[0].success=="true") - o.notify(type+" account removed!!","success",2); - else - o.notify(type+" account removal failed!!","imp",2); - } - }) + $.post("/desktop/save_account_info",{email:usernm,password:pwd,account:type,dowhat:what},function(result){ + if(what!="delete"){ + if(result[0].success=="true") + o.notify(type+" account connected!!","success",2); + else + o.notify(type+" account connection failed!!","imp",2); + }else{ + if(result[0].success=="true") + o.notify(type+" account removed!!","success",2); + else + o.notify(type+" account removal failed!!","imp",2); + } + }) } $("div#settings div#panel_r").load("/desktop/settingconnection",function(){ $.getJSON("desktop/getaccounts",function(accounts){ @@ -882,6 +881,7 @@ var orbitDesktop = function(dom){ } var list = function(){ // to open list part in journal papers page + var journalData; var bindHandlers = function(){ // to bind handlers for list page o.simple_drop_down(); @@ -892,16 +892,138 @@ var orbitDesktop = function(dom){ e.parents('.overview').width( baseWidth * count ); - $('.tinycanvas') .tinyscrollbar({ axis: 'x'}) .find('.scrollbar') .delay(1500) .addClass('op00', 500); + + + $("#journal_p div.toolbar ul#journal_selection_options a").click(function(){ + switch($(this).attr("href")){ + case "all": + $("#journal_p div#paper_list a.item_check_status").addClass("checked"); + break; + case "none": + $("#journal_p div#paper_list a.item_check_status").removeClass("checked"); + break; + } + return false; + }) + $("#journal_p div.toolbar ul#journal_view_selection a").click(function(){ + switch($(this).attr("href")){ + case "journal": + journalview(); + break; + case "keywords": + keywordsview(); + break; + case "title": + titleview(); + break; + case "abstract": + abstractview(); + break; + } + return false; + }) + } + + var bindSecondaryHandlers = function(){ + $("#journal_p div#paper_list a").click(function(){ + if($(this).hasClass("item_check_status")){ + $(this).toggleClass("checked"); + }else if($(this).hasClass("icon-star")){ + $(this).removeClass("icon-star").addClass("icon-star-empty"); + }else if($(this).hasClass("icon-star-empty")){ + $(this).removeClass("icon-star-empty").addClass("icon-star"); + } + return false; + }) + } + + var journalview = function(){ + $("#journal_p div#paper_list div.overview").empty(); + var column = $('
'), + counter = 1, + li; + $.each(journalData,function(i,journal){ + $.each(journal.papers,function(j,paper){ + li = $('
  • '+journal.title+'
    '+paper.title+'
  • '); + column.find("ul").append(li); + if(counter%5==0){ + $("#journal_p div#paper_list div.overview").append(column); + column = $('
    '); + } + counter++; + }) + }) + $("#journal_p div#paper_list div.overview").append(column); + bindSecondaryHandlers(); + } + + var keywordsview = function(){ + $("#journal_p div#paper_list div.overview").empty(); + var column = $('
    '), + counter = 1, + li; + $.each(journalData,function(i,journal){ + $.each(journal.papers,function(j,paper){ + li = $('
  • '+paper.title+'
    '+paper.keywords+'
  • '); + column.find("ul").append(li); + if(counter%5==0){ + $("#journal_p div#paper_list div.overview").append(column); + column = $('
    '); + } + counter++; + }) + }) + $("#journal_p div#paper_list div.overview").append(column); + bindSecondaryHandlers(); + } + + var titleview = function(){ + $("#journal_p div#paper_list div.overview").empty(); + var column = $('
    '), + counter = 1, + li; + $.each(journalData,function(i,journal){ + $.each(journal.papers,function(j,paper){ + li = $('
  • '+paper.title+'
  • '); + column.find("ul").append(li); + if(counter%5==0){ + $("#journal_p div#paper_list div.overview").append(column); + column = $('
    '); + } + counter++; + }) + }) + $("#journal_p div#paper_list div.overview").append(column); + bindSecondaryHandlers(); + } + + var abstractview = function(){ + $("#journal_p div#paper_list div.overview").empty(); + var column = $('
    '), + li; + $.each(journalData,function(i,journal){ + $.each(journal.papers,function(j,paper){ + li = $('
  • '+paper.title+'
    '+paper.abstract+paper.abstract+'
  • '); + column.find("ul").append(li); + $("#journal_p div#paper_list div.overview").append(column); + column = $('
    '); + }) + }) + $("#journal_p div#paper_list div.overview").append(column); + bindSecondaryHandlers(); } $("div#settings div#panel_r").load("/desktop/journal_p_list",function(){ - bindHandlers(); + $.getJSON("/desktop_publications/getjournals",function(journals){ + journalData = eval(journals); + journalview(); + bindHandlers(); + }) }) } diff --git a/app/controllers/desktop_controller.rb b/app/controllers/desktop_controller.rb index 0123aa87..93816d71 100644 --- a/app/controllers/desktop_controller.rb +++ b/app/controllers/desktop_controller.rb @@ -42,17 +42,7 @@ class DesktopController< ApplicationController render "desktop/settings/connections", :layout => false end - def journal_p - render :layout => false - end - - def journal_p_list - render "desktop/journal_pages/list", :layout => false - end - - def journal_p_add - render "desktop/journal_pages/add", :layout => false - end + #ajax data load.... def save_desktop_settings diff --git a/app/controllers/desktop_publications_controller.rb b/app/controllers/desktop_publications_controller.rb new file mode 100644 index 00000000..ed93c48c --- /dev/null +++ b/app/controllers/desktop_publications_controller.rb @@ -0,0 +1,30 @@ +class DesktopPublicationsController< ApplicationController + def journal_p + render "desktop/journal_p", :layout => false + end + + def journal_p_list + render "desktop/journal_pages/list", :layout => false + end + + def journal_p_add + render "desktop/journal_pages/add", :layout => false + end + + def create_journal + Journal.create(user_id: current_user.id, title: "2012, Material Chemistry and Physics Journal") + b = Array.new + b << {"success"=>"true"} + render :json=>b.to_json + end + + def getjournals + @journals = Journal.all + data = Array.new + @journals.each do |journal| + @papers = journal.papers.all + data << {"title" => journal.title, "papers" => @papers} + end + render :json=>data.to_json + end +end diff --git a/app/controllers/otheraccounts_controller.rb b/app/controllers/otheraccounts_controller.rb index 65a9b5a4..0abc14a2 100644 --- a/app/controllers/otheraccounts_controller.rb +++ b/app/controllers/otheraccounts_controller.rb @@ -49,8 +49,12 @@ class OtheraccountsController< ApplicationController end end + def twitter + + end + def getaccounts - @accounts = OtherAccount.where(:user_id.all => [current_user.id]) + @accounts = OtherAccount.where(:user_id.all => [current_user.id]).without(:encrypted_password) render :json => @accounts.to_json end end \ No newline at end of file diff --git a/app/models/desktop.rb b/app/models/desktop.rb index 2b3aa402..e2918adc 100644 --- a/app/models/desktop.rb +++ b/app/models/desktop.rb @@ -2,7 +2,7 @@ class Desktop include Mongoid::Document include Mongoid::Timestamps - field :theme, default: "default" + field :theme, default: "4f8d3f493b67fcd05f086359" field :customtheme field :wallpaper diff --git a/app/models/journal.rb b/app/models/journal.rb new file mode 100644 index 00000000..4b4cb8df --- /dev/null +++ b/app/models/journal.rb @@ -0,0 +1,19 @@ +class Journal + include Mongoid::Document + include Mongoid::Timestamps + + field :user_id + field :title + + belongs_to :user + has_many :papers, :autosave => true, :dependent => :destroy + + before_create :initialize_paper + + def initialize_paper + for i in 0..25 + self.papers.build + end + end + +end diff --git a/app/models/paper.rb b/app/models/paper.rb new file mode 100644 index 00000000..5e248a1d --- /dev/null +++ b/app/models/paper.rb @@ -0,0 +1,14 @@ +class Paper + include Mongoid::Document + include Mongoid::Timestamps + + field :keywords, default: "Material, Fracture Mechanism, Reliability Test, Solder Joints, Nano-material" + field :title, default: "The performance and fracture mechanism of solder joints under mechanical reliability test" + field :abstract, default: "The concept of microstructure engineering has gained increasingly attention with the goal to quantitatively link the operational parameters of an industrial process to the properties of its product. The key component of this concept is to accurately model the microstructure evolution along the processing path. Modelling of recrystallization in Cuinterconnects will be presented as an example of a conventional process model. Further, the potential of developing next generation process models will be discussed by using models across different length and time scale. The multi-scale modelling approach will be illustrated with a case study for phase transformation in Fe-Mn alloys." + field :level, default: "SCI" + field :coauthors, default: "Allen, Shelly, Eric, Manson, Chris, Clara, Anna, Albee, Vincent, Devin, Chunchi, Ika, Jaoshua, Ray, Matt, Lin, Spen" + + belongs_to :journal + + + end \ No newline at end of file diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 2b405e16..d09e563e 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -18,6 +18,7 @@ class User has_many :managing_apps,:class_name => "AppManager" has_one :desktop, :autosave => true, :dependent => :destroy has_many :other_accounts, :autosave => true, :dependent => :destroy + has_many :journals, :autosave => true, :dependent => :destroy belongs_to :role has_and_belongs_to_many :sub_roles accepts_nested_attributes_for :attribute_values, :allow_destroy => true diff --git a/app/views/desktop/journal_p.html.erb b/app/views/desktop/journal_p.html.erb index 209e3cbd..d3faa4c7 100644 --- a/app/views/desktop/journal_p.html.erb +++ b/app/views/desktop/journal_p.html.erb @@ -7,25 +7,23 @@
    - - -
    - -
    -
    + +
    +
    +
    diff --git a/app/views/desktop/journal_pages/list.html.erb b/app/views/desktop/journal_pages/list.html.erb index 432784e1..254bc393 100644 --- a/app/views/desktop/journal_pages/list.html.erb +++ b/app/views/desktop/journal_pages/list.html.erb @@ -2,16 +2,16 @@
    -
    More
    -
      + @@ -20,7 +20,7 @@
      Tag
      -
        +
          All
        • Starred
        • MIT
        • @@ -30,7 +30,7 @@
          Status
          -
            +
            • All
            • Published
            • Pending
            • @@ -40,19 +40,19 @@
              Share
              -
                +
                • Full
                • Abstract
                • Friends
                • @@ -66,64 +66,7 @@
                  -
                  -
                    -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  -
                  -
                  -
                    -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  • -
                    -
                    2012, Material Chemistry and Physics Journal
                    -
                    The performance and fracture mechanism of solder joints under mechanical reliability test
                    -
                  • -
                  -
                  +
              \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9dfe9218..99bf251d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -114,10 +114,14 @@ Orbit::Application.routes.draw do match '/desktop/settingsections/'=>'desktop#settingsections' match '/desktop/getapplist/'=>'desktop#getapplist' match '/desktop/newpositions/'=>'desktop#newpositions' - match '/desktop/journal_p/'=>'desktop#journal_p' - match '/desktop/journal_p_list/'=>'desktop#journal_p_list' - match '/desktop/journal_p_add/'=>'desktop#journal_p_add' match '/desktop/settingconnection/'=>'desktop#settingconnection' + + match '/desktop/journal_p/'=>'desktop_publications#journal_p' + match '/desktop/journal_p_list/'=>'desktop_publications#journal_p_list' + match '/desktop/journal_p_add/'=>'desktop_publications#journal_p_add' + match '/desktop_publications/getjournals' => 'desktop_publications#getjournals' + + match '/desktop/forgmail/'=>'otheraccounts#gmail' match '/desktop/getaccounts'=>'otheraccounts#getaccounts' match '/desktop/save_account_info/'=>'otheraccounts#saveaccountinfo'