Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added component to Apps Tab for showing app installation status on reload #242

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions plugins/040-apps/app/assets/javascripts/apps.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Apps =
selector: ".in_dashboard_checkbox"
parentSelector: "span:first"

if document.getElementsByClassName('app-installing')[0]
element = document.getElementsByClassName('installation-status')[0]
finder = element.classList[1].substr(9)
_this.trace_global_progress(finder)

app: (finder) ->
(if typeof (finder) is "string" then @app_by_identifier(finder) else @app_by_element(finder))

Expand Down Expand Up @@ -104,6 +109,22 @@ Apps =
message.innerHTML = content
@app(finder).get(0).querySelector(".spinner").style.display = "none"

global_update_progress:(progress) ->
element = document.getElementsByClassName('global-progress')[0]
element.style.width = "#{progress}%"
element.innerHTML = "#{progress}%"

wait_and_hide_global_progress:() ->
setTimeout (->
element = document.getElementsByClassName('app-installing')[0]
element.style.display = "none"
return
), 2000

hide_global_progress:() ->
element = document.getElementsByClassName('app-installing')[0]
element.style.display = "none"

trace_progress: (finder) ->
_this = this
$.ajax
Expand Down Expand Up @@ -166,5 +187,32 @@ Apps =
else
setTimeout (-> Apps.trace_progress(finder)), 2000

trace_global_progress: (finder) ->
_this = this
$.ajax
url: _this.app(finder).data("progressPath")
success: (data) ->
progress = data["progress"]

timeout_t = 0

if data["type"].indexOf("uninstall") != -1
progress = 100 - progress
if progress == 0
timeout_t = 2000
else
if progress == 100
timeout_t = 2000

_this.global_update_progress(progress)

if progress >=0 && progress <=100
if (progress == 0 && data["type"] == "uninstall") || (progress == 100 && data["type"] == "install")
_this.wait_and_hide_global_progress()
else
setTimeout (-> Apps.trace_global_progress(finder)), 2000
else
_this.hide_global_progress()

$(document).ready ->
Apps.initialize()
18 changes: 18 additions & 0 deletions plugins/040-apps/app/views/apps/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
.col-xs-6.col-sm-6.col-md-6.col-lg-6.get-apps = link_to 'Get apps', 'https://www.amahi.org/apps', :title => 'Amahi App Store', :target => '_blank', :id => 'btn-get-apps'
.col-xs-6.col-sm-6.col-md-6.col-lg-6.install-apps = link_to 'Install here!', apps_engine.root_path, :title => 'Refresh', :id => 'btn-install-apps'

- progress = Rails.cache.read("progress")
- type = Rails.cache.read("type")
- unless (progress.blank? || (progress == 0 && type == "uninstall") || (progress == 100 && type == "install") || (progress<0) || (progress>100))
- app_id = Rails.cache.read("app-id")
- app = AmahiApi::App.find(app_id)
- status = type == "install" ? t('installing_application') : t('uninstalling_application')
- progress = (100-progress) if type == "uninstall"

.container.app-installing
span.installation-status class="app_name_#{app_id}"
= status + ": " + app.name

// = button_tag t('clear'), :type => 'button', :class => 'btnn btn-create btn btn-info float-right mb-1', :id => "clear-app-installation", :data => { :related => "#new-user-step1" }

.progress.progress-bar-div.mt-2 style="width: 100%; display: inline-block; background: #c7c7c7;"
.progress-bar.progress-bar-striped.progress-bar-animated.bg-info.global-progress aria-valuemax="100" \aria-valuemin="0" aria-valuenow="0" role="progressbar" style="width: #{progress}%; height: 100%;"
= "#{progress}%"

#apps-table
.settings-table
- if @apps.any?
Expand Down
19 changes: 19 additions & 0 deletions plugins/040-apps/app/views/apps/installed.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
.app-store-header.row
.col-xs-6.col-sm-6.col-md-6.col-lg-6.get-apps = link_to 'Get apps', 'https://www.amahi.org/apps', :title => 'Amahi App Store', :target => '_blank', :id => 'btn-get-apps'
.col-xs-6.col-sm-6.col-md-6.col-lg-6.install-apps = link_to 'Install here!', apps_engine.root_path, :title => 'Refresh', :id => 'btn-install-apps'

- progress = Rails.cache.read("progress")
- type = Rails.cache.read("type")
- unless (progress.blank? || (progress == 0 && type == "uninstall") || (progress == 100 && type == "install") || (progress<0) || (progress>100))
- app_id = Rails.cache.read("app-id")
- app = AmahiApi::App.find(app_id)
- status = type == "install" ? t('installing_application') : t('uninstalling_application')
- progress = (100-progress) if type == "uninstall"

.container.app-installing
span.installation-status class="app_name_#{app_id}"
= status + ": " + app.name

// = button_tag t('clear'), :type => 'button', :class => 'btnn btn-create btn btn-info float-right mb-1', :id => "clear-app-installation", :data => { :related => "#new-user-step1" }

.progress.progress-bar-div.mt-2 style="width: 100%; display: inline-block; background: #c7c7c7;"
.progress-bar.progress-bar-striped.progress-bar-animated.bg-info.global-progress aria-valuemax="100" \aria-valuemin="0" aria-valuenow="0" role="progressbar" style="width: #{progress}%; height: 100%;"
= "#{progress}%"

#apps-table
.settings-table
- if @apps.any?
Expand Down
3 changes: 3 additions & 0 deletions plugins/040-apps/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
'en':
# put here your string symbols and translations
hello_world: Hello World! (yay for the Amahi plugins!)
installing_application: Installing Application
uninstalling_application: Uninstalling Application
clear: Clear
16 changes: 15 additions & 1 deletion public/themes/default/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1757,4 +1757,18 @@ span#setting_dns select{

.pd-l-12{
padding-left: 12px !important;
}
}

.app-installing{
background: white;
margin-top: 15px;
margin-bottom: 15px;
border-radius: 4px;
padding: 15px;
font-size: 15px;
}

.installation-status{
padding-top: 4px;
display: inline-block;
}