Files
olaper/templates/index.html
2025-07-26 04:41:47 +03:00

259 lines
13 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="{{ session.get('language', 'ru') }}">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ _('MyHoreca OLAPer') }}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<h1>{{ _('MyHoreca OLAP-to-GoogleSheets') }}</h1>
{% if current_user.is_authenticated %}
<div class="user-info">
{{ _('Logged in as:') }} <strong>{{ current_user.username }}</strong> |
<a href="{{ url_for('.logout') }}">{{ _('Logout') }}</a>
<span class="lang-switcher">
<a href="{{ url_for('.set_language', language='ru') }}" title="{{ _('Русский') }}">🇷🇺</a> /
<a href="{{ url_for('.set_language', language='en') }}" title="{{ _('English') }}">🇬🇧</a>
</span>
</div>
{% else %}
<div class="user-info">
<a href="{{ url_for('.login') }}">{{ _('Login') }}</a> |
<a href="{{ url_for('.register') }}">{{ _('Register') }}</a>
</div>
{% endif %}
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="flash-message flash-{{ category }}">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
{% if current_user.is_authenticated %}
<div class="container">
<!-- Секция RMS-сервера -->
<button type="button" class="collapsible">1. {{ _('Connection to RMS-server') }}</button>
<div class="content">
<h3>{{ _('RMS Server Configuration') }}</h3>
<p>
{% trans %}Enter the details for your RMS server API. This information is used to connect,
authenticate, and retrieve the list of available OLAP report presets.{% endtrans %}
</p>
<form action="{{ url_for('.configure_rms') }}" method="post">
<label for="host">{{ _('RMS-host (e.g., http://your-rms-api.com/resto):') }}</label>
<input type="text" id="host" name="host" value="{{ rms_config.get('host', '') }}" required /><br />
<label for="login">{{ _('API Login:') }}</label>
<input type="text" id="login" name="login" value="{{ rms_config.get('login', '') }}" required /><br />
<label for="password">{{ _('API Password:') }}</label>
<input type="password" id="password" name="password" value="" {% if not rms_config.password_is_set %}required{% endif %} /><br />
{% if rms_config.password_is_set %}
<small>{{ _('Password is saved. Enter a new one only if you need to change it.') }}</small><br/>
{% else %}
<small>{{ _('Enter the API password for your RMS server.') }}</small><br/>
{% endif %}
<button type="submit">{{ _('Check and Save RMS-config') }}</button>
</form>
{% if presets %}
<p><strong>{{ _('Status:') }}</strong> {% trans num=presets|length %}Successfully connected to RMS. Found %(num)s OLAP presets.{% endtrans %}</p>
{% elif rms_config.get('host') %}
<p><strong>{{ _('Status:') }}</strong> {{ _('RMS configuration saved. Presets not yet loaded or connection failed.') }}</p>
{% endif %}
</div>
<!-- Секция Google-таблиц -->
<button type="button" class="collapsible" {% if not rms_config.get('host') %}disabled title="{{ _('Configure RMS first') }}"{% endif %}>
2. {{ _('Google Sheets Configuration') }}
</button>
<div class="content">
<h3>{{ _('Google Sheets Configuration') }}</h3>
<p>
{% trans %}To allow the application to write to your Google Sheet, you need to provide
credentials for a Google Service Account. This account will act on behalf
of the application.{% endtrans %}
</p>
<p>
<strong>{{ _('How to get credentials:') }}</strong>
<br>1. {{ _('Go to Google Cloud Console.') }}
<br>2. {{ _('Create a new project or select an existing one.') }}
<br>3. {{ _('Enable the "Google Sheets API" and "Google Drive API" for the project.') }}
<br>4. {{ _('Go to "Credentials", click "Create Credentials", choose "Service Account".') }}
<br>5. {{ _('Give it a name and grant it the "Editor" role.') }}
<br>6. {{ _('Create a JSON key for the service account and download the file.') }}
<br>7. {% trans %}Share your target Google Sheet with the service account's email address (found in the downloaded JSON file, key `client_email`).{% endtrans %}
</p>
<form action="{{ url_for('.upload_credentials') }}" method="post" enctype="multipart/form-data">
<label for="cred_file">{{ _('Service Account Credentials (JSON file):') }}</label>
<input type="file" id="cred_file" name="cred_file" accept=".json" /><br />
{% if client_email %}
<p><strong>{{ _('Current Service Account Email:') }}</strong> <code>{{ client_email }}</code></p>
<small>{{ _('Upload a new file only if you need to change credentials.') }}</small><br/>
{% else %}
<small>{{ _('Upload the JSON file downloaded from Google Cloud Console.') }}</small><br/>
{% endif %}
<button type="submit">{{ _('Upload Credentials') }}</button>
</form>
<hr>
<p>
{% trans %}Enter the URL of the Google Sheet you want to use. The service account email
(shown above after uploading credentials) must have edit access to this sheet.{% endtrans %}
</p>
<form action="{{ url_for('.configure_google') }}" method="post">
<label for="sheet_url">{{ _('Google Sheet URL:') }}</label>
<input type="text" id="sheet_url" name="sheet_url" value="{{ google_config.get('sheet_url', '') }}" required placeholder="https://docs.google.com/spreadsheets/d/..."/>
<button type="submit" {% if not client_email %}disabled title="{{ _('Upload Service Account Credentials first') }}"{% endif %}>
{{ _('Connect Google Sheets') }}
</button>
{% if sheets %}
<p><strong>{{ _('Status:') }}</strong> {% trans num=sheets|length %}Successfully connected to Google Sheet. Found %(num)s worksheets.{% endtrans %}</p>
{% elif google_config.get('sheet_url') %}
<p><strong>{{ _('Status:') }}</strong> {{ _('Google Sheet URL saved. Worksheets not yet loaded or connection failed.') }}</p>
{% endif %}
</form>
</div>
<!-- Секция сопоставления листов-отчетов -->
<button type="button" class="collapsible" {% if not sheets or not presets %}disabled title="{{ _('Configure RMS and Google Sheets first') }}"{% endif %}>
3. {{ _('Mapping Sheets to OLAP Reports') }}
</button>
<div class="content">
<h3>{{ _('Map Worksheets to OLAP Reports') }}</h3>
<p>
{% trans %}Select which OLAP report from RMS should be rendered into each specific worksheet
(tab) in your Google Sheet.{% endtrans %}
</p>
{% if sheets and presets %}
<form action="{{ url_for('.mapping_set') }}" method="post">
<table>
<thead>
<tr>
<th>{{ _('Worksheet (Google Sheets)') }}</th>
<th>{{ _('OLAP-report (RMS)') }}</th>
</tr>
</thead>
<tbody>
{% for sheet in sheets %}
<tr>
<td>{{ sheet.title }}</td>
<td>
<select name="sheet_{{ sheet.id }}">
<option value="">-- {{ _('Not set') }} --</option>
{% for preset in presets %}
<option value="{{ preset['id'] }}" {% if mappings.get(sheet.title) == preset['id'] %}selected{% endif %}>
{{ preset['name'] }} ({{ preset['id'] }})
</option>
{% endfor %}
</select>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="submit">{{ _('Save Mappings') }}</button>
</form>
{% elif not sheets and not presets %}
<p>{{ _('Worksheets and OLAP presets are not loaded. Please configure RMS and Google Sheets first.') }}</p>
{% elif not sheets %}
<p>{{ _('Worksheets are not loaded. Check Google Sheets configuration.') }}</p>
{% elif not presets %}
<p>{{ _('OLAP presets are not loaded. Check RMS configuration.') }}</p>
{% endif %}
</div>
<!-- Секция отрисовки отчетов на листах -->
<button type="button" class="collapsible" {% if not mappings or mappings|length == 0 %}disabled title="{{ _('Configure Mappings first') }}"{% endif %}>
4. {{ _('Render Reports to Sheets') }}
</button>
<div class="content">
<h3>{{ _('Render Reports') }}</h3>
<p>
{% trans %}Select the date range and click "Render to sheet" for each mapping you wish to execute.
The application will retrieve the OLAP data from RMS for the selected report and period,
clear the corresponding worksheet in Google Sheets, and write the new data.{% endtrans %}
</p>
{% if mappings and mappings|length > 0 %}
<form action="{{ url_for('.render_olap') }}" method="post">
<label for="start_date">{{ _('From Date:') }}</label>
<input type="date" id="start_date" name="start_date" required /><br />
<label for="end_date">{{ _('To Date:') }}</label>
<input type="date" id="end_date" name="end_date" required /><br />
<table>
<thead>
<tr>
<th>{{ _('Worksheet') }}</th>
<th>{{ _('Mapped OLAP Report') }}</th>
<th>{{ _('Action') }}</th>
</tr>
</thead>
<tbody>
{% for sheet in sheets %}
{% set report_id = mappings.get(sheet.title) %}
{% if report_id %}
{% set matching_presets = presets | selectattr('id', 'equalto', report_id) | list %}
{% set preset_name = _('ID: ') + report_id %}
{% if matching_presets %}
{% set preset = matching_presets[0] %}
{% set preset_name = preset.get('name', _('Unnamed Preset')) %}
{% endif %}
<tr>
<td>{{ sheet.title }}</td>
<td>{{ preset_name }}</td>
<td>
<button type="submit" name="render_{{ sheet.title }}">
{{ _('Render to sheet') }}
</button>
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</form>
{% else %}
<p>{{ _('No mappings configured yet.') }}</p>
<p><small>{{ _('Please go to the "Mapping Sheets to OLAP Reports" section (Step 3) to set up mappings.') }}</small></p>
{% endif %}
</div>
</div> <!-- End Container -->
<script>
// JavaScript для сворачивания/разворачивания секций
var coll = document.getElementsByClassName("collapsible");
for (var i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function () {
// Не выполнять действие, если кнопка отключена
if (this.disabled) {
return;
}
this.classList.toggle("active");
var content = this.nextElementSibling;
// Если max-height установлен (т.е. секция открыта), то скрыть ее
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
// Иначе (секция закрыта), установить max-height равным высоте контента
// Это "раскроет" секцию с плавной анимацией
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
</script>
{% else %}
<p style="text-align: center; margin-top: 50px;">{{ _('Please,') }} <a href="{{ url_for('.login') }}">{{ _('login') }}</a> {{ _('or') }} <a href="{{ url_for('.register') }}">{{ _('register') }}</a></p>
{% endif %}
</body>
</html>