Archived
apps update -- app upload and activation
This commit is contained in:
1 parent
f2ada14b7a
commit
ed22a4d303
11 files changed
+230
-207
No files matched your search
@@ -0,0 +1,49 @@
|
||||
class DesktopAppsController < OrbitBackendController
|
||||
require "net/http"
|
||||
require "uri"
|
||||
require 'zip/zip'
|
||||
|
||||
def index
|
||||
@desktopapps = DesktopApp.all
|
||||
end
|
||||
|
||||
def upload
|
||||
if !params[:desktop_app].nil?
|
||||
temp_file = Tempfile.new("temp_file");
|
||||
original_file = params[:desktop_app][:package_file]
|
||||
temp_file.write(original_file.read.force_encoding("UTF-8"))
|
||||
temp_file.rewind
|
||||
filename = File.basename(original_file.original_filename,".zip")
|
||||
unzip_app(temp_file,filename)
|
||||
temp_file.close
|
||||
end
|
||||
end
|
||||
|
||||
def unzip_app(file, zip_name)
|
||||
Zip::ZipFile.open(file) { |zip_file|
|
||||
da = DesktopApp.new.from_json(zip_file.read("#{zip_name}/settings.json"))
|
||||
Dir.mktmpdir('f_path') { |dir|
|
||||
images_entries = []
|
||||
zip_file.entries.each do |entry|
|
||||
case (path = entry.to_s)
|
||||
when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
|
||||
images_entries << entry
|
||||
end
|
||||
end
|
||||
|
||||
images_entries.each do |image|
|
||||
da.images.build(:file => get_temp_file(zip_file,dir,image))
|
||||
end
|
||||
}
|
||||
da.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
|
||||
@@ -118,6 +118,7 @@ class DesktopController< ApplicationController
|
||||
cssfile = ""
|
||||
shape = "w1 h1"
|
||||
link = ""
|
||||
icon= ""
|
||||
fullsize = false
|
||||
if tile.data_category == "widget"
|
||||
widge = DesktopWidget.find(tile.desktop_widget_id.to_s)
|
||||
@@ -127,19 +128,17 @@ class DesktopController< ApplicationController
|
||||
cssfile = widge.css_default.file.as_json[:file]
|
||||
shape = widge.shape
|
||||
title = widge.name
|
||||
icon = widge.images.where(:name => widge.icon).first.file.url
|
||||
# binding.pry
|
||||
fullsize = widge.fullsize
|
||||
else
|
||||
data_content = tile.data_content
|
||||
title = tile.title
|
||||
case data_content
|
||||
when "envocab"
|
||||
link = "http://www.english-vocabulary.eu/"
|
||||
when "wikibooks"
|
||||
link = "http://www.wikibooks.org"
|
||||
end
|
||||
app = DesktopApp.find(tile.desktop_app_id.to_s)
|
||||
title = app.name
|
||||
link = app.url
|
||||
icon = app.images.where(:name => app.icon).first.file.url
|
||||
|
||||
end
|
||||
gr << {"id"=>tile.id,"data_category"=>tile.data_category,"data_content"=>data_content,"js"=>jsfile,"css"=>cssfile,"shape"=>shape,"position"=>tile.position,"row"=>tile.row,"column"=>tile.column, "title"=>title,"fullsize"=>fullsize,"link"=>link}
|
||||
gr << {"id"=>tile.id,"data_category"=>tile.data_category,"data_content"=>data_content,"js"=>jsfile,"css"=>cssfile,"shape"=>shape,"position"=>tile.position,"row"=>tile.row,"column"=>tile.column, "title"=>title,"fullsize"=>fullsize,"link"=>link,"icon"=>icon}
|
||||
|
||||
|
||||
end
|
||||
@@ -195,6 +194,7 @@ class DesktopController< ApplicationController
|
||||
|
||||
def getapplistforManager
|
||||
@dwss = DesktopWidget.all
|
||||
@dapps = DesktopApp.all
|
||||
@tiles = Array.new
|
||||
desktop = Desktop.find(params['desktopid'])
|
||||
sections = desktop.sections
|
||||
@@ -217,6 +217,18 @@ class DesktopController< ApplicationController
|
||||
end
|
||||
@allWidgets << {"id"=>dw.id, "data_category"=> "widget","title" => dw.name, "version" => dw.version, "author"=>dw.author, "last_update"=>dw.updated_at, "icon"=>dw.images.where(:name=>dw.icon).first.file.url, "text_color" => dw.text_color, "background" => dw.bg_color, "sections" => @sections}
|
||||
end
|
||||
validtiles = Array.new
|
||||
@dapps.each do |da|
|
||||
@id = da.id
|
||||
@validtiles = @tiles.select{|t| t.desktop_app_id == @id}
|
||||
@sections = Array.new
|
||||
@validtiles.each do |vt|
|
||||
grp = Group.find(vt.group_id)
|
||||
sec = Section.find(grp.section_id);
|
||||
@sections << {"id"=>sec.id,"name"=>sec.name}
|
||||
end
|
||||
@allWidgets << {"id"=>da.id, "data_category"=> "app","title" => da.name, "version" => da.version, "author"=>da.author, "last_update"=>da.updated_at, "icon"=>da.images.where(:name=>da.icon).first.file.url, "sections" => @sections}
|
||||
end
|
||||
render :json=>@allWidgets.to_json
|
||||
end
|
||||
|
||||
@@ -264,18 +276,37 @@ class DesktopController< ApplicationController
|
||||
|
||||
def appactivation
|
||||
@group = Section.find(params[:section_id]).groups.first
|
||||
@widget = DesktopWidget.find(params[:widget_id])
|
||||
status = params[:status]
|
||||
@type = params[:type]
|
||||
if @type == "widget"
|
||||
@widget = DesktopWidget.find(params[:id])
|
||||
status = params[:status]
|
||||
|
||||
case status
|
||||
when "true"
|
||||
tile = Tile.new(data_category: "widget", position: 8, desktop_widget_id: @widget.id)
|
||||
@group.tiles+=[tile]
|
||||
@group.save
|
||||
when "false"
|
||||
tile = @group.tiles.where("desktop_widget_id"=>@widget.id).first
|
||||
if tile != nil
|
||||
tile.destroy
|
||||
case status
|
||||
when "true"
|
||||
tile = Tile.new(data_category: "widget", position: 8, desktop_widget_id: @widget.id)
|
||||
@group.tiles+=[tile]
|
||||
@group.save
|
||||
when "false"
|
||||
tile = @group.tiles.where("desktop_widget_id"=>@widget.id).first
|
||||
if tile != nil
|
||||
tile.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @type == "app"
|
||||
@app = DesktopApp.find(params[:id])
|
||||
status = params[:status]
|
||||
case status
|
||||
when "true"
|
||||
tile = Tile.new(data_category: "app", position: 8, desktop_app_id: @app.id)
|
||||
@group.tiles+=[tile]
|
||||
@group.save
|
||||
when "false"
|
||||
tile = @group.tiles.where("desktop_app_id"=>@app.id).first
|
||||
if tile != nil
|
||||
tile.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user