Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sidepanel resize #225

Merged
merged 18 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file.
## Unreleased
**List of changes that are finished but not yet released in any final version.**

- [PR-225](https://github.com/Cognifide/aet/pull/225) Added sidebar resize functionality for report app
- [PR-221](https://github.com/Cognifide/aet/pull/221) Added crosshair buttons for scrolling Side Panel to currently opened url/test.
- [PR-209](https://github.com/Cognifide/aet/pull/209) Selenium upgraded to 3.8.1. Guava upgraded to 23.6-jre

Expand Down
2 changes: 1 addition & 1 deletion report/src/main/webapp/app/app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ require.config({
//toolbarBottom
'toolbarBottomController': 'layout/toolbar/toolbarBottom.controller',
//sidepanel
'sidepanelToggleDirective': 'layout/sidepanel/sidepanelToggle.directive',
'sidepanelDirective': 'layout/sidepanel/sidepanel.directive',
'sidepanelStatusFilterDirective': 'layout/sidepanel/sidepanelStatusFilter.directive',
'sidepanelSearchDirective': 'layout/sidepanel/sidepanelSearch.directive',
'sidepanelToggleLinkDirective': 'layout/sidepanel/toggleLink.directive',
Expand Down
10 changes: 3 additions & 7 deletions report/src/main/webapp/app/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define(['angularAMD',
'viewModeService',

// sidepanel
'sidepanelToggleDirective',
'sidepanelDirective',
'sidepanelStatusFilterDirective',
'sidepanelSearchDirective',
'sidepanelToggleLinkDirective',
Expand Down Expand Up @@ -94,12 +94,8 @@ define(['angularAMD',
$rootScope.fullSourceVisible = userSettingsService.isFullSourceVisible();
}]);

app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
'$compileProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider,
$compileProvider) {
$compileProvider.debugInfoEnabled(false);

app.config(['$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('root', angularAMD.route({
views: {
Expand Down
128 changes: 128 additions & 0 deletions report/src/main/webapp/app/layout/sidepanel/sidepanel.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* AET
*
* Copyright (C) 2013 Cognifide Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
define(['angularAMD'], function (angularAMD) {
'use strict';
// custom prefix for custom directive 'aet' see: http://bit.ly/29U2YFf
angularAMD.directive('aetSidepanel',
['$rootScope', 'localStorageService', SidepanelDirective]);

function SidepanelDirective($rootScope, localStorageService) {
var EXPANDED_SIDEBAR_KEY_NAME = 'aet:expandedSidepanel';
var INIT_SIDEPANEL_WIDTH = 350;
var $sidepanel;
var $content;
var $toggleIcon;

return {
restrict: 'AE',
link: linkFunc
};

function linkFunc($scope, $element) {
var newWidth = INIT_SIDEPANEL_WIDTH;
var isSidepanelResized = false;

$rootScope.$on('$stateChangeSuccess', function() {
$content = $element.find('.main');
$sidepanel = $element.find('.aside');
$toggleIcon = $element.find('.toolbar-toggle i');

if (!$scope.sidebarExpanded) {
expand();
}

$scope.sidebarExpanded = isExpanded();

$scope.$watch('sidebarExpanded', function(newValue, oldValue) {
if (newValue !== oldValue) {
toggleSidepanel();
}
});
});

$element.on('mousedown', '.aside-resizer', function (e) {
isSidepanelResized = true;

e.preventDefault();
});

$element.on('mousemove', function (e) {
if (isSidepanelResized) {
newWidth = limitSidepanelSize(e.pageX);
updateWidth(newWidth);
e.preventDefault();
}
});

$element.on('mouseup', function () {
isSidepanelResized = false;
});

$element.on('click', '.toolbar-toggle', function () {
$scope.sidebarExpanded = !$scope.sidebarExpanded;
$scope.$apply();
});
}

function isExpanded() {
return localStorageService.get(EXPANDED_SIDEBAR_KEY_NAME);
}

function toggleSidepanel() {
if (isExpanded()) {
close();
} else {
expand();
}
}

function onWindowResize() {
updateWidth(limitSidepanelSize($sidepanel.outerWidth()));
}

function expand() {
$content.css('left', $sidepanel.outerWidth());
$content.css('width', document.body.clientWidth - $sidepanel.outerWidth());
$sidepanel.css('left', 0);

$(window).on('resize', onWindowResize);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add throttle here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

localStorageService.put(EXPANDED_SIDEBAR_KEY_NAME, true);
}

function close() {
$content.css('left', 0);
$content.css('width', '100%');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just remove width then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, removed width inline style instead

$sidepanel.css('left', -$sidepanel.outerWidth());

$(window).off('resize', onWindowResize);
localStorageService.put(EXPANDED_SIDEBAR_KEY_NAME, false);
}

function updateWidth(newWidth) {
var newContentWidth = document.body.clientWidth - newWidth;

$content.css('left', newWidth);
$content.css('width', newContentWidth);
$sidepanel.css('width', newWidth);
}

function limitSidepanelSize(xPos) {
return Math.min(Math.max(INIT_SIDEPANEL_WIDTH, xPos), document.body.clientWidth/2);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
limitations under the License.

-->
<div class="aside" ui-view="aside" ng-class="{'has-filters-applied': asideHasFilters}">
<div class="aside" ui-view="aside">
<div class="logo-holder">
<a ui-sref="suite">
<img class="logo" src="assets/img/logo.png" alt="">
Expand Down Expand Up @@ -143,4 +143,6 @@ <h4 class="no-results" ng-if="sidepanel.testsStats.total === 0">
Discard all changes
</span>
</div>

<div class="aside-resizer"></div>
</div>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
-->

<div class="toolbar-top">
<div class="toolbar-toggle" data-aet-sidepanel-toggle>
<i class="glyphicon glyphicon-chevron-left"
data-ng-class="sidebarExpanded ? 'glyphicon-chevron-left' : 'glyphicon-chevron-right'"></i>
<div class="toolbar-toggle">
<i class="glyphicon"
data-ng-class="{ 'glyphicon-chevron-left' : sidebarExpanded, 'glyphicon-chevron-right' : !sidebarExpanded }"></i>
</div>
<div class="toolbar-blocks">
<div class="toolbar-block" ng-class="{'hidden': toolbarTop.pattern}">
Expand Down
Loading