See #19 Import Export presets v1.

This commit is contained in:
Quentin “Storm1er” Decaunes 2019-06-04 09:37:03 +00:00 committed by Quentin DECAUNES
parent 72ee5c1b53
commit 81572aa960
3 changed files with 70 additions and 2 deletions

View File

@ -161,7 +161,17 @@
</p> </p>
</li> </li>
<li class="uk-margin-top uk-margin-bottom uk-container" id="presetTab"></li> <li class="uk-margin-top uk-margin-bottom uk-container">
<div id="presetTab"></div>
<p class="uk-margin">
<button class="uk-button uk-button-secondary" uk-toggle="target: #modal-export-preset" type="button" onClick="preset_export()">
Export
</button>
<button class="uk-button uk-button-secondary" uk-toggle="target: #modal-import-preset" type="button">
Import
</button>
</p>
</li>
<li class="uk-margin-top uk-margin-bottom uk-container"> <li class="uk-margin-top uk-margin-bottom uk-container">
<!-- <h3>Auto start with system:</h3> --> <!-- <h3>Auto start with system:</h3> -->
@ -232,6 +242,32 @@
</div> </div>
</div> </div>
<!-- Export preset modal -->
<div id="modal-export-preset" uk-modal>
<div class="uk-modal-dialog uk-modal-body">
<h2 class="uk-modal-title">Export presets</h2>
<p>This is the data to be used by Ryzen Controller to import presets.</p>
<div class="uk-margin">
<textarea class="uk-textarea" rows="5" id="modal-export-preset-textarea" readonly></textarea>
</div>
<button class="uk-button uk-button-secondary uk-modal-close" type="button">Close</button>
</div>
</div>
<!-- Import preset modal -->
<div id="modal-import-preset" uk-modal>
<div class="uk-modal-dialog uk-modal-body">
<h2 class="uk-modal-title">Import presets</h2>
<p>Paste here the presets and valid, your current presets will be merged with this.</p>
<div class="uk-margin">
<textarea class="uk-textarea" rows="5" id="modal-import-preset-textarea"></textarea>
</div>
<button class="uk-button uk-button-primary uk-modal-close" type="button" onClick="preset_import()">Import</button>
<button class="uk-button uk-button-secondary uk-modal-close" type="button">Close</button>
</div>
</div>
<script type="text/javascript" src="./js/preset.js"></script>
<script type="text/javascript" src="./js/methods.js"></script> <script type="text/javascript" src="./js/methods.js"></script>
<script type="text/javascript" src="./js/app.js"></script> <script type="text/javascript" src="./js/app.js"></script>
</body> </body>

View File

@ -516,13 +516,13 @@ function updatePresetList() {
content += ` content += `
<li class="uk-margin"> <li class="uk-margin">
<span class="uk-text-lead">${presetName}</span> <span class="uk-text-lead">${presetName}</span>
<i class="uk-text-small">${valueSummary}</i>
<button class="uk-button uk-button-danger uk-align-right" type="button" onClick="presetDeletion('${presetName}')"> <button class="uk-button uk-button-danger uk-align-right" type="button" onClick="presetDeletion('${presetName}')">
Delete Delete
</button> </button>
<button class="uk-button uk-button-primary uk-align-right" type="button" onClick="applyPreset('${presetName}')"> <button class="uk-button uk-button-primary uk-align-right" type="button" onClick="applyPreset('${presetName}')">
Apply Apply
</button> </button>
<i class="uk-text-small">${valueSummary}</i>
</li> </li>
`; `;
} }

32
js/preset.js Normal file
View File

@ -0,0 +1,32 @@
function preset_export() {
const modalTextArea = document.getElementById('modal-export-preset-textarea');
const settings = require('electron-settings');
var presets = settings.get('presets');
presets = JSON.stringify(presets);
modalTextArea.innerHTML = btoa(presets);
}
function preset_import() {
const modalTextArea = document.getElementById('modal-import-preset-textarea');
const settings = require('electron-settings');
var currentPresets = settings.get('presets');
var presetsToBeImported = atob(modalTextArea.value);
try {
presetsToBeImported = JSON.parse(presetsToBeImported);
} catch (e) {
notification('danger', 'Unable to import presets, malformed data.');
console.error(e);
return;
}
var updatedPresets = Object.assign(
{},
currentPresets,
presetsToBeImported
);
settings.set('presets', updatedPresets);
updatePresetList();
modalTextArea.innerText = '';
}