create-react-app d2-dhis2-user-list-app
Step-2: Run this app
Type the below command in your terminal:
npm start
Go to browser and type: http://localhost:3000Step-3: Install React and React-Dom packages:
npm install –save react npm install –save react-dom npm install –save react-scripts npm install –save d2Now update your package.json file:
{ "name": "d2-dhis2-user-list-app", "version": "0.1.0", "private": true, "dependencies": { "d2": "^29.1.5", "react": "^16.3.1", "react-dom": "^16.3.1", "react-scripts": "1.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }Step-4: Create manifest.webapp Run in your terminal:
touch manifest.webappGenerate manifest Or Add the below code:
{ "launch_path": "index.html", "default_locale": "en", "activities": { "dhis": { "href": "*" } }, "appType": "APP", "name": "d2-dhis2-user-list-app ", "version": "0.1.0", "description": "This is for demo Apps", "developer": { "name": "Julhas Sujan" }, "icons": { "48": "/icon.png" }, "manifest_generated_at": "Mon Nov 06 2017 20:23:35 GMT+0600 (Bangladesh Standard Time)" }Step-5: Update index.js file that located at src/index.js:
import React from 'react'; import ReactDOM from 'react-dom'; // Import the init function from D2 import { init } from 'd2/lib/d2'; const rootEl = document.getElementById('root'); // Prepare the D2 init config: const initConfig = { baseUrl: 'http://localhost:8080/dhis/api', schemas: ['user', 'dataSet'], headers: { authorization: `Basic ${btoa('admin:district')}` } }; // User component - renders a single user function User({ user }) { return ; } // User list component - renders a list of User components function UserList({ users }) { return (Let’s run the application:); } console.info('Initializing D2...'); init(initConfig) .then(d2 => { console.info('D2 initialized:', d2); window.d2 = d2; d2.models.dataSets.list() .then(dataSets => { const dataSet = dataSets.toArray()[0]; dataSet.name = dataSet.name + '!'; return dataSet.save(); }) .then(res => { console.info('Saved data set:', res); }) .catch(err => { console.warn('Failed to save data set:'. err); }); d2.models.dataSets.list().then(users => { ReactDOM.render(Got {users.size} users:
{users.toArray().map(user =>)} , rootEl); }); }) .catch(error => { console.warn('D2 failed to initialize:', error); })
npm startStep-6: Build the application and upload in app store. Run in console:
npm run buildZip the build files and upload it in App-Management. See the output!
import {init} from 'd2/lib/d2'; import {getInstance} from 'd2/lib/d2'; init({baseUrl:'https://play.dhis2.org/2.29/api/29/'});Step-2: Add the below code in your App class:
getInstance().then( d2=> { console.log(d2.currentUser.name) /*const req = new d2.analytics.request() .addDataDimension(['iReVg2xgFPL.REPORTING_RATE']) //'iReVg2xgFPL.REPORTING_RATE' .addPeriodDimension('LAST_12_MONTHS')// 'LAST_12_MONTHS' .addOrgUnitDimension('SJhtJq6WthC'); //'SJhtJq6WthC'*/ const req = new d2.analytics.request() .addDataDimension(['BfMAe6Itzgt.REPORTING_RATE']) //'iReVg2xgFPL.REPORTING_RATE' .addPeriodDimension('LAST_12_MONTHS')// 'LAST_12_MONTHS' .addOrgUnitDimension('ImspTQPwCqd'); //'SJhtJq6WthC' d2.analytics.aggregate.get(req) .then(analyticsInfo => { console.log("analyticsInfo: ",analyticsInfo.rows); }); });
create-react-app d2-dhis2-user-list-app
Step-2: Run this app
Type the below command in your terminal:
npm start
Go to browser and type: http://localhost:3000Step-3: Install React and React-Dom packages:
npm install –save react npm install –save react-dom npm install –save react-scripts npm install –save d2Now update your package.json file:
{ "name": "d2-dhis2-user-list-app", "version": "0.1.0", "private": true, "dependencies": { "d2": "^29.1.5", "react": "^16.3.1", "react-dom": "^16.3.1", "react-scripts": "1.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } }Step-4: Create manifest.webapp Run in your terminal:
touch manifest.webappGenerate manifest Or Add the below code:
{ "launch_path": "index.html", "default_locale": "en", "activities": { "dhis": { "href": "*" } }, "appType": "APP", "name": "d2-dhis2-user-list-app ", "version": "0.1.0", "description": "This is for demo Apps", "developer": { "name": "Julhas Sujan" }, "icons": { "48": "/icon.png" }, "manifest_generated_at": "Mon Nov 06 2017 20:23:35 GMT+0600 (Bangladesh Standard Time)" }Step-5: Update index.js file that located at src/index.js:
import React from 'react'; import ReactDOM from 'react-dom'; // Import the init function from D2 import { init } from 'd2/lib/d2'; const rootEl = document.getElementById('root'); // Prepare the D2 init config: const initConfig = { baseUrl: 'http://localhost:8080/dhis/api', schemas: ['user', 'dataSet'], headers: { authorization: `Basic ${btoa('admin:district')}` } }; // User component - renders a single user function User({ user }) { return ; } // User list component - renders a list of User components function UserList({ users }) { return (Let’s run the application:); } console.info('Initializing D2...'); init(initConfig) .then(d2 => { console.info('D2 initialized:', d2); window.d2 = d2; d2.models.dataSets.list() .then(dataSets => { const dataSet = dataSets.toArray()[0]; dataSet.name = dataSet.name + '!'; return dataSet.save(); }) .then(res => { console.info('Saved data set:', res); }) .catch(err => { console.warn('Failed to save data set:'. err); }); d2.models.dataSets.list().then(users => { ReactDOM.render(Got {users.size} users:
{users.toArray().map(user =>)} , rootEl); }); }) .catch(error => { console.warn('D2 failed to initialize:', error); })
npm startStep-6: Build the application and upload in app store. Run in console:
npm run buildZip the build files and upload it in App-Management. See the output!
import {init} from 'd2/lib/d2'; import {getInstance} from 'd2/lib/d2'; init({baseUrl:'https://play.dhis2.org/2.29/api/29/'});Step-2: Add the below code in your App class:
getInstance().then( d2=> { console.log(d2.currentUser.name) /*const req = new d2.analytics.request() .addDataDimension(['iReVg2xgFPL.REPORTING_RATE']) //'iReVg2xgFPL.REPORTING_RATE' .addPeriodDimension('LAST_12_MONTHS')// 'LAST_12_MONTHS' .addOrgUnitDimension('SJhtJq6WthC'); //'SJhtJq6WthC'*/ const req = new d2.analytics.request() .addDataDimension(['BfMAe6Itzgt.REPORTING_RATE']) //'iReVg2xgFPL.REPORTING_RATE' .addPeriodDimension('LAST_12_MONTHS')// 'LAST_12_MONTHS' .addOrgUnitDimension('ImspTQPwCqd'); //'SJhtJq6WthC' d2.analytics.aggregate.get(req) .then(analyticsInfo => { console.log("analyticsInfo: ",analyticsInfo.rows); }); });