[enh] Install custom (github) app using regular form.

This commit is contained in:
opi 2014-06-04 22:28:02 +02:00
parent 1a817189ad
commit ea4dcb4d11
5 changed files with 126 additions and 2 deletions

View file

@ -791,6 +791,7 @@ app = Sammy('#main', function (sam) {
sam.get('#/apps/install/:app', function (c) { sam.get('#/apps/install/:app', function (c) {
c.api('/apps?raw', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8 c.api('/apps?raw', function(data) { // http://api.yunohost.org/#!/app/app_list_get_8
appData = data[c.params['app']]; appData = data[c.params['app']];
appData.id = c.params['app'];
// Loop through installation arguments // Loop through installation arguments
if (typeof appData.manifest.arguments.install !== 'undefined') { if (typeof appData.manifest.arguments.install !== 'undefined') {
@ -869,6 +870,98 @@ app = Sammy('#main', function (sam) {
}, 'POST', params); }, 'POST', params);
}); });
// Install custom app from github
sam.post('#/apps/install/custom', function(c) {
params = { 'label': c.params['label'], 'app': c.params['url'] }
delete c.params['label'];
delete c.params['url'];
// Get manifest.json to get additional parameters
jQuery.ajax({
url: params.app.replace('github.com', 'rawgit.com') + '/master/manifest.json',
type: 'GET',
crossdomain: true,
dataType: 'json',
})
.done(function(manifest) {
manifest = manifest || {};
// Fake appData (see '#/apps/install/:app' route)
var appData = {
manifest : manifest,
id : params.app,
multi_instance : manifest.multi_instance,
};
if (typeof appData.manifest.arguments.install !== 'undefined') {
$.each(appData.manifest.arguments.install, function(k, v) {
appData.manifest.arguments.install[k].allowedValues = [];
// Radio button
if (typeof appData.manifest.arguments.install[k].choices !== 'undefined') {
// Update choices values with key and checked data
$.each(appData.manifest.arguments.install[k].choices, function(ck, cv){
appData.manifest.arguments.install[k].choices[ck] = {
value: cv,
key: ck,
checked: (cv == appData.manifest.arguments.install[k].default) ? true : false,
};
});
}
// Special case for domain input.
// Display a list of available domains
if (v.name == 'domain') {
$.each(c.params.domains, function(key, domain){
appData.manifest.arguments.install[k].allowedValues.push({
value: domain,
label: domain,
});
})
appData.manifest.arguments.install[k].help = "<a href='#/domains'>"+y18n.t('manage_domains')+"</a>";
}
// Special case for admin input.
// Display a list of available users
if (v.name == 'admin') {
$.each(c.params.users, function(key, user){
appData.manifest.arguments.install[k].allowedValues.push({
value: user.username,
label: user.fullname+' ('+user.mail+')'
});
})
appData.manifest.arguments.install[k].help = "<a href='#/users'>"+y18n.t('manage_users')+"</a>";
}
// Multilingual description
appData.manifest.arguments.install[k].label = (typeof appData.manifest.arguments.install[k].ask[y18n.locale] !== 'undefined') ?
appData.manifest.arguments.install[k].ask[y18n.locale] :
appData.manifest.arguments.install[k].ask['en']
;
});
}
// Multilingual description
appData.description = (typeof appData.manifest.description[y18n.locale] !== 'undefined') ?
appData.manifest.description[y18n.locale] :
appData.manifest.description['en']
;
// Multi Instance settings
appData.manifest.multi_instance = (appData.manifest.multi_instance == 'true') ? y18n.t('yes') : y18n.t('no');
// View app install form
c.view('app/app_install', appData);
})
.fail(function(xhr) {
c.flash('fail', y18n.t('app_install_custom_no_manifest'));
store.clear('slide');
c.redirect('#/apps/install');
});
});
sam.get('#/apps/:app/uninstall', function (c) { sam.get('#/apps/:app/uninstall', function (c) {
if (confirm(y18n.t('confirm_uninstall', [c.params['app']]))) { if (confirm(y18n.t('confirm_uninstall', [c.params['app']]))) {
c.api('/apps/'+ c.params['app'], function() { // http://api.yunohost.org/#!/app/app_remove_delete_4 c.api('/apps/'+ c.params['app'], function() { // http://api.yunohost.org/#!/app/app_remove_delete_4

View file

@ -87,6 +87,7 @@
"app_list" : "App list", "app_list" : "App list",
"uninstall" : "Uninstall", "uninstall" : "Uninstall",
"install_name" : "Install %s", "install_name" : "Install %s",
"label" : "Label",
"label_for_manifestname" : "Label for %s", "label_for_manifestname" : "Label for %s",
"app_info_access_desc" : "Manage user access. Allowed users: %s.", "app_info_access_desc" : "Manage user access. Allowed users: %s.",
"app_info_default_desc" : "Redirect domain root to this application (%s).", "app_info_default_desc" : "Redirect domain root to this application (%s).",
@ -111,6 +112,8 @@
"manage_domains" : "Manage domains", "manage_domains" : "Manage domains",
"manage_users" : "Manage users", "manage_users" : "Manage users",
"install_time" : "Install time", "install_time" : "Install time",
"custom_app_install" : "Install custom app",
"custom_app_url_only_github" : "Currently only from GitHub",
"backup" : "Backup", "backup" : "Backup",
"backup_warning_title" : "The backup system is not implemented yet.", "backup_warning_title" : "The backup system is not implemented yet.",

View file

@ -87,6 +87,7 @@
"app_list" : "Liste des applications", "app_list" : "Liste des applications",
"uninstall" : "Désinstaller", "uninstall" : "Désinstaller",
"install_name" : "Installer %s", "install_name" : "Installer %s",
"label" : "Libellé",
"label_for_manifestname" : "Libellé pour %s", "label_for_manifestname" : "Libellé pour %s",
"app_info_access_desc" : "Gestion des droits d'accès. Utilisateurs autorisés : %s.", "app_info_access_desc" : "Gestion des droits d'accès. Utilisateurs autorisés : %s.",
"app_info_default_desc" : "Redirige la racine du domaine vers cette application (%s).", "app_info_default_desc" : "Redirige la racine du domaine vers cette application (%s).",

View file

@ -17,7 +17,7 @@
<div class="panel-body"> <div class="panel-body">
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>{{t 'id'}}</dt> <dt>{{t 'id'}}</dt>
<dd>{{manifest.id}}</dd> <dd>{{id}}</dd>
<dt>{{t 'description'}}</dt> <dt>{{t 'description'}}</dt>
<dd>{{description}}</dd> <dd>{{description}}</dd>
<dt>{{t 'multi_instance'}}</dt> <dt>{{t 'multi_instance'}}</dt>
@ -68,7 +68,7 @@
</div> </div>
{{/manifest.arguments.install}} {{/manifest.arguments.install}}
<hr> <hr>
<input type="hidden" name="app" value="{{manifest.id}}"> <input type="hidden" name="app" value="{{id}}">
<div class="text-center"> <div class="text-center">
<input type="submit" class="btn btn-success slide back" value="{{t 'install'}}"> <input type="submit" class="btn btn-success slide back" value="{{t 'install'}}">
</div> </div>

View file

@ -48,3 +48,30 @@
{{/apps}} {{/apps}}
</div> </div>
{{^installed}}
<div 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>
<div class="panel-body">
<form action="#/apps/install/custom" method="POST" class="form-horizontal">
<div class="form-group has-feedback">
<label for="label" class="col-sm-12">{{t 'url'}}</label>
<div class="col-sm-12">
<input type="url" id="url" name="url" class="form-control" value="" placeholder="https://github.com/USER/REPOSITORY" required pattern="^https://github.com/[a-z]*/[a-z]*">
<p class="text-warning">
<span class="fa-github"></span> {{t 'custom_app_url_only_github'}}
</p>
</div>
</div>
<div class="form-group">
<div class="text-center">
<input type="submit" class="btn btn-success slide back" value="{{t 'install'}}">
</div>
</div>
</form>
</div>
</div>
{{/installed}}