122 lines
3.5 KiB
JavaScript
122 lines
3.5 KiB
JavaScript
import jsonpath from "jsonpath";
|
|
import data from "../../data/collections.json";
|
|
import {
|
|
getBasicSearchDetails,
|
|
getBasicSearchDetailsPaged,
|
|
} from "../../actions";
|
|
|
|
/*
|
|
* Get the lookup collection by the appeal type entity
|
|
* @param String formtype - string from appeal entity name
|
|
*/
|
|
export const getFormCollection = (formtype) => {
|
|
const collectionName = jsonpath.query(
|
|
data,
|
|
"$..[?(@.LogicalName=='" + formtype + "')]"
|
|
);
|
|
return collectionName[0];
|
|
};
|
|
|
|
export const getFormCollectionByID = (appealTypeID) => {
|
|
const collectionName = jsonpath.query(
|
|
data,
|
|
"$..[?(@.appealTypeID =='" + appealTypeID + "')]"
|
|
);
|
|
return collectionName[0];
|
|
};
|
|
|
|
export const getPickListLabel = (data, picklistType, picklistID) => {
|
|
const pickListData = jsonpath.query(
|
|
data,
|
|
"$..[?(@.LogicalName=='" + picklistType + "')]"
|
|
);
|
|
|
|
const pickListLabel = jsonpath.query(
|
|
pickListData,
|
|
"$..[?(@.Value=='" + picklistID + "')].Label.LocalizedLabels..Label"
|
|
);
|
|
return pickListLabel[0];
|
|
};
|
|
|
|
/*
|
|
* Get the details of a case from the appeal type
|
|
* @param object searchResultsObj
|
|
*/
|
|
export const getSearchDetails = (searchResultsObj) => {
|
|
//console.log(searchResultsObj);
|
|
|
|
let detailsArr = [];
|
|
searchResultsObj = searchResultsObj.value;
|
|
const detailsObj = searchResultsObj.map((searchDetail, index) => {
|
|
if (searchDetail.pinswg_appealcasetype == null) {
|
|
console.log(searchDetail.title);
|
|
} else {
|
|
let formMeta = getFormCollectionByID(
|
|
searchDetail.pinswg_appealcasetype
|
|
);
|
|
//console.log(formMeta);
|
|
detailsArr.push(
|
|
getBasicSearchDetails(
|
|
formMeta.LogicalCollectionName,
|
|
searchDetail.title,
|
|
formMeta.PrimaryIdAttribute,
|
|
searchDetail.incidentid
|
|
)
|
|
);
|
|
}
|
|
});
|
|
//console.log(detailsArr);
|
|
return Promise.all(detailsArr);
|
|
};
|
|
|
|
/*
|
|
* Get the details of a case from the appeal type
|
|
* @param object searchResultsObj
|
|
*/
|
|
export const getSearchDetailsPaged = (searchResultsObj) => {
|
|
//console.log(searchResultsObj);
|
|
|
|
let detailsArr = [];
|
|
//console.log("search results", searchResultsObj);
|
|
searchResultsObj = searchResultsObj.value;
|
|
const detailsObj = searchResultsObj.map((searchDetail, index) => {
|
|
//console.log(searchDetail);
|
|
if (searchDetail.pinswg_appealcasetype == null) {
|
|
console.log(searchDetail.title);
|
|
} else {
|
|
let formMeta = getFormCollectionByID(
|
|
searchDetail.pinswg_appealcasetype
|
|
);
|
|
|
|
detailsArr.push(
|
|
getBasicSearchDetailsPaged(
|
|
formMeta.LogicalCollectionName,
|
|
searchDetail.title,
|
|
formMeta.PrimaryIdAttribute,
|
|
searchDetail.incidentid
|
|
)
|
|
);
|
|
}
|
|
});
|
|
// console.log(detailsArr);
|
|
return Promise.all(detailsArr);
|
|
};
|
|
|
|
// export const absoluteUrl = (req, setLocalhost) => {
|
|
// var protocol = "https:";
|
|
// var host = req
|
|
// ? req.headers["x-forwarded-host"] || req.headers["host"]
|
|
// : window.location.host;
|
|
|
|
// if (host.indexOf("localhost") > -1) {
|
|
// if (setLocalhost) host = setLocalhost;
|
|
// protocol = "http:";
|
|
// }
|
|
|
|
// return {
|
|
// protocol: protocol,
|
|
// host: host,
|
|
// origin: protocol + "//" + host,
|
|
// };
|
|
// };
|