Skip to content

Commit

Permalink
MB-25475: Use ES6 modules in ng1 eventing UI
Browse files Browse the repository at this point in the history
We no longer use scripts. Instead we are using es6 modules.
This change is example of how to migrate from scripts to modules.

As part of the migration we are starting to use package.json
in order to manage all our dependencies and convert them into
es6 modules.

Change-Id: Ideaef75f30226476698614e0e9882009507f9b8c
Reviewed-on: http://review.couchbase.org/122330
Reviewed-by: Pavel Blagodov <stochmail@gmail.com>
Tested-by: Pavel Blagodov <stochmail@gmail.com>
  • Loading branch information
pavel-blagodov authored and Sriram Melkote committed Mar 27, 2020
1 parent 2e630f2 commit 5cd9e03
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
8 changes: 8 additions & 0 deletions ui/eventing-ui/app-model.js
@@ -1,3 +1,11 @@
import _ from "/ui/web_modules/lodash.js"
export {Application,
ApplicationManager,
ApplicationModel,
formatCode,
determineUIStatus,
getWarnings};

function Application(data) {
for (var key of Object.keys(data)) {
this[key] = data[key];
Expand Down
5 changes: 3 additions & 2 deletions ui/eventing-ui/err-model.js
@@ -1,3 +1,4 @@
export {ErrorMessage, ErrorHandler};
// Base template for error messages.
function ErrorMessage(version, revision, error, details) {
this.version = version;
Expand All @@ -7,7 +8,7 @@ function ErrorMessage(version, revision, error, details) {
}

ErrorMessage.prototype.hasRetry = function(errorCode) {
return $.inArray('retry', this.error[errorCode].attrs) !== -1;
return this.error[errorCode].attrs.includes('retry');
};

// Provides error handling capabilities according to attributes of errors.
Expand Down Expand Up @@ -72,4 +73,4 @@ ErrorHandler.prototype.tryResolve = function(promiseFunc, promiseCallback, error

retry();
}
};
};
3 changes: 2 additions & 1 deletion ui/eventing-ui/ui-current/adapter.js
@@ -1,3 +1,4 @@
export default Adapter;
// Config is the format required by the server
// Binding is the format required by the front-end

Expand Down Expand Up @@ -104,4 +105,4 @@ Adapter.prototype.createCurlBinding = function(config) {
binding.auth_type = 'no-auth';
}
return binding;
};
};
48 changes: 38 additions & 10 deletions ui/eventing-ui/ui-current/eventing.js
@@ -1,4 +1,33 @@
angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault'])
import angular from "/ui/web_modules/angular.js";
import _ from "/ui/web_modules/lodash.js";

import uiRouter from "/ui/web_modules/@uirouter/angularjs.js";
import mnPoolDefault from "/ui/app/components/mn_pool_default.js";
import mnPluggableUiRegistry from "/ui/app/components/mn_pluggable_ui_registry.js";
import mnJquery from "/ui/app/components/mn_jquery.js";
import mnPermissions from "/ui/app/components/mn_permissions.js";

import Adapter from "./adapter.js";

import {
Application,
ApplicationManager,
ApplicationModel,
formatCode,
determineUIStatus,
getWarnings} from "../app-model.js";

import {ErrorMessage, ErrorHandler} from "../err-model.js";

export default 'eventing';

angular.module('eventing', [
mnPluggableUiRegistry,
uiRouter,
mnPoolDefault,
mnJquery,
mnPermissions
])
// Controller for the summary page.
.controller('SummaryCtrl', ['$q', '$scope', '$rootScope', '$state', '$uibModal', '$timeout', '$location', 'ApplicationService', 'serverNodes', 'isEventingRunning', 'mnPoller',
function($q, $scope, $rootScope, $state, $uibModal, $timeout, $location, ApplicationService, serverNodes, isEventingRunning, mnPoller) {
Expand Down Expand Up @@ -541,8 +570,8 @@ angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault
}
])
// Controller for the buttons in header.
.controller('HeaderCtrl', ['$q', '$scope', '$uibModal', '$state', 'mnPoolDefault', 'ApplicationService',
function($q, $scope, $uibModal, $state, mnPoolDefault, ApplicationService) {
.controller('HeaderCtrl', ['$q', '$scope', '$uibModal', '$state', 'mnPoolDefault', 'ApplicationService', 'jQuery',
function($q, $scope, $uibModal, $state, mnPoolDefault, ApplicationService, $) {
var self = this;
self.isEventingRunning = true;

Expand Down Expand Up @@ -881,8 +910,8 @@ angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault
}
])
// Controller for editing handler code.
.controller('HandlerCtrl', ['$q', '$uibModal', '$timeout', '$state', '$scope', '$rootScope', '$stateParams', '$transitions', 'ApplicationService',
function($q, $uibModal, $timeout, $state, $scope, $rootScope, $stateParams, $transitions, ApplicationService) {
.controller('HandlerCtrl', ['$q', '$uibModal', '$timeout', '$state', '$scope', '$rootScope', '$stateParams', '$transitions', 'ApplicationService', 'jQuery',
function($q, $uibModal, $timeout, $state, $scope, $rootScope, $stateParams, $transitions, ApplicationService, $) {
var self = this,
isDebugOn = false,
debugScope = $scope.$new(true),
Expand Down Expand Up @@ -1184,7 +1213,7 @@ angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault
}
])
// Controller to copy the debug URL.
.controller('DebugCtrl', [function() {
.controller('DebugCtrl', ['jQuery', function ($) {
var self = this;

self.copyUrl = function() {
Expand Down Expand Up @@ -1691,9 +1720,9 @@ angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault
bindingError,
hostnameValid,
hostnameError,
bindingsValidList = []
hostnameValidList = []
form = formCtrl.createAppForm;
bindingsValidList = [],
hostnameValidList = [],
form = formCtrl.createAppForm;

for (var binding of bindings) {
if (binding.value.length) {
Expand Down Expand Up @@ -1807,4 +1836,3 @@ angular.module('eventing', ['mnPluggableUiRegistry', 'ui.router', 'mnPoolDefault
});
}
]);
angular.module('mnAdmin').requires.push('eventing');
9 changes: 1 addition & 8 deletions ui/eventing-ui/ui-current/head.frag.html
@@ -1,13 +1,6 @@
<script src="../_p/ui/event/lib/esprima.min.js"></script>
<script src="../_p/ui/event/lib/escodegen.min.js"></script>
<script src="../_p/ui/event/gen/version.js"></script>
<script src="../_p/ui/event/ui-current/eventing.js" type="text/javascript"
charset="utf8"></script>
<script src="../_p/ui/event/ui-current/adapter.js" type="text/javascript"
charset="utf8"></script>
<script src="../_p/ui/event/app-model.js" type="text/javascript"
charset="utf8"></script>
<script src="../_p/ui/event/err-model.js" type="text/javascript"
charset="utf8"></script>

<link rel="stylesheet" type="text/css"
href="../_p/ui/event/ui-current/fragments/styles.css"/>

0 comments on commit 5cd9e03

Please sign in to comment.