Skip to content

Commit 629823d

Browse files
authored
Merge branch 'master' into mkirova/fix-5200-master
2 parents 73f9726 + eea1b99 commit 629823d

File tree

15 files changed

+400
-213
lines changed

15 files changed

+400
-213
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ All notable changes for each version of this project will be documented in this
2828
- Replaces the current paginator in all grids. Can be used as a standalone component.
2929
- `IgxCombo`
3030
- Input `[overlaySettings]` - allows an object of type `OverlaySettings` to be passed. These custom overlay settings control how the drop-down list displays.
31+
- `IgxForOf` now offers usage of local variables `even`, `odd`, `first` and `last` to help with the distinction of the currently iterated element.
32+
3133

3234
## 8.0.2
3335
- `igx-list-theme` now have some new parameters for styling.

projects/igniteui-angular/src/lib/core/grid-selection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ export class IgxGridCRUDService {
105105
return new IgxRow(cell.id.rowID, cell.rowIndex, cell.rowData);
106106
}
107107

108-
sameRow(rowID): boolean {
109-
return this.row && this.row.id === rowID;
108+
sameRow(rowIndex): boolean {
109+
return this.row && this.row.index === rowIndex;
110110
}
111111

112112
sameCell(cell: IgxCell): boolean {
@@ -175,7 +175,7 @@ export class IgxGridCRUDService {
175175
return;
176176
}
177177

178-
if (this.row && !this.sameRow(this.cell.id.rowID)) {
178+
if (this.row && !this.sameRow(this.cell.rowIndex)) {
179179
this.grid.endEdit(true);
180180
this.cell = this.createCell(cell);
181181
this.beginRowEdit();

projects/igniteui-angular/src/lib/core/styles/components/navdrawer/_navdrawer-theme.scss

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@
343343

344344
@include igx-scope('.igx-typography') {
345345
%item {
346-
@include igx-type-style($type-scale, $item) {
347-
margin: 0;
348-
}
346+
@include igx-type-style($type-scale, $item);
349347
}
350348

351349
%item--header {

projects/igniteui-angular/src/lib/core/styles/themes/schemas/light/_navdrawer.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/// @prop {map} item-hover-text-color [igx-color: 'surface', text-contrast: (), rgba: .87] - The item's hover text color.
2323
/// @prop {map} item-hover-icon-color [igx-color: 'surface', text-contrast: (), rgba: .87] - The item's hover icon color.
2424
/// @prop {map} elevation [16] - The elevation level of the drawer, between 0 - 24.
25-
/// @prop {Number} border-radius [.16667] - The border radius fraction, between 0 - 36 to be used for the navdrawer component.
25+
/// @prop {Number} border-radius [0] - The border radius fraction, between 0 - 36 to be used for the navdrawer component.
2626
/// @prop {Number} item-border-radius [.16667] - The border radius fraction, between 0 - 24 to be used for the navdrawer item.
2727
///
2828
/// @see $default-palette
@@ -37,10 +37,6 @@ $_light-navdrawer: extend(
3737

3838
border-color: rgba(0, 0, 0, .14),
3939

40-
border-radius: 0,
41-
42-
item-border-radius: .16667,
43-
4440
item-header-text-color: (
4541
igx-color: 'surface',
4642
text-contrast: (),

projects/igniteui-angular/src/lib/core/styles/themes/schemas/shape/_navdrawer.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
/// @author <a href="https://github.com/simeonoff" target="_blank">Simeon Simeonoff</a>
55
////
66
$_default-shape-navdrawer: (
7-
border-radius: .2,
7+
border-radius: 0,
8+
item-border-radius: .16667,
89
);
910

1011
$_round-shape-navdrawer: (
1112
border-radius: 1,
13+
item-border-radius: 1,
1214
);
1315

1416
$_square-shape-navdrawer: (
1517
border-radius: 0%,
16-
border-radius-item: 0%
18+
item-border-radius: 0%
1719
);

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.spec.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,46 @@ describe('IgxForOf directive -', () => {
10861086
expect(children.length).toEqual(expectedElementsLength);
10871087
});
10881088
});
1089+
describe('even odd first last functions', () => {
1090+
configureTestSuite();
1091+
let fix: ComponentFixture<LocalVariablesComponent>;
1092+
1093+
beforeEach(async(() => {
1094+
TestBed.configureTestingModule({
1095+
declarations: [
1096+
TestIgxForOfDirective,
1097+
LocalVariablesComponent
1098+
],
1099+
imports: [IgxForOfModule]
1100+
}).compileComponents();
1101+
}));
1102+
1103+
beforeEach(() => {
1104+
fix = TestBed.createComponent(LocalVariablesComponent);
1105+
fix.detectChanges();
1106+
});
1107+
1108+
it('should differentiate even odd items', () => {
1109+
const allItems: DebugElement[] = fix.debugElement.queryAll(By.css('igx-display-container'))[0].children;
1110+
expect(allItems.length).toEqual(100);
1111+
for (let i = 0; i < allItems.length; i++) {
1112+
if (i === 0) {
1113+
expect(allItems[i].classes['first']).toBe(true);
1114+
}
1115+
if (i === allItems.length - 1) {
1116+
expect(allItems[i].classes['last']).toBe(true);
1117+
}
1118+
if (i % 2 === 0) {
1119+
expect(allItems[i].classes['even']).toBe(true);
1120+
} else {
1121+
expect(allItems[i].classes['odd']).toBe(true);
1122+
}
1123+
}
1124+
});
1125+
1126+
1127+
});
1128+
10891129
});
10901130

10911131
class DataGenerator {
@@ -1574,3 +1614,40 @@ export class NoWidthAndHeightComponent {
15741614
}
15751615
}
15761616
}
1617+
1618+
@Component({
1619+
template: `
1620+
<div class='container'>
1621+
<ng-template igxFor let-item [igxForOf]="data" #virtDirVertical
1622+
[igxForScrollOrientation]="'vertical'"
1623+
[igxForContainerSize]='"500px"'
1624+
[igxForItemSize]='itemSize'
1625+
let-rowIndex="index"
1626+
let-odd="odd"
1627+
let-even="even"
1628+
let-first="first"
1629+
let-last="last">
1630+
1631+
<div #markupItem
1632+
[ngClass]="{
1633+
first: first,
1634+
last: last,
1635+
even: even,
1636+
odd: odd
1637+
}"
1638+
[style.height]='itemSize'>
1639+
{{rowIndex}} : {{item.text}}
1640+
</div>
1641+
</ng-template>
1642+
</div>
1643+
`,
1644+
})
1645+
export class LocalVariablesComponent {
1646+
public data = [];
1647+
1648+
constructor() {
1649+
for (let i = 0; i < 100; i++) {
1650+
this.data.push({text: i + ''});
1651+
}
1652+
}
1653+
}

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ import { VirtualHelperComponent } from './virtual.helper.component';
3131
import { IgxScrollInertiaModule } from './../scroll-inertia/scroll_inertia.directive';
3232
import { IgxForOfSyncService } from './for_of.sync.service';
3333

34+
/**
35+
* @publicApi
36+
*/
37+
export class IgxForOfContext<T> {
38+
constructor(
39+
public $implicit: T,
40+
public index: number,
41+
public count: number
42+
) {}
43+
44+
/**
45+
* A function that returns whether the element is the first or not
46+
*/
47+
get first(): boolean { return this.index === 0; }
48+
49+
/**
50+
* A function that returns whether the element is the last or not
51+
*/
52+
get last(): boolean { return this.index === this.count - 1; }
53+
54+
/**
55+
* A function that returns whether the element is even or not
56+
*/
57+
get even(): boolean { return this.index % 2 === 0; }
58+
59+
/**
60+
* A function that returns whether the element is odd or not
61+
*/
62+
get odd(): boolean { return !this.even; }
63+
64+
}
65+
3466
@Directive({ selector: '[igxFor][igxForOf]' })
3567
export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestroy {
3668

@@ -323,7 +355,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
323355
const input = this.igxForOf[i];
324356
const embeddedView = this.dc.instance._vcr.createEmbeddedView(
325357
this._template,
326-
{ $implicit: input, index: this.igxForOf.indexOf(input) }
358+
new IgxForOfContext<T>(input, this.getContextIndex(input), this.igxForOf.length)
327359
);
328360
this._embeddedViews.push(embeddedView);
329361
}
@@ -789,6 +821,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
789821
const cntx = embView.context;
790822
cntx.$implicit = input;
791823
cntx.index = this.getContextIndex(input);
824+
cntx.count = this.igxForOf.length;
792825
const view: ViewRef = this.dc.instance._vcr.detach(0);
793826
this.dc.instance._vcr.insert(view);
794827
this._embeddedViews.push(embView);
@@ -832,6 +865,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
832865
const cntx = (embView as EmbeddedViewRef<any>).context;
833866
cntx.$implicit = input;
834867
cntx.index = this.getContextIndex(input);
868+
cntx.count = this.igxForOf.length;
835869
}
836870
}
837871

@@ -903,6 +937,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
903937
const cntx = (embView as EmbeddedViewRef<any>).context;
904938
cntx.$implicit = input;
905939
cntx.index = this.getContextIndex(input);
940+
cntx.count = this.igxForOf.length;
906941
}
907942
this.dc.changeDetectorRef.detectChanges();
908943
if (prevChunkSize !== this.state.chunkSize) {
@@ -1165,7 +1200,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
11651200
const input = this.igxForOf[elemIndex];
11661201
const embeddedView = this.dc.instance._vcr.createEmbeddedView(
11671202
this._template,
1168-
{ $implicit: input, index: elemIndex }
1203+
new IgxForOfContext<T>(input, this.getContextIndex(input), this.igxForOf.length)
11691204
);
11701205

11711206
this._embeddedViews.push(embeddedView);
@@ -1516,7 +1551,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15161551
const input = this.igxForOf[elemIndex];
15171552
const embeddedView = this.dc.instance._vcr.createEmbeddedView(
15181553
this._template,
1519-
{ $implicit: input, index: elemIndex }
1554+
new IgxForOfContext<T>(input, this.getContextIndex(input), this.igxForOf.length)
15201555
);
15211556

15221557
this._embeddedViews.push(embeddedView);
@@ -1550,6 +1585,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15501585
const cntx = (embView as EmbeddedViewRef<any>).context;
15511586
cntx.$implicit = input;
15521587
cntx.index = this.getContextIndex(input);
1588+
cntx.count = this.igxForOf.length;
15531589
}
15541590
if (prevChunkSize !== this.state.chunkSize) {
15551591
this.onChunkLoad.emit(this.state);

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
584584
const editableCell = this.crudService.cell;
585585
const editMode = !!(crud.row || crud.cell);
586586

587-
588587
if (this.editable && editMode && !this.row.deleted) {
589588
if (editableCell) {
590589
this.gridAPI.update_cell(editableCell, editableCell.editValue);
@@ -595,9 +594,9 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
595594
return;
596595
}
597596

598-
if (editableCell && crud.sameRow(this.cellID.rowID)) {
597+
if (editableCell && crud.sameRow(this.rowIndex)) {
599598
this.gridAPI.submit_value();
600-
} else if (editMode && !crud.sameRow(this.cellID.rowID)) {
599+
} else if (editMode && !crud.sameRow(this.rowIndex)) {
601600
this.grid.endEdit(true);
602601
}
603602
}
@@ -979,14 +978,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
979978
}
980979

981980
if (this.editMode) {
982-
const v = this.crudService.cell;
983-
const args = {
984-
cellID: v.id,
985-
rowID: v.id.rowID,
986-
oldValue: v.value,
987-
newValue: v.editValue,
988-
cancel: false
989-
} as IGridEditEventArgs;
981+
const args = this.crudService.cell.createEditEventArgs();
990982
this.grid.onCellEditCancel.emit(args);
991983
if (args.cancel) {
992984
return;

projects/igniteui-angular/src/lib/grids/column.component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,20 @@ export class IgxColumnComponent implements AfterContentInit {
126126
*/
127127
@Input()
128128
get editable(): boolean {
129-
let result = false;
129+
// Updating the primary key when grid has transactions (incl. row edit)
130+
// should not be allowed, as that can corrupt transaction state.
131+
const rowEditable = this.grid && this.grid.rowEditable;
132+
const hasTransactions = this.grid && this.grid.transactions.enabled;
133+
134+
if (this.isPrimaryColumn && (rowEditable || hasTransactions)) {
135+
return false;
136+
}
137+
130138
if (this._editable !== undefined) {
131-
result = this._editable;
139+
return this._editable;
132140
} else {
133-
result = this.grid && this.grid.rowEditable && this.field !== this.grid.primaryKey;
141+
return rowEditable;
134142
}
135-
return result;
136143
}
137144
/**
138145
* Sets whether the column is editable.
@@ -1085,6 +1092,12 @@ export class IgxColumnComponent implements AfterContentInit {
10851092
* @hidden
10861093
*/
10871094
protected _editable: boolean;
1095+
/**
1096+
* @hidden
1097+
*/
1098+
protected get isPrimaryColumn(): boolean {
1099+
return this.field !== undefined && this.grid !== undefined && this.field === this.grid.primaryKey;
1100+
}
10881101
/**
10891102
*@hidden
10901103
*/

projects/igniteui-angular/src/lib/grids/grid/grid-mrl-keyboard-nav.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation', () => {
28832883
await wait(100);
28842884
fix.detectChanges();
28852885

2886-
targetCell = grid.getCellByColumn(0, 'ID');
2886+
targetCell = grid.getCellByColumn(0, 'PostalCode');
28872887
expect(targetCell.focused).toBe(true);
28882888
});
28892889

0 commit comments

Comments
 (0)