Merge pull request #174 from JimboJoe/enh-add-change-url

Add app change URL feature
This commit is contained in:
Laurent Peuch 2018-01-14 00:24:49 +01:00 committed by GitHub
commit 478b8a0d32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 0 deletions

View file

@ -592,4 +592,50 @@
); );
}); });
// Get app change URL page
app.get('#/apps/:app/changeurl', function (c) {
c.api('/apps/'+c.params['app']+'?raw', function(app_data) {
c.api('/domains', function(domain_data) { // http://api.yunohost.org/#!/domain/domain_list_get_2
// Display a list of available domains
var domains = [];
$.each(domain_data.domains, function(k, domain) {
domains.push({
value: domain,
label: domain,
// Select current domain
selected: (domain == app_data.settings.domain ? true : false)
});
});
data = {
id: c.params['app'],
label: app_data.manifest.name,
domains: domains,
// Pre-fill with current path
path: app_data.settings.path
};
c.view('app/app_changeurl', data);
});
});
});
// Change app URL
app.post('#/apps/:app/changeurl', function (c) {
c.confirm(
y18n.t('applications'),
y18n.t('confirm_app_change_url', [c.params['app']]),
function() {
params = {'domain': c.params['domain'], 'path': c.params['path']};
c.api('/apps/' + c.params['app'] + '/changeurl', function(data) { // Call changeurl API
store.clear('slide');
c.redirect('#/apps/'+ c.params['app']);
}, 'PUT', params);
},
function() {
store.clear('slide');
c.redirect('#/apps/'+ c.params['app'] + '/changeurl');
}
);
});
})(); })();

View file

@ -42,6 +42,23 @@
return new Handlebars.SafeString(result); return new Handlebars.SafeString(result);
}); });
// Block helper to add a tooltip to any element
Handlebars.registerHelper('tooltip', function(tooltip, options) {
return new Handlebars.SafeString(
'<span data-toggle="tooltip" title="' + tooltip + '" data-placement="right">'
+ options.fn(this)
+ '</span>');
});
// Load tooltips on the page; needed if using tooltips
Handlebars.registerHelper('load_tooltips', function() {
return new Handlebars.SafeString(
'<script>'
+ '$(document).ready(function(){'
+ '$(\'[data-toggle="tooltip"]\').tooltip();'
+ '});'
+ '</script>');
});
// Look for supported type of storage to use // Look for supported type of storage to use
/** /**

View file

@ -13,11 +13,14 @@
"app_access_removeall_btn": "Remove all access", "app_access_removeall_btn": "Remove all access",
"app_access_removeall_desc": "No users will have access to %s.", "app_access_removeall_desc": "No users will have access to %s.",
"app_access_title": "%s access", "app_access_title": "%s access",
"app_change_url": "Change URL",
"app_debug_no_logs": "Application's logs are not available", "app_debug_no_logs": "Application's logs are not available",
"app_debug_tab": "Display debug information", "app_debug_tab": "Display debug information",
"app_info_access_desc": "Manage user access. Allowed users: %s", "app_info_access_desc": "Manage user access. Allowed users: %s",
"app_info_debug_desc": "Display debugging information for this application.", "app_info_debug_desc": "Display debugging information for this application.",
"app_info_default_desc": "Redirect domain root to this application (%s).", "app_info_default_desc": "Redirect domain root to this application (%s).",
"app_info_changeurl_desc": "Change the access URL of this application (domain and/or path).",
"app_info_change_url_disabled_tooltip": "This feature hasn't been implemented in this app yet",
"app_info_uninstall_desc": "Remove this application.", "app_info_uninstall_desc": "Remove this application.",
"app_install_cancel": "Installation cancelled.", "app_install_cancel": "Installation cancelled.",
"app_install_custom_no_manifest": "No manifest.json file", "app_install_custom_no_manifest": "No manifest.json file",
@ -60,6 +63,7 @@
"confirm_access_clear": "Are you sure you want to clear all access to %s ?", "confirm_access_clear": "Are you sure you want to clear all access to %s ?",
"confirm_access_remove_all": "Are you sure you want to remove all access to %s ?", "confirm_access_remove_all": "Are you sure you want to remove all access to %s ?",
"confirm_access_remove_user": "Are you sure you want to remove access to %s for %s ?", "confirm_access_remove_user": "Are you sure you want to remove access to %s for %s ?",
"confirm_app_change_url": "Are you sure you want to change the app access URL ?",
"confirm_app_default": "Are you sure you want to make this app default ?", "confirm_app_default": "Are you sure you want to make this app default ?",
"confirm_change_maindomain": "Are you sure you want to change the main domain ?", "confirm_change_maindomain": "Are you sure you want to change the main domain ?",
"confirm_delete": "Are you sure you want to delete %s ?", "confirm_delete": "Are you sure you want to delete %s ?",
@ -212,6 +216,7 @@
"passwords_dont_match": "Passwords don't match", "passwords_dont_match": "Passwords don't match",
"passwords_too_short": "Password is too short", "passwords_too_short": "Password is too short",
"path": "Path", "path": "Path",
"path_url": "Path",
"port": "Port", "port": "Port",
"ports": "Ports", "ports": "Ports",
"postinstall": "Post-installation", "postinstall": "Post-installation",

View file

@ -0,0 +1,38 @@
<div class="btn-breadcrumb">
<a href="#/" ><i class="fa-home"></i><span class="sr-only">{{t 'home'}}</span></a>
<a href="#/apps" class="hidden-xs">{{t 'applications'}}</a>
<a href="#/apps" class="visible-xs">&hellip;</a>
<a href="#/apps/{{id}}">{{label}}</a>
<a href="#/apps/{{id}}/changeurl">{{t 'app_change_url'}}</a>
</div>
<div class="separator"></div>
<form action="#/apps/{{id}}/changeurl" method="POST" class="form-horizontal form-app-install">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title"><span class="fa-fw fa-exchange"></span> {{t 'app_change_url'}}</h2>
</div>
<div class="panel-body">
<div class="form-group">
<label for="domain" class="col-sm-12">{{t 'domain'}}</label>
<div class="col-sm-12">
<select id="domain" name="domain" required class="form-control" {{{attributes}}}>
{{#each domains}}<option value="{{this.value}}" {{#if selected}}selected{{/if}}>{{this.label}}</option>{{/each}}
</select>
<span class="help-block help-block--link"><a href='#/domains'>{{t 'manage_domains'}}</a></span>
</div>
<label for="path" class="col-sm-12">{{t 'path_url'}}</label>
<div class="col-sm-12">
<input class="col-sm-12" type="text" id="path" name="path" class="form-control" value="{{path}}" required="required">
</div>
</div>
<hr>
<input type="hidden" name="app" value="{{id}}">
<div class="text-center">
<input type="submit" class="btn btn-success slide back" value="{{t 'app_change_url'}}">
</div>
</div>
</div>
</form>

View file

@ -48,6 +48,21 @@
</a> </a>
</div> </div>
<hr> <hr>
<div class="container">
<p>{{t 'app_info_changeurl_desc' settings.domain}}</p>
{{#if change_url}}
<a href="#/apps/{{settings.id}}/changeurl" class="btn btn-info slide">
<span class="fa-exchange"></span> {{t 'app_change_url'}}
</a>
{{else}}
{{#tooltip (t 'app_info_change_url_disabled_tooltip') }}
<a href="#/apps/{{settings.id}}/changeurl" class="btn btn-info slide disabled">
<span class="fa-exchange"></span> {{t 'app_change_url'}}
</a>
{{/tooltip}}
{{/if}}
</div>
<hr>
<div class="container"> <div class="container">
<p>{{t 'app_info_uninstall_desc'}}</p> <p>{{t 'app_info_uninstall_desc'}}</p>
<a href="#/apps/{{settings.id}}/uninstall" class="btn btn-danger slide back"> <a href="#/apps/{{settings.id}}/uninstall" class="btn btn-danger slide back">
@ -63,3 +78,4 @@
</div> </div>
</div> </div>
</div> </div>
{{load_tooltips}}