Skip to content
Snippets Groups Projects
Commit 343ce0f4 authored by Freedom Coder's avatar Freedom Coder
Browse files

Merge branch 'export-import-schedule' into 'dev'

Export/Import custom schedule

See merge request !47
parents 5bca8598 289299b6
Branches dev
1 merge request!47Export/Import custom schedule
Pipeline #156 passed with stages
in 50 seconds
......@@ -19,7 +19,11 @@
"mySubgroupsDescription": "Filter schedule for your subgroup",
"mySubgroupsChange": "Change",
"autoScroll": "Auto scroll today",
"autoScrollDescription": "Scroll to today automatically"
"autoScrollDescription": "Scroll to today automatically",
"customSchedule": "Custom Schedule",
"customScheduleDescription": "Export and import custom schedule",
"exportSchedule": "Export",
"importSchedule": "Import"
},
"info": {
"nav": "Info",
......
......@@ -19,7 +19,11 @@
"mySubgroupsDescription": "Фильтр расписания для вашей подгруппы",
"mySubgroupsChange": "Изменить",
"autoScroll": "Автопролистывание",
"autoScrollDescription": "Автоматически пролистывать расписание до сегодняшнего дня"
"autoScrollDescription": "Автоматически пролистывать расписание до сегодняшнего дня",
"customSchedule": "Пользовательское расписание",
"customScheduleDescription": "Экспорт и импорт пользовательского расписания",
"exportSchedule": "Экспорт",
"importSchedule": "Импорт"
},
"info": {
"nav": "Инфо",
......
......@@ -6,7 +6,7 @@
import UpdateMeButton from "../components/UpdateMeButton.svelte";
import ThemePicker from "../components/ThemePicker.svelte";
import MySubgroupModal from "../components/MySubgroupModal.svelte";
import {preferences} from "../stores.ts";
import {preferences, customSchedule} from "../stores.ts";
import {_icon_literal} from "../utils/icon.js";
import {_} from "svelte-i18n";
// import tg from "../res/telegram.svg";
......@@ -14,6 +14,7 @@
const __unused = _icon_literal("check")
let scheduleImporter;
let ip;
let error = null;
let submitting = false;
......@@ -29,6 +30,29 @@
}
}
function exportSchedule() {
const exporter = document.createElement('a');
exporter.href = 'data:attachment/text,' + encodeURI(JSON.stringify($customSchedule));
exporter.target = '_blank';
exporter.download = 'customSchedule.json';
exporter.click();
}
async function importSchedule(file) {
try {
const text = await file.text();
const json = JSON.parse(text);
if (!Array.isArray(json.insertions) || !Array.isArray(json.deletions)) {
throw new Error("Invalid schedule format: 'insertions' or 'deletions' not found");
}
customSchedule.set(json);
} catch (error) {
console.error(error);
}
}
const dataPromise = apiGetStudentInfo();
let clientInfo = {};
clientInfo[$_('page.info.clientInfo.version', {default: 'App version'})]= APP_VERSION;
......@@ -67,5 +91,35 @@
</button>
</nav>
</div>
<div class="field" style="height: max-content;">
<nav class="no-padding">
<div class="max">
<h6>{$_('page.settings.customSchedule', {default: 'Custom Schedule'})}</h6>
<div>{$_('page.settings.customScheduleDescription', {default: 'Export and import custom schedule'})}</div>
</div>
<div class="row max wrap right-align">
<button on:click={exportSchedule}>
<MIcon>download</MIcon>
{$_('page.settings.exportSchedule', {default: 'Export'})}
</button>
<button on:click={scheduleImporter.click()}>
<MIcon>upload_file</MIcon>
{$_('page.settings.importSchedule', {default: 'Import'})}
<input
type="file"
style="display: none;"
accept="application/json"
bind:this={scheduleImporter}
on:change={(event) => {
const files = event.currentTarget.files;
if (files && files.length > 0) importSchedule(files.item(0));
scheduleImporter.value = "";
}}
/>
</button>
</div>
</nav>
</div>
</article>
</Navbar>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment