Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config panel ynh arguments #251

Merged
merged 10 commits into from
Jul 2, 2019
11 changes: 11 additions & 0 deletions src/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,17 @@ input[type='radio'].nice-radio {
margin-top: -5px;
}

.auto-width {
width: auto;
}

.input-hidden {
display: none;
}

.alert-debug {
background-color: white;
}

.app-card .panel-body {
padding: 1.5rem;
Expand Down
7 changes: 6 additions & 1 deletion src/js/yunohost/controllers/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@
// Get app config panel
app.get('#/apps/:app/config-panel', function (c) {
c.api('/apps/'+c.params['app']+'/config-panel', function(data) {
$.each(data.config_panel.panel, function(_, panel) {
$.each(panel.sections, function(_, section) {
formatYunoHostStyleArguments(section.options, c.params);
});
});
c.view('app/app_config-panel', data);
});
});
Expand Down Expand Up @@ -340,7 +345,7 @@
args[k].inputType = 'text';
args[k].isPassword = false;
args[k].isDisplayText = false;
args[k].required = (typeof v.optional !== 'undefined' && v.optional == "true") ? '' : 'required';
args[k].required = (typeof v.optional !== 'undefined' && (v.optional == "true" || v.optional == true)) ? '' : 'required';
args[k].attributes = "";
args[k].helpText = "";
args[k].helpLink = "";
Expand Down
2 changes: 1 addition & 1 deletion src/js/yunohost/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
' (<a href="'+ item.url +'" class="alert-link" target="_blank">'+y18n.t('read_more')+'</a>)';
c.flash('warning', warning);
// Store viewed item
viewedItems.push(item.guid);i
viewedItems.push(item.guid);
}
});
// Saved viewed items to cookie
Expand Down
2 changes: 2 additions & 0 deletions src/js/yunohost/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
app.before(/apps\/install\//, prefetchUsers);
app.before(/apps\/\w+\/actions/, prefetchUsers);
app.before(/apps\/\w+\/actions/, prefetchDomains);
app.before(/apps\/\w+\/config-panel/, prefetchUsers);
app.before(/apps\/\w+\/config-panel/, prefetchDomains);


app.before({except: {path: ['#/logout', '#/login', '#/postinstall', '#/postinstall/domain', '#/postinstall/password']}}, function (req) {
Expand Down
46 changes: 29 additions & 17 deletions src/views/app/app_config-panel.ms
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{{#config_panel}}
<h2>{{../app_name}} configuration panel</h2>
<hr>
<form class="form-horizontal" action="#/apps/{{../app_id}}/config" method="POST">
{{#panel}}
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-{{ @index }}">
Expand All @@ -28,40 +29,51 @@
</div>
<div id="collapse-{{ @index }}" class="panel-collapse collapse {{#if (eq @index 0)}}in{{/if}}" role="tabpanel" aria-labelledby="heading-{{ @index }}">
<div class="panel-body">
<form class="form-horizontal" action="#/apps/{{../../app_id}}/config" method="POST">
{{#sections}}
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{name}} <small>{{help}}</small></h3></div>
<div class="panel-body">
<ul>
{{#options}}
<div class="form-group">
<label for="{{id}}" class="col-sm-2 control-label">{{name}}</label>
<div class="form-group input-{{inputType}}">
<label for="{{name}}" class="col-sm-2 control-label">{{label}}</label>

<div class="col-sm-10">
{{#if (in type "number" "text" "password" "color" "date" "datetime-local" "email" "month number" "range" "search" "tel" "time" "url" "week")}}
<input type="number" class="form-control" id="{{id}}" name="{{id}}" placeholder="{{placeholder}}">
<span class="help-block">{{ help }}</span>
{{else if (eq type "bool")}}
<input type="radio" name="{{id}}" value="true" {{#if value}}checked{{/if}}> yes
<input type="radio" name="{{id}}" value="false"{{#if (eq value false)}}checked{{/if}}> no
<span class="help-block">{{ help }}</span>
{{/if}}

{{#if choices}}
<select id="{{name}}" name="{{name}}" required class="form-control" {{{attributes}}}>
{{#choices}}<option value="{{value}}" {{#if selected}}selected{{/if}}>{{label}}</option>{{/choices}}
</select>
{{else if (eq inputType "checkbox")}}
<input type="{{inputType}}" id="{{name}}" name="{{name}}" class="form-control auto-width" value="{{default}}" placeholder="{{example}}" {{required}} {{{attributes}}}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{{{ on attributes is correct or? Not familiar with this syntax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came from here from where the code is adapted from https://github.com/YunoHost/yunohost-admin/blob/stretch-unstable/src/views/app/app_install.ms#L68

Tbh I don't know either, I think it's simply the **kwargs of python in mustache templates.

{{else}}
<input type="{{inputType}}" id="{{name}}" name="{{name}}" class="form-control" value="{{default}}" placeholder="{{example}}" {{required}} {{{attributes}}}>
{{/if}}

{{#if helpLink}}
<span class="help-block help-block--link">{{{helpLink}}}</span>
{{/if}}

{{#if example}}
<span class="help-block help-block--example">{{t 'form_input_example' example}}</span>
{{/if}}

{{#if helpText}}
<span class="help-block">{{{helpText}}}</span>
{{/if}}
</div>
</div>
{{/options}}
</ul></li>
</ul>
</div>
</div>
{{/sections}}

<br>
<div><button class="btn btn-primary" type="submit">Save</button></div>
</form>
</div>
</div>
</div>
{{/panel}}
<br>
<div><button class="btn btn-primary" type="submit">Save</button></div>
</form>
{{/config_panel}}
</div>

Expand Down
6 changes: 4 additions & 2 deletions src/views/app/app_info.ms
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
<dd>{{manifest.multi_instance}}</dd>
<dt>{{t 'install_time'}}</dt>
<dd>{{formatTime install_time day="numeric" month="long" year="numeric" hour="numeric" minute="numeric"}}</dd>
<dt>{{t 'url'}}</dt>
<dd><a href="https://{{settings.domain}}{{settings.path}}" target="_blank">https://{{settings.domain}}{{settings.path}}</a></dd>
{{#if settings.domain}}
<dt>{{t 'url'}}</dt>
<dd><a href="https://{{settings.domain}}{{settings.path}}" target="_blank">https://{{settings.domain}}{{settings.path}}</a></dd>
{{/if}}
</dl>
</div>
</div>
Expand Down