Skip to content

Commit

Permalink
GG-20269 Backport to 2.5-master of GG-18625 Save visible value on cha…
Browse files Browse the repository at this point in the history
…nge of measure. (#63)

(cherry picked from commit 9315659)

(cherry picked from commit 19cd6ba)

(cherry picked from commit 43452e8)
  • Loading branch information
vsisko authored and vsisko committed Jun 21, 2019
1 parent fb73d4d commit 39fec20
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ test('Create cluster basic/advanced clusters amount redirect', async(t) => {
await overviewPage.removeAllItems();
});


test('Cluster edit basic/advanced redirect based on caches amount', async(t) => {
const clusterName = 'Seven caches cluster';
const clusterEditLink = overviewPage.clustersTable.findCell(0, 'Name').find('a');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ export default class PCFormFieldSizeController<T> implements IInputErrorNotifier
}

set sizeScale(value: ISizeTypeOption) {
const oldScale = this._sizeScale;
this._sizeScale = value;
if (this.onScaleChange) this.onScaleChange({$event: this.sizeScale});
if (this.ngModel) this.assignValue(this.ngModel.$viewValue);

if (this.ngModel)
this.assignValue(oldScale ? this.ngModel.$viewValue / oldScale.value * value.value : this.ngModel.$viewValue);
}

get sizeScale() {
Expand All @@ -115,6 +118,10 @@ export default class PCFormFieldSizeController<T> implements IInputErrorNotifier

assignValue(rawValue: number) {
if (!this.sizesMenu) this.setDefaultSizeType();

if (rawValue && rawValue !== this.ngModel.$viewValue)
this.ngModel.$setViewValue(rawValue);

return this.value = rawValue
? rawValue / this.sizeScale.value
: rawValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2019 GridGain Systems, Inc. and Contributors.
*
* Licensed under the GridGain Community Edition License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
*
* 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.
*/

import 'mocha';
import {assert} from 'chai';
import componentModule from '../../index';

suite('form-field-size', () => {
let $scope: ng.IScope;
let $compile: ng.ICompileService;

setup(() => {
angular.module('test', [componentModule.name]);
angular.mock.module('test');
angular.mock.inject((_$rootScope_: ng.IScope, _$compile_: ng.ICompileService) => {
$compile = _$compile_;
$scope = _$rootScope_.$new();
});
});

test('Switch editor measure', async() => {
$scope.model = 1;
const el = angular.element(`
<form-field-size
ng-model='model'
id='period'
name='period'
label='period:'
size-type='time'
size-scale-label='sec'
min='0'
ng-ref='ctrl'
/>
`);
$compile(el)($scope);
$scope.$digest();
const ctrl = $scope.ctrl;
ctrl.sizeScale = {label: 'hour', value: 60 * 60};
$scope.$digest();
assert.equal($scope.model, 60 * 60, 'Model value is recalculated on measure switch');
});
});

0 comments on commit 39fec20

Please sign in to comment.