Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit d14bf9c

Browse files
author
Sam Graber
authored
Merge pull request #403 from RenovoSolutions/soup-du-jour
Component changes to help with Service Event List settings
2 parents 440b6c4 + abf9f2c commit d14bf9c

File tree

6 files changed

+114
-4
lines changed

6 files changed

+114
-4
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-angular-components",
3-
"version": "4.2.2",
3+
"version": "4.2.3",
44
"description": "Reusable responsive angular components",
55
"author": "Renovo Development Team",
66
"keywords": [
@@ -112,7 +112,7 @@
112112
"rl-http": "~1.5.1",
113113
"rxjs": "~5.0.0",
114114
"systemjs": "^0.19.28",
115-
"typescript-angular-utilities": "~4.1.1",
115+
"typescript-angular-utilities": "~4.1.2",
116116
"ui-select": "~0.14.7",
117117
"zone.js": "~0.7.2"
118118
},

source/components/cardContainer/builder/cardContainerBuilderOld.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface ICardContainerBuilderOld {
4040
useSelection(): void;
4141
renderFilters(): void;
4242
saveWhenInvalid(): void;
43+
findColumnByFieldName(fieldName: string): IColumn<any>;
4344
}
4445

4546

@@ -101,6 +102,10 @@ export class CardContainerBuilderOld implements ICardContainerBuilderOld {
101102
this._columns.push(column);
102103
}
103104

105+
findColumnByFieldName(fieldName: string): IColumn<any> {
106+
return this._columns.find(column => column.fieldName === fieldName);
107+
}
108+
104109
useClickableCards(): void {
105110
this._clickableCards = true;
106111
}

source/components/cardContainer/cardContainer.ng1.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ export class CardContainerController {
150150
//*use card container event service?
151151
$scope.$on('updateDisabledSelections', this.updateDisabledSelections);
152152

153-
this.dataSource.changed.subscribe(this.addViewData);
153+
this.dataSource.changed.subscribe(() => {
154+
this.addViewData();
155+
this.updateVisualColumnSorting();
156+
});
154157
this.dataSource.redrawing.subscribe(this.clearFilteredSelections);
155158

156159
this.addViewData();
@@ -164,6 +167,11 @@ export class CardContainerController {
164167
flipSort: true,
165168
};
166169
}
170+
else {
171+
this.dataSource.changed.subscribe(() => {
172+
this.updateVisualColumnSorting();
173+
});
174+
}
167175

168176
if (this.dataSource.sorts == null) {
169177
this.dataSource.sorts = [];

source/components/cardContainer/filters/filterGroup/filterGroup.directive.ng1.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class FilterGroupController {
3131
this.expanded = true;
3232
}
3333

34+
$onInit(): void {
35+
this.filterGroup.changeFromDefault$.subscribe(() => this.expanded = false);
36+
}
37+
3438
get headerTitle(): string {
3539
if (!this.disabled) {
3640
return this.filterGroup.label + ': ' + this.filterGroup.activeOption.label

source/components/cardContainer/filters/filterGroup/filterGroupOld.service.tests.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,60 @@ describe('FilterGroupOld', () => {
150150

151151
expect(filterGroup.serialize()).to.equal(4);
152152
});
153+
154+
it('should notify when the active option is changed from the default', () => {
155+
// arrange
156+
let nonDefaultOption: IFilterOptionMock = {
157+
active: false,
158+
value: 0,
159+
};
160+
let defaultOption: IFilterOptionMock = {
161+
active: true,
162+
value: 1,
163+
};
164+
let changeFromDefaultSpy = sinon.spy();
165+
166+
filterGroup = buildFilter({
167+
options: [nonDefaultOption, defaultOption],
168+
});
169+
filterGroup.initOptions();
170+
filterGroup.changeFromDefault$.subscribe(changeFromDefaultSpy);
171+
172+
// act
173+
filterGroup.setActiveOptionByValue(nonDefaultOption.value);
174+
175+
// assert
176+
sinon.assert.calledOnce(changeFromDefaultSpy);
177+
});
178+
179+
it('should not notify when the active option is changed from a non-default option', () => {
180+
// arrange
181+
let nonDefaultOption: IFilterOptionMock = {
182+
active: false,
183+
value: 0,
184+
};
185+
let defaultOption: IFilterOptionMock = {
186+
active: true,
187+
value: 1,
188+
};
189+
let anotherOption: IFilterOptionMock = {
190+
active: false,
191+
value: 2,
192+
}
193+
let changeFromDefaultSpy = sinon.spy();
194+
195+
filterGroup = buildFilter({
196+
options: [nonDefaultOption, defaultOption],
197+
});
198+
filterGroup.initOptions();
199+
filterGroup.changeFromDefault$.subscribe(changeFromDefaultSpy);
200+
filterGroup.setActiveOptionByValue(nonDefaultOption.value);
201+
changeFromDefaultSpy.reset();
202+
203+
// act
204+
filterGroup.setActiveOptionByValue(anotherOption.value);
205+
206+
// assert
207+
sinon.assert.notCalled(changeFromDefaultSpy);
208+
});
153209
});

source/components/cardContainer/filters/filterGroup/filterGroupOld.service.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as _ from 'lodash';
2+
import { ReplaySubject, Observable } from 'rxjs/Rx';
23

34
import { services, filters } from 'typescript-angular-utilities';
45
import __object = services.object;
@@ -28,8 +29,11 @@ export interface IFilterGroupOld extends filters.IFilterWithCounts, filters.ISer
2829
type: string;
2930
options: IFilterOptionOld[];
3031
activeOption: IFilterOptionOld;
32+
changeFromDefault$: ReplaySubject<any>;
3133
setActiveOption(index: number): void;
3234
setOptionCounts(counts: number[]): void;
35+
setActiveOptionByValue(value: number): void;
36+
setActiveOptionByLabel(label: string): void;
3337
}
3438

3539
export class FilterGroupOld extends filters.SerializableFilter<any> implements IFilterGroupOld {
@@ -39,14 +43,17 @@ export class FilterGroupOld extends filters.SerializableFilter<any> implements I
3943
template: string = '<rl-filter-group filter-group="filter" source="dataSource"></rl-filter-group>';
4044
settings: IFilterGroupSettingsOld;
4145

46+
private _defaultOption: IFilterOptionOld;
4247
private _activeOption: IFilterOptionOld;
48+
private _changeFromDefault$: ReplaySubject<any>;
4349

4450
object: __object.IObjectUtility;
4551

4652
constructor(settings: IFilterGroupSettingsOld, object: __object.IObjectUtility) {
4753
super();
4854
this.object = object;
4955

56+
this._changeFromDefault$ = new ReplaySubject<any>(1);
5057
this.settings = settings;
5158
this.label = settings.label;
5259
this.type = settings.type != null ? settings.type : settings.label;
@@ -55,7 +62,8 @@ export class FilterGroupOld extends filters.SerializableFilter<any> implements I
5562

5663
initOptions():void {
5764
this.options = this.settings.options;
58-
this.activeOption = this.setDefaultOption();
65+
this._defaultOption = this.setDefaultOption();
66+
this.activeOption = this._defaultOption;
5967

6068
_.each(this.options, (option: IFilterOptionOld): void => {
6169
if (_.isUndefined(option.type)) {
@@ -66,11 +74,18 @@ export class FilterGroupOld extends filters.SerializableFilter<any> implements I
6674
});
6775
}
6876

77+
get changeFromDefault$(): ReplaySubject<any> {
78+
return this._changeFromDefault$;
79+
}
80+
6981
get activeOption(): IFilterOptionOld {
7082
return this._activeOption;
7183
}
7284

7385
set activeOption(value: IFilterOptionOld) {
86+
if (this._activeOption == this._defaultOption && value != this._defaultOption) {
87+
this._changeFromDefault$.next(value);
88+
}
7489
this._activeOption = value;
7590
this.onChange(false);
7691
}
@@ -106,6 +121,28 @@ export class FilterGroupOld extends filters.SerializableFilter<any> implements I
106121
}
107122
}
108123

124+
setActiveOptionByValue(value: number): void {
125+
_.each(this.options, (option: IFilterOptionOld): void => {
126+
if (option.value === value) {
127+
if (!option.active) {
128+
this.activeOption = option;
129+
}
130+
return;
131+
}
132+
});
133+
}
134+
135+
setActiveOptionByLabel(label: string): void {
136+
_.each(this.options, (option: IFilterOptionOld): void => {
137+
if (option.label === label) {
138+
if (!option.active) {
139+
this.activeOption = option;
140+
}
141+
return;
142+
}
143+
});
144+
}
145+
109146
setOptionCounts(counts: number[]): void {
110147
_.each(this.options, (option: IConfiguredFilterOption): void => {
111148
if (_.has(counts, option.type)) {

0 commit comments

Comments
 (0)