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

Angular 6 and rxjs 6 support #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '5'
- '8'
before_install:
- npm install -g codeclimate-test-reporter
script: npm test -- --browsers PhantomJS
Expand Down
3 changes: 1 addition & 2 deletions examples/systemjs/app/data-filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from "lodash";
import {Pipe, PipeTransform} from "@angular/core";

@Pipe({
Expand All @@ -8,7 +7,7 @@ export class DataFilterPipe implements PipeTransform {

transform(array: any[], query: string): any {
if (query) {
return _.filter(array, row=>row.name.indexOf(query) > -1);
return array.filter(row=>row.name.indexOf(query) > -1);
}
return array;
}
Expand Down
7 changes: 0 additions & 7 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ module.exports = function (config) {
watched: false
},

// Lodash
{
pattern: 'node_modules/lodash/lodash.js',
included: false,
watched: false
},

// The testing library
{
pattern: 'systemjs.config.js',
Expand Down
40 changes: 17 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-datatable",
"version": "0.6.0",
"version": "2.0.0",
"description": "DataTable component for Angular2 framework",
"main": "index.js",
"scripts": {
Expand All @@ -19,8 +19,7 @@
},
"keywords": [
"angular",
"angularjs",
"angular2",
"angular6",
"ng",
"ng2",
"table",
Expand All @@ -35,12 +34,13 @@
},
"homepage": "https://github.com/mariuszfoltak/angular2-datatable#readme",
"devDependencies": {
"@angular/core": "^2.1.0",
"@angular/compiler": "^2.1.0",
"@angular/common": "^2.1.0",
"@angular/platform-browser": "^2.1.0",
"@angular/platform-browser-dynamic": "^2.1.0",
"@angular/compiler-cli": "^2.1.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@types/jasmine": "^2.5.35",
"core-js": "^2.4.1",
"http-server": "^0.9.0",
"jasmine-core": "^2.4.1",
Expand All @@ -49,24 +49,18 @@
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"lodash": "^4.0.0",
"phantomjs-prebuilt": "^2.1.7",
"remap-istanbul": "^0.7.0",
"rxjs": "5.0.0-beta.12",
"systemjs": "^0.19.39",
"typescript": "~2.1.0",
"zone.js": "^0.6.25",
"rimraf": "^2.5.4",
"@types/lodash": "ts2.0",
"@types/jasmine": "^2.5.35"
},
"dependencies": {
"lodash": "^4.0.0"
"rxjs": "^6.0.0",
"systemjs": "^0.19.47",
"typescript": "~2.7.2",
"zone.js": "^0.6.25"
},
"peerDependencies": {
"@angular/core": "^2.0.0",
"@angular/common": "^2.0.0",
"@angular/platform-browser": "^2.0.0",
"rxjs": "^5.0.0-beta.12"
"@angular/core": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"rxjs": "^6.0.0"
}
}
3 changes: 1 addition & 2 deletions src/BootstrapPaginator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, Input, OnChanges} from "@angular/core";
import {DataTable} from "./DataTable";
import * as _ from "lodash";

@Component({
selector: "mfBootstrapPaginator",
Expand Down Expand Up @@ -57,7 +56,7 @@ export class BootstrapPaginator implements OnChanges {

ngOnChanges(changes: any): any {
if (changes.rowsOnPageSet) {
this.minRowsOnPage = _.min(this.rowsOnPageSet)
this.minRowsOnPage = this.rowsOnPageSet.reduce((previous, current) => current < previous ? current : previous);
}
}
}
86 changes: 56 additions & 30 deletions src/DataTable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {SimpleChange, Component} from "@angular/core";
import {DataTable, PageEvent, SortEvent} from "./DataTable";
import {TestBed, ComponentFixture} from "@angular/core/testing";
import {By} from "@angular/platform-browser";
import * as _ from "lodash";
import {switchMap} from 'rxjs/operators';
import {range} from "rxjs";

@Component({
template: `<table [mfData]="[]"></table>`
Expand All @@ -29,13 +30,13 @@ describe("DataTable directive tests", ()=> {
{id: 5, name: 'Ðrone'},
{id: 4, name: 'Ananas'}
];
datatable.ngOnChanges({inputData: new SimpleChange(null, datatable.inputData)});
datatable.ngOnChanges({inputData: new SimpleChange(null, datatable.inputData, false)});
});

describe("initializing", ()=> {

it("data should be empty array if inputData is undefined or null", () => {
datatable.ngOnChanges({inputData: new SimpleChange(null, null)});
datatable.ngOnChanges({inputData: new SimpleChange(null, null, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual([]);
});
Expand Down Expand Up @@ -108,12 +109,19 @@ describe("DataTable directive tests", ()=> {
});

datatable.rowsOnPage = 3;
datatable.ngOnChanges({rowsOnPage: new SimpleChange(2, 3)});
datatable.ngOnChanges({rowsOnPage: new SimpleChange(2, 3, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual([{id: 3, name: 'banana'}, {id: 1, name: 'Duck'}, {id: 2, name: 'ącki'}]);


});

it("should emit a dataLength of 0 when inputData is null or undefined", (done) => {
datatable.onPageChange.subscribe((pageOptions: PageEvent)=> {
expect(pageOptions.dataLength).toEqual(0);
done();
});
datatable.inputData = null;
datatable.setPage(2, 3);
})
});

describe("sorting", ()=> {
Expand All @@ -128,8 +136,8 @@ describe("DataTable directive tests", ()=> {
datatable.sortBy = "id";
datatable.sortOrder = "asc";
datatable.ngOnChanges({
sortBy: new SimpleChange(null, datatable.sortBy),
sortOrder: new SimpleChange(null, datatable.sortOrder)
sortBy: new SimpleChange(null, datatable.sortBy, false),
sortOrder: new SimpleChange(null, datatable.sortOrder, false)
});
datatable.ngDoCheck();
expect(datatable.data).toEqual([
Expand All @@ -151,8 +159,8 @@ describe("DataTable directive tests", ()=> {
datatable.sortBy = "id";
datatable.sortOrder = "desc";
datatable.ngOnChanges({
sortBy: new SimpleChange(null, datatable.sortBy),
sortOrder: new SimpleChange(null, datatable.sortOrder)
sortBy: new SimpleChange(null, datatable.sortBy, false),
sortOrder: new SimpleChange(null, datatable.sortOrder, false)
});
datatable.ngDoCheck();

Expand All @@ -167,7 +175,7 @@ describe("DataTable directive tests", ()=> {
datatable.ngDoCheck();
datatable.sortBy = "id";
datatable.ngOnChanges({
sortBy: new SimpleChange(null, datatable.sortBy)
sortBy: new SimpleChange(null, datatable.sortBy, false)
});
datatable.ngDoCheck();
expect(datatable.sortOrder).toEqual("asc");
Expand All @@ -181,10 +189,10 @@ describe("DataTable directive tests", ()=> {
});
datatable.ngDoCheck();
datatable.sortBy = "id";
datatable.sortOrder = "bulb";
datatable.sortOrder = "bulb" as any;
datatable.ngOnChanges({
sortBy: new SimpleChange(null, datatable.sortBy),
sortOrder: new SimpleChange(null, datatable.sortOrder)
sortBy: new SimpleChange(null, datatable.sortBy, false),
sortOrder: new SimpleChange(null, datatable.sortOrder, false)
});
datatable.ngDoCheck();
expect(datatable.sortOrder).toEqual("asc");
Expand All @@ -197,24 +205,40 @@ describe("DataTable directive tests", ()=> {
]);
});

it("should set sortOrder to 'asc' if setSort is given something else than 'asc' or 'desc'", () => {
datatable.setSort("id", "bulb" as any);
expect(datatable.getSort()).toEqual({sortBy: "id", sortOrder: "asc"});
datatable.ngDoCheck();
expect(datatable.sortOrder).toEqual("asc");
expect(datatable.data).toEqual([
{id: 1, name: 'Duck'},
{id: 2, name: 'ącki'},
{id: 3, name: 'banana'},
{id: 4, name: 'Ananas'},
{id: 5, name: 'Ðrone'}
]);
});

it("shouldn't change order when only order provided", (done)=> {
done();
datatable.onSortChange.subscribe(()=> {
done.fail("OnSortChange shouldn't been fired");
});
datatable.ngDoCheck();
datatable.sortOrder = "desc";
datatable.ngOnChanges({sortOrder: new SimpleChange(null, datatable.sortOrder)});
datatable.ngOnChanges({sortOrder: new SimpleChange(null, datatable.sortOrder, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual(datatable.inputData);
});

it("should call output event when sorting changed", (done)=> {
datatable.ngDoCheck();
datatable.sortByChange.switchMap((sortBy: string)=> {
expect(sortBy).toEqual("id");
return datatable.sortOrderChange;
}).subscribe((sortOrder: string)=> {
datatable.sortByChange.pipe(
switchMap((sortBy: string)=> {
expect(sortBy).toEqual("id");
return datatable.sortOrderChange;
})
).subscribe((sortOrder: string)=> {
expect(sortOrder).toEqual("desc");
done();
});
Expand All @@ -228,8 +252,8 @@ describe("DataTable directive tests", ()=> {
done.fail("Shouldn't call sortOrderChange");
});
done();
datatable.sortOrder = "bulb";
datatable.ngOnChanges({sortOrder: new SimpleChange(null, datatable.sortOrder)});
datatable.sortOrder = "bulb" as any;
datatable.ngOnChanges({sortOrder: new SimpleChange(null, datatable.sortOrder, false)});
datatable.ngDoCheck();
});
// Wywołanie outputa gdy zmiana z innej strony
Expand Down Expand Up @@ -272,14 +296,16 @@ describe("DataTable directive tests", ()=> {
{name: 'Claire', age: 9},
{name: 'Anna', age: 34},
{name: 'Claire', age: 16},
{name: 'Anna', age: 12},
{name: 'Claire', age: 7},
{name: 'Anna', age: 12}
];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.setSort(['name', 'age'], "asc");
datatable.ngDoCheck();

expect(datatable.data).toEqual([
{name: 'Anna', age: 12},
{name: 'Anna', age: 12},
{name: 'Anna', age: 34},
{name: 'Claire', age: 7},
Expand All @@ -297,7 +323,7 @@ describe("DataTable directive tests", ()=> {
{name: 'Claire', city: {zip: '11111'}},
{name: 'Anna', city: {zip: '21111'}}
];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.setSort("city.zip", "asc");
datatable.ngDoCheck();

Expand All @@ -315,7 +341,7 @@ describe("DataTable directive tests", ()=> {
describe("data change", ()=> {
it("should refresh data when inputData change", ()=> {
let newData = [{id: 5, name: 'Ðrone'}, {id: 4, name: 'Ananas'}];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual([{id: 5, name: 'Ðrone'}, {id: 4, name: 'Ananas'}]);
});
Expand Down Expand Up @@ -347,7 +373,7 @@ describe("DataTable directive tests", ()=> {
done();
});
let newData = [{id: 5, name: 'Ðrone'}, {id: 4, name: 'Ananas'}];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.ngDoCheck();
});

Expand Down Expand Up @@ -375,7 +401,7 @@ describe("DataTable directive tests", ()=> {
expect(opt.rowsOnPage).toEqual(2);
done();
});
_.times(3, ()=>datatable.inputData.pop());
range(0, 3).forEach(()=>datatable.inputData.pop());
datatable.ngDoCheck();
});

Expand All @@ -384,7 +410,7 @@ describe("DataTable directive tests", ()=> {
datatable.ngDoCheck();

let newData = [{id: 5, name: 'Ðrone'}, {id: 4, name: 'Ananas'}];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual(newData);
});
Expand All @@ -406,7 +432,7 @@ describe("DataTable directive tests", ()=> {
datatable.ngDoCheck();

let newData = [{id: 5, name: 'Ðrone'}, {id: 1, name: 'Duck'}, {id: 4, name: 'Ananas'}];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.ngDoCheck();
expect(datatable.data).toEqual([{id: 1, name: 'Duck'}]);
});
Expand Down Expand Up @@ -436,7 +462,7 @@ describe("DataTable directive tests", ()=> {
datatable.ngDoCheck();

let newData = [];
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData, false)});
datatable.ngDoCheck();
expect(datatable.activePage).toEqual(1);
});
Expand All @@ -445,7 +471,7 @@ describe("DataTable directive tests", ()=> {
datatable.setPage(2, 1);
datatable.ngDoCheck();

_.times(5, ()=>datatable.inputData.pop());
range(0, 5).forEach(()=>datatable.inputData.pop());
datatable.ngDoCheck();
expect(datatable.inputData.length).toEqual(0);
expect(datatable.activePage).toEqual(1);
Expand Down
Loading