Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Nox committed Jun 13, 2023
1 parent e1ea374 commit 25b96f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 103 deletions.
83 changes: 0 additions & 83 deletions src/Controller/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
use itnovum\openITCOCKPIT\Core\Views\StatehistoryHost;
use itnovum\openITCOCKPIT\Core\Views\UserTime;
use itnovum\openITCOCKPIT\Database\PaginateOMat;
use itnovum\openITCOCKPIT\Filter\ChangelogsFilter;
use itnovum\openITCOCKPIT\Filter\HostFilter;
use itnovum\openITCOCKPIT\Grafana\GrafanaApiConfiguration;
use SLAModule\Model\Table\SlasTable;
Expand Down Expand Up @@ -2660,88 +2659,6 @@ public function hoststatus($uuid = null) {
$this->viewBuilder()->setOption('serialize', ['hoststatus']);
}

/**
* @param $id
* @return void
* @throws MethodNotAllowedException
* @throws NotFoundException
*/
public function changelog($id = null): void {
if ($this->isHtmlRequest()) {
return;
}
$session = $this->request->getSession();
$session->close();

if (!$this->isApiRequest()) {
throw new MethodNotAllowedException();
}

/** @var HostsTable $HostsTable */
$HostsTable = TableRegistry::getTableLocator()->get('Hosts');

if (!$HostsTable->existsById($id)) {
throw new NotFoundException(__('Invalid host'));
}

$host = $HostsTable->getHostById($id);

if (!$this->allowedByContainerId($host->getContainerIds(), false)) {
$this->render403();
return;
}

$filter = new ChangelogsFilter($this->request);

/** @var SystemsettingsTable $SystemsettingsTable */
$SystemsettingsTable = TableRegistry::getTableLocator()->get('Systemsettings');

$result = $SystemsettingsTable->getSystemsettingByKey('FRONTEND.HIDDEN_USER_IN_CHANGELOG');
$includeUser = $result->get('value') === '0';

$User = new User($this->getUser());
$UserTime = $User->getUserTime();
$todayMidnight = strtotime('today');

/** @var ChangelogsTable $ChangelogTable */
$ChangelogsTable = TableRegistry::getTableLocator()->get('Changelogs');
$changelogEntries = $ChangelogsTable->getChangelogByHostId($id, $includeUser, $filter);
foreach ($changelogEntries as $index => $change) {
$changeTimestamp = $change['created']->getTimestamp();
$changelogEntries[$index]['time'] = $UserTime->format($changeTimestamp);
$isToday = ($changeTimestamp > $todayMidnight);
if ($isToday) {
$changelogEntries[$index]['time'] = date('H:i:s', $changeTimestamp);
}

$dataUnserialized = unserialize($change['data']);
$dataUnserialized = $ChangelogsTable->replaceFieldValues($dataUnserialized);
$dataUnserialized = $ChangelogsTable->formatDataForView($dataUnserialized, $change['action']);
$dataUnserialized = $ChangelogsTable->replaceTableNames($dataUnserialized);

$changelogEntries[$index]['isToday'] = $isToday;
$changelogEntries[$index]['timeAgoInWords'] = $UserTime->timeAgoInWords($changeTimestamp, [
'end' => 0,
'accuracy' => [
'year' => 'month', // The format if years > 0 (default "day")
'month' => 'month', // The format if months > 0 (default "day")
'week' => 'day', // The format if weeks > 0 (default "day")
'day' => 'hour', // The format if weeks > 0 (default "hour")
'hour' => 'minute', // The format if hours > 0 (default "minute")
'minute' => 'minute', // The format if minutes > 0 (default "minute")
'second' => 'second', // The format if seconds > 0 (default "second")
]
]);
$changelogEntries[$index]['recordExists'] = $ChangelogsTable->recordExists($change['model'], $change['object_id']);
$changelogEntries[$index]['data_unserialized'] = $dataUnserialized;
$changelogEntries[$index]['color'] = $ChangelogsTable->getColorByAction($change['action']);
$changelogEntries[$index]['icon'] = $ChangelogsTable->getIconByAction($change['action']);
$changelogEntries[$index]['includeUser'] = $includeUser;
}
$this->set('all_changes', $changelogEntries);
$this->viewBuilder()->setOption('serialize', ['all_changes']);
}

/**
* @param int|null $id
* @throws MissingDbBackendException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
angular.module('openITCOCKPIT')
.controller('ChangelogsIndexController', function ($scope, $http, SortService, QueryStringService, $stateParams) {
.controller('ChangelogsIndexController', function($scope, $http, SortService, QueryStringService, $stateParams){

SortService.setSort(QueryStringService.getStateValue($stateParams, 'sort', 'Changelogs.id'));
SortService.setDirection(QueryStringService.getStateValue($stateParams, 'direction', 'desc'));
$scope.useScroll = true;
$scope.currentPage = 1;

/*** Filter Settings ***/
var defaultFilter = function () {
var defaultFilter = function(){
var now = new Date();

$scope.filter = {
Expand Down Expand Up @@ -53,29 +53,29 @@ angular.module('openITCOCKPIT')
$scope.showFilter = false;
$scope.init = true;

var getActionsFilter = function () {
var getActionsFilter = function(){
var selectedActions = [];
for (var actionName in $scope.filter.Actions) {
if ($scope.filter.Actions[actionName] === 1) {
for(var actionName in $scope.filter.Actions){
if($scope.filter.Actions[actionName] === 1){
selectedActions.push(actionName);
}
}

return selectedActions;
};

var getModelsFilter = function () {
var getModelsFilter = function(){
var selectedModels = [];
for (var modelName in $scope.filter.Models) {
if ($scope.filter.Models[modelName] === 1) {
for(var modelName in $scope.filter.Models){
if($scope.filter.Models[modelName] === 1){
selectedModels.push(modelName);
}
}

return selectedModels;
};

$scope.load = function () {
$scope.load = function(){
var params = {
'angular': true,
'scroll': $scope.useScroll,
Expand All @@ -91,30 +91,30 @@ angular.module('openITCOCKPIT')

$http.get("/changelogs/index.json", {
params: params
}).then(function (result) {
}).then(function(result){
$scope.changes = result.data.all_changes;
$scope.paging = result.data.paging;
$scope.scroll = result.data.scroll;
$scope.init = false;
});
};

$scope.triggerFilter = function () {
$scope.triggerFilter = function(){
$scope.showFilter = !$scope.showFilter === true;
};

$scope.resetFilter = function () {
$scope.resetFilter = function(){
defaultFilter();
};

$scope.changepage = function (page) {
if (page !== $scope.currentPage) {
$scope.changepage = function(page){
if(page !== $scope.currentPage){
$scope.currentPage = page;
$scope.load();
}
};

$scope.changeMode = function (val) {
$scope.changeMode = function(val){
$scope.useScroll = val;
$scope.load();
};
Expand All @@ -124,19 +124,19 @@ angular.module('openITCOCKPIT')
SortService.setCallback($scope.load);

//Watch on filter change
$scope.$watch('filter', function () {
$scope.$watch('filter', function(){
$scope.currentPage = 1;
$scope.load();
}, true);

$scope.$watch('from_time', function (dateObject) {
if (dateObject !== undefined && dateObject instanceof Date) {
$scope.$watch('from_time', function(dateObject){
if(dateObject !== undefined && dateObject instanceof Date){
var dateString = date('d.m.Y H:i', dateObject.getTime() / 1000);
$scope.filter.from = dateString;
}
});
$scope.$watch('to_time', function (dateObject) {
if (dateObject !== undefined && dateObject instanceof Date) {
$scope.$watch('to_time', function(dateObject){
if(dateObject !== undefined && dateObject instanceof Date){
var dateString = date('d.m.Y H:i', dateObject.getTime() / 1000);
$scope.filter.to = dateString;
}
Expand Down

0 comments on commit 25b96f1

Please sign in to comment.