chg: [broods] Moved to use the new factories

pull/37/head
mokaddem 2021-01-14 12:42:05 +01:00
parent 36cc3d82fe
commit 93f1467d5e
6 changed files with 84 additions and 50 deletions

View File

@ -14,10 +14,17 @@ class BroodsController extends AppController
$this->CRUD->index([
'filters' => ['name', 'uuid', 'url', 'description', 'Organisations.id', 'trusted', 'pull', 'authkey'],
'quickFilters' => ['name', 'uuid', 'description'],
'contextFilters' => [
'fields' => [
'pull',
'Organisations.name',
]
],
'contain' => ['Organisations']
]);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
$responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) {
return $responsePayload;
}
$this->set('metaGroup', 'Sync');
}
@ -25,8 +32,9 @@ class BroodsController extends AppController
public function add()
{
$this->CRUD->add();
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
$responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) {
return $responsePayload;
}
$this->set('metaGroup', 'Sync');
$this->loadModel('Organisations');
@ -41,8 +49,9 @@ class BroodsController extends AppController
public function view($id)
{
$this->CRUD->view($id, ['contain' => ['Organisations']]);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
$responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) {
return $responsePayload;
}
$this->set('metaGroup', 'Sync');
}
@ -50,8 +59,9 @@ class BroodsController extends AppController
public function edit($id)
{
$this->CRUD->edit($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
$responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) {
return $responsePayload;
}
$this->set('metaGroup', 'Sync');
$this->render('add');
@ -60,8 +70,9 @@ class BroodsController extends AppController
public function delete($id)
{
$this->CRUD->delete($id);
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
$responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) {
return $responsePayload;
}
$this->set('metaGroup', 'Sync');
}

View File

@ -44,6 +44,10 @@ class BroodsTable extends AppTable
'error' => __('Authentication failure'),
'reason' => __('Invalid user credentials.')
],
404 => [
'error' => __('Not found'),
'reason' => __('Incorrect URL or proxy error')
],
405 => [
'error' => __('Insufficient privileges'),
'reason' => __('The remote user account doesn\'t have the required privileges to synchronise.')

View File

@ -3,7 +3,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'data' => $data,
'top_bar' => [
'pull' => 'right',
'children' => [
[
'type' => 'simple',
@ -11,11 +10,14 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'type' => 'simple',
'text' => __('Add brood'),
'class' => 'btn btn-primary',
'popover_url' => '/broods/add'
]
]
],
[
'type' => 'context_filters',
'context_filters' => $filteringContexts
],
[
'type' => 'search',
'button' => __('Filter'),
@ -67,15 +69,15 @@ echo $this->element('genericElements/IndexTable/index_table', [
'icon' => 'eye'
],
[
'onclick' => 'populateAndLoadModal(\'/broods/edit/[onclick_params_data_path]\');',
'onclick_params_data_path' => 'id',
'open_modal' => '/broods/edit/[onclick_params_data_path]',
'modal_params_data_path' => 'id',
'icon' => 'edit'
],
[
'onclick' => 'populateAndLoadModal(\'/broods/delete/[onclick_params_data_path]\');',
'onclick_params_data_path' => 'id',
'open_modal' => '/broods/delete/[onclick_params_data_path]',
'modal_params_data_path' => 'id',
'icon' => 'trash'
]
],
]
]
]);

View File

@ -168,7 +168,7 @@ class AJAXApi {
this.provideFeedback({
variant: 'danger',
title: 'There has been a problem with the operation',
body: error
body: error.message
}, true, skipFeedback);
toReturn = Promise.reject(error);
} finally {
@ -205,7 +205,7 @@ class AJAXApi {
this.provideFeedback({
variant: 'danger',
title: 'There has been a problem with the operation',
body: error
body: error.message
}, true, skipFeedback);
toReturn = Promise.reject(error);
} finally {
@ -244,7 +244,7 @@ class AJAXApi {
this.provideFeedback({
variant: 'danger',
title: 'There has been a problem with the operation',
body: error
body: error.message
}, true, skipFeedback);
toReturn = Promise.reject(error);
} finally {
@ -304,7 +304,7 @@ class AJAXApi {
this.provideFeedback({
variant: 'danger',
title: 'There has been a problem with the operation',
body: error
body: error.message
}, true, feedbackShown);
toReturn = Promise.reject(error);
}
@ -312,7 +312,7 @@ class AJAXApi {
this.provideFeedback({
variant: 'danger',
title: 'There has been a problem with the operation',
body: error
body: error.message
}, true, feedbackShown);
toReturn = Promise.reject(error);
}

View File

@ -120,6 +120,7 @@ class UIFactory {
promise.finally(() => {
loadingOverlay.hide()
})
return promise
}
}

View File

@ -27,35 +27,51 @@ function executeStateDependencyChecks(dependenceSourceSelector) {
}
function testConnection(id) {
$.ajax({
url: '/broods/testConnection/' + id,
type: 'GET',
beforeSend: function () {
$("#connection_test_" + id).html('Running test...');
},
error: function(){
$("#connection_test_" + id).html('<span class="red bold">Internal error</span>');
},
success: function(result) {
var html = '';
if (result['error']) {
html += '<strong>Status</strong>: <span class="text-danger">OK</span> (' + $("<span>").text(result['ping']).html() + ' ms)<br />';
html += '<strong>Status</strong>: <span class="text-danger">Error: ' + result['error'] + '</span>';
html += '<strong>Reason</strong>: <span class="text-danger">' + result['reason'] + '</span>';
} else {
html += '<strong>Status</strong>: <span class="text-success">OK</span> (' + $("<span>").text(result['ping']).html() + ' ms)<br />';
html += '<strong>Remote</strong>: ' + $("<span>").text(result['response']['application']).html() + ' v' + $("<span>").text(result['response']['version']).html() + '<br />';
html += '<strong>User</strong>: ' + $("<span>").text(result['response']['user']).html() + ' (' + $("<span>").text(result['response']['role']['name']).html() + ')' + '<br />';
var canSync = result['response']['role']['perm_admin'] || result['response']['role']['perm_sync'];
if (canSync) {
html += '<strong>Sync permission</strong>: <span class="text-success">Yes</span><br />';
} else {
html += '<strong>Sync permission</strong>: <span class="text-danger">No</span><br />';
}
}
$("#connection_test_" + id).html(html);
}
$container = $(`#connection_test_${id}`)
UI.overlayUntilResolve(
$container[0],
AJAXApi.quickFetchJSON(`/broods/testConnection/${id}`),
{text: 'Running test'}
).then(result => {
const $testResult = attachTestConnectionResultHtml(result, $container)
$(`#connection_test_${id}`).append($testResult)
})
.catch((error) => {
const $testResult = attachTestConnectionResultHtml(error.message, $container)
$(`#connection_test_${id}`).append($testResult)
})
}
function attachTestConnectionResultHtml(result, $container) {
function getKVHtml(key, value, valueClasses=[], extraValue='') {
return $('<div/>').append(
$('<strong/>').text(key + ': '),
$('<span/>').addClass(valueClasses).text(value),
$('<span/>').text(extraValue.length > 0 ? ` (${extraValue})` : '')
)
}
$container.find('div.tester-result').remove()
$testResultDiv = $('<div class="tester-result"></div>');
if (typeof result !== 'object') {
$testResultDiv.append(getKVHtml('Internal error', result, ['text-danger font-weight-bold']))
} else {
if (result['error']) {
$testResultDiv.append(
getKVHtml('Status', 'OK', ['text-danger'], `${result['ping']} ms`),
getKVHtml('Status', `Error: ${result['error']}`, ['text-danger']),
getKVHtml('Reason', result['reason'], ['text-danger'])
)
} else {
const canSync = result['response']['role']['perm_admin'] || result['response']['role']['perm_sync'];
$testResultDiv.append(
getKVHtml('Status', 'OK', ['text-success'], `${result['ping']} ms`),
getKVHtml('Remote', `${result['response']['application']} v${result['response']['version']}`),
getKVHtml('User', result['response']['user'], [], result['response']['role']['name']),
getKVHtml('Sync permission', (canSync ? 'Yes' : 'No'), [(canSync ? 'text-success' : 'text-danger')]),
)
}
}
return $testResultDiv
}
var UI