diff --git a/app/controllers/desktop_widgets_controller.rb b/app/controllers/desktop_widgets_controller.rb new file mode 100644 index 00000000..6807082c --- /dev/null +++ b/app/controllers/desktop_widgets_controller.rb @@ -0,0 +1,61 @@ +class DesktopWidgetsController < OrbitBackendController + require "net/http" + require "uri" + require 'zip/zip' + + def index + end + + def upload + if !params[:desktop_widget].nil? + temp_file = Tempfile.new("temp_file") + original_file = params[:desktop_widget][:package_file] + #if original_file.content_type == 'application/zip' + temp_file.write(original_file.read.force_encoding('UTF-8')) + temp_file.rewind + filename = File.basename(original_file.original_filename,".zip") + unzip_widget(temp_file, filename) + #else + # flash[:error] = "Upload file should be in zip format" + #end + temp_file.close + end + end + + def unzip_widget(file, zip_name) + Zip::ZipFile.open(file) { |zip_file| + dw = DesktopWidget.new.from_json(zip_file.read("#{zip_name}/settings.json")) + Dir.mktmpdir('f_path') { |dir| + javascripts_entries = [] + images_entries = [] + + zip_file.entries.each do |entry| + case (path = entry.to_s) + when /\A(#{zip_name})\/(default\.css)\z/ #for default css + dw.build_css_default(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(widget\.html)\z/ #for layout html + dw.build_widget_layout(:file => get_temp_file(zip_file, dir, entry)) + when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js + javascripts_entries << entry + when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img + images_entries << entry + end + end + + ['javascripts', 'images'].each do |type| + eval("#{type}_entries").each do |entry| + eval("dw.#{type}").build(:file => get_temp_file(zip_file, dir, entry)) + end + end + } + dw.save + } + end + def get_temp_file(zip_file, dir, entry) + filename = File.basename(entry.to_s) + temp_file = File.new(dir + '/' + filename, 'w+') + temp_file.write (zip_file.read entry ).force_encoding('UTF-8') + temp_file + end + +end \ No newline at end of file diff --git a/app/controllers/otheraccounts_controller.rb b/app/controllers/otheraccounts_controller.rb index 454f108e..d946bd3c 100644 --- a/app/controllers/otheraccounts_controller.rb +++ b/app/controllers/otheraccounts_controller.rb @@ -1,4 +1,4 @@ -class OtheraccountsController< ApplicationController +class Desktop::OtheraccountsController< ApplicationController require 'open-uri' require 'rexml/document' require 'net/http' diff --git a/app/models/design/css_default.rb b/app/models/design/css_default.rb index 3ee5a58c..9b2b17fc 100644 --- a/app/models/design/css_default.rb +++ b/app/models/design/css_default.rb @@ -1,5 +1,6 @@ class CssDefault < Stylesheet belongs_to :design + belongs_to :desktop_widget end diff --git a/app/models/design/image.rb b/app/models/design/image.rb index 91c4a733..355f66f7 100644 --- a/app/models/design/image.rb +++ b/app/models/design/image.rb @@ -11,6 +11,7 @@ class Image mount_uploader :file, ImageUploader belongs_to :design + belongs_to :desktop_widget before_save :set_name diff --git a/app/models/design/javascript.rb b/app/models/design/javascript.rb index 439e3b98..4d13d0a3 100644 --- a/app/models/design/javascript.rb +++ b/app/models/design/javascript.rb @@ -1,3 +1,4 @@ class Javascript < DesignFile belongs_to :design + belongs_to :desktop_widget end diff --git a/app/models/design/stylesheet.rb b/app/models/design/stylesheet.rb index 525e40f3..47c13585 100644 --- a/app/models/design/stylesheet.rb +++ b/app/models/design/stylesheet.rb @@ -1,5 +1,6 @@ class Stylesheet < DesignFile belongs_to :design + belongs_to :desktop_widget mount_uploader :file_orig, AssetUploader def parse_urls @@ -32,5 +33,35 @@ class Stylesheet < DesignFile self.save } end + def parse_widgets_urls + orig_content = content = self.file.read.force_encoding("UTF-8") + # self.remove_file! + # self.remove_file_orig! + names = [] + images = self.desktop_widget.images + content.scan(/(?<=url)(.*?)(?=\))/){ + css_name = $1.gsub(' ','').gsub('(','') + name = File.basename(css_name).gsub(/[\\\"]/, '') + image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil + image.update_attribute(:in_css, true) if image + file_name = image.file_url rescue nil + names << [css_name, file_name] + } + names.each do |name| + content.gsub!(name[0], name[1]) if name[1] + end + Dir.mktmpdir('f_path') { |dir| + orig_file_name = self.file_identifier + + temp_file = File.new(dir + '/' + orig_file_name, 'w+') + temp_file.write orig_content.force_encoding("UTF-8") + self.file_orig = temp_file + + temp_file = File.new(dir + '/' + orig_file_name, 'w+') + temp_file.write content.force_encoding("UTF-8") + self.file = temp_file + self.save + } + end end diff --git a/app/models/desktop.rb b/app/models/desktop/desktop.rb similarity index 86% rename from app/models/desktop.rb rename to app/models/desktop/desktop.rb index e8c1e9c4..20a6e577 100644 --- a/app/models/desktop.rb +++ b/app/models/desktop/desktop.rb @@ -9,7 +9,7 @@ class Desktop belongs_to :user has_many :sections, :autosave => true, :dependent => :destroy - has_many :desktop_widgets, :autosave => true, :dependent => :destroy + # has_many :desktop_widgets, :autosave => true, :dependent => :destroy before_create :initialize_section diff --git a/app/models/desktop_theme.rb b/app/models/desktop/desktop_theme.rb similarity index 100% rename from app/models/desktop_theme.rb rename to app/models/desktop/desktop_theme.rb diff --git a/app/models/desktop/desktop_widget.rb b/app/models/desktop/desktop_widget.rb new file mode 100644 index 00000000..20eda85a --- /dev/null +++ b/app/models/desktop/desktop_widget.rb @@ -0,0 +1,31 @@ +class DesktopWidget + include Mongoid::Document + include Mongoid::Timestamps + include ParserLayoutWidget + + field :name + field :author + field :shape + field :version, :type => String + + has_one :css_default, :autosave => true, :dependent => :destroy + has_one :widget_layout, :autosave => true, :dependent => :destroy + has_many :images, :autosave => true, :dependent => :destroy + has_many :javascripts, :autosave => true, :dependent => :destroy + + accepts_nested_attributes_for :images, :allow_destroy => true + accepts_nested_attributes_for :javascripts, :allow_destroy => true + + after_save :parse_css_for_images + + # belongs_to :desktop + + + protected + + def parse_css_for_images + self.css_default.parse_widgets_urls + parse_widget_for_images(self) + end + +end \ No newline at end of file diff --git a/app/models/group.rb b/app/models/desktop/group.rb similarity index 100% rename from app/models/group.rb rename to app/models/desktop/group.rb diff --git a/app/models/other_account.rb b/app/models/desktop/other_account.rb similarity index 100% rename from app/models/other_account.rb rename to app/models/desktop/other_account.rb diff --git a/app/models/section.rb b/app/models/desktop/section.rb similarity index 100% rename from app/models/section.rb rename to app/models/desktop/section.rb diff --git a/app/models/tile.rb b/app/models/desktop/tile.rb similarity index 97% rename from app/models/tile.rb rename to app/models/desktop/tile.rb index 70066d1b..306338a1 100644 --- a/app/models/tile.rb +++ b/app/models/desktop/tile.rb @@ -9,6 +9,5 @@ class Tile field :title belongs_to :group - - + end diff --git a/app/models/desktop/widget_layout.rb b/app/models/desktop/widget_layout.rb new file mode 100644 index 00000000..25389682 --- /dev/null +++ b/app/models/desktop/widget_layout.rb @@ -0,0 +1,18 @@ +class WidgetLayout < DesignFile + + attr_reader :content + + field :body + + belongs_to :desktop_widget + + + def content + self.file.read.force_encoding("UTF-8") rescue '' + end + + def self.exist_one? + WidgetLayout.count > 0 + end + +end diff --git a/app/models/desktop_widget.rb b/app/models/desktop_widget.rb deleted file mode 100644 index eb0446de..00000000 --- a/app/models/desktop_widget.rb +++ /dev/null @@ -1,13 +0,0 @@ -class DesktopWidget - include Mongoid::Document - include Mongoid::Timestamps - - field :name - field :author - field :shape - field :desktop_id - field :status - field :section - - belongs_to :desktop -end \ No newline at end of file diff --git a/app/views/desktop_widgets/upload.html.erb b/app/views/desktop_widgets/upload.html.erb new file mode 100644 index 00000000..19d3ff1a --- /dev/null +++ b/app/views/desktop_widgets/upload.html.erb @@ -0,0 +1,12 @@ +

Upload Widget Package

+
+ <%= form_tag '',:multipart => true,:action=>"post" do |f| %> + +

+ <%= file_field :desktop_widget,:package_file %> +

+ <%= submit_tag %> + + <% end %> + +
\ No newline at end of file diff --git a/config/application.rb b/config/application.rb index ccc4a65e..f0e40fcc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -33,6 +33,7 @@ module Orbit config.autoload_paths += %W(#{config.root}/app/models/meta) config.autoload_paths += %W(#{config.root}/app/models/purchase) config.autoload_paths += %W(#{config.root}/app/models/user) + config.autoload_paths += %W(#{config.root}/app/models/desktop) # Include all helpers # 'helper :all' must be removed in ApplicationController diff --git a/config/routes.rb b/config/routes.rb index 88a39f42..17e96a60 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,7 +143,17 @@ Orbit::Application.routes.draw do resources :users end - match '/desktop/'=>'desktop#index' + resources :desktop_widgets do + collection do + get 'upload' + get 'delete' + post 'upload' + end + end + +namespace :desktop do + + match "/"=>"desktop#index" # Sinatra Routes start @@ -178,46 +188,46 @@ Orbit::Application.routes.draw do # 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'=>'desktop#desktop' + match '/app_manager'=>'desktop#app_manager' + match '/sections'=>'desktop#sections' + match '/settings'=>'desktop#settings' + match '/get_desktop_settings/'=>'desktop#get_desktop_settings' + match '/save_desktop_settings/'=>'desktop#save_desktop_settings' + match '/getgroups/'=>'desktop#getgroups' + match '/getsectionlist/'=>'desktop#getsectionlist' + match '/settingthemes/'=>'desktop#settingthemes' + match '/settingsections/'=>'desktop#settingsections' + match '/getapplist/'=>'desktop#getapplist' + match '/newpositions/'=>'desktop#newpositions' + match '/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/books' => 'desktop_publications#books' - match '/desktop/books_list/'=>'desktop_publications#books_list' - match '/desktop/books_add/'=>'desktop_publications#books_add' + match '/journal_p/'=>'desktop_publications#journal_p' + match '/journal_p_list/'=>'desktop_publications#journal_p_list' + match '/journal_p_add/'=>'desktop_publications#journal_p_add' + match '/books' => 'desktop_publications#books' + match '/books_list/'=>'desktop_publications#books_list' + match '/books_add/'=>'desktop_publications#books_add' - match '/desktop/seminar_p' => 'desktop_publications#seminar_p' - match '/desktop/seminar_p_list/'=>'desktop_publications#seminar_p_list' - match '/desktop/seminar_p_add/'=>'desktop_publications#seminar_p_add' + match '/seminar_p' => 'desktop_publications#seminar_p' + match '/seminar_p_list/'=>'desktop_publications#seminar_p_list' + match '/seminar_p_add/'=>'desktop_publications#seminar_p_add' - match '/desktop/research_d' => 'desktop_research#research_d' - match '/desktop/research_d_list/' => 'desktop_research#research_d_list' - match '/desktop/research_d_add' => 'desktop_research#research_d_add' + match '/research_d' => 'desktop_research#research_d' + match '/research_d_list/' => 'desktop_research#research_d_list' + match '/research_d_add' => 'desktop_research#research_d_add' - match '/desktop/research_p' => 'desktop_research#research_p' - match '/desktop/research_p_list/' => 'desktop_research#research_p_list' - match '/desktop/research_p_add' => 'desktop_research#research_p_add' + match '/research_p' => 'desktop_research#research_p' + match '/research_p_list/' => 'desktop_research#research_p_list' + match '/research_p_add' => 'desktop_research#research_p_add' + match '/temp_func/'=>'desktop#temp_func' +end - - match '/desktop/twitter/'=>'otheraccounts#twitter' - match '/desktop/forgmail/'=>'otheraccounts#gmail' - match '/desktop/getaccounts'=>'otheraccounts#getaccounts' - match '/desktop/save_account_info/'=>'otheraccounts#saveaccountinfo' + match '/twitter/'=>'otheraccounts#twitter' + match '/forgmail/'=>'otheraccounts#gmail' + match '/getaccounts'=>'otheraccounts#getaccounts' + match '/save_account_info/'=>'otheraccounts#saveaccountinfo' match '/desktop_appstore/appstore'=>'desktop_appstore#appstore' match '/desktop_appstore/widgets'=>'desktop_appstore#widgets' @@ -228,13 +238,14 @@ Orbit::Application.routes.draw do match '/desktop_orbit/eventajaxload'=> 'desktop_orbit#eventajaxload' match '/desktop_orbit/gettimelinespan' => 'desktop_orbit#gettimelinespan' + match '/desktop_publications/getjournals' => 'desktop_publications#getjournals' #match '/desktop_orbit/eventajaxload' => 'desktop_publications#create_journal' #match '/desktop_orbit/eventajaxload' => 'desktop_publications#delete_journal' # match '/desktop_orbit/eventajaxload' => 'desktop_publications#update_journal' - match '/desktop/temp_func/'=>'desktop#temp_func' + match '/panel/:app_name/front_end/:app_action/:id(/:controller_action)' => 'pages#show_from_link', :constraints => lambda { |request| !request.query_string.include?("inner=true") diff --git a/lib/parsers/parser_layout_widget.rb b/lib/parsers/parser_layout_widget.rb new file mode 100644 index 00000000..6749dae3 --- /dev/null +++ b/lib/parsers/parser_layout_widget.rb @@ -0,0 +1,15 @@ +module ParserLayoutWidget + require 'nokogiri' + + def parse_widget_for_images(widget) + widge = Nokogiri::HTML(widget.widget_layout.body) + + widge.css('.widget_image').each do |page_image| + image = widget.images.where( file: File.basename(page_image['src']))[0] + image.update_attributes(:html_id => page_image['id'], :html_class => page_image['class'], :in_html => true) if image + end + + end + + +end diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/index.html.erb b/public/desktop_widgets/4fa7810ac88514014d7c59bc/index.html.erb deleted file mode 100755 index 2a69e24c..00000000 --- a/public/desktop_widgets/4fa7810ac88514014d7c59bc/index.html.erb +++ /dev/null @@ -1,81 +0,0 @@ - - -
- \ No newline at end of file diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_blue.png b/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_blue.png deleted file mode 100755 index ea275d1b..00000000 Binary files a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_blue.png and /dev/null differ diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_green.png b/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_green.png deleted file mode 100755 index 393618c2..00000000 Binary files a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_green.png and /dev/null differ diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_orange.png b/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_orange.png deleted file mode 100755 index 84d32207..00000000 Binary files a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/bg_orange.png and /dev/null differ diff --git a/public/desktop_widgets/4fa7817cc88514014d7c59c2/index.html.erb b/public/desktop_widgets/4fa7817cc88514014d7c59c2/index.html.erb deleted file mode 100644 index 9862a505..00000000 --- a/public/desktop_widgets/4fa7817cc88514014d7c59c2/index.html.erb +++ /dev/null @@ -1,45 +0,0 @@ - -
-
- sunny -
- 29°C -
-
Sunny
-
-
- weekly report -
-
Hsin-Chu
- > Weekly Report -
- \ No newline at end of file diff --git a/public/desktop_widgets/4fa7818cc88514014d7c59c3/index.html.erb b/public/desktop_widgets/4fa7818cc88514014d7c59c3/index.html similarity index 100% rename from public/desktop_widgets/4fa7818cc88514014d7c59c3/index.html.erb rename to public/desktop_widgets/4fa7818cc88514014d7c59c3/index.html diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/clock.css b/public/desktop_widgets/clock/default.css similarity index 100% rename from public/desktop_widgets/4fa7810ac88514014d7c59bc/temp/clock.css rename to public/desktop_widgets/clock/default.css diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_blue.png b/public/desktop_widgets/clock/images/bg_blue.png similarity index 100% rename from public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_blue.png rename to public/desktop_widgets/clock/images/bg_blue.png diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_green.png b/public/desktop_widgets/clock/images/bg_green.png similarity index 100% rename from public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_green.png rename to public/desktop_widgets/clock/images/bg_green.png diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_orange.png b/public/desktop_widgets/clock/images/bg_orange.png similarity index 100% rename from public/desktop_widgets/4fa7810ac88514014d7c59bc/img/bg_orange.png rename to public/desktop_widgets/clock/images/bg_orange.png diff --git a/public/desktop_widgets/4fa7810ac88514014d7c59bc/4fa7810ac88514014d7c59bc.js b/public/desktop_widgets/clock/javascripts/clock.js similarity index 100% rename from public/desktop_widgets/4fa7810ac88514014d7c59bc/4fa7810ac88514014d7c59bc.js rename to public/desktop_widgets/clock/javascripts/clock.js diff --git a/public/desktop_widgets/clock/settings.json b/public/desktop_widgets/clock/settings.json new file mode 100644 index 00000000..8aa41d20 --- /dev/null +++ b/public/desktop_widgets/clock/settings.json @@ -0,0 +1,7 @@ +{ + "author" : "Harry", + "name" : "Clock", + "shape" : "w2 h1", + "version" : "1.0" + +} diff --git a/public/desktop_widgets/clock/widget.html b/public/desktop_widgets/clock/widget.html new file mode 100755 index 00000000..aeb6a444 --- /dev/null +++ b/public/desktop_widgets/clock/widget.html @@ -0,0 +1,5 @@ + +
+ \ No newline at end of file diff --git a/public/desktop_widgets/weather/default.css b/public/desktop_widgets/weather/default.css new file mode 100644 index 00000000..ef65207d --- /dev/null +++ b/public/desktop_widgets/weather/default.css @@ -0,0 +1,26 @@ +.g_weather { position: relative; height: 198px; } + .g_weather img { float: left; display: block; margin: 0; padding: 12px; } + .g_weather .gw_recent { + overflow: hidden; + height: 96%; + padding-top: 4%; + } + .g_weather .gw_weekly { display: none; } + .g_weather .gw_location { + position: absolute; + left: 0; + bottom: 0; + font-size: 15px; + line-height: 20px; + } + .g_weather .gw_condition_des { font-size: 22px; } + .g_weather .gw_temp { margin-top: 26px; } + .g_weather .gw_temp_num { font-size: 56px; } + .g_weather .gw_temp_unit { font-size: 26px; } + .g_weather .gw_forecast { + position: absolute; + right: 0; + bottom: 0; + font-size: 13px; + line-height: 20px; +} \ No newline at end of file diff --git a/public/desktop_widgets/4fa7817cc88514014d7c59c2/img/sunny.png b/public/desktop_widgets/weather/images/sunny.png similarity index 100% rename from public/desktop_widgets/4fa7817cc88514014d7c59c2/img/sunny.png rename to public/desktop_widgets/weather/images/sunny.png diff --git a/public/desktop_widgets/4fa7817cc88514014d7c59c2/4fa7817cc88514014d7c59c2.js b/public/desktop_widgets/weather/javascripts/weather.js similarity index 100% rename from public/desktop_widgets/4fa7817cc88514014d7c59c2/4fa7817cc88514014d7c59c2.js rename to public/desktop_widgets/weather/javascripts/weather.js diff --git a/public/desktop_widgets/weather/settings.json b/public/desktop_widgets/weather/settings.json new file mode 100644 index 00000000..67e5a378 --- /dev/null +++ b/public/desktop_widgets/weather/settings.json @@ -0,0 +1,7 @@ +{ + "author" : "Devin", + "name" : "Weather", + "shape" : "w2 h2", + "version" : "0.0" + +} diff --git a/public/desktop_widgets/weather/widget.html b/public/desktop_widgets/weather/widget.html new file mode 100644 index 00000000..8cc412f2 --- /dev/null +++ b/public/desktop_widgets/weather/widget.html @@ -0,0 +1,17 @@ +
+
+ sunny +
+ 29°C +
+
Sunny
+
+
+ weekly report +
+
Hsin-Chu
+ > Weekly Report +
+ \ No newline at end of file