🧲 New features Custom user role permissions Employee edit form updated Employee daily task list Attendance and employee distribution charts on dashboard Improvements to company structure and company assets module Improved tables for displaying data in several modules Faster data loading (specially for employee module) Initials based profile pictures Re-designed login page Re-designed user profile page Improvements to filtering New REST endpoints for employee qualifications 🐛 Bug fixes Fixed, issue with managers being able to create performance reviews for employees who are not their direct reports Fixed, issues related to using full profile image instead of using smaller version of profile image Changing third gender to other Improvements and fixes for internal frontend data caching
115 lines
3.3 KiB
JavaScript
115 lines
3.3 KiB
JavaScript
const axios = require('axios');
|
|
|
|
class IceDataPipe {
|
|
constructor(adapter, pageSize = 10) {
|
|
this.adapter = adapter;
|
|
this.pageSize = pageSize;
|
|
}
|
|
|
|
readMetaData() {
|
|
this.adapter.initFieldMasterData();
|
|
}
|
|
|
|
get({
|
|
page, search, sortField, sortOrder, filters, limit,
|
|
}) {
|
|
const pageSize = limit || this.pageSize;
|
|
const start = (page - 1) * pageSize;
|
|
const dataUrl = this.getDataUrl(
|
|
this.adapter.getDataMapping(),
|
|
search,
|
|
filters,
|
|
);
|
|
let url = `${dataUrl}&iDisplayStart=${start}&iDisplayLength=${pageSize}`;
|
|
url = this.applySortingData(this.adapter.getDataMapping(), url, sortField, sortOrder);
|
|
// $.post(url, (data) => {
|
|
// that.getSuccessCallBack(callBackData, data);
|
|
// }, 'json').always(() => { that.hideLoader(); });
|
|
url = `${url}&version=v2`;
|
|
return axios.post(url, {})
|
|
.then((data) => {
|
|
const key = this.getRequestKey(page, search, sortField, sortOrder, filters, limit);
|
|
const response = {
|
|
items: data.data.objects,
|
|
total: data.data.totalRecords,
|
|
};
|
|
if (this.adapter.localStorageEnabled) {
|
|
window.localStorage.setItem(key, JSON.stringify(response));
|
|
}
|
|
|
|
return response;
|
|
});
|
|
}
|
|
|
|
getCachedResponse({
|
|
page, search, sortField, sortOrder, filters, limit,
|
|
}) {
|
|
const key = this.getRequestKey(page, search, sortField, sortOrder, filters, limit);
|
|
const cachedResponse = window.localStorage.getItem(key);
|
|
if (!cachedResponse) {
|
|
return null;
|
|
}
|
|
|
|
return JSON.parse(cachedResponse);
|
|
}
|
|
|
|
clearCachedResponse({
|
|
page, search, sortField, sortOrder, filters, limit,
|
|
}) {
|
|
const key = this.getRequestKey(page, search, sortField, sortOrder, filters, limit);
|
|
window.localStorage.setItem(key, null);
|
|
}
|
|
|
|
getRequestKey(page, search, sortField, sortOrder, filters, limit) {
|
|
return `${this.adapter.table}|${page}|${search}|${sortField}|${sortOrder}|${filters}|${limit}`;
|
|
}
|
|
|
|
applySortingData(columns, url, sortField, sortOrder) {
|
|
let orderBy = '';
|
|
if (sortField) {
|
|
url = `${url}&sorting=1`;
|
|
url = `${url}&iSortCol_0=${columns.indexOf(sortField)}`;
|
|
url = `${url}&sSortDir_0=${(sortOrder === 'descend') ? 'DESC' : 'ASC'}`;
|
|
} else if (this.adapter.getOrderBy() !== null) {
|
|
// Setting the fix ordering
|
|
orderBy = this.adapter.getOrderBy();
|
|
url = `${url}&ob=${orderBy}`;
|
|
}
|
|
|
|
return url;
|
|
}
|
|
|
|
getDataUrl(_columns, searchTerm, filters) {
|
|
const sourceMappingJson = JSON.stringify(this.adapter.getSourceMapping());
|
|
|
|
const columns = JSON.stringify(_columns);
|
|
|
|
let filterJson = '';
|
|
if (this.adapter.getFilter() !== null) {
|
|
filterJson = JSON.stringify(this.adapter.getFilter());
|
|
}
|
|
|
|
let url = this.adapter.moduleRelativeURL.replace('service.php', 'data.php');
|
|
url = `${url}?t=${this.adapter.table}`;
|
|
url = `${url}&sm=${sourceMappingJson}`;
|
|
url = `${url}&cl=${columns}`;
|
|
url = `${url}&ft=${filterJson}`;
|
|
|
|
if (searchTerm && searchTerm.trim() !== '') {
|
|
url += `&sSearch=${searchTerm}`;
|
|
}
|
|
|
|
if (this.adapter.isSubProfileTable()) {
|
|
url = `${url}&type=sub`;
|
|
}
|
|
|
|
if (this.adapter.remoteTableSkipProfileRestriction()) {
|
|
url = `${url}&skip=1`;
|
|
}
|
|
|
|
return url;
|
|
}
|
|
}
|
|
|
|
export default IceDataPipe;
|