fix(ui): fix dirty checking on devportal page
Another attempt to fix dirty checking. Always difficult in AngularJS...
MODIFY
manager/ui/war/plugins/api-manager/html/api/api-devportal.html
manager/ui/war/plugins/api-manager/html/api/api-devportal.html
</div>
<div id="editor"></div>
<!-- /row -->
+ </div>
+
+
+ </div>
+
<!-- save -->
+ <div class="row">
<hr />
<div apiman-permission="apiEdit"
class="actions"
</div>
</div>
</div>
- </div>
<!-- /Content -->
</div>
</div> <!-- /container-pf-nav-pf-vertical container-fluid -->

MODIFY
manager/ui/war/plugins/api-manager/ts/api/api-devportal.ts
manager/ui/war/plugins/api-manager/ts/api/api-devportal.ts
@@ -168,7 +168,7 @@ function devPortalBusinessLogic(
"data",
(oldValue, newValue) => {
if (!angular.equals(oldValue, newValue)) {
- Logger.debug("Dirty set to true {0} vs {1}", oldValue, newValue);
+ Logger.info("Dirty set to true {0} vs {1}", oldValue, newValue);
$rootScope.isDirty = true;
if (newValue.exposeInPortal) {
@@ -207,28 +207,33 @@ function devPortalBusinessLogic(
};
markdownEditor = new toast(options);
+ markdownEditor.setMarkdown("");
+
+ if ($scope.data.apiVersion.extendedDescription) {
Logger.info(
"Setting extended description to: {0}",
$scope.data.apiVersion.extendedDescription
);
markdownEditor.setMarkdown($scope.data.apiVersion.extendedDescription, true);
}
+ }
// Dirty check the MD editor pane every 2 seconds (avoids excessive checking).
- const intervalPromise: Promise<any> = $interval(() => {
+ const intervalPromise: Promise<any> = $interval(function () {
+ if ($scope.data.apiVersion.exposeInPortal) {
editorDirtyCheck();
+ }
}, 1000);
const editorDirtyCheck = function (): void {
- if (markdownEditor == null) {
+ if (!markdownEditor) {
initEditor();
}
let latestDescription = markdownEditor.getMarkdown();
// If original description != latestDescription, and latest poll != previous poll
- if (
- dataClone.apiVersion.extendedDescription !== latestDescription &&
- $scope.data.apiVersion.extendedDescription !== latestDescription
- ) {
+ if (normaliseString(dataClone.apiVersion.extendedDescription) !== normaliseString(latestDescription) &&
+ normaliseString($scope.data.apiVersion.extendedDescription) !== normaliseString(latestDescription)) {
+ Logger.info("Setting dirty true");
$rootScope.isDirty = true;
$scope.data.apiVersion.extendedDescription = latestDescription;
}
@@ -237,14 +242,21 @@ function devPortalBusinessLogic(
/** Save, and reset **/
// Reset (copy saved pristine copy back over).
- $scope.reset = () => {
+ $scope.reset = function () {
+ Logger.info("Resetting");
$scope.data = angular.copy(dataClone);
- markdownEditor.setMarkdown($scope.data.apiVersion.extendedDescription, true);
+ markdownEditor.setMarkdown(
+ $scope.data.apiVersion.extendedDescription,
+ true
+ );
$rootScope.isDirty = false;
};
$scope.$on("$destroy", function () {
+ console.log("destroy");
$interval.cancel(intervalPromise);
+ markdownEditor && markdownEditor.reset();
+ markdownEditor && markdownEditor.destroy();
});
// Save
@@ -349,6 +361,14 @@ function devPortalBusinessLogic(
console.log(answer);
return answer;
}
+
+ function normaliseString(str: string): string {
+ if (!str || str.length === 0) {
+ return "";
+ } else {
+ return str;
+ }
+ }
}
_module.controller("Apiman.DevPortalImageCropper",

fix(ui): fix dirty checking on devportal page

Another attempt to fix dirty checking. Always difficult in AngularJS...