Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing created/updated date and user who created/updated the contract #198

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
33 changes: 26 additions & 7 deletions src/components/contracts/ContractService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Contract from "./Contract";
import PluginRegistry from "../core/PluginRegistry";
import { getOrgUnitCoverage, checkSubContractCoverage, checkNonVisibleOverlap, getOverlaps } from "./utils/index";
import { getStartDateFromPeriod, getEndDateFromPeriod, getQuarterFromDate } from "./utils/periodsUtils";
import moment from "moment";

class ContractService {
constructor(api, program, allEventsSqlViewId) {
Expand Down Expand Up @@ -36,6 +37,11 @@ class ContractService {
path: event.orgUnitPath,
ancestors: event.ancestors || [],
};
contract.storedBy = event.storedBy;
contract.lastUpdatedBy = event.lastUpdatedBy;
contract.createdDate = event.createdDate;
contract.lastUpdatedDate = event.lastUpdatedDate;

return new Contract(contract);
}

Expand Down Expand Up @@ -108,12 +114,16 @@ class ContractService {
} catch (err) {
throw new Error("failed to parse : " + row[indexes.data_values].value + " " + err.message);
}

const dataValues = Object.keys(dataVals).map((k) => {
return {
dataElement: k,
...dataVals[k],
lastUpdatedBy: dataVals[k].lastUpdatedByUserInfo?.username ?? "",
storedBy: dataVals[k].createdByUserInfo?.username ?? "",
};
});

const ancestors = [];
const level = row[indexes.level];
for (var i = 1; i <= level; i += 1) {
Expand All @@ -124,6 +134,12 @@ class ContractService {
name: row[nameIndex],
});
}
const additionalInfos = dataValues[0];
const storedBy = additionalInfos.storedBy;
const lastUpdatedBy = additionalInfos.lastUpdatedBy;
const createdDate = moment(additionalInfos.created).format("DD/MM/YYYY HH:mm:ss");
const lastUpdatedDate = moment(additionalInfos.lastUpdated).format("DD/MM/YYYY HH:mm:ss");

return {
event: row[indexes.event_id],
orgUnit: row[indexes.org_unit_id],
Expand All @@ -133,11 +149,14 @@ class ContractService {
program: row[indexes.program_id],
programStage: row[indexes.program_stage_id],
dataValues: dataValues,
storedBy: storedBy,
lastUpdatedBy: lastUpdatedBy,
createdDate: createdDate,
lastUpdatedDate: lastUpdatedDate,
};
});

const contracts = events.map((e) => this.toContract(e));

return contracts;
}

Expand Down Expand Up @@ -276,19 +295,19 @@ class ContractService {

getEvent = (contractInfo, orgUnitId, contractId) => {
const dataValues = [];
const ignoredFields = ["id", "orgUnit"];
const ignoredFields = ["id", "orgUnit", "createdDate", "lastUpdatedDate", "storedBy", "lastUpdatedBy"];

Object.keys(contractInfo).forEach((fieldKey) => {
if (!ignoredFields.includes(fieldKey)) {
const dataElement = Object.values(this.mappings).find((mapping) => mapping.code === fieldKey);
if (dataElement === undefined) {
throw new Error(
"no mapping for field " +
fieldKey +
" vs " +
Object.values(this.mappings)
.map((m) => m.code)
.join(","),
fieldKey +
" vs " +
Object.values(this.mappings)
.map((m) => m.code)
.join(","),
);
}
let value = contractInfo[fieldKey];
Expand Down
52 changes: 46 additions & 6 deletions src/components/contracts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const contractsTableColumns = (
) => {
const hasSubContractEnabled = !!contractFields.find((c) => c.code == "contract_main_orgunit");

const columns = [
let columns = [
{
name: "id",
label: t("id"),
Expand Down Expand Up @@ -256,6 +256,47 @@ export const contractsTableColumns = (
});
}
});

let notStandardFields = [
{
name: "fieldValues.storedBy",
label: t("contracts.created_by"),
options: {
filter: true,
display: false,
sort: true
},
},
{
name: "fieldValues.createdDate",
label: t("contracts.created_at"),
options: {
filter: true,
display: false,
sort: true
}
},
{
name: "fieldValues.lastUpdatedBy",
label: t("contracts.updated_by"),
options: {
filter: true,
display: true,
sort: true
}
},
{
name: "fieldValues.lastUpdatedDate",
label: t("contracts.updated_at"),
options: {
filter: true,
display: true,
sort: true
}
}
];

columns = columns.concat(notStandardFields);
columns.push({
name: "id",
label: t("table.actions.title"),
Expand Down Expand Up @@ -288,11 +329,10 @@ export const contractsTableColumns = (
{!isDetail && (
<Tooltip placement="bottom" title={t("contracts.seeOrgUnit")} arrow>
<Link
to={`/contracts/${
contract.fieldValues.contract_main_orgunit
? contract.fieldValues.contract_main_orgunit
: contract.orgUnit.id
}`}
to={`/contracts/${contract.fieldValues.contract_main_orgunit
? contract.fieldValues.contract_main_orgunit
: contract.orgUnit.id
}`}
className={classes.marginLeft}
>
<IconButton size="small">
Expand Down
6 changes: 5 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
"contract_main_orgunit_id": "Main org unit id",
"massUpdate": "Mass Update",
"warnings": "Warnings",
"showAll":"Show non editable contracts"
"showAll":"Show non editable contracts",
"created_at" : "Created At",
"created_by" : "Created by",
"updated_at" : "Updated At",
"updated_by" : "Updated by"
},
"dataEntry": {
"accessAndApproval": "Access & Approval Workflow",
Expand Down
6 changes: 5 additions & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
"contract_main_orgunit_id": "Id de l'unité d'organisation principale",
"massUpdate": "Update en masse",
"warnings": "Warnings",
"showAll": "Montrer les contrats non éditable"
"showAll": "Montrer les contrats non éditable",
"created_at" : "Créé le",
"created_by" : "Créé par",
"updated_at" : "Modifié le",
"updated_by" : "Modifié par"
},
"dataEntry": {
"accessAndApproval": "Workflow d'approbation et droit d'accès",
Expand Down