diff --git a/Gemfile b/Gemfile index 907187b2..1aa6c5df 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ gem 'rake' gem 'ruby-debug19' gem 'rubyzip' gem 'sinatra' +gem 'sinatra-contrib' gem 'sprockets' gem 'tinymce-rails' gem 'therubyracer' if RUBY_PLATFORM.downcase.include?("linux") diff --git a/Gemfile.lock b/Gemfile.lock index 339bae0f..3585cbc9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,7 @@ GEM multi_json (~> 1.0) archive-tar-minitar (0.5.2) arel (2.2.3) + backports (2.5.3) bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1-x86-mingw32) brakeman (1.5.1) @@ -79,6 +80,7 @@ GEM diff-lcs (1.1.3) encrypted_strings (0.3.3) erubis (2.7.0) + eventmachine (0.12.10) exception_notification (2.5.2) actionmailer (>= 3.0.4) execjs (1.3.0) @@ -206,6 +208,13 @@ GEM rack (~> 1.3, >= 1.3.6) rack-protection (~> 1.2) tilt (~> 1.3, >= 1.3.3) + sinatra-contrib (1.3.1) + backports (>= 2.0) + eventmachine + rack-protection + rack-test + sinatra (~> 1.3.0) + tilt (~> 1.3) spork (0.9.0) spork (0.9.0-x86-mingw32) win32-process @@ -273,8 +282,10 @@ DEPENDENCIES shoulda-matchers simplecov sinatra + sinatra-contrib spork sprockets tinymce-rails uglifier + warden watchr diff --git a/config/application.rb b/config/application.rb index cef8c446..b77655c7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -35,6 +35,7 @@ module Orbit config.autoload_paths += %W(#{config.root}/app/models/purchase) config.autoload_paths += %W(#{config.root}/app/models/user) + # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] diff --git a/config/routes.rb b/config/routes.rb index 10a73b21..97ddec52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -101,36 +101,71 @@ Orbit::Application.routes.draw do namespace :panel do resources :users end + match '/desktop/'=>'desktop#index' - match '/desktop/desktop'=>'desktop#desktop' - match '/desktop/app_manager'=>'desktop#app_manager' - match '/desktop/sections'=>'desktop#sections' - match '/desktop/settings'=>'desktop#settings' - match '/desktop/get_desktop_settings/'=>'desktop#get_desktop_settings' - match '/desktop/save_desktop_settings/'=>'desktop#save_desktop_settings' - match '/desktop/getgroups/'=>'desktop#getgroups' - match '/desktop/getsectionlist/'=>'desktop#getsectionlist' - match '/desktop/settingthemes/'=>'desktop#settingthemes' - match '/desktop/settingsections/'=>'desktop#settingsections' - match '/desktop/getapplist/'=>'desktop#getapplist' - match '/desktop/newpositions/'=>'desktop#newpositions' - match '/desktop/settingconnection/'=>'desktop#settingconnection' + + # Sinatra Routes start + + match '/desktop/desktop', :to => Desktopapp::DesktopApp + match '/desktop/app_manager', :to => Desktopapp::DesktopApp + match '/desktop/sections', :to => Desktopapp::DesktopApp + match '/desktop/settings', :to => Desktopapp::DesktopApp + match '/desktop/get_desktop_settings/', :to => Desktopapp::DesktopApp + match '/desktop/save_desktop_settings/', :to => Desktopapp::DesktopApp + match '/desktop/getgroups/', :to => Desktopapp::DesktopApp + match '/desktop/getsectionlist/', :to => Desktopapp::DesktopApp + match '/desktop/settingthemes/', :to => Desktopapp::DesktopApp + match '/desktop/settingsections/', :to => Desktopapp::DesktopApp + match '/desktop/getapplist/', :to => Desktopapp::DesktopApp + match '/desktop/newpositions/', :to => Desktopapp::DesktopApp + match '/desktop/settingconnection/', :to => Desktopapp::DesktopApp + + match '/desktop/journal_p/', :to => Desktopapp::DesktopAppPublications + match '/desktop/journal_p_list/', :to => Desktopapp::DesktopAppPublications + match '/desktop/journal_p_add/', :to => Desktopapp::DesktopAppPublications + match '/desktop_publications/getjournals', :to => Desktopapp::DesktopAppPublications + + # match '/desktop/twitter/', :to => Desktopapp::Otheraccounts + # match '/desktop/forgmail/', :to => Desktopapp::Otheraccounts + # match '/desktop/getaccounts', :to => Desktopapp::Otheraccounts + # match '/desktop/save_account_info/', :to => Desktopapp::Otheraccounts + + match '/desktop_appstore/appstore', :to => Desktopapp::DesktopAppAppstore + match '/desktop_appstore/widgets', :to => Desktopapp::DesktopAppAppstore + match '/desktop_appstore/getuserwidgets', :to => Desktopapp::DesktopAppAppstore + match '/desktop_appstore/widgets_settings', :to => Desktopapp::DesktopAppAppstore + + # Sinatra Routes end + + # match '/desktop/desktop'=>'desktop#desktop' + # match '/desktop/app_manager'=>'desktop#app_manager' + # match '/desktop/sections'=>'desktop#sections' + # match '/desktop/settings'=>'desktop#settings' + # match '/desktop/get_desktop_settings/'=>'desktop#get_desktop_settings' + # match '/desktop/save_desktop_settings/'=>'desktop#save_desktop_settings' + # match '/desktop/getgroups/'=>'desktop#getgroups' + # match '/desktop/getsectionlist/'=>'desktop#getsectionlist' + # match '/desktop/settingthemes/'=>'desktop#settingthemes' + # match '/desktop/settingsections/'=>'desktop#settingsections' + # match '/desktop/getapplist/'=>'desktop#getapplist' + # match '/desktop/newpositions/'=>'desktop#newpositions' + # 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/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/twitter/'=>'otheraccounts#twitter' match '/desktop/forgmail/'=>'otheraccounts#gmail' match '/desktop/getaccounts'=>'otheraccounts#getaccounts' match '/desktop/save_account_info/'=>'otheraccounts#saveaccountinfo' - match '/desktop_appstore/appstore'=>'desktop_appstore#appstore' - match '/desktop_appstore/widgets'=>'desktop_appstore#widgets' - match '/desktop_appstore/getuserwidgets'=>'desktop_appstore#getuserwidgets' - match '/desktop_appstore/widgets_settings'=>'desktop_appstore#widgets_settings' + # match '/desktop_appstore/appstore'=>'desktop_appstore#appstore' + # match '/desktop_appstore/widgets'=>'desktop_appstore#widgets' + # match '/desktop_appstore/getuserwidgets'=>'desktop_appstore#getuserwidgets' + # match '/desktop_appstore/widgets_settings'=>'desktop_appstore#widgets_settings' match '/desktop/temp_func/'=>'desktop#temp_func' diff --git a/lib/desktopapp/desktop_app.rb b/lib/desktopapp/desktop_app.rb new file mode 100644 index 00000000..c626849f --- /dev/null +++ b/lib/desktopapp/desktop_app.rb @@ -0,0 +1,148 @@ +class Desktopapp::DesktopApp < Sinatra::Base + + #set :views, settings.root+'/desktop/' + + get "/desktop/desktop" do + erb :desktop + end + + get "/desktop/app_manager" do + erb :app_manager + end + + get "/desktop/sections" do + erb :sections + end + + get "/desktop/settings" do + erb :settings + end + + post "/desktop/save_desktop_settings" do + @desktop = Desktop.find(params["desktopid"]) + @savewhat = params["save"] + case @savewhat + when "theme" + @desktop.update_attributes(:theme => params["theme"]) + @desktop.update_attributes(:wallpaper => nil) + when "desktopnames" + @sections = @desktop.sections + x = 0; + @sections.each do |section| + @desktopnewnames = params["desktopnms"] + section.update_attributes(:name => @desktopnewnames[x] ) + x = x+1 + end + when "appnewsection" + @section = Section.find(params["newsectionid"]) + @groups = @section.groups + @app = Tile.find(params["appid"]) + @groups.each do |group| + @tiles = group.tiles.where(:data_category.all => ["app"]) + if @tiles.length < 12 + @app.update_attributes(:group_id => group.id) + break + end + end + when "customtheme" + @desktop.update_attributes(:theme => "custom") + @desktop.update_attributes(:customtheme => params['theme']) + when "wallpaper" + @desktop.update_attributes(:wallpaper => params["wallpapernm"]) + end + a = Array.new + a << {"success"=>"true"} + a.to_json + end + + get "/desktop/get_desktop_settings" do + @desktop = Desktop.find(params["desktopid"]) + @getwhat = params["get"] + case @getwhat + when "desktop" + @desktop.to_json + when "sectionnames" + secnames = Array.new + @sections = @desktop.sections + @sections.each do |section| + secnames << section.name + end + secnames.to_json + when "theme" + @theme = @desktop.theme + @theme.to_json + end + end + + get "/desktop/getgroups" do + @section = Section.find(params["sectionid"]) + @groups = @section.groups + a = Array.new + @groups.each do |group| + a << group.tiles + end + a.to_json + end + + get "/desktop/getsectionlist" do + @desktop = Desktop.find(params["desktopid"]) + @sections = @desktop.sections + @sections.to_json + end + + get "/desktop/settingthemes" do + @themes = DesktopTheme.all + erb :'settings/themes' + end + + get "/desktop/settingsections" do + erb :'settings/sections' + end + + get "/desktop/getapplist" do + @desktop = Desktop.find(params["desktopid"]) + @sections = @desktop.sections + a = Array.new + @sections.each do |section| + @groups = section.groups + @groups.each do |group| + @tiles = group.tiles.where(:data_category.all => ["app"]) + a << @tiles + end + end + a.to_json + end + + post "/desktop/newpositions" do + @newpositions = params["newpos"] + @section = Section.find(params["sectionid"]) + @groupids = params["groupids"] + @groups = @section.groups + z = 0 + @newpositions.each do |grp| + x = 1 + grp.each do |tileid| + if x != 1 + y = 1 + tileid.each do |id| + @tile = Tile.find(id) + @tile.update_attributes({:position => y}) + if @tile.group_id != @groupids[z] + @tile.update_attributes({:group_id => @groupids[z]}) + end + y = y + 1 + end + z = z + 1 + end + x = x + 1 + end + end + b = Array.new + b << {"success"=>"true"} + b.to_json + end + + get "/desktop/settingconnection" do + erb :'settings/connections' + end +end \ No newline at end of file diff --git a/lib/desktopapp/desktop_app_appstore.rb b/lib/desktopapp/desktop_app_appstore.rb new file mode 100644 index 00000000..5e7f6b87 --- /dev/null +++ b/lib/desktopapp/desktop_app_appstore.rb @@ -0,0 +1,96 @@ +class Desktopapp::DesktopAppAppstore < Sinatra::Base + register Sinatra::Warden + get '/desktop_appstore/appstore' do + erb :appstore + end + + get '/desktop_appstore/widgets' do + erb :'appstore/widgets' + end + + get '/desktop_appstore/getuserwidgets' do + # @widgets = current_user.desktop.desktop_widgets + # @groups = Array.new + # @sections = current_user.desktop.sections + + # @sections.each do |section| + # @groups << section.groups + # end + + # @widgets.each do |widget| + # @count = 0; + # @sectionids = Array.new + # @groups.each do |group| + # group.each do |grp| + # @widge = 0 + # @gid = widget.id.to_s + # @widge = grp.tiles.where(:data_content.all => [@gid]).count + # @count = @count + @widge + # if @widge > 0 + # @sectionids << grp.section_id + # end + # end + # end + # if @count > 0 + # widget.status = "Installed" + # widget.section = @sectionids + # else + # widget.status = "Downloaded" + # end + # end + # @widgets.to_json + current_user.to_json + end + + get '/desktop_appstore/widgets_settings' do + what = params["what"] + @widgetid = params["widget"] + @sectionid = params["section"] + @msg = Array.new + case what + when "remove" + @section = Section.find(@sectionid) + @groups = @section.groups + @groups.each do |group| + @tile = group.tiles.where(:data_content.all => [@widgetid]) + if @tile.count > 0 + @thistile = @tile + end + end + @t = Tile.find(@thistile.first.id) + @t.delete + @msg << {"success"=>true} + when "add" + @widget = current_user.desktop.desktop_widgets.find(@widgetid) + @section = Section.find(@sectionid) + @groups = @section.groups + @totalwidgets = 0 + @groups.each do |group| + @tile = group.tiles.where(:data_content.all => [@widgetid]).count + if @tile > 0 + @msg << {"success"=>false,"error"=>"Duplicate widget"} + else + no_of_widgets = group.tiles.where(:data_category.all => ["widget"]).count + @totalwidgets = @totalwidgets + no_of_widgets + end + end + if @totalwidgets >= 12 + @msg << {"success"=>false,"error"=>"Section full"} + else + wshape = @widget.shape + wdata_content = @widgetid + wdata_category = "widget" + wname = @widget.name + if @groups.first.tiles.where(:data_category.all => ["widget"]).count >= 6 + groupid = @groups.last.id + else + groupid = @groups.first.id + end + Tile.create(data_category: wdata_category,data_content: wdata_content, group_id: groupid, position: 10, title: wname, shape: wshape) + @msg << {"success"=>true} + end + end + @msg.to_json + end + +end \ No newline at end of file diff --git a/lib/desktopapp/desktop_app_publications.rb b/lib/desktopapp/desktop_app_publications.rb new file mode 100644 index 00000000..e88d78fa --- /dev/null +++ b/lib/desktopapp/desktop_app_publications.rb @@ -0,0 +1,25 @@ +class Desktopapp::DesktopAppPublications < Sinatra::Base + + get "/desktop/journal_p" do + erb :journal_p + end + + get "/desktop/journal_p_list" do + erb :'journal_pages/list' + end + + get '/desktop/journal_p_add' do + erb :'journal_pages/add' + end + + get '/desktop_publications/getjournals' do + @journals = Journal.all + data = Array.new + @journals.each do |journal| + @papers = journal.papers.all + data << {"title" => journal.title, "papers" => @papers} + end + data.to_json + end + +end \ No newline at end of file diff --git a/lib/desktopapp/otheraccounts.rb b/lib/desktopapp/otheraccounts.rb new file mode 100644 index 00000000..65a24a18 --- /dev/null +++ b/lib/desktopapp/otheraccounts.rb @@ -0,0 +1,61 @@ +class Desktopapp::Otheraccounts < Sinatra::Base + require 'open-uri' + require 'rexml/document' + require 'net/http' + require 'net/https' + # require 'twitter' + include REXML + + + get '/desktop/save_account_info' do + @dowhat = params['dowhat'] + @email = params['email'] + @password = params['password'] + @account = params['account'] + case @dowhat + when "new" + OtherAccount.create(user_id: current_user.id, email: @email, encrypted_password: @password, type: @account) + when "edit" + @otheraccount = OtherAccount.where(:type.all => [@account],:user_id.all => [current_user.id]) rescue nil + @otheraccount.first.update_attributes(:email => @email, :encrypted_password => @password) + when "delete" + @otheraccount = OtherAccount.where(:type.all => [@account], :user_id.all => [current_user.id]) rescue nil + @otheraccount.destroy_all + end + a = Array.new + a << {"success"=>"true"} + a.to_json + end + + get '/desktop/forgmail' do + @gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id]) rescue nil + + # if @gmailaccount.first != nil + # @decrypted_password = @gmailaccount.first.encrypted_password.decrypt + # @email = @gmailaccount.first.email + # url = URI.parse("https://mail.google.com/mail/feed/atom") + # #url = URI.parse("https://www.google.com/m8/feeds/contacts/default/full") + # req = Net::HTTP::Get.new(url.path) + # req.basic_auth @email, @decrypted_password + # req.content_type = 'text/xml' + + # http = Net::HTTP.new(url.host, url.port) + # http.use_ssl = true + # response = http.start { |http| http.request(req) } + + # root = Document.new(response.read_body).root + # root + # else + # msg = "trueAccount setting problem." + # # respond_to do |m| + # # m.xml {render :xml=>msg} + # # end + # msg.to_xml + # end + end + + get '/desktop/getaccounts' do + @accounts = OtherAccount.where(:user_id.all => [current_user.id]).without(:encrypted_password) + @accounts.to_json + end +end \ No newline at end of file diff --git a/lib/desktopapp/views/app_manager.erb b/lib/desktopapp/views/app_manager.erb new file mode 100755 index 00000000..b6a54fe3 --- /dev/null +++ b/lib/desktopapp/views/app_manager.erb @@ -0,0 +1,36 @@ +
+
+ +
+ +
+
+
+
+
+
+ + + +
+
+
+
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/app_view1.html.erb b/lib/desktopapp/views/app_view1.html.erb new file mode 100644 index 00000000..795c9ab0 --- /dev/null +++ b/lib/desktopapp/views/app_view1.html.erb @@ -0,0 +1,12 @@ +
+
+ +
+ +
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/appstore.erb b/lib/desktopapp/views/appstore.erb new file mode 100644 index 00000000..c92ac427 --- /dev/null +++ b/lib/desktopapp/views/appstore.erb @@ -0,0 +1,26 @@ +
+
+ +
+ + +
+ +
+
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/appstore/widgets.erb b/lib/desktopapp/views/appstore/widgets.erb new file mode 100644 index 00000000..4fd150c4 --- /dev/null +++ b/lib/desktopapp/views/appstore/widgets.erb @@ -0,0 +1,11 @@ +
Your Widgets
+
+
+
+
+
+ +
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/desktop.erb b/lib/desktopapp/views/desktop.erb new file mode 100755 index 00000000..93827506 --- /dev/null +++ b/lib/desktopapp/views/desktop.erb @@ -0,0 +1,30 @@ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/index.html.erb b/lib/desktopapp/views/index.html.erb new file mode 100755 index 00000000..98ac23e3 --- /dev/null +++ b/lib/desktopapp/views/index.html.erb @@ -0,0 +1,100 @@ +
+
+ +
+
+
+
+ +
+ + +
+
+ + + +
+ + + diff --git a/lib/desktopapp/views/journal_p.erb b/lib/desktopapp/views/journal_p.erb new file mode 100644 index 00000000..6dddb734 --- /dev/null +++ b/lib/desktopapp/views/journal_p.erb @@ -0,0 +1,33 @@ +
+
+ +
+ +
+
+
+
+
+
+ \ No newline at end of file diff --git a/lib/desktopapp/views/journal_pages/add.erb b/lib/desktopapp/views/journal_pages/add.erb new file mode 100644 index 00000000..324432b6 --- /dev/null +++ b/lib/desktopapp/views/journal_pages/add.erb @@ -0,0 +1,109 @@ +
+
+ + +
+
+
Entry Year
+
+ +
+
+
+
Language
+
+ +
+
+
+
Share
+
+ +
+
+
+
+
+
+
+
+
+
+
+
    +
  • +
  • +
  • +
    + +
      +
    • +
    • +
    • +
    • +
    • +
    • +
    • +
    • +
    • +
    • +
    +
    +
  • +
  • +
  • +
  • +
  • +
  • +
  • +
+
+
+
    +
  • +
  • + + +
  • +
  • +
  • +
  • +
  • +
  • +
+
+
+
    +
  • +
+
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/journal_pages/list.erb b/lib/desktopapp/views/journal_pages/list.erb new file mode 100644 index 00000000..e32e4d6c --- /dev/null +++ b/lib/desktopapp/views/journal_pages/list.erb @@ -0,0 +1,75 @@ +
+
+
+
+ +
+
+
+
More
+
+ +
+
+
+
Tag
+
+ +
+
+
+
Status
+
+ +
+
+
+
View
+
+ +
+
+
+
Share
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/sections.erb b/lib/desktopapp/views/sections.erb new file mode 100644 index 00000000..d8e8208e --- /dev/null +++ b/lib/desktopapp/views/sections.erb @@ -0,0 +1,178 @@ +
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/settings.erb b/lib/desktopapp/views/settings.erb new file mode 100644 index 00000000..8b7ad2d1 --- /dev/null +++ b/lib/desktopapp/views/settings.erb @@ -0,0 +1,27 @@ +
+
+ +
+ +
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/settings/connections.erb b/lib/desktopapp/views/settings/connections.erb new file mode 100644 index 00000000..148762da --- /dev/null +++ b/lib/desktopapp/views/settings/connections.erb @@ -0,0 +1,44 @@ +
+
+
+
+
    +
  • No Connection
  • +
  • Facebook

  • +
  • +
  • +
  • +
    + Connect + +
    +
  • +
+
    +
  • No Connection
  • +
  • Twitter

  • +
  • +
  • +
  • +
    + Connect + +
    +
  • +
+
    +
  • No Connection
  • +
  • Gmail

  • +
  • +
  • +
  • +
    + Connect + +
    +
  • +
+
+ +
+
diff --git a/lib/desktopapp/views/settings/sections.erb b/lib/desktopapp/views/settings/sections.erb new file mode 100644 index 00000000..dcb92237 --- /dev/null +++ b/lib/desktopapp/views/settings/sections.erb @@ -0,0 +1,18 @@ +
+
+
+
+
Section Names
+
    +
  • +
  • +
  • +
  • +
+
sample desciption
+
+ Confirm +
+
+
+
\ No newline at end of file diff --git a/lib/desktopapp/views/settings/themes.erb b/lib/desktopapp/views/settings/themes.erb new file mode 100644 index 00000000..6a3c34f8 --- /dev/null +++ b/lib/desktopapp/views/settings/themes.erb @@ -0,0 +1,86 @@ +
+ +
+
+
+
+
+
+
+ <% @themes.each do |theme| %> +
<%= theme.name %>
+ <% end %> +
+
+ + +
+
Preview
+
+
Theme Text1
+
+
+
Theme Text2
+
+
Theme Text
+
+
+
+ + + + + + + + + + + + + +
Theme ColorLine ColorText ColorBackground Color
+ + + + + + + + + + +
+
+ Confirm +
+
+
+
+
+
+
1.jpg
+
2.jpg
+
3.jpg
+
4.jpg
+
5.jpg
+
6.jpg
+
7.jpg
+
8.jpg
+
9.jpg
+
10.jpg
+
11.jpg
+
12.jpg
+
+ +
+
+
+
+
\ No newline at end of file