From 1592ab4e7337a537ab7931ad432b333c1e1682f3 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 27 Apr 2020 03:24:15 +0200 Subject: [PATCH] Fix custom app install + misc detail in regular app install --- src/js/yunohost/controllers/apps.js | 110 ++++++++++++++------------ src/js/yunohost/filters.js | 2 + src/views/app/app_catalog_category.ms | 7 +- src/views/app/app_install.ms | 4 +- 4 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/js/yunohost/controllers/apps.js b/src/js/yunohost/controllers/apps.js index a0ccf5b03..ba5647d54 100644 --- a/src/js/yunohost/controllers/apps.js +++ b/src/js/yunohost/controllers/apps.js @@ -235,6 +235,22 @@ jQuery("#filter-app-cards").on("keyup", function() { cardGrid.isotope({ filter: filterApps }); }); + + $("#install-custom-app a[role='button']").on('click', function() { + + var url = $("#install-custom-app input[name='url']")[0].value; + if (url.indexOf("github.com") < 0) { + return; + } + + c.confirm( + y18n.t('applications'), + y18n.t('confirm_install_custom_app'), + function(){ + c.redirect_to('#/apps/install/custom/' + encodeURIComponent(url)); + } + ); + }); }; // render @@ -376,13 +392,6 @@ }); }) - // Special case for custom app installation. - app.get('#/apps/install/custom', function (c) { - // If we try to GET /apps/install/custom, it means that installation fail. - // Need to redirect to apps/install to get rid of pacamn and see the log. - c.redirect_to('#/apps/install'); - }); - // Helper function that formats YunoHost style arguments for generating a form function formatYunoHostStyleArguments(args, params) { if (!args) { @@ -533,16 +542,24 @@ displayLicense: (manifest['license'] !== undefined && manifest['license'] !== 'free') }; - formatYunoHostStyleArguments(data.manifest.arguments.install, params); + formatYunoHostStyleArguments(manifest.arguments.install, params); // Multilingual description - data.description = (typeof data.manifest.description[y18n.locale] !== 'undefined') ? - data.manifest.description[y18n.locale] : - data.manifest.description['en'] - ; + if (typeof manifest.description === 'string') + { + data.description = manifest.description; + } + else if (typeof manifest.description[y18n.locale] !== 'undefined') + { + data.description = manifest.description[y18n.locale]; + } + else + { + data.description = manifest.description['en']; + } // Multi Instance settings boolean to text - data.manifest.multi_instance = data.manifest.multi_instance ? y18n.t('yes') : y18n.t('no'); + data.manifest.multi_instance = manifest.multi_instance ? y18n.t('yes') : y18n.t('no'); // View app install form c.view('app/app_install', data); @@ -573,13 +590,16 @@ app_infos.manifest, c.params ); + }, + function () { + c.redirect_to('#/apps/catalog'); } ); } else { c.appInstallForm( - c.params['app'], + app_name, app_infos.manifest, c.params ); @@ -624,45 +644,31 @@ }); // Install custom app from github - app.post('#/apps/install/custom', function(c) { - - var params = { - label: c.params['label'], - app: c.params['url'] - }; - delete c.params['label']; - delete c.params['url']; - - c.confirm( - y18n.t('applications'), - y18n.t('confirm_install_custom_app'), - function(){ - - // Force trailing slash - params.app = params.app.replace(/\/?$/, '/'); - - // Get manifest.json to get additional parameters - jQuery.ajax({ - url: params.app.replace('github.com', 'raw.githubusercontent.com') + 'master/manifest.json', - type: 'GET', - }) - .done(function(manifest) { - // raw.githubusercontent.com serve content as plain text - manifest = jQuery.parseJSON(manifest) || {}; - - c.appInstallForm( - params.app, - manifest, - c.params - ); + app.get('#/apps/install/custom/:url', function(c) { + + // Force trailing slash + url = c.params['url']; + url = url.replace(/\/?$/, '/'); + raw_manifest_url = url.replace('github.com', 'raw.githubusercontent.com') + 'master/manifest.json' + + // Fetch manifest.json + jQuery.ajax({ url: raw_manifest_url, type: 'GET' }) + .done(function(manifest) { + // raw.githubusercontent.com serve content as plain text + manifest = jQuery.parseJSON(manifest) || {}; + + c.appInstallForm( + url, + manifest, + c.params + ); + + }) + .fail(function(xhr) { + c.flash('fail', y18n.t('app_install_custom_no_manifest')); + c.redirect("#/apps/catalog/"); + }); - }) - .fail(function(xhr) { - c.flash('fail', y18n.t('app_install_custom_no_manifest')); - c.refresh(); - }); - } - ); }); // Get app change label page diff --git a/src/js/yunohost/filters.js b/src/js/yunohost/filters.js index c35a94501..aa7f67224 100644 --- a/src/js/yunohost/filters.js +++ b/src/js/yunohost/filters.js @@ -28,6 +28,8 @@ app.before(/domains\/add/, prefetchDomains); app.before(/apps\/install\//, prefetchDomains); app.before(/apps\/install\//, prefetchUsers); + app.before(/apps\/install\/custom\//, prefetchDomains); + app.before(/apps\/install\/custom\//, prefetchUsers); app.before(/apps\/\w+\/actions/, prefetchUsers); app.before(/apps\/\w+\/actions/, prefetchDomains); app.before(/apps\/\w+\/config-panel/, prefetchUsers); diff --git a/src/views/app/app_catalog_category.ms b/src/views/app/app_catalog_category.ms index fd3ac12e1..edba41060 100644 --- a/src/views/app/app_catalog_category.ms +++ b/src/views/app/app_catalog_category.ms @@ -83,7 +83,7 @@ {{/apps}} -
+

{{t 'custom_app_install'}}

@@ -92,7 +92,8 @@ {{t 'confirm_install_custom_app'}}

-
+ +
@@ -104,7 +105,7 @@
diff --git a/src/views/app/app_install.ms b/src/views/app/app_install.ms index b5ec27dd3..8acc68da5 100644 --- a/src/views/app/app_install.ms +++ b/src/views/app/app_install.ms @@ -16,9 +16,9 @@
{{t 'id'}}
-
{{id}}
+
{{manifest.id}}
{{t 'description'}}
-
{{manifest.description}}
+
{{description}}
{{#displayLicense}}
{{t 'license'}}
{{manifest.license}}