chg: [broods] Moved to use the new factories
parent
36cc3d82fe
commit
93f1467d5e
|
@ -14,10 +14,17 @@ class BroodsController extends AppController
|
||||||
$this->CRUD->index([
|
$this->CRUD->index([
|
||||||
'filters' => ['name', 'uuid', 'url', 'description', 'Organisations.id', 'trusted', 'pull', 'authkey'],
|
'filters' => ['name', 'uuid', 'url', 'description', 'Organisations.id', 'trusted', 'pull', 'authkey'],
|
||||||
'quickFilters' => ['name', 'uuid', 'description'],
|
'quickFilters' => ['name', 'uuid', 'description'],
|
||||||
|
'contextFilters' => [
|
||||||
|
'fields' => [
|
||||||
|
'pull',
|
||||||
|
'Organisations.name',
|
||||||
|
]
|
||||||
|
],
|
||||||
'contain' => ['Organisations']
|
'contain' => ['Organisations']
|
||||||
]);
|
]);
|
||||||
if ($this->ParamHandler->isRest()) {
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
return $this->restResponsePayload;
|
if (!empty($responsePayload)) {
|
||||||
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Sync');
|
$this->set('metaGroup', 'Sync');
|
||||||
}
|
}
|
||||||
|
@ -25,8 +32,9 @@ class BroodsController extends AppController
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$this->CRUD->add();
|
$this->CRUD->add();
|
||||||
if ($this->ParamHandler->isRest()) {
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
return $this->restResponsePayload;
|
if (!empty($responsePayload)) {
|
||||||
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Sync');
|
$this->set('metaGroup', 'Sync');
|
||||||
$this->loadModel('Organisations');
|
$this->loadModel('Organisations');
|
||||||
|
@ -41,8 +49,9 @@ class BroodsController extends AppController
|
||||||
public function view($id)
|
public function view($id)
|
||||||
{
|
{
|
||||||
$this->CRUD->view($id, ['contain' => ['Organisations']]);
|
$this->CRUD->view($id, ['contain' => ['Organisations']]);
|
||||||
if ($this->ParamHandler->isRest()) {
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
return $this->restResponsePayload;
|
if (!empty($responsePayload)) {
|
||||||
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Sync');
|
$this->set('metaGroup', 'Sync');
|
||||||
}
|
}
|
||||||
|
@ -50,8 +59,9 @@ class BroodsController extends AppController
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$this->CRUD->edit($id);
|
$this->CRUD->edit($id);
|
||||||
if ($this->ParamHandler->isRest()) {
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
return $this->restResponsePayload;
|
if (!empty($responsePayload)) {
|
||||||
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Sync');
|
$this->set('metaGroup', 'Sync');
|
||||||
$this->render('add');
|
$this->render('add');
|
||||||
|
@ -60,8 +70,9 @@ class BroodsController extends AppController
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
$this->CRUD->delete($id);
|
$this->CRUD->delete($id);
|
||||||
if ($this->ParamHandler->isRest()) {
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
return $this->restResponsePayload;
|
if (!empty($responsePayload)) {
|
||||||
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('metaGroup', 'Sync');
|
$this->set('metaGroup', 'Sync');
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,10 @@ class BroodsTable extends AppTable
|
||||||
'error' => __('Authentication failure'),
|
'error' => __('Authentication failure'),
|
||||||
'reason' => __('Invalid user credentials.')
|
'reason' => __('Invalid user credentials.')
|
||||||
],
|
],
|
||||||
|
404 => [
|
||||||
|
'error' => __('Not found'),
|
||||||
|
'reason' => __('Incorrect URL or proxy error')
|
||||||
|
],
|
||||||
405 => [
|
405 => [
|
||||||
'error' => __('Insufficient privileges'),
|
'error' => __('Insufficient privileges'),
|
||||||
'reason' => __('The remote user account doesn\'t have the required privileges to synchronise.')
|
'reason' => __('The remote user account doesn\'t have the required privileges to synchronise.')
|
||||||
|
|
|
@ -3,7 +3,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'data' => [
|
'data' => [
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'top_bar' => [
|
'top_bar' => [
|
||||||
'pull' => 'right',
|
|
||||||
'children' => [
|
'children' => [
|
||||||
[
|
[
|
||||||
'type' => 'simple',
|
'type' => 'simple',
|
||||||
|
@ -11,11 +10,14 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'data' => [
|
'data' => [
|
||||||
'type' => 'simple',
|
'type' => 'simple',
|
||||||
'text' => __('Add brood'),
|
'text' => __('Add brood'),
|
||||||
'class' => 'btn btn-primary',
|
|
||||||
'popover_url' => '/broods/add'
|
'popover_url' => '/broods/add'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'type' => 'context_filters',
|
||||||
|
'context_filters' => $filteringContexts
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'type' => 'search',
|
'type' => 'search',
|
||||||
'button' => __('Filter'),
|
'button' => __('Filter'),
|
||||||
|
@ -67,15 +69,15 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'icon' => 'eye'
|
'icon' => 'eye'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'onclick' => 'populateAndLoadModal(\'/broods/edit/[onclick_params_data_path]\');',
|
'open_modal' => '/broods/edit/[onclick_params_data_path]',
|
||||||
'onclick_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
'icon' => 'edit'
|
'icon' => 'edit'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'onclick' => 'populateAndLoadModal(\'/broods/delete/[onclick_params_data_path]\');',
|
'open_modal' => '/broods/delete/[onclick_params_data_path]',
|
||||||
'onclick_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
'icon' => 'trash'
|
'icon' => 'trash'
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -168,7 +168,7 @@ class AJAXApi {
|
||||||
this.provideFeedback({
|
this.provideFeedback({
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
title: 'There has been a problem with the operation',
|
title: 'There has been a problem with the operation',
|
||||||
body: error
|
body: error.message
|
||||||
}, true, skipFeedback);
|
}, true, skipFeedback);
|
||||||
toReturn = Promise.reject(error);
|
toReturn = Promise.reject(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -205,7 +205,7 @@ class AJAXApi {
|
||||||
this.provideFeedback({
|
this.provideFeedback({
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
title: 'There has been a problem with the operation',
|
title: 'There has been a problem with the operation',
|
||||||
body: error
|
body: error.message
|
||||||
}, true, skipFeedback);
|
}, true, skipFeedback);
|
||||||
toReturn = Promise.reject(error);
|
toReturn = Promise.reject(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -244,7 +244,7 @@ class AJAXApi {
|
||||||
this.provideFeedback({
|
this.provideFeedback({
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
title: 'There has been a problem with the operation',
|
title: 'There has been a problem with the operation',
|
||||||
body: error
|
body: error.message
|
||||||
}, true, skipFeedback);
|
}, true, skipFeedback);
|
||||||
toReturn = Promise.reject(error);
|
toReturn = Promise.reject(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -304,7 +304,7 @@ class AJAXApi {
|
||||||
this.provideFeedback({
|
this.provideFeedback({
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
title: 'There has been a problem with the operation',
|
title: 'There has been a problem with the operation',
|
||||||
body: error
|
body: error.message
|
||||||
}, true, feedbackShown);
|
}, true, feedbackShown);
|
||||||
toReturn = Promise.reject(error);
|
toReturn = Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ class AJAXApi {
|
||||||
this.provideFeedback({
|
this.provideFeedback({
|
||||||
variant: 'danger',
|
variant: 'danger',
|
||||||
title: 'There has been a problem with the operation',
|
title: 'There has been a problem with the operation',
|
||||||
body: error
|
body: error.message
|
||||||
}, true, feedbackShown);
|
}, true, feedbackShown);
|
||||||
toReturn = Promise.reject(error);
|
toReturn = Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,7 @@ class UIFactory {
|
||||||
promise.finally(() => {
|
promise.finally(() => {
|
||||||
loadingOverlay.hide()
|
loadingOverlay.hide()
|
||||||
})
|
})
|
||||||
|
return promise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,35 +27,51 @@ function executeStateDependencyChecks(dependenceSourceSelector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testConnection(id) {
|
function testConnection(id) {
|
||||||
$.ajax({
|
$container = $(`#connection_test_${id}`)
|
||||||
url: '/broods/testConnection/' + id,
|
UI.overlayUntilResolve(
|
||||||
type: 'GET',
|
$container[0],
|
||||||
beforeSend: function () {
|
AJAXApi.quickFetchJSON(`/broods/testConnection/${id}`),
|
||||||
$("#connection_test_" + id).html('Running test...');
|
{text: 'Running test'}
|
||||||
},
|
).then(result => {
|
||||||
error: function(){
|
const $testResult = attachTestConnectionResultHtml(result, $container)
|
||||||
$("#connection_test_" + id).html('<span class="red bold">Internal error</span>');
|
$(`#connection_test_${id}`).append($testResult)
|
||||||
},
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
.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
|
var UI
|
||||||
|
|
Loading…
Reference in New Issue