From c0a4e9e5bda2981204b2f15274070ff58f272c2f Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 7 Jul 2022 13:32:20 +0200 Subject: [PATCH] Add initial support to add applinks --- src/js/client.js | 105 ++++++++++++++++++++++++++++++-------------- src/js/index.js | 4 +- src/views/apps.html | 26 +++++++++++ src/views/apps.js | 33 ++++++++++++++ 4 files changed, 134 insertions(+), 34 deletions(-) diff --git a/src/js/client.js b/src/js/client.js index 3f1f5b165..cef83be47 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1844,6 +1844,38 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getApplinks = function (callback) { + get('/api/v1/applinks', null, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + // amend properties to mimick full app + data.applinks.forEach(function (applink) { + applink.fqdn = applink.upstreamUri; // this fqdn may contain the protocol! + applink.manifest = { addons: {}}; + applink.installationState = ISTATES.INSTALLED; + applink.runState = RSTATES.RUNNING; + applink.health = HSTATES.HEALTHY; + applink.accessLevel = 'operator'; + }); + + callback(null, data.applinks); + }); + }; + + Client.prototype.addApplink = function (applink, callback) { + var data = { + upstreamUri: applink.upstreamUri + }; + + post('/api/v1/applinks', data, null, function (error, data, status) { + if (error) return callback(error); + if (status !== 201) return callback(new ClientError(status, data)); + + callback(null); + }); + }; + Client.prototype.addUser = function (user, callback) { var data = { email: user.email, @@ -2223,49 +2255,56 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout this.getApps(function (error, apps) { if (error) return callback(error); - async.eachLimit(apps, 20, function (app, iteratorCallback) { - app.ssoAuth = (app.manifest.addons['ldap'] || app.manifest.addons['proxyAuth']) && app.sso; + that.getApplinks(function (error, applinks) { + if (error) return callback(error); - if (app.accessLevel !== 'operator' && app.accessLevel !== 'admin') { // only fetch if we have permissions - app.progress = 0; - app.message = ''; - app.taskMinutesActive = 0; + apps = apps.concat(applinks); - that._updateAppCache(app); + async.eachLimit(apps, 20, function (app, iteratorCallback) { + app.ssoAuth = (app.manifest.addons['ldap'] || app.manifest.addons['proxyAuth']) && app.sso; - return iteratorCallback(); - } - - var getTaskFunc = app.taskId ? that.getAppTask.bind(null, app.id) : function (next) { return next(); }; - getTaskFunc(function (error, task) { - if (error) return iteratorCallback(error); - - if (task) { - app.progress = task.percent; - app.message = task.message; - app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes(); - } else { + if (app.accessLevel !== 'operator' && app.accessLevel !== 'admin') { // only fetch if we have permissions app.progress = 0; app.message = ''; app.taskMinutesActive = 0; + + that._updateAppCache(app); + + return iteratorCallback(); } - that._updateAppCache(app); + var getTaskFunc = app.taskId ? that.getAppTask.bind(null, app.id) : function (next) { return next(); }; + getTaskFunc(function (error, task) { + if (error) return iteratorCallback(error); - iteratorCallback(); + if (task) { + app.progress = task.percent; + app.message = task.message; + app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes(); + } else { + app.progress = 0; + app.message = ''; + app.taskMinutesActive = 0; + } + + that._updateAppCache(app); + + iteratorCallback(); + }); + }, function iteratorDone(error) { + if (error) return callback(error); + + + // filter out old apps, going backwards to allow splicing + for (var i = that._installedApps.length - 1; i >= 0; --i) { + if (!apps.some(function (elem) { return (elem.id === that._installedApps[i].id); })) { + var removed = that._installedApps.splice(i, 1); + delete that._installedAppsById[removed[0].id]; + } + } + + callback(null); }); - }, function iteratorDone(error) { - if (error) return callback(error); - - // filter out old apps, going backwards to allow splicing - for (var i = that._installedApps.length - 1; i >= 0; --i) { - if (!apps.some(function (elem) { return (elem.id === that._installedApps[i].id); })) { - var removed = that._installedApps.splice(i, 1); - delete that._installedAppsById[removed[0].id]; - } - } - - callback(null); }); }); }; diff --git a/src/js/index.js b/src/js/index.js index d55a308b0..cc3a140c9 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -149,7 +149,9 @@ app.filter('applicationLink', function () { if (!app) return ''; if (!app.pendingPostInstallConfirmation) { - return 'https://' + app.fqdn; + // app links have http already in the fqdn + if (app.fqdn.indexOf('http') !== 0) return 'https://' + app.fqdn; + else return app.fqdn; } else { return ''; } diff --git a/src/views/apps.html b/src/views/apps.html index f5add5fd6..c9024d47c 100644 --- a/src/views/apps.html +++ b/src/views/apps.html @@ -31,6 +31,31 @@ + + +
@@ -57,6 +82,7 @@

{{ 'apps.title' | tr }} +
diff --git a/src/views/apps.js b/src/views/apps.js index 27e79510a..ba29ba4dd 100644 --- a/src/views/apps.js +++ b/src/views/apps.js @@ -89,6 +89,32 @@ angular.module('Application').controller('AppsController', ['$scope', '$translat } }; + $scope.applinksAdd = { + error: {}, + busy: false, + upstreamUri: '', + + show: function () { + $scope.applinksAdd.error = {}; + $scope.applinksAdd.busy = false; + $scope.applinksAdd.upstreamUri = ''; + + $('#applinksAddModal').modal('show'); + + return false; // prevent propagation and default + }, + + submit: function () { + if (!$scope.applinksAdd.upstreamUri) return; + + Client.addApplink({ upstreamUri: $scope.applinksAdd.upstreamUri }, function (error, result) { + if (error) return console.error('Failed to add applink', error); + + $('#applinksAddModal').modal('hide'); + }); + } + }; + $scope.showAppConfigure = function (app, view) { $location.path('/app/' + app.id + '/' + view); }; @@ -136,6 +162,13 @@ angular.module('Application').controller('AppsController', ['$scope', '$translat }); }); + // setup all the dialog focus handling + ['applinksAddModal'].forEach(function (id) { + $('#' + id).on('shown.bs.modal', function () { + $(this).find("[autofocus]:first").focus(); + }); + }); + $('.collapse').on('shown.bs.collapse', function(){ $(this).parent().find('.fa-angle-right').removeClass('fa-angle-right').addClass('fa-angle-down'); }).on('hidden.bs.collapse', function(){