First iteration back button

This commit is contained in:
JuanCarlos 2019-01-16 16:16:00 +01:00
parent abf191a0d6
commit 6e6cce3820
12 changed files with 90 additions and 36 deletions

View File

@ -34,7 +34,7 @@ const app = uiModules.get('app/wazuh', ['ngCookies', 'ngMaterial']);
app.config([
'$compileProvider',
function($compileProvider) {
function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(
/^\s*(https?|ftp|mailto|data|blob):/
);
@ -43,11 +43,38 @@ app.config([
app.config([
'$httpProvider',
function($httpProvider) {
function ($httpProvider) {
$httpProvider.useApplyAsync(true);
}
]);
app.run(function ($rootScope, $route, $location, appState) {
appState.setNavigation(false);
$rootScope.reloaded = false;
$rootScope.$on('$routeChangeSuccess', () => {
$rootScope.prevLocation = $location.path();
if (!$rootScope.reloaded) {
appState.setNavigation(true);
} else {
$rootScope.reloaded = false;
}
});
$rootScope.$on('$locationChangeSuccess', () => {
$rootScope.currLocation = $location.path();
if (!appState.getNavigation() && $rootScope.prevLocation &&
$rootScope.currLocation !== '/wazuh-discover/' &&
$rootScope.currLocation !== '/overview/' &&
$rootScope.currLocation !== '/agents') {
if ($rootScope.currLocation === $rootScope.prevLocation) {
$rootScope.reloaded = true;
$route.reload();
}
}
appState.setNavigation(false);
});
});
// Font Awesome, Kibana UI framework and others
import './utils/fontawesome/css/font-awesome.min.css';
@ -72,6 +99,7 @@ import './services';
import './controllers';
import './factories';
import './directives';
import { runInContext } from 'vm';
// Added due to Kibana 6.3.0. Do not modify.
uiModules.get('kibana').provider('dashboardConfig', () => {

View File

@ -50,6 +50,7 @@ export class ConfigurationController {
sections,
navigate = true
) => {
this.appState.setNavigation(true);
this.$scope.navigate = navigate;
try {
this.$scope.configSubTab = JSON.stringify({
@ -77,6 +78,7 @@ export class ConfigurationController {
* Navigate to woodle
*/
this.$scope.switchWodle = (wodleName, navigate = true) => {
this.appState.setNavigation(true);
this.$scope.navigate = navigate;
this.$scope.configWodle = wodleName;
if (!this.$location.search().configWodle) {
@ -89,6 +91,7 @@ export class ConfigurationController {
* Navigate to configuration
*/
this.$scope.switchConfigurationTab = (configurationTab, navigate) => {
this.appState.setNavigation(true);
this.$scope.navigate = navigate;
this.configurationHandler.switchConfigurationTab(
configurationTab,

View File

@ -133,6 +133,7 @@ export function GroupsController(
$scope.totalFiles = count.data.data.totalItems;
$scope.fileViewer = false;
$scope.currentGroup = group;
$location.search('currentGroup', group.name);
$scope.$emit('setCurrentGroup',{currentGroup: $scope.currentGroup})
$scope.fileViewer = false;
if (!$scope.$$phase) $scope.$digest();

View File

@ -18,7 +18,7 @@ export class ManagementController {
* @param {*} $location
* @param {*} shareAgent
*/
constructor($scope, $location, shareAgent) {
constructor($scope, $location, shareAgent, appState) {
this.$scope = $scope;
this.$location = $location;
this.shareAgent = shareAgent;
@ -28,12 +28,13 @@ export class ManagementController {
this.wazuhManagementTabs = ['ruleset', 'groups'];
this.statusReportsTabs = ['status', 'logs', 'reporting', 'monitoring'];
this.currentGroup = false;
this.$scope.$on('setCurrentGroup',(ev,params) => {
this.$scope.$on('setCurrentGroup', (ev, params) => {
this.currentGroup = (params || {}).currentGroup || false;
})
this.$scope.$on('removeCurrentGroup',() => {
this.$scope.$on('removeCurrentGroup', () => {
this.currentGroup = false;
})
this.appState = appState;
}
/**
@ -65,7 +66,10 @@ export class ManagementController {
* This switch to a selected tab
* @param {String} tab
*/
switchTab(tab) {
switchTab(tab, setNav = false) {
if (setNav) {
this.appState.setNavigation(true);
}
this.tab = tab;
if (this.tab === 'groups') {

View File

@ -103,7 +103,10 @@ export class SettingsController {
* This switch to a selected tab
* @param {Object} tab
*/
switchTab(tab) {
switchTab(tab, setNav = false) {
if (setNav) {
this.appState.setNavigation(true);
}
this.tab = tab;
this.$location.search('tab', this.tab);
}
@ -192,7 +195,7 @@ export class SettingsController {
this.errorHandler.info(
`API ${
this.apiEntries[index]._source.cluster_info.manager
this.apiEntries[index]._source.cluster_info.manager
} set as default`,
'Settings'
);

View File

@ -16,14 +16,15 @@ export function clickAction(
instance,
shareAgent,
$location,
$scope
$scope,
appState
) {
appState.setNavigation(true);
if (
instance.path === '/agents' ||
new RegExp(/^\/agents\/groups\/[a-zA-Z0-9_\-.]*$/).test(instance.path)
) {
shareAgent.setAgent(item);
// Check location target and go to that path
switch (openAction) {
case 'configuration':

View File

@ -90,7 +90,7 @@ app.directive('wzTable', function() {
* Common functions
*/
$scope.clickAction = (item, openAction = false) =>
clickAction(item, openAction, instance, shareAgent, $location, $scope);
clickAction(item, openAction, instance, shareAgent, $location, $scope, appState);
const fetch = async (options = {}) => {
try {

View File

@ -20,8 +20,9 @@ class WzWelcomeCard {
private template: string;
private restrict: string;
private scope: object;
private appState: any;
constructor() {
constructor(appState: any) {
this.restrict = 'E';
this.scope = {
title: '=title',
@ -33,11 +34,15 @@ class WzWelcomeCard {
};
this.replace = true;
this.template = template;
this.appState = appState;
}
link(scope, elm, attrs) {
scope.callSwitchTab = () => scope.switchTab();
scope.callSwitchTab = () => {
this.appState.setNavigation(true);
scope.switchTab()
};
}
}
app.directive('wzWelcomeCard',() => new WzWelcomeCard());
app.directive('wzWelcomeCard',(appState: any) => new WzWelcomeCard(appState));

View File

@ -18,6 +18,7 @@ export class AppState {
constructor($cookies, $window) {
this.$cookies = $cookies;
this.$window = $window;
this.navigate = false;
}
//Extensions setters and getters
@ -134,4 +135,12 @@ export class AppState {
removeSessionStorageItem(key) {
this.$window.sessionStorage.removeItem(key);
}
setNavigation(state) {
this.navigate = state;
}
getNavigation() {
return this.navigate;
}
}

View File

@ -10,12 +10,12 @@
<div layout="row" layout-padding>
<!-- If you're not on the Welcome tab, show a functional breadcrumb -->
<div ng-if="mctrl.tab !== 'welcome' && !mctrl.currentGroup">
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('welcome')">Management</span>
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('welcome', true)">Management</span>
<span> / {{ mctrl.tabNames[mctrl.tab] }}</span>
</div>
<div ng-if="mctrl.tab === 'groups' && mctrl.currentGroup && mctrl.currentGroup.name">
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('welcome')">Management</span>
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('groups')"> / {{ mctrl.tabNames[mctrl.tab] }}</span>
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('welcome', true)">Management</span>
<span class="wz-text-link cursor-pointer" ng-click="mctrl.switchTab('groups', true)"> / {{ mctrl.tabNames[mctrl.tab] }}</span>
<span> / {{ mctrl.currentGroup.name }} </span>
</div>
<!-- If you're on the Welcome tab, show a blank, simple breadcrumb -->
@ -34,8 +34,8 @@
ng-show="mctrl.tab !== 'welcome'"
md-selected-nav-item="mctrl.tab"
nav-bar-aria-label="Wazuh management navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('ruleset')" name="ruleset">Ruleset</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('groups')" name="groups">Groups</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('ruleset', true)" name="ruleset">Ruleset</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('groups', true)" name="groups">Groups</md-nav-item>
</md-nav-bar>
<!-- End Wazuh management navigation bar -->
@ -46,9 +46,9 @@
ng-show="mctrl.tab !== 'welcome'"
md-selected-nav-item="mctrl.tab"
nav-bar-aria-label="Status and reports navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('status')" name="status">Status</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('logs')" name="logs">Logs</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('monitoring')" name="monitoring">Cluster</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('reporting')" name="reporting">Reporting</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('status', true)" name="status">Status</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('logs', true)" name="logs">Logs</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('monitoring', true)" name="monitoring">Cluster</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="mctrl.switchTab('reporting', true)" name="reporting">Reporting</md-nav-item>
</md-nav-bar>
<!-- End Status and reports navigation bar -->

View File

@ -17,17 +17,17 @@
<div class="euiFlexGrid euiFlexGrid--gutterLarge euiFlexGrid--halves">
<wz-welcome-card
class="euiFlexItem" logo="'icons/ruleset.png'" title="'Ruleset'"
switch-tab="mctrl.switchTab('ruleset')" current-tab="'rules'"
switch-tab="mctrl.switchTab('ruleset', true)" current-tab="'rules'"
description="'Explore your Wazuh cluster ruleset.'"
></wz-welcome-card>
<wz-welcome-card
class="euiFlexItem" logo="'icons/groups.png'"
title="'Groups'" switch-tab="mctrl.switchTab('groups')" current-tab="'groups'"
title="'Groups'" switch-tab="mctrl.switchTab('groups', true)" current-tab="'groups'"
description="'Check your agent groups.'"
></wz-welcome-card>
<wz-welcome-card
class="euiFlexItem" logo="'icons/app_devtools.svg'"
title="'Configuration'" switch-tab="mctrl.switchTab('configuration')" current-tab="'configuration'"
title="'Configuration'" switch-tab="mctrl.switchTab('configuration', true)" current-tab="'configuration'"
description="'Check your Wazuh cluster configuration.'"
></wz-welcome-card>
</div>
@ -40,22 +40,22 @@
<div class="euiFlexGrid euiFlexGrid--gutterLarge euiFlexGrid--halves">
<wz-welcome-card
class="euiFlexItem" logo="'icons/app_monitoring.svg'" title="'Status'"
switch-tab="mctrl.switchTab('status')" current-tab="'status'"
switch-tab="mctrl.switchTab('status', true)" current-tab="'status'"
description="'Check your Wazuh cluster status.'"
></wz-welcome-card>
<wz-welcome-card
class="euiFlexItem" logo="'icons/app_logging.svg'" title="'Logs'"
switch-tab="mctrl.switchTab('logs')" current-tab="'logs'"
switch-tab="mctrl.switchTab('logs', true)" current-tab="'logs'"
description="'Logs from your Wazuh cluster.'"
></wz-welcome-card>
<wz-welcome-card
class="euiFlexItem" logo="'icons/app_index_pattern.svg'" title="'Cluster'"
switch-tab="mctrl.switchTab('monitoring')" current-tab="'monitoring'"
switch-tab="mctrl.switchTab('monitoring', true)" current-tab="'monitoring'"
description="'Visualize your Wazuh cluster.'"
></wz-welcome-card>
<wz-welcome-card
class="euiFlexItem" logo="'icons/reporting.png'" title="'Reporting'"
switch-tab="mctrl.switchTab('reporting')" current-tab="'reporting'"
switch-tab="mctrl.switchTab('reporting', true)" current-tab="'reporting'"
description="'Check your stored Wazuh reports.'"
></wz-welcome-card>
</div>

View File

@ -31,11 +31,11 @@
class="wz-nav-bar"
md-selected-nav-item="ctrl.tab"
nav-bar-aria-label="Settings navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('api')" name="api">API</md-nav-item>
<md-nav-item class="wz-nav-item" ng-if="ctrl.apiEntries && ctrl.apiEntries.length" md-nav-click="ctrl.switchTab('extensions')" name="extensions">Extensions</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('pattern')" name="pattern">Pattern</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('configuration')" name="configuration">Configuration</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('logs'); ctrl.refreshLogs()" name="logs">Logs</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('about')" name="about">About</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('api', true)" name="api">API</md-nav-item>
<md-nav-item class="wz-nav-item" ng-if="ctrl.apiEntries && ctrl.apiEntries.length" md-nav-click="ctrl.switchTab('extensions', true)" name="extensions">Extensions</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('pattern', true)" name="pattern">Pattern</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('configuration', true)" name="configuration">Configuration</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('logs', true); ctrl.refreshLogs()" name="logs">Logs</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="ctrl.switchTab('about', true)" name="about">About</md-nav-item>
</md-nav-bar>
<!-- End navigation bar -->