EventManager: add "on-demand" trigger

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-01-21 15:41:24 +01:00
parent 53f17b5715
commit 7b5bebc588
20 changed files with 410 additions and 49 deletions

View File

@@ -193,7 +193,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</div>
</div>
<div class="card bg-light mb-3 trigger trigger-fs trigger-provider trigger-schedule">
<div class="card bg-light mb-3 trigger trigger-fs trigger-provider trigger-schedule trigger-on-demand">
<div class="card-header">
<b>Name filters</b>
</div>
@@ -247,7 +247,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</div>
</div>
<div class="card bg-light mb-3 trigger trigger-fs trigger-schedule">
<div class="card bg-light mb-3 trigger trigger-fs trigger-schedule trigger-on-demand">
<div class="card-header">
<b>Group name filters</b>
</div>
@@ -301,7 +301,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</div>
</div>
<div class="card bg-light mb-3 trigger trigger-fs trigger-schedule trigger-provider">
<div class="card bg-light mb-3 trigger trigger-fs trigger-schedule trigger-provider trigger-on-demand">
<div class="card-header">
<b>Role name filters</b>
</div>
@@ -710,21 +710,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
$('.trigger').hide();
switch (val) {
case '1':
case 1:
$('.trigger-fs').show();
break;
case '2':
case 2:
$('.trigger-provider').show();
break;
case '3':
case 3:
$('.trigger-schedule').show();
break;
case '4':
case 4:
case '5':
case 5:
break;
case '6':
$('.trigger-on-demand').show();
break;
default:
console.log(`unsupported event trigger type: ${val}`);

View File

@@ -29,6 +29,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
<div id="errorTxt" class="card-body text-form-error"></div>
</div>
<div id="successMsg" class="card mb-4 border-left-success" style="display: none;">
<div id="successTxt" class="card-body"></div>
</div>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">View and manage event rules</h6>
@@ -38,6 +41,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<table class="table table-hover nowrap" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Status</th>
<th>Description</th>
@@ -48,6 +52,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<tbody>
{{range .Rules}}
<tr>
<td>{{.Trigger}}</td>
<td>{{.Name}}</td>
<td>{{if eq .Status 1 }}Active{{else}}Inactive{{end}}</td>
<td>{{.Description}}</td>
@@ -87,6 +92,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
</div>
</div>
</div>
<div class="modal fade" id="runModal" tabindex="-1" role="dialog" aria-labelledby="runModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="runModalLabel">
Confirmation required
</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">Do you want to execute the selected rule?</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">
Cancel
</button>
<a class="btn btn-warning" href="#" onclick="runAction()">
Run
</a>
</div>
</div>
</div>
</div>
{{end}}
{{define "extra_js"}}
@@ -102,11 +132,51 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
<script src="{{.StaticURL}}/vendor/datatables/ellipsis.js"></script>
<script type="text/javascript">
function runAction(){
let table = $('#dataTable').DataTable();
table.button('run:name').enable(false);
let name = table.row({ selected: true }).data()[1];
let path = '{{.EventRuleURL}}' + "/run/" + fixedEncodeURIComponent(name);
$('#runModal').modal('hide');
$.ajax({
url: path,
type: 'POST',
dataType: 'json',
headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
timeout: 15000,
success: function (result) {
$('#successTxt').text("Rule actions started");
$('#successMsg').show();
setTimeout(function () {
$('#successMsg').hide();
}, 8000);
},
error: function ($xhr, textStatus, errorThrown) {
var txt = "Unable to run the selected rule";
if ($xhr) {
var json = $xhr.responseJSON;
if (json) {
if (json.message){
txt += ": " + json.message;
} else {
txt += ": " + json.error;
}
}
}
$('#errorTxt').text(txt);
$('#errorMsg').show();
setTimeout(function () {
$('#errorMsg').hide();
}, 8000);
}
});
}
function deleteAction() {
var table = $('#dataTable').DataTable();
let table = $('#dataTable').DataTable();
table.button('delete:name').enable(false);
var name = table.row({ selected: true }).data()[0];
var path = '{{.EventRuleURL}}' + "/" + fixedEncodeURIComponent(name);
let name = table.row({ selected: true }).data()[1];
let path = '{{.EventRuleURL}}' + "/" + fixedEncodeURIComponent(name);
$('#deleteModal').modal('hide');
$.ajax({
url: path,
@@ -133,7 +203,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
$('#errorMsg').show();
setTimeout(function () {
$('#errorMsg').hide();
}, 5000);
}, 8000);
}
});
}
@@ -153,8 +223,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
name: 'edit',
titleAttr: "Edit",
action: function (e, dt, node, config) {
var name = table.row({ selected: true }).data()[0];
var path = '{{.EventRuleURL}}' + "/" + fixedEncodeURIComponent(name);
let name = table.row({ selected: true }).data()[1];
let path = '{{.EventRuleURL}}' + "/" + fixedEncodeURIComponent(name);
window.location.href = path;
},
enabled: false
@@ -170,6 +240,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
enabled: false
};
$.fn.dataTable.ext.buttons.run = {
text: '<i class="fas fa-play"></i>',
name: 'run',
titleAttr: "Run",
action: function (e, dt, node, config) {
$('#runModal').modal('show');
},
enabled: false
};
var table = $('#dataTable').DataTable({
"select": {
"style": "single",
@@ -186,15 +266,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
],
"columnDefs": [
{
"targets": [0,1],
"targets": [0],
"visible": false,
"searchable": false,
"className": "noVis"
},
{
"targets": [2],
"targets": [1,2],
"className": "noVis"
},
{
"targets": [3],
"visible": false
},
{
"targets": [4],
"targets": [5],
"render": $.fn.dataTable.render.ellipsis(100, true)
},
],
@@ -204,11 +290,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"language": {
"emptyTable": "No event rules defined"
},
"order": [[0, 'asc']]
"order": [[1, 'asc']]
});
new $.fn.dataTable.FixedHeader( table );
table.button().add(0,'run');
table.button().add(0,'delete');
table.button().add(0,'edit');
table.button().add(0,'add');
@@ -219,6 +306,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
var selectedRows = table.rows({ selected: true }).count();
table.button('delete:name').enable(selectedRows == 1);
table.button('edit:name').enable(selectedRows == 1);
if (selectedRows == 1){
table.button('run:name').enable(table.row({ selected: true }).data()[0] == 6);
} else {
table.button('run:name').enable(false);
}
});
});

View File

@@ -572,11 +572,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
function onEventChanged(val){
switch (val){
case '1':
case 1:
selectFsEvents();
break;
case '2':
case 2:
selectProviderEvents();
break;
default:

View File

@@ -204,15 +204,15 @@ function deleteAction() {
titleAttr: 'Quota Scan',
action: function (e, dt, node, config) {
dt.button('quota_scan:name').enable(false);
var folderName = dt.row({ selected: true }).data()[1];
var path = '{{.FolderQuotaScanURL}}'+ "/" + fixedEncodeURIComponent(folderName);
let folderName = dt.row({ selected: true }).data()[1];
let path = '{{.FolderQuotaScanURL}}'+ "/" + fixedEncodeURIComponent(folderName);
$.ajax({
url: path,
type: 'POST',
headers: {'X-CSRF-TOKEN' : '{{.CSRFToken}}'},
timeout: 15000,
success: function (result) {
dt.button('quota_scan:name').enable(true);
//dt.button('quota_scan:name').enable(true);
$('#successTxt').text("Quota scan started for the selected folder. Please reload the folders page to check when the scan ends");
$('#successMsg').show();
setTimeout(function () {