Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1367 from SAP/feature/migrations-diff-view
Browse files Browse the repository at this point in the history
feat: migrations diff view
  • Loading branch information
ThuF authored Mar 8, 2022
2 parents 41cd4b0 + b1e8358 commit 439105e
Show file tree
Hide file tree
Showing 19 changed files with 501 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ derby.log
!releng/buildpacks/**/bin/

# Ignore Neo SDK
resources/resources-neo-sdk/src/main/resources/META-INF/dirigible/resources-neo-sdk/
resources/resources-neo-sdk/src/main/resources/META-INF/dirigible/resources-neo-sdk/*
!resources/resources-neo-sdk/src/main/resources/META-INF/dirigible/resources-neo-sdk/differ.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Copyright (c) 2022 SAP SE or an SAP affiliate company and XSK contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License, v2.0
* which accompanies this distribution, and is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and XSK contributors
* SPDX-License-Identifier: Apache-2.0
*/
require.config({ paths: { vs: "/services/v4/web/ide-monaco/monaco-editor/min/vs" } });
let editors = [];
migrationLaunchView.controller("ChangesViewController", [
"$scope",
"$http",
"$messageHub",
"$timeout",
"migrationDataState",
function ($scope, $http, $messageHub, $timeout, migrationDataState) {
$scope.migrationDataState = migrationDataState;
$scope.isVisible = false;
$scope.dataLoaded = false;
let viewWidth = document.querySelectorAll(".changes-body")[0].clientWidth | 100;
$scope.isDiffViewSplit = viewWidth > 1100 ? true : false;
$scope.data = [];

function startMigration() {
body = {
neo: {
hostName: migrationDataState.neoHostName,
subaccount: migrationDataState.neoSubaccount,
},
hana: {
databaseSchema: migrationDataState.schemaName,
username: migrationDataState.dbUsername,
password: migrationDataState.dbPassword,
},
connectionId: migrationDataState.connectionId,
workspace: migrationDataState.selectedWorkspace,
du: migrationDataState.selectedDeliveryUnits,
processInstanceId: migrationDataState.processInstanceId,
};

$http
.post("/services/v4/js/ide-migration/server/migration/api/migration-rest-api.mjs/continue-process", JSON.stringify(body), {
headers: { "Content-Type": "application/json" },
})
.then((response) => {
const timer = setInterval(function () {
$http
.post(
"/services/v4/js/ide-migration/server/migration/api/migration-rest-api.mjs/get-process",
JSON.stringify(body),
{
headers: { "Content-Type": "application/json" },
}
)
.then(
function (response) {
clearInterval(timer);
let diffViewData = response.data.diffViewData;
// Add additional keys needed by AngularJS
for (let i = 0; i < diffViewData.length; i++) {
diffViewData[i]["id"] = `m-${i}`;
diffViewData[i]["collapsed"] = false;
diffViewData[i]["excluded"] = false;
}
// Set data variable
$scope.data = diffViewData;
// Set full width for better experience
$scope.$parent.setFullWidthEnabled(true);
// Show data
$scope.dataLoaded = true;
$scope.$apply();
},
function (response) {
clearInterval(timer);
if (response.data) {
if ("error" in response.data) {
if ("message" in response.data.error) {
$messageHub.announceAlertError(defaultErrorTitle, response.data.error.message);
} else {
$messageHub.announceAlertError(defaultErrorTitle, defaultErrorDesc);
}
console.error(`HTTP $response.status`, response.data.error);
} else {
$messageHub.announceAlertError(defaultErrorTitle, defaultErrorDesc);
}
} else {
$messageHub.announceAlertError(defaultErrorTitle, defaultErrorDesc);
}
errorOccurred();
}
);
}, 1000);
});
}

$scope.createDiffEditor = function (index) {
$timeout(function () {
createDiffView(
$scope.data[index].id,
$scope.data[index].type,
$scope.data[index].original,
$scope.data[index].modified,
$scope.isDiffViewSplit
);
});
};

$scope.startMigration = function () {
// TODO
for (let i = 0; i < $scope.data.length; i++) {
if (!$scope.data[i].excluded) {
console.log("Migrating file:", $scope.data[i].file);
}
}
$scope.$parent.migrateClicked();
};

$scope.splitDiffView = function () {
$scope.isDiffViewSplit = true;
for (let i = 0; i < editors.length; i++) {
editors[i].updateOptions({ renderSideBySide: true });
}
};

$scope.inlineDiffView = function () {
$scope.isDiffViewSplit = false;
for (let i = 0; i < editors.length; i++) {
editors[i].updateOptions({ renderSideBySide: false });
}
};

$scope.previousClicked = function () {
$scope.$parent.previousClicked();
};

$messageHub.on(
"migration.changes",
function (msg) {
if ("isVisible" in msg.data) {
$scope.$apply(function () {
$scope.dataLoaded = false;
$scope.isVisible = msg.data.isVisible;
if (msg.data.isVisible) {
$scope.$parent.setBottomNavEnabled(false);
} else {
$scope.data = [];
editors = [];
}
});
if (msg.data.isVisible) {
startMigration();
}
}
}.bind(this)
);
},
]);

function createDiffView(containerId, filetype, originalTxt, modifiedTxt, renderSideBySide = true) {
require(["vs/editor/editor.main"], function () {
let container = document.getElementById(containerId);
let containerLoading = document.querySelector(`#${containerId} > p:first-of-type`);
monaco.editor.setTheme(monacoTheme);
let diffEditor = monaco.editor.createDiffEditor(container, {
automaticLayout: true,
readOnly: true,
scrollBeyondLastLine: false,
enableSplitViewResizing: false,
renderSideBySide: renderSideBySide,
});

const updateHeight = () => {
const topBorder = parseInt(getComputedStyle(container).getPropertyValue("border-top-width"), 10);
const bottomBorder = parseInt(getComputedStyle(container).getPropertyValue("border-bottom-width"), 10);
const contentHeight = diffEditor.getModifiedEditor().getContentHeight() + topBorder + bottomBorder;
container.style.height = `${contentHeight}px`;
};

diffEditor.getModifiedEditor().onDidContentSizeChange(updateHeight);
diffEditor.setModel({
original: monaco.editor.createModel(originalTxt, filetype),
modified: monaco.editor.createModel(modifiedTxt, filetype),
});

editors.push(diffEditor);
containerLoading.remove();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ migrationLaunchView.controller("DeliveryUnitViewController", [
$scope.duDropdownText = $scope.duSelectedUItext.length ? $scope.duSelectedUItext.join(", ") : $scope.duDropdownInitText;
$scope.selectAllText =
migrationDataState.selectedDeliveryUnits.length == $scope.deliveryUnitList.length ? "Unselect all" : "Select all";
$scope.$parent.setFinishEnabled(true);
$scope.$parent.setNextEnabled(true);
};

$messageHub.on(
Expand All @@ -201,16 +201,12 @@ migrationLaunchView.controller("DeliveryUnitViewController", [
$scope.descriptionText = descriptionList[0];
$scope.isVisible = msg.data.isVisible;
if (msg.data.isVisible) {
if (migrationDataState.selectedDeliveryUnits) {
$scope.$parent.setFinishEnabled(true);
} else {
$scope.$parent.setFinishEnabled(false);
}
$scope.$parent.setFullWidthEnabled(false);
$scope.$parent.setBottomNavEnabled(false);
$scope.$parent.setPreviousVisible(true);
$scope.$parent.setPreviousEnabled(true);
$scope.$parent.setNextVisible(false);
$scope.$parent.setFinishVisible(true);
$scope.$parent.setNextEnabled(false);
$scope.$parent.setNextVisible(true);
}
});
if (msg.data.isVisible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ migrationLaunchView.controller("HanaCredentialsViewController", [
$scope.databaseSelected = function (database) {
migrationDataState.schemaName = database;
$scope.databasesDropdownText = database;
$scope.userInput();
};

$messageHub.on(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and XSK contributors
* SPDX-License-Identifier: Apache-2.0
*/
var migrationLaunchView = angular.module("migration-launch", ['angularFileUpload']);
var migrationLaunchView = angular.module("migration-launch", ["angularFileUpload"]);

migrationLaunchView.factory("$messageHub", [
function () {
Expand Down Expand Up @@ -83,12 +83,15 @@ migrationLaunchView.controller("MigrationLaunchViewController", [
topicId: "migration.hana-credentials",
},
{ id: 3, name: "Delivery Units", topicId: "migration.delivery-unit" },
{ id: 4, name: "Migration", topicId: "migration.start-migration" },
{ id: 4, name: "Changes", topicId: "migration.changes" },
{ id: 5, name: "Migration", topicId: "migration.start-migration" },
];
$scope.zipsteps = [
{ id: 1, name: "Upload ZIP file", topicId: "migration.upload-zip-migration" },
{ id: 2, name: "Migration", topicId: "migration.start-zip-migration" },
];

$scope.fullWidthEnabled = false;
$scope.onStatisticsPage = true;
$scope.migrationFromZip = false;
$scope.bottomNavHidden = false;
Expand All @@ -112,7 +115,7 @@ migrationLaunchView.controller("MigrationLaunchViewController", [
$scope.setFinishVisible(true);
$scope.setBottomNavEnabled(false);
$scope.currentStep = $scope.zipsteps[0];
}
};

$scope.setFinishVisible = function (visible) {
$scope.finishVisible = visible;
Expand All @@ -122,6 +125,10 @@ migrationLaunchView.controller("MigrationLaunchViewController", [
$scope.finishDisabled = !enabled;
};

$scope.setFullWidthEnabled = function (enabled) {
$scope.fullWidthEnabled = enabled;
};

$scope.setNextVisible = function (visible) {
$scope.nextVisible = visible;
};
Expand Down Expand Up @@ -185,7 +192,7 @@ migrationLaunchView.controller("MigrationLaunchViewController", [
}
};

$scope.finishClicked = function () {
$scope.migrateClicked = function () {
$messageHub.message($scope.currentStep.topicId, { isVisible: false });
$scope.currentStep = $scope.steps[$scope.steps.length - 1];
$messageHub.message($scope.currentStep.topicId, { isVisible: true });
Expand All @@ -204,6 +211,6 @@ migrationLaunchView.controller("MigrationLaunchViewController", [
else return "inactive";
};

$messageHub.on("migration.launch", function (msg) { }.bind(this));
$messageHub.on("migration.launch", function (msg) {}.bind(this));
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ migrationLaunchView.controller("NeoCredentialsViewController", [
$scope.regionSelected = function (regionObject) {
migrationDataState.neoHostName = regionObject.region;
$scope.regionDropdownText = regionObject.name;

$scope.$parent.setFinishEnabled(true);
};

$scope.filterRegions = function () {
Expand Down Expand Up @@ -120,7 +118,6 @@ migrationLaunchView.controller("NeoCredentialsViewController", [
$scope.$parent.setPreviousVisible(false);
$scope.$parent.setPreviousEnabled(true);
$scope.$parent.setNextVisible(true);
$scope.$parent.setFinishVisible(false);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,36 @@ migrationLaunchView.controller("StartMigrationViewController", [
if ("isVisible" in msg.data) {
$scope.$apply(function () {
$scope.isVisible = msg.data.isVisible;
if (msg.data.isVisible) $scope.$parent.setFullWidthEnabled(false);
});
if (msg.data.isVisible) {
startMigration();
}
}
}.bind(this)
);
$messageHub.on('migration.start-zip-migration', function (msg) {
if ("isVisible" in msg.data) {
$scope.$apply(function () {
$scope.isZipMigrationVisible = msg.data.isVisible;
});
}
if ("migrationFinished" in msg.data) {
$scope.$apply(function () {
$scope.migrationFinished = msg.data.migrationFinished;
if ("workspace" in msg.data)
migrationDataState.selectedWorkspace = msg.data.workspace;
$scope.progressTitle = titleList[1];
$scope.statusMessage = ("status" in msg.data) ? msg.data.status : ("workspace" in msg.data)
? `Successfully migrated uploaded Delivery Unit(s)! Go to workspace "${msg.data.workspace}" and publish them.` :
"Successfully migrated uploaded Delivery Unit(s)!";

});
}
}.bind(this));
$messageHub.on(
"migration.start-zip-migration",
function (msg) {
if ("isVisible" in msg.data) {
$scope.$apply(function () {
$scope.isZipMigrationVisible = msg.data.isVisible;
});
}
if ("migrationFinished" in msg.data) {
$scope.$apply(function () {
$scope.migrationFinished = msg.data.migrationFinished;
if ("workspace" in msg.data) migrationDataState.selectedWorkspace = msg.data.workspace;
$scope.progressTitle = titleList[1];
$scope.statusMessage =
"status" in msg.data
? msg.data.status
: "workspace" in msg.data
? `Successfully migrated uploaded Delivery Unit(s)! Go to workspace "${msg.data.workspace}" and publish them.`
: "Successfully migrated uploaded Delivery Unit(s)!";
});
}
}.bind(this)
);
},
]);
Loading

0 comments on commit 439105e

Please sign in to comment.