diff --git a/lib/desktop_widgets/browser.zip b/lib/desktop_widgets/browser.zip new file mode 100755 index 000000000..837d633bb Binary files /dev/null and b/lib/desktop_widgets/browser.zip differ diff --git a/lib/desktop_widgets/clock.zip b/lib/desktop_widgets/clock.zip new file mode 100755 index 000000000..af5c10e85 Binary files /dev/null and b/lib/desktop_widgets/clock.zip differ diff --git a/lib/desktop_widgets/googlescholar.zip b/lib/desktop_widgets/googlescholar.zip new file mode 100755 index 000000000..d1fe1869c Binary files /dev/null and b/lib/desktop_widgets/googlescholar.zip differ diff --git a/lib/desktop_widgets/googlesearch.zip b/lib/desktop_widgets/googlesearch.zip new file mode 100755 index 000000000..a7329cc79 Binary files /dev/null and b/lib/desktop_widgets/googlesearch.zip differ diff --git a/lib/desktop_widgets/quotes.zip b/lib/desktop_widgets/quotes.zip new file mode 100755 index 000000000..0c69ee2cd Binary files /dev/null and b/lib/desktop_widgets/quotes.zip differ diff --git a/lib/desktop_widgets/weather.zip b/lib/desktop_widgets/weather.zip new file mode 100755 index 000000000..a5f452f6f Binary files /dev/null and b/lib/desktop_widgets/weather.zip differ diff --git a/lib/tasks/desktop.rake b/lib/tasks/desktop.rake index 0ad9468c8..ffe7a5740 100644 --- a/lib/tasks/desktop.rake +++ b/lib/tasks/desktop.rake @@ -1,24 +1,76 @@ # encoding: utf-8 -namespace :tiles do - task :destroy_build_tiles => :environment do - Tile.destroy_all - secs = Section.all - dws = DesktopWidget.all - secs.each do |sec,x| - grp = sec.groups.first - t = Tile.new(data_category: "app", data_content: "wikibooks", position: 1, shape: "w1 h1", title: "WikiBooks") - grp.tiles+=[t] - t = Tile.new(data_category: "app", data_content: "envocab", position: 2, shape: "w1 h1", title: "English Vocabulary") - grp.tiles+=[t] - @i = 3 - dws.each do |dw| - t = Tile.new(data_category: "widget", position: @i,desktop_widget_id: dw.id) - @i = @i + 1 - grp.tiles+=[t] - end - grp.save! +require 'zip/zip' +namespace :desktop do + task :upload_all_packages => :environment do + DesktopWidget.destroy_all + # 1. DesktopWidget.destroy_all + # 2. Upload alll the widgets + # 3. Tun rake task tiles:destroy_build_tiles + package_location = "lib/desktop_widgets/" + widget_packages = %w[browser.zip googlescholar.zip quotes.zip clock.zip googlesearch.zip weather.zip] + + widget_packages.each do |package_file_name| + temp_file = Tempfile.new("temp_file") + original_file = File.open(package_location+package_file_name) + #if original_file.content_type == 'application/zip' + temp_file.write(original_file.read.force_encoding('UTF-8')) + temp_file.rewind + filename = File.basename(package_file_name,".zip") + unzip_widget(temp_file, filename) + #else + # flash[:error] = "Upload file should be in zip format" + #end + temp_file.close + end + Rake::Task["tiles:destroy_build_tiles"].execute + 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 + + task :destroy_build_desktop => :environment do + Desktop.all.destroy_all + u = User.all + u.each do |us| + Thread.new { + us.initialize_desktop.save! + puts "Desktop created for " + us.email.to_s + }.join end - puts "Section " + x + " done!" end end \ No newline at end of file