Skip to content

Commit

Permalink
Merge pull request #536 from EyeSeeTea/feature/support-dhis2-40-86942…
Browse files Browse the repository at this point in the history
…d0mj

Support DHIS2 40.0
  • Loading branch information
adrianq authored Jul 22, 2024
2 parents af3a2f6 + 01a44ae commit c96b638
Show file tree
Hide file tree
Showing 20 changed files with 380 additions and 92 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ bak/
src/dev
.eslintcache
/server
deploy/auth.sh
37 changes: 37 additions & 0 deletions deploy/build-and-deploy-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e -u -o pipefail

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
zipfile=data-management-app.zip

debug() {
echo "$@" >&2
}

build_app() {
test "${SKIP_BUILD:-}" && return 0
debug "Build App"
yarn build-webapp
}

deploy_app() {
local url=$1 auth=$2
test "${SKIP_DEPLOY_APP:-}" && return 0

debug "Post App: $zipfile -> $url"
curl -X POST -u "$auth" -v -F file=@"$zipfile" "$url/api/apps"
}

build_and_deploy() {
local url=$1 auth=$2 host=${3:-}

build_app
deploy_app "$url" "$auth"
if test "$host"; then
bash "$script_dir/deploy-scripts.sh" "$host"
fi

echo "Done"
}

build_and_deploy "$@"
15 changes: 15 additions & 0 deletions deploy/clone-pro-to-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e -u -o pipefail

# Actions:
#
# - In PRO: Create docker image and push to Harbor.
# - In TEST: Pull docker from Harbor and start.

# Requirements: Open vendorlink (spintldhis01, stintldhis01)

cd "$(dirname "$0")"
source "./lib.sh"

run spintldhis01 bash push-pro-docker.sh
run stintldhis01 bash deploy-test-from-pro.sh
26 changes: 26 additions & 0 deletions deploy/deploy-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# shellcheck disable=SC2029
set -e -u -o pipefail

script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

debug() {
echo "$@" >&2
}

get_current_branch() {
git rev-parse --abbrev-ref HEAD
}

deploy_scripts() {
local host=$1

local current_branch
current_branch=$(get_current_branch)
debug "Deploy branch: $current_branch -> $host"

rsync -v "$script_dir/deploy-remote-scripts.sh" "$host:"
ssh "$host" "sudo bash deploy-remote-scripts.sh $current_branch"
}

deploy_scripts "$@"
45 changes: 45 additions & 0 deletions deploy/deploy-test-from-pro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e -u -o pipefail

cd "$(dirname "$0")"
script_dir=$(pwd)
source "./lib.sh"
source "./tasks.sh"

image_test="docker.eyeseetea.com/samaritans/dhis2-data:40.4.0-sp-ip-test"

start_from_pro() {
local url=$1
local image_test_running

image_test_running=$(d2-docker list | grep RUN | awk '{print $1}' | grep -m1 ip-test) || true
if test "$image_test_running"; then
d2-docker commit "$image_test_running"
d2-docker copy "$image_test_running" "backup/sp-ip-test-$(timestamp)"
d2-docker stop "$image_test_running"
fi

d2-docker pull "$image_pro"
d2-docker copy "$image_pro" "$image_test"
sudo image=$image_test /usr/local/bin/start-dhis2-test

wait_for_dhis2_server "$url"
}

post_clone() {
local url=$1

#set_email_password "$url"
change_server_name "$url" "SP Platform - Test"
set_logos "$url" "$script_dir/test-icons"
}

main() {
local url
url=$(get_url 80)

start_from_pro "$url"
post_clone "$url"
}

main "$@"
3 changes: 2 additions & 1 deletion deploy/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]:-$0}")")"
source "$script_dir/auth.sh"

export image_pro="docker.eyeseetea.com/eyeseetea/dhis2-data:2.36.11.1-sp-ip-pro"
export image_test="docker.eyeseetea.com/samaritans/dhis2-data:2.36.11.1-sp-ip-test"
export image_dev="docker.eyeseetea.com/samaritans/dhis2-data:2.36.11.1-sp-ip-dev"
export image_training="docker.eyeseetea.com/samaritans/dhis2-data:2.36.11.1-sp-ip-training"

Expand Down Expand Up @@ -59,13 +58,15 @@ get_user_role_ids() {

change_server_name() {
local url=$1 title=$2

debug "Change server name: $title"
curl -sS -X POST "$url/api/systemSettings/applicationTitle" \
-d "$title" -H "Content-Type: application/json"
}

join_by() {
local IFS="$1"

shift
echo "$*"
}
2 changes: 1 addition & 1 deletion deploy/tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enable_users() {
}

set_email_password() {
local url=$url
local url=$1
echo "Set email password"
curl -sS -H 'Content-Type: text/plain' -u "$auth" \
"$url/api/systemSettings/keyEmailPassword" \
Expand Down
Binary file added deploy/test-icons/logo_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deploy/test-icons/logo_front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "data-management-app",
"description": "DHIS2 Data Management App",
"version": "1.7.1",
"version": "2.0.0",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand All @@ -10,7 +10,7 @@
"url": "git+https://github.com/eyeseetea/project-monitoring-app.git"
},
"dependencies": {
"@dhis2/app-runtime": "2.11.1",
"@dhis2/app-runtime": "3.2.1",
"@dhis2/d2-i18n": "1.1.1",
"@dhis2/d2-i18n-extract": "1.0.8",
"@dhis2/d2-i18n-generate": "1.2.0",
Expand Down Expand Up @@ -51,6 +51,7 @@
"striptags": "3.2.0",
"styled-components": "^5.2.1",
"styled-jsx": "3.4.1",
"use-debounce": "7.0.0",
"word-wrap": "1.2.5",
"xlsx": "^0.18.5"
},
Expand Down
11 changes: 7 additions & 4 deletions src/components/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ function autoResizeIframeByContent(
iframe: HTMLIFrameElement,
setHeight: (height: number) => void
): IntervalId {
const resize = () => {
// Get the first element that has the real height of the full dashboard (and not the forced large value).
function resize() {
// Get element with real height of the dashboard (not the initially forced large value).
const document = iframe?.contentWindow?.document;
const height = document?.querySelector(".dashboard-scroll-container > div")?.scrollHeight;

if (height && height > 0) setHeight(height);
};
if (height && height > 1000) {
setHeight(height);
}
}

return window.setInterval(resize, 1000);
}

Expand Down
6 changes: 6 additions & 0 deletions src/components/data-entry/data-entry-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export interface Options {
getOnSaveEvent?: boolean;
}

declare global {
interface Window {
jQuery: any;
}
}

/* Function to eval within the iframe to send/receive events to/from the parent page */
function setupDataEntryInterceptors(options: Options = {}) {
const iframeWindow = window as unknown as DataEntryWindow;
Expand Down
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import "./utils/lodash-mixins";
import { D2Api } from "./types/d2-api";
import i18n from "./locales";

import { Config } from "@dhis2/app-service-config/build/types/types";

import whyDidYouRender from "@welldone-software/why-did-you-render";

const apiVersion = 40;

async function getBaseUrl(): Promise<string> {
if (process.env.NODE_ENV === "development") {
const baseUrl = `/dhis2`;
Expand Down Expand Up @@ -43,7 +47,12 @@ async function main() {
const api = new D2Api({ baseUrl, backend: "fetch", timeout: 60 * 1000 });
const userSettings = (await api.get("/userSettings").getData()) as UserSettings;
configI18n(userSettings);
const config = { baseUrl, apiVersion: 30 };

const config: Config = {
baseUrl: baseUrl,
apiVersion: apiVersion,
systemInfo: d2.system.systemInfo,
};

try {
ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion src/models/Dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function getChartDashboardItem(
return {
id: getUid("dashboardItem", chart.id),
type: "CHART" as const,
chart: { id: chart.id },
visualization: { id: chart.id },
...(dashboardItemAttributes || {}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/ProjectDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default class ProjectDataSet {
.getData();
}

private getAttributeOptionCombo() {
getAttributeOptionCombo() {
const categoryOption = this.config.categoryOptions[this.dataSetType];
const aoc = categoryOption.categoryOptionCombos[0];
if (!aoc) throw new Error("Cannot get attribute option combo");
Expand Down
2 changes: 2 additions & 0 deletions src/models/ProjectDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export default class ProjectDb {

const dataSetTargetMetadata = this.getDataSetMetadata(orgUnit, {
name: `${project.name} Target`,
shortName: `${project.name.slice(0, 25)} [${project.id}] Target`,
code: "TARGET",
attributeValues: dataSetAttributeValues,
workflow: { id: config.dataApprovalWorkflows.project.id },
Expand All @@ -306,6 +307,7 @@ export default class ProjectDb {

const dataSetActualMetadata = this.getDataSetMetadata(orgUnit, {
name: `${project.name} Actual`,
shortName: `${project.name.slice(0, 25)} [${project.id}] Actual`,
code: "ACTUAL",
attributeValues: dataSetAttributeValues,
workflow: { id: config.dataApprovalWorkflows.project.id },
Expand Down
Loading

0 comments on commit c96b638

Please sign in to comment.