Skip to content

Commit

Permalink
update #570
Browse files Browse the repository at this point in the history
- Added shared for dashboard. added remove for dashboard
  • Loading branch information
oyeaussie committed Sep 2, 2024
1 parent f68b3d4 commit 0ea5ba0
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 30 deletions.
139 changes: 132 additions & 7 deletions apps/Core/Components/Dashboards/DashboardsComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,103 @@ public function viewAction()
return $this->basepackages->widgets->getWidget($this->getData()['wid'], 'content', $dashboardWidget)['content'];
}
} else {
if (is_string($this->app['settings'])) {
$this->app['settings'] = $this->helper->decode($this->app['settings'], true);
}

if (isset($this->getData()['id'])) {
$this->view->sharedAccounts = [];

if ($this->getData()['id'] != 0) {
$dashboardId = $this->getData()['id'];

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

if (isset($this->app['settings']['defaultDashboard'])) {
if ($this->app['settings']['defaultDashboard'] == $dashboard['id']) {
$dashboard['is_app_default'] = true;
}

$this->view->isAppDefault = true;
}

if (isset($dashboard['shared']) && is_string($dashboard['shared'])) {
$dashboard['shared'] = $this->helper->decode($dashboard['shared'], true);
}

if ($dashboard['shared'] && count($dashboard['shared']) > 0) {
$sharedAccounts = [];

foreach ($dashboard['shared'] as $accountId) {
$account = $this->basepackages->accounts->getAccountById($accountId);

if ($account) {
$sharedAccounts[] =
['id' => $account['id'], 'email' => $account['email']];
}
}

$this->view->sharedAccounts = $sharedAccounts;
} else {
$dashboard['shared'] = [];
}

$this->view->dashboard = $dashboard;
}

$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'];
}

$this->view->isAppDefault = true;
$dashboards = $this->basepackages->dashboards->dashboards;
$dashboards = msort($dashboards, 'is_default');

if ($this->access->auth->account()) {
foreach ($dashboards as $dashboardKey => &$dashboard) {
//Check app default dashboard
if ($dashboard['id'] == $dashboardId) {
$dashboard['name'] = $dashboard['name'] . ' (App Default)';

continue;
}

//Check shared
$isShared = false;
if ($dashboard['shared']) {
if (is_string($dashboard['shared'])) {
$dashboard['shared'] = $this->helper->decode($dashboard['shared'], true);
}

if (in_array($this->access->auth->account()['id'], $dashboard['shared'])) {
$dashboard['name'] = $dashboard['name'] . ' (Shared By ' . $this->basepackages->accounts->getAccountById($dashboard['created_by'])['email'] . ')';
$isShared = true;
}
}

//Check Creator
if ($dashboard['created_by'] != $this->access->auth->account()['id'] &&
!$isShared
) {
unset($dashboards[$dashboardKey]);
}

//Default
if ($dashboard['is_default'] && !$isShared) {
$dashboardId = $dashboard['id'];

$dashboard['name'] = $dashboard['name'] . ' (User Default)';
}
}
}

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

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

$this->view->widgetsTree = $this->basepackages->widgets->getWidgetsTree();
}
Expand Down Expand Up @@ -148,4 +221,56 @@ public function getDashboardWidgetsAction()
$this->basepackages->dashboards->packagesData->responseData
);
}

public function searchAccountAction()
{
$this->requestIsPost();

if ($this->postData()['search']) {
$searchQuery = $this->postData()['search'];

if (strlen($searchQuery) < 3) {
return;
}

$searchAccounts = $this->basepackages->accounts->searchAccountInternal($searchQuery);

if ($searchAccounts) {
$currentAccount = $this->access->auth->account();

if ($currentAccount) {
foreach ($searchAccounts as $accountKey => &$account) {
if ($account['id'] == $currentAccount['id']) {
unset($accounts[$accountKey]);
continue;
}

$profile = $this->basepackages->profiles->getProfile($account['id']);

$account['name'] = $profile['full_name'];
}

$this->addResponse(
$this->basepackages->accounts->packagesData->responseMessage,
$this->basepackages->accounts->packagesData->responseCode,
['accounts' => $searchAccounts]
);
} else {
$this->addResponse(
$this->basepackages->accounts->packagesData->responseMessage,
$this->basepackages->accounts->packagesData->responseCode,
['accounts' => $searchAccounts]
);
}
} else {
$this->addResponse(
$this->basepackages->accounts->packagesData->responseMessage,
$this->basepackages->accounts->packagesData->responseCode,
['accounts' => []]
);
}
} else {
$this->addResponse('search query missing', 1);
}
}
}
52 changes: 37 additions & 15 deletions apps/Core/Views/Default/html/dashboards/dashboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
)}}
</div>
<script>
/* globals paginatedPNotify GridStack Swal BazContentFields */
/* globals paginatedPNotify GridStack Swal BazContentFields Pace BazCore BazContentLoader */
var dataCollectionComponent, dataCollectionSection, dataCollectionSectionForm;

if (!window['dataCollection']['{{componentId}}']) {
Expand Down Expand Up @@ -152,12 +152,16 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
addWidgetToGrid(response.responseData.widgetsData[widget]);
}

if (isOwner) {
if (isOwner && grid.save().length > 0) {
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', false);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', false);
} else {
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', true);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', true);
}
grid.enableMove(false);
grid.enableResize(false);
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', true);
} else {
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', false);
paginatedPNotify('error', {'text' : 'Error loading widgets for dashboard. Please contact administrator.'});
Expand All @@ -171,6 +175,7 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
paginatedPNotify('info', {'text' : response.responseMessage});
}
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', false);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', true);
}
$('#{{componentId}}-{{sectionId}}-dashboard-loader').attr('hidden', true);
}, 'json');
Expand All @@ -189,14 +194,16 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d

var url = '{{links.url("dashboards/q/widgets/content/id/' + item.id + '/did/' + item.dashboard_id + '/wid/' + item.widget_id + '")}}';
$(item.el).find('.card-body').load(url, null, function (response, status, xhr) {
if (xhr.getResponseHeader('tokenKey') && xhr.getResponseHeader('token')) {
$('#security-token').attr('name', xhr.getResponseHeader('tokenKey'));
$('#security-token').val(xhr.getResponseHeader('token'));
}
fixHeight(item);
addToken(xhr);
});
}

function addToken(xhr) {
$('#security-token').attr('name', xhr.getResponseHeader('tokenKey'));
$('#security-token').val(xhr.getResponseHeader('token'));
}

function initWidgetCardButtons() {
$('.btn-tool-widgetRemove').off();
$('.btn-tool-widgetRemove').click(function() {
Expand Down Expand Up @@ -373,9 +380,12 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d

addWidgetToGrid(response.responseData);
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', true);
if (isOwner) {
if (isOwner && grid.save().length > 0) {
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', false);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', false);
} else {
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', true);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', true);
}

$('#{{componentId}}-{{sectionId}}-modal-button-add').attr('disabled', true);
Expand Down Expand Up @@ -443,10 +453,8 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d

if (grid.save().length === 0) {
$('#{{componentId}}-{{sectionId}}-no-widgets').attr('hidden', false);
if (isOwner) {
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', true);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', true);
}
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('disabled', true);
$('#{{componentId}}-{{sectionId}}-edit-widgets').attr('hidden', true);
} else {
var postData = { };
postData[$('#security-token').attr('name')] = $('#security-token').val();
Expand Down Expand Up @@ -526,13 +534,27 @@ <h6><i class="fa fa-fw fa-info-circle text-info"></i> No widgets added to this d
$("#security-token").val(response.token);
}

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

return;
BazContentLoader.loadAjax($('#{{componentId}}-{{sectionId}}-remove'), {
ajaxBefore : function () {
Pace.restart();
$("#baz-content").empty();
$("#loader").attr('hidden', false);
},
ajaxFinished : function () {
BazCore.updateBreadcrumb();
$("#loader").attr('hidden', true);
},
ajaxError : function () {
$("#loader").attr('hidden', true);
BazCore.updateBreadcrumb();
}
});
} else {
paginatedPNotify('error', {'text' : response.responseMessage});
}

paginatedPNotify('error', {'text' : response.responseMessage});
}, 'json');
}
});
Expand Down
Loading

0 comments on commit 0ea5ba0

Please sign in to comment.