Merge branch 'desktop_harry' of github.com:Rulingcom/orbit into desktop_harry

Conflicts:
	Gemfile.lock
	app/assets/javascripts/.DS_Store
	app/assets/stylesheets/style.css.erb
	app/views/layouts/_orbit_bar.html.erb
This commit is contained in:
Christophe Vilayphiou committed 2012-06-29 16:10:29 +08:00
commit a1e74987dc
389 files changed
+6931 -1

No files matched your search

@@ -0,0 +1,101 @@
class DesktopAppstoreController< ApplicationController
def appstore
render "desktop/appstore", :layout => false
end
def widgets
render "desktop/appstore/widgets", :layout => false
end
def onlinestore
render "desktop/appstore/onlinestore", :layout => false
end
def getuserwidgets
@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
render :json=>@widgets.to_json
end
def widgets_settings
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
render :json=>@msg.to_json
end
end
+186
View File
@@ -0,0 +1,186 @@
class DesktopController< ApplicationController
layout 'desktop'
before_filter :authenticate_user!
#to load pages...
def index
@desktop = current_user.desktop
@currentusername = current_user.name
@title = "Desktop - " + @currentusername
@section = @desktop.sections.first
end
def desktop
render :layout => false
end
def app_manager
render :layout => false
end
def sections
render :layout => false
end
def settings
render :layout => false
end
def settingthemes
@themes = DesktopTheme.all
# raise @themes.inspect
render "desktop/settings/themes", :layout => false
end
def settingsections
render "desktop/settings/sections", :layout => false
end
def settingconnection
render "desktop/settings/connections", :layout => false
end
#ajax data load....
def save_desktop_settings
@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"}
render :json=>a.to_json
end
def get_desktop_settings
@desktop = Desktop.find(params["desktopid"])
@getwhat = params["get"]
case @getwhat
when "desktop"
render :json => @desktop.to_json
when "sectionnames"
secnames = Array.new
@sections = @desktop.sections
@sections.each do |section|
secnames << section.name
end
render :json => secnames.to_json
when "theme"
@theme = @desktop.theme
render :json => @theme.to_json
end
end
def getgroups
@section = Section.find(params["sectionid"])
@groups = @section.groups
a = Array.new
@groups.each do |group|
a << group.tiles
end
render :json =>a.to_json
end
def getsectionlist
@desktop = Desktop.find(params["desktopid"])
@sections = @desktop.sections
render :json => @sections.to_json
end
def temp_func
@section = Section.find(params["sectionid"])
@groups = @section.groups
@groups.each do |group|
a = 1;
@tiles = group.tiles
@tiles.each do |tile|
tile.update_attributes({:data_category => "widget",:data_content => "temp", :position => a})
a = a+1;
end
end
b = Array.new
b << {"success"=>"true"}
render :json=>b.to_json
end
def getapplist
@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
render :json=>a.to_json
end
def newpositions
@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"}
render :json=>b.to_json
end
def forgmail
feed = Net::HTTP.get_response(URI.parse("https://mail.google.com/mail/feed/atom")).body
render :xml=>feed
end
end
@@ -0,0 +1,20 @@
class DesktopOrbitController< ApplicationController
def orbit
render "desktop/orbit", :layout => false
end
def getevents
@event = params["event"]
@data = Array.new
case @event
when "papers"
@journals = current_user.journals
@journals.each do |journal|
@data << {"title"=> journal.title,"papers"=> journal.papers}
end
end
render :json=>@data.to_json
end
end
@@ -0,0 +1,38 @@
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: "Google")
b = Array.new
b << {"success"=>"true"}
render :json=>b.to_json
end
def getjournals
@journals = current_user.journals
data = Array.new
@journals.each do |journal|
@papers = journal.papers.all
data << {"title" => journal.title, "papers" => @papers}
end
render :json=>data.to_json
end
def delete_journal
@journals = Journal.find("")
@journals.delete
b = Array.new
b << {"success"=>"true"}
render :json=>b.to_json
end
end
@@ -0,0 +1,78 @@
class OtheraccountsController< ApplicationController
require 'open-uri'
require 'rexml/document'
require 'net/http'
require 'net/https'
# require 'twitter'
include REXML
def saveaccountinfo
@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"}
render :json=>a.to_json
end
def gmail
@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
render :text=>root
else
msg = "<HEAD><ERROR>true</ERROR><ERRORMSG>Account setting problem.</ERRORMSG></HEAD>"
respond_to do |m|
m.xml {render :xml=>msg}
end
end
end
def twitter
# token = "Yh9qYe0lhWk27TZJamnhrA"
# secret = "iBgxJ5BrxfGFLkp7aB6pyCSzd0zcJiYDqJGFBK6Wdo"
# oauth = Twitter::OAuth.new(token,secret)
# oauth_token = oauth.request_token.token
# oauth_secret = oauth.request_token.secret
#require File.dirname(__FILE__)+"/../lib/contacts"
@gmailaccount = OtherAccount.where(:type.all => ["gmail"],:user_id.all => [current_user.id]) rescue nil
if @gmailaccount.first != nil
login = @gmailaccount.first.encrypted_password.decrypt
password = @gmailaccount.first.email
@contacts = Contacts::Gmail.new(login, password).contacts
render :json => @contacts.to_json
end
end
def getaccounts
@accounts = OtherAccount.where(:user_id.all => [current_user.id]).without(:encrypted_password)
render :json => @accounts.to_json
end
end