Skip to content

Commit

Permalink
Fix custom app install + misc detail in regular app install
Browse files Browse the repository at this point in the history
  • Loading branch information
alexAubin committed Apr 27, 2020
1 parent a3a0d8f commit 1592ab4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
110 changes: 58 additions & 52 deletions src/js/yunohost/controllers/apps.js
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/js/yunohost/filters.js
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/views/app/app_catalog_category.ms
Expand Up @@ -83,7 +83,7 @@
{{/apps}}
</div>

<div class="panel panel-default">
<div id="install-custom-app" class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-download"></span> {{t 'custom_app_install'}}</h2>
</div>
Expand All @@ -92,7 +92,8 @@
<span class="fa-fw fa-warning"></span>
{{t 'confirm_install_custom_app'}}
</p>
<form action="#/apps/install/custom" method="POST" class="form-horizontal">

<form class="form-horizontal">
<div class="form-group has-feedback">
<label for="url" class="col-sm-12">{{t 'url'}}</label>
<div class="col-sm-12">
Expand All @@ -104,7 +105,7 @@
</div>
<div class="form-group">
<div class="text-center">
<input type="submit" role="button" class="btn btn-success slide" value="{{t 'install'}}">
<a role="button" class="btn btn-success slide">{{t 'install'}}</a>
</div>
</div>
</form>
Expand Down
4 changes: 2 additions & 2 deletions src/views/app/app_install.ms
Expand Up @@ -16,9 +16,9 @@
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{{t 'id'}}</dt>
<dd>{{id}}</dd>
<dd>{{manifest.id}}</dd>
<dt>{{t 'description'}}</dt>
<dd>{{manifest.description}}</dd>
<dd>{{description}}</dd>
{{#displayLicense}}
<dt>{{t 'license'}}</dt>
<dd>{{manifest.license}}</dd>
Expand Down

0 comments on commit 1592ab4

Please sign in to comment.