Skip to content

Commit

Permalink
Initial commit #570
Browse files Browse the repository at this point in the history
  • Loading branch information
oyeaussie committed Sep 1, 2024
1 parent 6542d8a commit 40e5f43
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 102 deletions.
64 changes: 42 additions & 22 deletions apps/Core/Components/Dashboards/DashboardsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,52 +27,78 @@ public function viewAction()
if (isset($this->getData()['id'])) {
if ($this->getData()['id'] != 0) {
$dashboardId = $this->getData()['id'];

$this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false);
}

$this->view->pick('dashboards/dashboards/dashboard');

return;
} else {
if (is_string($this->app['settings'])) {
$this->app['settings'] = $this->helper->decode($this->app['settings'], true);
}

if (isset($this->app['settings']['defaultDashboard'])) {
$dashboardId = $this->app['settings']['defaultDashboard'];
}
}

if (isset($dashboardId)) {
$dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false);

$this->view->setViewsDir($this->modules->views->getPhalconViewPath() . $this->getURI());
$this->view->isAppDefault = true;
}

$this->view->dashboard = $dashboard;
$this->view->dashboard = $this->basepackages->dashboards->getDashboardById($dashboardId, true, false);

$this->view->dashboards = $this->basepackages->dashboards->dashboards;

$this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree();

return;
}
}

}

/**
* @acl(name=add)
*/
public function addAction()
{
return;
$this->requestIsPost();

$this->basepackages->dashboards->addDashboard($this->postData());

$this->addResponse(
$this->basepackages->dashboards->packagesData->responseMessage,
$this->basepackages->dashboards->packagesData->responseCode
);
}

/**
* @acl(name=update)
*/
public function updateAction()
{
return;
$this->requestIsPost();

$this->basepackages->dashboards->updateDashboard($this->postData());

$this->addResponse(
$this->basepackages->dashboards->packagesData->responseMessage,
$this->basepackages->dashboards->packagesData->responseCode
);
}

/**
* @acl(name=remove)
*/
public function removeAction()
{
return;
$this->requestIsPost();

$this->basepackages->dashboards->removeDashboard($this->postData());

$this->addResponse(
$this->basepackages->dashboards->packagesData->responseMessage,
$this->basepackages->dashboards->packagesData->responseCode
);
}

/**
* @acl(name=add)
*/
public function addWidgetToDashboardAction()
{
$this->requestIsPost();
Expand All @@ -86,9 +112,6 @@ public function addWidgetToDashboardAction()
);
}

/**
* @acl(name=update)
*/
public function updateWidgetToDashboardAction()
{
$this->requestIsPost();
Expand All @@ -101,9 +124,6 @@ public function updateWidgetToDashboardAction()
);
}

/**
* @acl(name=remove)
*/
public function removeWidgetFromDashboardAction()
{
$this->requestIsPost();
Expand Down
27 changes: 0 additions & 27 deletions apps/Core/Views/Default/html/common/errors/forbidden.html

This file was deleted.

123 changes: 89 additions & 34 deletions apps/Core/Views/Default/html/dashboards/dashboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
</div>
</div>
<div class="row">
<div class="col">
<div class="col" id="grid-main">
<div class="grid-stack"></div>
</div>
</div>
Expand Down Expand Up @@ -60,22 +60,6 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
]
)}}
</div>
<div>
{{adminltetags.useTag('modal',
[
'component' : component,
'componentName' : componentName,
'componentId' : componentId,
'sectionId' : sectionId,
'modalId' : 'share-modal',
'modalBodyInclude' : 'dashboards/dashboards/share',
'modalSize' : 'lg',
'modalHeader' : true,
'modalFooter' : true,
'modalTitle' : '<i class="fa fas fa-fw fa-share"></i> SHARE DASHBOARD'
]
)}}
</div>
<script>
/* globals paginatedPNotify GridStack Swal BazContentFields */
var dataCollectionComponent, dataCollectionSection, dataCollectionSectionForm;
Expand Down Expand Up @@ -107,6 +91,8 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
dataCollectionComponent['{{componentId}}-{{sectionId}}']['grid'].destroy(removeDom);
}

$('#grid-main').html('<div class="grid-stack"></div>');
grid = null;
grid = dataCollectionComponent['{{componentId}}-{{sectionId}}']['grid'] = GridStack.init({
'draggable' :
{
Expand All @@ -116,16 +102,24 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
'animate' : false,
'sizeToContent' : true
});
}

initGrid();
grid.on('added', function(e, items) {
items.forEach(function(item) {
populateGridData(item);
});
initWidgetCardButtons();
});

grid.on('added', function(e, items) {
items.forEach(function(item) {
populateGridData(item);
grid.on('resizestart', function(e, el) {
$(el).find('.card-header').attr('hidden', true);
});
initWidgetCardButtons();
});

grid.on('resizestop', function(e, el) {
$(el).find('.card-header').attr('hidden', false);
});
}
initGrid();


function fixHeight(item) {
var itemHeight = $(item.el).find('.card')[0].offsetHeight + 20;//20 for padding
Expand All @@ -141,14 +135,6 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
initWidgetCardButtons();
});

grid.on('resizestart', function(e, el) {
$(el).find('.card-header').attr('hidden', true);
});

grid.on('resizestop', function(e, el) {
$(el).find('.card-header').attr('hidden', false);
});

function populateGridStructure() {
var postData = { };
postData[$('#security-token').attr('name')] = $('#security-token').val();
Expand Down Expand Up @@ -179,7 +165,11 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
} else if (response.responseCode === 1) {
paginatedPNotify('error', {'text' : 'Error loading widgets for dashboard. Please contact administrator.'});
} else if (response.responseCode === 2) {
paginatedPNotify('error', {'text' : response.responseMessage});
if (response.responseMessage.includes('CSRF')) {
paginatedPNotify('error', {'text' : response.responseMessage});
} else {
paginatedPNotify('info', {'text' : response.responseMessage});
}
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', false);
}
$('#{{componentId}}-{{sectionId}}-dashboard-loader').attr('hidden', true);
Expand Down Expand Up @@ -283,7 +273,6 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
'fieldId' : "{{componentId}}-{{sectionId}}-worldclock-" + $(this).parents('.grid-stack-item').attr('gs-id') + "-clocks"
});
});

}

function addWidgetToGrid(widgetsData) {
Expand Down Expand Up @@ -484,6 +473,72 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
$('#{{componentId}}-{{sectionId}}-widget-info').empty();
$('#{{componentId}}-{{sectionId}}-widget-no-widgets').attr('hidden', false);
});

function initDashboardButtons() {
var href = $('#{{componentId}}-{{sectionId}}-edit').attr('href');
$('#{{componentId}}-{{sectionId}}-edit').attr(
'href',
href +
$('#{{componentId}}-{{sectionId}}-dashboards').select2().val()
);

$('#{{componentId}}-{{sectionId}}-dashboards').on('select2:select', function(e) {
$('#{{componentId}}-{{sectionId}}-edit').attr(
'href',
href +
e.params.data.id
);
$('#{{componentId}}-{{sectionId}}-dashboard-loader').attr('hidden', false);
initGrid();
populateGridStructure();
});

$('#{{componentId}}-{{sectionId}}-remove').click(function(e) {
e.preventDefault();

Swal.fire({
title : '<span class="text-danger"> Remove dashboard?</span>',
icon : 'question',
background : 'rgba(0,0,0,.8)',
backdrop : 'rgba(0,0,0,.6)',
buttonsStyling : false,
confirmButtonText : 'Remove',
customClass : {
'confirmButton' : 'btn btn-danger text-uppercase',
'cancelButton' : 'ml-2 btn btn-secondary text-uppercase',
},
showCancelButton : true,
keydownListenerCapture : true,
allowOutsideClick : true,
allowEscapeKey : true,
didOpen : function() {
swalSound.play();
}
}).then((result) => {
if (result.value) {
var postData = { };
postData[$('#security-token').attr('name')] = $('#security-token').val();
postData['id'] = $('#{{componentId}}-{{sectionId}}-dashboards').select2().val();

$.post('{{links.url("dashboards/remove")}}', postData, function(response) {
if (response.tokenKey && response.token) {
$("#security-token").attr("name", response.tokenKey);
$("#security-token").val(response.token);
}

if (response.responseCode === 0) {
paginatedPNotify('success', {'text' : response.responseMessage});

return;
}

paginatedPNotify('error', {'text' : response.responseMessage});
}, 'json');
}
});
});
}
initDashboardButtons();
}
});
</script>
34 changes: 34 additions & 0 deletions apps/Core/Views/Default/html/dashboards/dashboards/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% if dashboard['id'] is defined %}
{% set dashboardId = dashboard['id'] %}
{% set title = 'Dashboard (' ~ dashboard['name'] ~ ')' %}
{% else %}
{% set dashboardId = '' %}
{% set title = 'New Dashboard' %}
{% endif %}
{{adminltetags.useTag('content',
[
'component' : component,
'componentName' : componentName,
'componentId' : componentId,
'parentComponentId' : parent,
'sectionId' : 'main',
'contentType' : 'sectionWithForm',
'cardHeader' : true,
'cardFooter' : true,
'cardType' : 'primary',
'cardIcon' : 'dashboard',
'cardTitle' : title,
'cardAdditionalClass' : 'rounded-0',
'cardBodyInclude' : 'dashboards/dashboards/form',
'formButtons' :
[
'updateButtonId' : dashboardId,
'addActionUrl' : 'dashboards/add',
'addSuccessRedirectUrl' : 'dashboards',
'updateActionUrl' : 'dashboards/update',
'updateSuccessRedirectUrl' : 'dashboards',
'cancelActionUrl' : 'dashboards',
'closeActionUrl' : 'dashboards'
]
]
)}}
Loading

0 comments on commit 40e5f43

Please sign in to comment.