Closed anbu-squad closed 9 months ago
This is just a start to formulate conditions depending on the status of the miner
in fact, I’m thinking of adding a configuration change depending on the maximum hashrate for a certain period of time
as well as drop-down lists of miner versions depending on supported algorithms
Yes you would add a metod into ajax-actions.php
(add-rule
in your case I think) that adds or updates the rule to the database. Then in the endpoint.php you would check the rules and get the correct configuration to return to the miner.
If you want to do it like you have done it then I would suggest pre-populating that table with all the existing statuses, so that you can just run "update" in the database to change it.
Then you would do something like this in ajax-actions.php
(haven't tested it myself):
case 'add-rule':
$base->tableModify(getConn(), 'update', 'rules', 'rule', ['config'], ['status']);
$base->unam_echoSuccess("{$larr['Rule']} {$larr['has_been_updated']}.");
break;
(and in your form change ms_status
to status
and cf_name
to name
)
UnamWebPanel/assets/php/templates.php
function unamtStatusSelect($label, $id, $statusOptions, $selectAttributes = [], $optionAttributes = [])
{
// Создаем выпадающий список аналогично функции unamtSelect
$select = (!empty($label) ? "<label>{$label}</label>" : '') . "<select name='{$id}' id='{$id}'";
// Изменяем атрибут classes на нужное значение
$select .= " class='form-control select2 hook-select2 {$options['classes']}'";
if (!empty($selectAttributes)) {
foreach ($selectAttributes as $attr => $value) {
$select .= " {$attr}='{$value}'";
}
}
$select .= ">\n";
foreach ($statusOptions as $value => $text) {
$select .= "<option value='{$value}'";
if (!empty($optionAttributes)) {
foreach ($optionAttributes as $attr => $attrValue) {
$select .= " {$attr}='{$attrValue}'";
}
}
$select .= ">{$text}</option>\n";
}
$select .= "</select>\n";
return $select;
}
function generateConfigSelect($label, $id, $optionsArray, $selectedValue = null, $classes = '', $extras = ''){
$select = "<select name='{$id}' class='form-control select2 hook-select2 {$classes}' {$extras}>";
foreach ($optionsArray as $option) {
$value = $option['value'];
$text = $option['text'];
$selected = ($selectedValue !== null && $selectedValue == $value) ? 'selected' : '';
$select .= "<option value='{$value}' {$selected}>{$text}</option>";
}
$select .= "</select>";
return (!empty($label) ? "<label>{$label}</label>" : '') . $select;
}
UnamWebPanel/internalPages/configurationsAjax.php
$configOptionsForRules = [];
$conditionalConfigOptions = [];
foreach ($configs as $configdata) {
$configOptions = [
'value' => $configdata['cf_configID'],
'text' => $configdata['cf_name']
];
$configOptionsForRules[] = $configOptions;
$conditionalConfigOptions[] = $configOptions;
}
$statusOptions = [
'Stopped' => unamtMinerStatus(1),
'Active' => unamtMinerStatus(2),
'Idle' => unamtMinerStatus(3),
'Insufficient VRAN' => unamtMinerStatus(5),
'Error' => unamtMinerStatus(7),
];
echo unamtSection($larr['Configurations'],
unamtRow(
unamtCard('col-lg-6 col-xl-4', "<h4>Automated Configuration Rules</h4>", '',
unamtFormContainer('add-rule', 'api/ajax-actions.php',
unamtFormGroup(
unamtStatusSelect("Select Status", 'status', $statusOptions, ['classes'=>'nav-select'])
).
unamtFormGroup(
generateConfigSelect("Select Current Configuration", 'current_config_id', $configOptionsForRules, ['classes' => 'nav-select'])
).
unamtFormGroup(
generateConfigSelect("Select Conditional Configuration", 'conditional_config_id', $conditionalConfigOptions, ['classes' => 'nav-select'])
).
unamtFormGroup(
unamtSubmit("Add Rule", ['classes' => 'col btn-primary']) // Кнопку Add Rule переместили сюда
)
)
)
)
);
I updated the form to create rules based on status
however, I am having difficulty displaying the created rules on the configuration page, is it most likely better to do this as a table?
Sorry I thought I had posted my reply, my mistake. Displaying the created rules as a table would probably be easiest yes since I assume you would also want something like a delete button for the rules, so a table would be the easiest for that.
I try to add functionality to create the rules of automatic change of configurations depending on the status to start
Added status drop-down list function templates.php
echo unamtSection($larr['Configurations'], unamtRow( unamtCard('col-lg-6 col-xl-4', "
Automated Configuration Rules
", '', unamtFormContainer('add-rule', 'api/ajax-actions.php', unamtFormGroup( unamtStatusSelect("Select Status", 'ms_status', $statusOptions, ['classes'=>'nav-select']) ). unamtFormGroup( unamtSelect("Select Configuration", 'cf_name', $configoptions, ['classes'=>'nav-select', 'extras'=>"data-page='configurations'"]) ). unamtFormGroup( unamtHidden('cf_configID', getConfigValue('cf_configID')) ). unamtFormGroup( unamtSubmit("Add Rule", ['classes' => 'col btn-primary']) ) ). unamtFormContainer('config-update', 'api/ajax-actions.php', unamtFormGroup(unamtHidden('index', getConfigValue('cf_configID'))). unamtFormGroup(unamtTextarea("{$larr['Configuration']} JSON", 'data', getConfigValue('cf_data'), ['extras'=>''])) ) ) ) );CREATE TABLE rules ( rule_id INTEGER PRIMARY KEY AUTOINCREMENT, rule_status INTEGER, rule_config INTEGER DEFAULT 0 )