Current File : /home/inlingua/public_html/crm/ninexb/wp-content/plugins/tablesome/src/table/src/reducers.js
let self;class ReducersClass{constructor(e){self=this,self.hooks=e}getViewableRecords(e,t){return this.getPaginatedRecords(e,t.pagination)}getSfsRecords(e,t){let r=e;return r=this.getFilteredRecords(r,t.filters),r=this.getSearchedRecords(r,t.search,t.columns),r=this.getSortedRecords(r,t.sort),r}getPaginatedRecords(e,t){const r=t.currentPage*t.numOfRecordsPerPage,o=parseInt(r)+parseInt(t.numOfRecordsPerPage);return e.slice(r,o)}getTableSortRecords(e,t){return"read-only"!==t.mode||e.sort(((e,r)=>{let o=e[t.sortingBy],n=r[t.sortingBy],l="asc"===t.sortingOrder,s="created_at"===t.sortingBy||"updated_at"===t.sortingBy,i="custom"==t.sortingBy;return s?(o=new Date(o).getTime(),n=new Date(n).getTime(),l?o-n:n-o):i?l?o.localeCompare(n):n.localeCompare(o):void 0})),e}getFilteredRecords(e,t){let r=e;return t.forEach(((e,t)=>{e.column_id=e.filter_column_id,r=self.getFilteredRecordsFromSingleFilter(r,e)})),r}getSearchedRecords(e,t,r){return null==t||0==t.length?e:(t=t.toLowerCase(),e.filter((function(e){let o=!1;for(let n=0;n<e.content.length;n++){const l=e.content[n];let s=l.value,i=!1;const a=r[n].format;let c={isContentMatch:i,searchQuery:t,cell:l,cellType:a,column:r[n]};c=self.hooks.applyFilters("getSearchRecords",c),i=c.isContentMatch,"file"==a?i=parseInt(t)==parseInt(s)||i:i||(s="string"==typeof s?s.toLowerCase():"",i=s.toLowerCase().indexOf(t)>=0||i),i&&(o=!0)}return o})))}getSortedRecords(e,t){const r=t.order;return null==r||e.sort(((e,o)=>{let n={};if(-1==t.index){let r,l,s;"created_at"==t.field||"updated_at"==t.field?(r=new Date(e[t.field]).getTime()/1e3,l=new Date(o[t.field]).getTime()/1e3,s="number"):(r=e[t.field],l=o[t.field],s="text"),n={valueA:r,valueB:l,rowA:e[t.field],rowB:o[t.field],cellType:"text",sortType:s}}else n={valueA:"",valueB:"",rowA:e.content[t.index],rowB:o.content[t.index],cellType:t.column.format,sortType:"text"},n=self.hooks.applyFilters("getSortRecords",n);let l=n.valueA,s=n.valueB;return l===s?0:0==l.length?1:0==s.length?-1:"desc"==r?"number"==n.sortType?s-l:l<s?1:-1:"number"==n.sortType?l-s:l<s?-1:1})),e}getFilteredRecordsFromSingleFilter(e,t){return e.filter((function(e){let r=e.content[t.column_index].value;t.value;"textarea"==t.format&&(r=e.content[t.column_index].html,r=r.replace(/<[^>]+>/g,""));const o=null===r||""==r;if("empty"===t.operator.value)return o;if("not_empty"===t.operator.value)return!o;let n=!1,l={isContentMatch:n,filter:t,cell:e.content[t.column_index]};return l=self.hooks.applyFilters("getFilterRecords",l),n=l.isContentMatch,n}))}filterText(e,t,r){return t=t.toLowerCase(),r=r.toLowerCase(),"is"==e?t==r:"is_not"==e?t!=r:"contains"==e?t.includes(r):"does_not_contain"==e?!t.includes(r):"starts_with"==e?t.startsWith(r):"ends_with"==e?t.endsWith(r):"empty"==e||"not_empty"==e?t<=r:void 0}filterNumber(e,t,r){return"="==e?t==r:"!="==e?t!=r:">"==e?t>r:"<"==e?t<r:">="==e?t>=r:"<="==e?t<=r:void 0}}export default ReducersClass;