xenos
Version:
Xenos is a data grid built upon angular2 and bootstrap.
252 lines • 9.36 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require("@angular/core");
var view_source_1 = require("./view-source");
var fts_filter_descriptor_1 = require("./fts-filter-descriptor");
var i18n_service_1 = require("./i18n.service");
var observable_array_1 = require("./observable-array");
var DataGrid = (function () {
function DataGrid(renderer, elementRef, i18nService) {
var _this = this;
this.renderer = renderer;
this.elementRef = elementRef;
this.i18nService = i18nService;
this.itemsPresenter = [];
this.pagingRangeInternal = [];
this.deferRefreshInternal = false;
this.viewSource = new view_source_1.ViewSource();
this.viewSource.itemsViewChanging
.subscribe(function (x) { return _this.lastSnapShotInternal = x; });
this.viewSource.itemsViewChanged
.subscribe(function (x) { return _this.onItemsViewChanged(x); });
this.viewSource.filterDescriptors.itemsChanged.subscribe(function (x) {
_this.autoRefresh();
});
this.viewSource.sortDescriptors.itemsChanged.subscribe(function (x) {
_this.autoRefresh();
});
this.columnsInternal = new observable_array_1.ObservableArray();
this.columnsInternal.itemsChanged.subscribe(function (x) {
x.itemsRemoved.forEach(function (x) { return x.dataGrid = undefined; });
x.itemsAdded.forEach(function (x) {
x.dataGrid = _this;
if (x.initialSortDirection) {
x.sortDirection = x.initialSortDirection;
}
});
});
}
Object.defineProperty(DataGrid.prototype, "pageSize", {
get: function () {
return this.viewSource.pageSize;
},
set: function (value) {
this.viewSource.pageSize = value;
this.autoRefresh();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "searchPhrase", {
set: function (phrase) {
var index = this.filterDescriptors.findIndex(function (x) { return x.id === fts_filter_descriptor_1.FtsFilterDescriptor.id; });
if (~index) {
this.filterDescriptors.splice(index, 1);
}
if (!phrase) {
return;
}
this.filterDescriptors.push(new fts_filter_descriptor_1.FtsFilterDescriptor(this.columns, phrase));
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "itemsViewChanging", {
get: function () {
return this.viewSource.itemsViewChanging;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "itemsViewChanged", {
get: function () {
return this.viewSource.itemsViewChanged;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "i18n", {
get: function () {
return this.i18nService;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "columns", {
get: function () {
return this.columnsInternal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "working", {
get: function () {
return this.viewSource.working;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "filterDescriptors", {
get: function () {
return this.viewSource.filterDescriptors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "sortDescriptors", {
get: function () {
return this.viewSource.sortDescriptors;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "pageCount", {
get: function () {
return this.viewSource.pageCount;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "pageIndex", {
get: function () {
return this.viewSource.pageIndex;
},
set: function (value) {
this.viewSource.pageIndex = value;
this.autoRefresh();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "itemsSource", {
get: function () {
return this.viewSource.itemsSource;
},
set: function (source) {
this.viewSource.itemsSource = source;
this.autoRefresh();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "lastSnapShot", {
get: function () {
if (!this.lastSnapShotInternal) {
return undefined;
}
return this.lastSnapShotInternal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DataGrid.prototype, "items", {
get: function () {
return this.itemsPresenter;
},
enumerable: true,
configurable: true
});
DataGrid.prototype.deferRefresh = function () {
this.deferRefreshInternal = true;
};
DataGrid.prototype.refresh = function () {
this.viewSource.refresh();
this.deferRefreshInternal = false;
};
DataGrid.prototype.autoRefresh = function () {
if (this.deferRefreshInternal)
return;
this.viewSource.refresh();
};
DataGrid.prototype.onItemsViewChanged = function (items) {
var _this = this;
this.itemsPresenter.splice(0);
items.forEach(function (x) { return _this.itemsPresenter.push(x); });
};
DataGrid.prototype.onHeaderClicked = function (event, column) {
event.stopPropagation();
event.preventDefault();
if (column.disableSorting) {
return;
}
this.deferRefresh();
if (!event.ctrlKey) {
this.columns.forEach(function (x) {
if (x.id === column.id)
return;
x.sortDirection = undefined;
});
}
column.cycleSortDirections();
this.refresh();
};
DataGrid.prototype.onPageChanged = function (event, i) {
event.preventDefault();
this.viewSource.pageIndex = i;
this.autoRefresh();
};
Object.defineProperty(DataGrid.prototype, "pagingRange", {
get: function () {
this.pagingRangeInternal.splice(0);
var start = this.pageIndex - 4;
var end = this.pageIndex + 5;
if (start < 0) {
var s = Math.abs(start);
start += s;
end = Math.min(end + Math.abs(s), this.pageCount);
}
if (end > this.pageCount) {
var e = end;
end = end + (this.pageCount - e);
start = Math.max(start + (this.pageCount - e), 0);
}
for (var i = start; i < end; i++) {
this.pagingRangeInternal.push(i);
}
return this.pagingRangeInternal;
},
enumerable: true,
configurable: true
});
DataGrid.prototype.ngAfterViewInit = function () {
};
__decorate([
core_1.ViewChild("table"),
__metadata('design:type', core_1.ElementRef)
], DataGrid.prototype, "table", void 0);
__decorate([
core_1.Input(),
__metadata('design:type', Number),
__metadata('design:paramtypes', [Number])
], DataGrid.prototype, "pageSize", null);
DataGrid = __decorate([
core_1.Component({
moduleId: module.id,
selector: "data-grid",
templateUrl: "data-grid.component.html",
styleUrls: ["data-grid.component.min.css"]
}),
__metadata('design:paramtypes', [core_1.Renderer, core_1.ElementRef, i18n_service_1.I18nService])
], DataGrid);
return DataGrid;
}());
exports.DataGrid = DataGrid;
//# sourceMappingURL=data-grid.component.js.map