Skip to content

Commit d199386

Browse files
Svetoslav KrastevSvetoslav Krastev
authored andcommitted
refactor(pivotDate): Add getter/setters for pivot date dimension and make contstructor props private.
1 parent 9861f2c commit d199386

File tree

1 file changed

+56
-8
lines changed

1 file changed

+56
-8
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-dimensions.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface IPivotDateDimensionOptions {
4747
export class IgxPivotDateDimension implements IPivotDimension {
4848
/** Enables/Disables a particular dimension from pivot structure. */
4949
public enabled = true;
50-
50+
5151
/**
5252
* Gets/Sets data type
5353
*/
@@ -75,12 +75,57 @@ export class IgxPivotDateDimension implements IPivotDimension {
7575
return this._resourceStrings;
7676
}
7777

78+
/**
79+
* Gets/Sets the base dimension that is used by this class to determine the other dimensions and their values.
80+
* Having base dimension set is required in order for the Date Dimensions to show.
81+
*/
82+
public get baseDimension(): IPivotDimension {
83+
return this._baseDimension;
84+
}
85+
public set baseDimension(value: IPivotDimension) {
86+
this._baseDimension = value;
87+
this.initialize(this.baseDimension, this.options);
88+
}
89+
90+
/**
91+
* Gets/Sets the options for the predefined date dimensions whether to show quarter, years and etc.
92+
*/
93+
public get options(): IPivotDateDimensionOptions {
94+
return this._options;
95+
}
96+
public set options(value: IPivotDateDimensionOptions) {
97+
this._options = value;
98+
if (this.baseDimension) {
99+
this.initialize(this.baseDimension, this.options);
100+
}
101+
}
102+
103+
/**
104+
* @deprecated in version 15.1.x. Please use the new `options`
105+
*
106+
* Gets the base dimension that is used by this class to determine the other dimensions and their values.
107+
* Having base dimension set is required in order for the Date Dimensions to show.
108+
*/
109+
public get inBaseDimension(): IPivotDimension {
110+
return this._baseDimension;
111+
}
112+
113+
/**
114+
* @deprecated in version 15.1.x. Please use the new `options`
115+
*
116+
* Gets the options for the predefined date dimensions whether to show quarter, years and etc.
117+
*/
118+
public get inOptions(): IPivotDateDimensionOptions {
119+
return this._options;
120+
}
121+
78122
/** @hidden @internal */
79123
public childLevel?: IPivotDimension;
80124
/** @hidden @internal */
81125
public memberName = 'AllPeriods';
82126
private _resourceStrings = CurrentResourceStrings.GridResStrings;
83-
127+
private _baseDimension: IPivotDimension;
128+
private _options: IPivotDateDimensionOptions = {};
84129
/**
85130
* Creates additional pivot date dimensions based on a provided dimension describing date data:
86131
*
@@ -92,13 +137,16 @@ export class IgxPivotDateDimension implements IPivotDimension {
92137
* new IgxPivotDateDimension({ memberName: 'Date', enabled: true }, { total: false, months: false });
93138
* ```
94139
*/
95-
constructor(public inBaseDimension: IPivotDimension, public inOptions: IPivotDateDimensionOptions = {}) {
96-
const options = { ...this.defaultOptions, ...inOptions };
97-
98-
if (!inBaseDimension) {
99-
console.warn(`Please provide data child level to the pivot dimension.`);
100-
return;
140+
constructor(private _inBaseDimension: IPivotDimension, private _inOptions: IPivotDateDimensionOptions = {}) {
141+
this._options = _inOptions;
142+
this._baseDimension = _inBaseDimension;
143+
if (this.baseDimension && this.options) {
144+
this.initialize(this.baseDimension, this.options);
101145
}
146+
}
147+
148+
protected initialize(inBaseDimension, inOptions) {
149+
const options = { ...this.defaultOptions, ...inOptions };
102150

103151
this.dataType = GridColumnDataType.Date;
104152
inBaseDimension.dataType = GridColumnDataType.Date;

0 commit comments

Comments
 (0)