angular4-material-table
Version:
Angular 4 table based on @angular/cdk table structure, to allow row insertion, edition, validation and deletion.
1 lines • 3.89 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("@angular/forms"),require("@angular/cdk/collections"),require("rxjs/BehaviorSubject"),require("rxjs/Subject"),require("lodash.clonedeep")):"function"==typeof define&&define.amd?define(["exports","@angular/common","@angular/core","@angular/forms","@angular/cdk/collections","rxjs/BehaviorSubject","rxjs/Subject","lodash.clonedeep"],e):e((t.ng=t.ng||{},t.ng["angular-material-table"]={}),t.ng.common,t.ng.core,t.ng.forms,t.ng.cdk.collections,t.Rx,t.Rx,t.index)}(this,function(t,e,r,o,n,i,a,c){"use strict";c=c&&c.hasOwnProperty("default")?c.default:c;var u=function(){return function(){}}();u.decorators=[{type:r.NgModule,args:[{declarations:[],imports:[e.CommonModule],exports:[]}]}],u.ctorParameters=function(){return[]};var s=function(){function t(){}return t.prototype.getRowValidator=function(){return new o.FormGroup({})},t}();s.decorators=[{type:r.Injectable}],s.ctorParameters=function(){return[]};var d=function(){function t(t){Object.assign(this,t)}return t.prototype.delete=function(){this.source.delete(this.id)},t.prototype.confirmCreate=function(){this.editing=!1,this.source.confirmCreate(this)},t.prototype.confirmEditCreate=function(){this.originalData=void 0,this.editing=!1,-1==this.id?this.source.confirmCreate(this):this.source.confirmEdit(this)},t.prototype.startEdit=function(){this.originalData=c(this.currentData),this.editing=!0},t.prototype.cancel=function(){-1!=this.id&&this.editing?(this.currentData=this.originalData,this.editing=!1):this.delete()},t}(),l=function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}}(),f=function(t){function e(e,r,o){var n=t.call(this)||this;if(n.validatorService=o,o||(n.validatorService=new s),r)n.dataConstructor=r;else{if(!(e&&e.length>0))throw new Error("You must define either a non empty array, or an associated class to build the table.");n.dataKeys=Object.keys(e[0])}return n.rowsSubject=new i.BehaviorSubject(n.getRowsFromData(e)),n.datasourceSubject=new a.Subject,n.rowsSubject.subscribe(function(t){return n.updateDatasource(t)}),n}return l(e,t),e.prototype.confirmEdit=function(t){if(t.validator.valid){var e=this.rowsSubject.getValue();e[t.id]=t,this.rowsSubject.next(e)}},e.prototype.confirmCreate=function(t){if(t.validator.valid){var e=this.rowsSubject.getValue();t.id=e.length-1,this.rowsSubject.next(e)}},e.prototype.createNew=function(){var t=this.rowsSubject.getValue();(0==t.length||t[t.length-1].id>-1)&&(t.push(new d({id:-1,editing:!0,currentData:this.createNewObject(),source:this,validator:this.validatorService.getRowValidator()})),this.rowsSubject.next(t))},e.prototype.delete=function(t){var e=this.rowsSubject.getValue(),r=-1==t?e.length-1:t;e.splice(r,1),this.rowsSubject.next(e)},e.prototype.getDataFromRows=function(t){return t.filter(function(t){return-1!=t.id}).map(function(t){return t.originalData?t.originalData:t.currentData})},e.prototype.updateDatasource=function(t){this.datasourceSubject.next(this.getDataFromRows(t))},e.prototype.getRowsFromData=function(t){var e=this;return t.map(function(t,r){return new d({id:r,editing:!1,currentData:t,source:e,validator:e.validatorService.getRowValidator()})})},e.prototype.createNewObject=function(){return this.dataConstructor?new this.dataConstructor:this.dataKeys.reduce(function(t,e){return t[e]=void 0,t},{})},e.prototype.connect=function(){return this.rowsSubject.asObservable()},e.prototype.disconnect=function(){},e}(n.DataSource);t.AppModule=u,t.DefaultValidatorService=s,t.TableDataSource=f,t.TableElement=d,Object.defineProperty(t,"__esModule",{value:!0})});