Skip to content

Commit

Permalink
Merge pull request #7 from openimis/feature/OMT-25
Browse files Browse the repository at this point in the history
Feature/omt 25
  • Loading branch information
xgill authored Oct 14, 2019
2 parents 3170662 + 71f9c2c commit 8ab318b
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 79 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins":[
"@babel/plugin-proposal-class-properties"
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ COPY . /app/
WORKDIR /app
RUN node openimis-config.js
RUN . ./modules-installs.txt
RUN yarn install
RUN yarn install --network-timeout 1000000
RUN yarn build
RUN yarn global add serve
15 changes: 12 additions & 3 deletions openimis-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ function processLocales(config) {
},
{}
);
locales.write(`export const locales = ${JSON.stringify(config['locales'].map((lc) => lc.intl))}\n`);
let filesByLang = config['locales'].reduce(
(fls, lc) => {
lc.languages.forEach((lg) => fls[lg] = lc.fileNames);
return fls
},
{}
);
locales.write(`export const locales = ${JSON.stringify(config['locales'].map((lc) => lc.intl))}`);
locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`);
locales.write(`\nexport default ${JSON.stringify(localeByLang)}`);
}

Expand All @@ -20,15 +28,16 @@ function processModules(config) {
var modulesLinks = fs.createWriteStream('./modules-links.txt');
var modulesUnlinks = fs.createWriteStream('./modules-unlinks.txt');

modulesInstalls.write('yarn add')
config['modules'].forEach((module) => {
let lib = module.npm.substring(0, module.npm.lastIndexOf('@'));
srcModules.write(`import { ${module.name} } from '${lib}';\n`);
modulesInstalls.write(`yarn remove ${lib}\n`);
modulesInstalls.write(`yarn add ${module.npm}\n`);
modulesInstalls.write(` ${module.npm}`);
modulesRemoves.write(`yarn remove ${lib}\n`);
modulesLinks.write(`yarn link ${lib}\n`);
modulesUnlinks.write(`yarn unlink ${lib}\n`);
});
modulesInstalls.write('\n')
srcModules.write("\nfunction logicalName(npmName) {\n\t");
srcModules.write("return [...npmName.match(/([^/]*)\\/([^@]*).*/)][2];\n");
srcModules.write("}\n");
Expand Down
54 changes: 37 additions & 17 deletions openimis.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,65 @@
{
"locales": [{"intl": "en-GB", "languages":["en"]}],
"locales": [
{
"languages": [
"en", "en-GB"
],
"intl": "en-GB",
"fileNames": "en"
}
],
"modules": [
{
"name": "CoreModule",
"npm": "@openimis/fe-core@0.0.12"
"npm": "@openimis/fe-core@0.0.27"
},
{
"name": "HomeModule",
"npm": "@openimis/fe-home@0.0.5"
},
"npm": "@openimis/fe-home@0.0.11"
},
{
"name": "LocationModule",
"npm": "@openimis/fe-location@0.0.3"
},
"npm": "@openimis/fe-location@0.0.11"
},
{
"name": "InsureeModule",
"npm": "@openimis/fe-insuree@0.0.8"
"npm": "@openimis/fe-insuree@0.0.17"
},
{
"name": "MedicalModule",
"npm": "@openimis/fe-medical@0.0.3"
},
"npm": "@openimis/fe-medical@0.0.10"
},
{
"name": "MedicalPriceListModule",
"npm": "@openimis/fe-medical_pricelist@0.0.3"
},
{
"name": "ProductModule",
"npm": "@openimis/fe-product@0.0.5"
},
{
"name": "PolicyModule",
"npm": "@openimis/fe-policy@0.0.6"
},
"npm": "@openimis/fe-policy@0.0.13"
},
{
"name": "ClaimModule",
"npm": "@openimis/fe-claim@0.0.8"
"npm": "@openimis/fe-claim@0.0.22"
},
{
"name": "ClaimBatchModule",
"npm": "@openimis/fe-claim_batch@0.0.6"
},
{
"name": "AdminModule",
"npm": "@openimis/fe-admin@0.0.9"
"npm": "@openimis/fe-admin@0.0.16"
},
{
"name": "ToolsModule",
"npm": "@openimis/fe-tools@0.0.7"
"npm": "@openimis/fe-tools@0.0.13"
},
{
"name": "ProfileModule",
"npm": "@openimis/fe-profile@0.0.7"
}
"npm": "@openimis/fe-profile@0.0.12"
}
]
}
}
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
"homepage": "http://localhost/front",
"dependencies": {
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@material-ui/core": "^4.1.2",
"@date-io/core": "^1.3.9",
"@date-io/moment": "^1.3.9",
"@material-ui/core": "^4.3.3",
"@material-ui/icons": "^4.2.1",
"@openimis/fe-home": "0.0.2",
"@material-ui/pickers": "^3.2.2",
"classnames": "^2.2.6",
"express": "^4.16.4",
"history": "^4.9.0",
"lodash": "^4.17.11",
"jquery": "^3.4.1",
"lodash": "^4.17.15",
"lodash-uuid": "^0.0.3",
"moment": "^2.24.0",
"nepali-date-picker": "^2.0.1",
"prop-types": "^15.5.4",
"react": "^16.8.6",
"react-autosuggest": "^9.4.3",
Expand Down Expand Up @@ -51,7 +56,8 @@
]
},
"devDependencies": {
"babel-cli": "^6.26.0",
"@babel/cli": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"react-app-rewired": "^2.1.3"
}
}
3 changes: 3 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://unpkg.com/nepali-date-picker@2.0.0/dist/jquery.nepaliDatePicker.min.js" integrity="sha384-bBN6UZ/L0DswJczUYcUXb9lwIfAnJSGWjU3S0W5+IlyrjK0geKO+7chJ7RlOtrrF" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://unpkg.com/nepali-date-picker@2.0.0/dist/nepaliDatePicker.min.css" integrity="sha384-Fligaq3qH5qXDi+gnnhQctSqfMKJvH4U8DTA+XGemB/vv9AUHCwmlVR/B3Z4nE+q" crossorigin="anonymous">
</body>
</html>
19 changes: 19 additions & 0 deletions src/HistoryProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, Children } from "react";
import PropTypes from "prop-types";

class HistoryProvider extends Component {
static propTypes = {
history: PropTypes.object.isRequired,
}
static childContextTypes = {
history: PropTypes.object.isRequired,
}
getChildContext() {
const { history } = this.props
return { history }
}
render() {
return Children.only(this.props.children)
}
}
export default HistoryProvider
6 changes: 5 additions & 1 deletion src/LocalesManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addLocaleData } from "react-intl";
import localeByLang, { locales } from "./locales";
import localeByLang, { locales, fileNamesByLang } from "./locales";

class LocalesManager {

Expand All @@ -11,6 +11,10 @@ class LocalesManager {
return localeByLang[lang];
}

getFileNameByLang(lang) {
return fileNamesByLang[lang];
}

}

export default LocalesManager;
40 changes: 24 additions & 16 deletions src/ModulesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@ class ModulesManager {
this.modules = modules(cfg);
this.contributionsCache = {};
this.controlsCache = this.buildControlsCache();
this.componentsCache = this.buildComponentsCache();
this.refsCache = this.buildRefsCache();
}

buildControlsCache() {
let ctrls = {};
const ctrls = {};
for (var k in this.cfg) {
if (!!this.cfg[k].controls) {
this.cfg[k].controls.forEach(c => ctrls[c['fieldName']] = c['usage']);
for (var i in this.cfg[k].controls) {
var c = this.cfg[k].controls[i];
ctrls[k+'.'+c['field']] = c['usage'];
}
}
}
return ctrls;
}

buildComponentsCache() {
return this.getContributions("components")
.reduce((comps, comp) => {
comps[comp.key] = comp.component;
return comps
buildRefsCache() {
return this.getContribs("refs")
.reduce((refs, r) => {
refs[r.key] = r.ref;
return refs
}, {});
}

Expand All @@ -37,19 +40,24 @@ class ModulesManager {
return versions;
}

skipControl(module, key) {
return this.controlsCache['fe-'+module+"."+key] === "S";
hideField(module, key) {
return this.controlsCache['fe-'+module+"."+key] & 1;
}

getComponent(key) {
return this.componentsCache[key];
getRef(key) {
return this.refsCache[key];
}

getContributions(key) {
getProjection(key) {
const proj = this.getRef(key);
return !!proj ? `{${proj.join(", ")}}` : "";
}

getContribs(key) {
if (this.contributionsCache[key]) {
return this.contributionsCache[key];
}
let res = this.modules.reduce((contributions, module) => {
const res = this.modules.reduce((contributions, module) => {
const contribs = (module || {})[key];
if (contribs) {
contributions.push(...contribs);
Expand All @@ -60,8 +68,8 @@ class ModulesManager {
return res;
}

getConfiguration(module, key, defaultValue = null) {
let moduleCfg = this.cfg[module] || {};
getConf(module, key, defaultValue = null) {
const moduleCfg = this.cfg[module] || {};
return moduleCfg[key] !== undefined ? moduleCfg[key] : defaultValue;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { createBrowserHistory } from "history";
export default createBrowserHistory();
Loading

0 comments on commit 8ab318b

Please sign in to comment.