Commit 531b0c6c authored by colemanw's avatar colemanw Committed by Seamus Lee

CRM-20312 - Perform actions from within system status screen

parent 63809327
......@@ -39,13 +39,20 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component {
$messages = array();
$missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices();
if ($missingIndices) {
$messages[] = new CRM_Utils_Check_Message(
$msg = new CRM_Utils_Check_Message(
__FUNCTION__,
ts('You have missing indices on some tables. This may cause poor performance. Please run System.updateindexes from the api explorer'),
ts('You have missing indices on some tables. This may cause poor performance.'),
ts('Performance warning: Missing indices'),
\Psr\Log\LogLevel::WARNING,
'fa-server'
);
$msg->addAction(
ts('Update Incices'),
ts('Update all database indices now? This may take a few minutes and cause a noticeable performance lag for all users while running.'),
'api3',
array('System', 'updateindexes', array())
);
$messages[] = $msg;
}
return $messages;
}
......
......@@ -58,6 +58,12 @@ class CRM_Utils_Check_Message {
*/
private $help;
/**
* @var array
* actions which can be performed with this message
*/
private $actions = array();
/**
* @var string
* crm-i css class
......@@ -154,6 +160,27 @@ class CRM_Utils_Check_Message {
$this->help = $help;
}
/**
* Set optional additional actions text.
*
* @param string $title
* Text displayed on the status message as a link or button.
* @param string $confirmation
* Optional confirmation message before performing action
* @param string $type
* Currently supports: api3 or href
* @param array $params
* Params to be passed to CRM.api3 or CRM.url depending on type
*/
public function addAction($title, $confirmation, $type, $params) {
$this->actions[] = array(
'title' => $title,
'confirm' => $confirmation,
'type' => $type,
'params' => $params,
);
}
/**
* Set severity level
*
......@@ -195,6 +222,9 @@ class CRM_Utils_Check_Message {
if (!empty($this->help)) {
$array['help'] = $this->help;
}
if (!empty($this->actions)) {
$array['actions'] = $this->actions;
}
return $array;
}
......
......@@ -30,6 +30,9 @@
href="javascript:void(0)"
>
</a>
<div ng-if="status.actions" class="crm-status-item-actions">
<button ng-repeat="action in status.actions" ng-click="doAction(action)">{{ action.title }}</button>
</div>
</div>
</div>
</div>
......
......@@ -7,21 +7,26 @@
$scope.formatDate = CRM.utils.formatDate;
$scope.statuses = statusData.values;
// updates a status preference and refreshes status data
$scope.setPref = function(status, until, visible) {
// Use an array because it's important that one api call executes before the other
var apiCalls = [
['StatusPreference', 'create', {
"name": status.name,
"ignore_severity": visible ? 0 : status.severity,
"hush_until": until
}],
['System', 'check', {sequential: 1}]
];
// Refresh the list. Optionally execute api calls first.
function refresh(apiCalls) {
apiCalls = (apiCalls || []).concat([['System', 'check', {sequential: 1}]]);
$('#crm-status-list').block();
crmApi(apiCalls, true)
.then(function(result) {
$scope.statuses = result[1].values;
$scope.statuses = result[result.length - 1].values;
$('#crm-status-list').unblock();
});
}
// updates a status preference and refreshes status data
$scope.setPref = function(status, until, visible) {
refresh([
['StatusPreference', 'create', {
name: status.name,
ignore_severity: visible ? 0 : status.severity,
hush_until: until
}]
]);
};
$scope.countVisible = function(visibility) {
......@@ -29,6 +34,29 @@
return s.is_visible == visibility && s.severity_id >= 2;
}).length;
};
$scope.doAction = function(action) {
function run() {
switch (action.type) {
case 'href':
window.location = CRM.url(action.params.path, action.params.query, action.params.mode);
break;
case 'api3':
refresh([action.params]);
break;
}
}
if (action.confirm) {
CRM.confirm({
title: action.title,
message: action.confirm
}).on('crmConfirm:yes', run);
} else {
run();
}
};
});
})(angular, CRM.$, CRM._);
Markdown is supported
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