<div class="alert" data-bind="visible: octoprintUnconfigured()">{% trans %}
    Please configure the <strong>checkout folder</strong> of OctoPrint, otherwise
    this plugin won't be able to update it. Click on the <i class="fa fa-wrench"></i> button
    to do this. Also refer to the <a href="https://github.com/foosel/OctoPrint/wiki/Plugin:-Software-Update" target="_blank">Documentation</a>.
{% endtrans %}</div>
<div class="alert" data-bind="visible: !octoprintUnconfigured() && octoprintUnreleased()">{% trans %}
    <p>
        <strong>You are running a non-release version of OctoPrint but are tracking OctoPrint
        releases.</strong>
    </p><p>
        You probably want OctoPrint to track the matching development version instead.
        If you have a local OctoPrint checkout folder switched to another branch,
        <strong>simply switching over to "Commit" tracking</strong> will already
        take care of that. Otherwise please take a look at the
        <a href="https://github.com/foosel/OctoPrint/wiki/Plugin:-Software-Update" target="_blank">Documentation</a>.
    </p>
{% endtrans %}</div>
<div class="alert" data-bind="visible: !environmentSupported()">{% trans %}
    <p>
        <strong>This version of the Python environment is not supported for direct updates.</strong>
    </p>
    <p>
        To reduce the likelihood of running into update problems in outdated environments, the following minimal
        versions are required to use this updater to update OctoPrint or any installed plugins:
    </p>
{% endtrans %}
    <ul data-bind="foreach: environmentVersions">
        <li><span data-bind="text: name"></span>: <span data-bind="text: minimum"></span> ({{ _('you have') }}: <span data-bind="text: current"></span>)</li>
    </ul>
{% trans %}
    <p>
        Please take a look at <a href="https://faq.octoprint.org/unsupported-python-environment" target="_blank">this FAQ entry on how to proceed</a>.
    </p>
{% endtrans %}</div>

<div class="pull-right">
    <button class="btn btn-small" data-bind="click: function() { $root.showPluginSettings(); }" title="{{ _('Plugin Configuration') }}"><i class="fa fa-wrench"></i></button>
</div>

<h3>{{ _('Current versions') }}</h3>

<div id="settings_plugin_softwareupdate_updatelist">
    <table class="table table-striped table-hover table-condensed table-hover">
        <tbody data-bind="foreach: versions.paginatedItems">
        <tr data-bind="attr: {title: displayName}">
            <td class="settings_plugin_softwareupdate_column_update">
                <span data-bind="invisible: !updateAvailable"><i class="fa fa-bell-o" title="{{ _('Update available') }}"></i></span>
            </td>
            <td class="settings_plugin_softwareupdate_column_information">
                <a href="javascript:void(0)" data-bind="click: function() { $root.update(false, [$data]) }, visible: updateAvailable && updatePossible" class="btn btn-primary pull-right">{{ _('Update') }}</a>
                <strong data-bind="text: displayName"></strong>: <span data-bind="text: displayVersion"></span> <span data-bind="invisible: updatePossible"><i class="fa fa-exclamation-triangle" data-bind="css: {'fa-unlink': !online && information && information.needs_online, 'fa-exclamation-triangle': !(!online && information && information.needs_online)}, attr: {title: $root.iconTitleForEntry($data)}"></i></span><br>
                <small class="muted">
                    <span class="line">{{ _('Installed:') }} <span data-bind="text: information.local.name"></span></span>
                    <span class="line">{{ _('Available:') }} <span data-bind="text: information.remote.name"></span></span>
                    <span class="line" data-bind="visible: releaseNotes">{{ _('Release Notes:') }} <a data-bind="attr: {href: releaseNotes}, text: releaseNotes" target="_blank" rel="noreferrer noopener"></a></span>
                    <span class="line text-error" data-bind="visible: error, text: $root.errorTextForEntry($data)"></span>
                </small>
            </td>
        </tr>
        </tbody>
    </table>
</div>

<button class="btn btn-primary btn-block" data-bind="click: function() { $root.update(); }, enable: enableUpdate, css: {disabled: !enableUpdate}"><i class="fa fa-spinner fa-spin" data-bind="visible: updateInProgress"></i> {{ _('Update all') }}</button>
<button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, false, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fa fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Check for update now') }}</button>

<div>
    <div><small><a href="#" class="muted" onclick="$(this).children().toggleClass('fa-caret-right fa-caret-down').parent().parent().parent().next().slideToggle('fast')"><i class="fa fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
    <div class="hide">
        <small class="muted" style="display: block">{{ _('Last cache refresh:') }} <span data-bind="text: cacheTimestampText"></span></small>
        <button class="btn btn-block" data-bind="click: function() { $root.performCheck(true, true, true); }, enable: !checking(), css: {disabled: checking()}"><i class="fa fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force check for update (overrides cache used for update checks)') }}</button>
        <button class="btn btn-block btn-danger" data-bind="visible: CONFIG_DEBUG, click: function() { $root.update(true); }, enable: !checking(), css: {disabled: checking()}"><i class="fa fa-spinner fa-spin" data-bind="visible: checking"></i> {{ _('Force update now (even if no new versions are available)') }}</button>
    </div>
</div>

<div id="settings_plugin_softwareupdate_configurationdialog" class="modal hide fade">
    <div class="modal-header">
        <a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
        <h3>{{ _('Plugin Configuration') }}</h3>
    </div>
    <div class="modal-body">
        <form class="form-horizontal">
            {% include "snippets/plugins/softwareupdate/versionTracking.jinja2" %}
            {% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
            {% include "snippets/plugins/softwareupdate/releaseChannel.jinja2" %}
            <div class="control-group">
                <label class="control-label">{{ _('Version cache TTL') }}</label>
                <div class="controls">
                    <div class="input-append">
                        <input type="number" class="input-mini" data-bind="value: config_cacheTtl">
                        <span class="add-on">min</span>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <label class="checkbox">
                        <input type="checkbox" data-bind="checked: config_notifyUsers"> {{ _('Show update notifications to users') }}
                        <span class="help-block">{{ _('If you uncheck this, only logged in admins will see update notifications. Update notifications shown to users do not include the "Update now" button.') }}</span>
                    </label>
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">{{ _('Cancel') }}</button>
        <button class="btn btn-primary" data-bind="enable: enable_configSave, css: {disabled: !enable_configSave()}, click: savePluginSettings" aria-hidden="true">{{ _('Save') }}</button>
    </div>
</div>

<div id="settings_plugin_softwareupdate_workingdialog" class="modal hide fade">
    <div class="modal-header">
        <h3 data-bind="text: workingTitle"></h3>
    </div>
    <div class="modal-body">
        <pre id="settings_plugin_softwareupdate_workingdialog_output" class="pre-scrollable pre-output" style="height: 170px; display: none" data-bind="visible: loginState.isAdmin, foreach: loglines"><span data-bind="text: line, css: {stdout: stream == 'stdout', stderr: stream == 'stderr', call: stream == 'call', message: stream == 'message'}"></span></pre>
        <p style="display: none" data-bind="visible: !loginState.isAdmin() && $root.working()"><i class="fa fa-spinner fa-spin"></i> {{ _('Update in progress, please wait.') }}</p>
        <p style="display: none" data-bind="visible: !loginState.isAdmin() && !$root.working()">{{ _('Update done, please close this window.') }}</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" data-bind="enable: !$root.working()" aria-hidden="true">{{ _('Close') }}</button>
    </div>
</div>

