From e69fff25f64ba5c05230ff300cfcfc1923510810 Mon Sep 17 00:00:00 2001 From: sukhbir-singh Date: Tue, 25 Jun 2019 01:46:59 +0530 Subject: [PATCH 1/2] added component for showing app installation status on top --- .../app/assets/javascripts/apps.js.coffee | 48 +++++++++++++++++++ .../040-apps/app/views/apps/index.html.slim | 18 +++++++ plugins/040-apps/config/locales/en.yml | 3 ++ public/themes/default/stylesheets/style.css | 16 ++++++- 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/plugins/040-apps/app/assets/javascripts/apps.js.coffee b/plugins/040-apps/app/assets/javascripts/apps.js.coffee index b0b37265..dcd6feda 100644 --- a/plugins/040-apps/app/assets/javascripts/apps.js.coffee +++ b/plugins/040-apps/app/assets/javascripts/apps.js.coffee @@ -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)) @@ -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 @@ -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() diff --git a/plugins/040-apps/app/views/apps/index.html.slim b/plugins/040-apps/app/views/apps/index.html.slim index 53cb382d..4a4c60a8 100644 --- a/plugins/040-apps/app/views/apps/index.html.slim +++ b/plugins/040-apps/app/views/apps/index.html.slim @@ -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? diff --git a/plugins/040-apps/config/locales/en.yml b/plugins/040-apps/config/locales/en.yml index fb36bfb7..c09c279b 100644 --- a/plugins/040-apps/config/locales/en.yml +++ b/plugins/040-apps/config/locales/en.yml @@ -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 diff --git a/public/themes/default/stylesheets/style.css b/public/themes/default/stylesheets/style.css index 86bec6fe..4582443d 100644 --- a/public/themes/default/stylesheets/style.css +++ b/public/themes/default/stylesheets/style.css @@ -1757,4 +1757,18 @@ span#setting_dns select{ .pd-l-12{ padding-left: 12px !important; -} \ No newline at end of file +} + +.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; +} From 058b43b278ac55ba72f32db2b1019f17cf0b4686 Mon Sep 17 00:00:00 2001 From: sukhbir-singh Date: Tue, 25 Jun 2019 01:57:46 +0530 Subject: [PATCH 2/2] added app installation status component to installed apps tab --- .../app/views/apps/installed.html.slim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/040-apps/app/views/apps/installed.html.slim b/plugins/040-apps/app/views/apps/installed.html.slim index 42b842f9..f4da4170 100644 --- a/plugins/040-apps/app/views/apps/installed.html.slim +++ b/plugins/040-apps/app/views/apps/installed.html.slim @@ -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?