From 0fcc4a5be93359df875a3b6533e6d4040926d541 Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Fri, 30 Aug 2019 00:39:16 +0300 Subject: [PATCH 1/8] Feature: Support Multiple WebUI --- .env | 1 + .env.example | 1 + app/index.ejs | 1 + app/scripts/app.js | 6 +- app/scripts/components/webUI/index.js | 17 +++ .../webUI/manage/webUIManage.component.js | 12 ++ .../webUI/manage/webUIManage.controller.js | 68 +++++++++ .../components/webUI/manage/webUIManage.html | 91 ++++++++++++ .../webUI/select/webUISelect.component.js | 12 ++ .../webUI/select/webUISelect.controller.js | 28 ++++ .../components/webUI/select/webUISelect.html | 8 ++ .../webUI/services/webUI.account.js | 22 +++ .../webUI/services/webUI.service.js | 131 ++++++++++++++++++ app/scripts/components/webUI/webUI.scss | 86 ++++++++++++ app/scripts/i18n/webUI/ru.json | 54 ++++++++ app/views/web-ui.html | 12 +- package.json | 5 +- webpack.config.js | 21 ++- 18 files changed, 572 insertions(+), 4 deletions(-) create mode 100644 .env create mode 100644 .env.example create mode 100644 app/scripts/components/webUI/index.js create mode 100644 app/scripts/components/webUI/manage/webUIManage.component.js create mode 100644 app/scripts/components/webUI/manage/webUIManage.controller.js create mode 100644 app/scripts/components/webUI/manage/webUIManage.html create mode 100644 app/scripts/components/webUI/select/webUISelect.component.js create mode 100644 app/scripts/components/webUI/select/webUISelect.controller.js create mode 100644 app/scripts/components/webUI/select/webUISelect.html create mode 100644 app/scripts/components/webUI/services/webUI.account.js create mode 100644 app/scripts/components/webUI/services/webUI.service.js create mode 100644 app/scripts/components/webUI/webUI.scss create mode 100644 app/scripts/i18n/webUI/ru.json diff --git a/.env b/.env new file mode 100644 index 00000000..89191b8a --- /dev/null +++ b/.env @@ -0,0 +1 @@ +WEBUI_MULTIPLE=true \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..e4a708c0 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +WEBUI_MULTIPLE=false \ No newline at end of file diff --git a/app/index.ejs b/app/index.ejs index 2759f7be..2dc3ed15 100644 --- a/app/index.ejs +++ b/app/index.ejs @@ -40,6 +40,7 @@ +

diff --git a/app/scripts/app.js b/app/scripts/app.js index 83fb15f1..bdeada0b 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -84,6 +84,7 @@ import routingModule from './app.routes'; // Internal components import LoginFormModule from './components/loginForm/index'; +import WebUIModule from './components/webUI/index'; //----------------------------------------------------------------------------- /** @@ -114,11 +115,13 @@ const module = angular metaTypeFilterModule, dumbTemplateModule, LoginFormModule, + WebUIModule, ///'toggle-switch', 'plotly', 'ui-rangeSlider', - 'ngToast' + 'ngToast', + 'ngBootbox', ]) .value('historyMaxPoints', 1000) .value('webuiConfigPath', '/etc/wb-webui.conf') @@ -297,6 +300,7 @@ const realApp = angular.module('realHomeuiApp', [module.name, mqttServiceModule, urlTemplate: '/scripts/i18n/{part}/{lang}.json' }); $translateProvider.preferredLanguage('ru'); + $translateProvider.usePostCompiling(true); }]) .run(($rootScope, $window, mqttClient, ConfigEditorProxy, webuiConfigPath, errors, whenMqttReady, uiConfig, $timeout, configSaveDebounceMs, ngToast, $sce) => { diff --git a/app/scripts/components/webUI/index.js b/app/scripts/components/webUI/index.js new file mode 100644 index 00000000..1aad6bfd --- /dev/null +++ b/app/scripts/components/webUI/index.js @@ -0,0 +1,17 @@ +'use strict'; + +import webUIManageComponent from './manage/webUIManage.component'; +import webUISelectComponent from './select/webUISelect.component'; +import webUIService from './services/webUI.service'; + +import './webUI.scss'; + +export default angular + .module('HomeuiApp.webUI', []) + .config(['$translatePartialLoaderProvider', ($translatePartialLoaderProvider) => { + $translatePartialLoaderProvider.addPart('webUI'); + }]) + .component('webUiManage', webUIManageComponent) + .component('webUiSelect', webUISelectComponent) + .factory('webUIService', webUIService) + .name; \ No newline at end of file diff --git a/app/scripts/components/webUI/manage/webUIManage.component.js b/app/scripts/components/webUI/manage/webUIManage.component.js new file mode 100644 index 00000000..3f483870 --- /dev/null +++ b/app/scripts/components/webUI/manage/webUIManage.component.js @@ -0,0 +1,12 @@ +'use strict'; + +import template from './webUIManage.html'; +import controller from './webUIManage.controller'; + +export default { + restrict: 'E', + bindings: { + }, + template, + controller +}; \ No newline at end of file diff --git a/app/scripts/components/webUI/manage/webUIManage.controller.js b/app/scripts/components/webUI/manage/webUIManage.controller.js new file mode 100644 index 00000000..dc01e29b --- /dev/null +++ b/app/scripts/components/webUI/manage/webUIManage.controller.js @@ -0,0 +1,68 @@ +'use strict'; + +class WebUIManageController { + + constructor ($scope, $window, $translate, $ngBootbox, rolesFactory, webUIService) { + 'ngInject'; + + this.$scope = $scope; + this.$window = $window; + this.$translate = $translate; + this.$ngBootbox = $ngBootbox; + this.rolesFactory = rolesFactory; + this.service = webUIService; + + this.accounts = webUIService.accounts; + this.current = webUIService.current; + this.editable = null; + + this.isMultiple = process.env.WEBUI_MULTIPLE; + if (!this.isMultiple) { + this.editable = this.current; + } + + $scope.$watch('$ctrl.service.getCurrent()', (newValue, oldValue) => { + if (newValue !== oldValue) { + this.current = newValue; + } + }); + } + + create() { + this.editable = this.service.create(); + } + + update(account) { + this.editable = account; + } + + remove(account) { + this.$translate('webUI.manager.prompt.remove', { name: account.name }).then((translation) => { + this.$ngBootbox.confirm(translation).then(() => { + this.service.remove(account); + }); + }); + } + + save() { + this.service.save(this.editable); + + if (this.editable === this.current) { + this.login(this.current); + } + + if (this.isMultiple) { + this.editable = false; + } + } + + cancel() { + this.editable = null; + } + + login(account) { + this.service.login(account); + } +} + +export default WebUIManageController; \ No newline at end of file diff --git a/app/scripts/components/webUI/manage/webUIManage.html b/app/scripts/components/webUI/manage/webUIManage.html new file mode 100644 index 00000000..18674b13 --- /dev/null +++ b/app/scripts/components/webUI/manage/webUIManage.html @@ -0,0 +1,91 @@ +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
{{'webUI.manager.table.header.name' | translate}}{{'webUI.manager.table.header.host' | translate}}{{'webUI.manager.table.header.port' | translate}}{{'webUI.manager.table.header.user' | translate}}{{'webUI.manager.table.header.prefix' | translate}}
{{ account.name }}{{ account.host }}{{ account.port }}{{ account.user }} + + + +
+
+ +
+ +
+
+
+
+
+
+ + +
{{'webUI.manager.error.name.empty' | translate}}
+
+
+ + +
{{'webUI.manager.error.host.empty' | translate}}
+
+
+ + +
{{'webUI.manager.error.port.empty' | translate}}
+
{{'webUI.manager.error.port.invalid' | translate}}
+
+
+ +
+
+
+ + +
{{'webUI.manager.error.user.empty' | translate}}
+
+
+ + +
{{'webUI.manager.error.password.empty' | translate}}
+
+
+
+ +
+
+
+
+ + +
+
+
\ No newline at end of file diff --git a/app/scripts/components/webUI/select/webUISelect.component.js b/app/scripts/components/webUI/select/webUISelect.component.js new file mode 100644 index 00000000..a38a12f1 --- /dev/null +++ b/app/scripts/components/webUI/select/webUISelect.component.js @@ -0,0 +1,12 @@ +'use strict'; + +import template from './webUISelect.html'; +import controller from './webUISelect.controller'; + +export default { + restrict: 'E', + bindings: { + }, + template, + controller +}; \ No newline at end of file diff --git a/app/scripts/components/webUI/select/webUISelect.controller.js b/app/scripts/components/webUI/select/webUISelect.controller.js new file mode 100644 index 00000000..7e05123c --- /dev/null +++ b/app/scripts/components/webUI/select/webUISelect.controller.js @@ -0,0 +1,28 @@ +'use strict'; + +class AccountSelectController { + + constructor ($scope, $element, rolesFactory, webUIService) { + 'ngInject'; + + this.$scope = $scope; + this.$element = $element; + this.rolesFactory = rolesFactory; + this.service = webUIService; + + this.accounts = webUIService.accounts; + this.current = webUIService.current; + + $scope.$watch('$ctrl.current', (newValue, oldValue) => { + if (newValue !== oldValue) { + this.login(newValue); + } + }); + } + + login(account) { + this.service.login(account); + } +} + +export default AccountSelectController; \ No newline at end of file diff --git a/app/scripts/components/webUI/select/webUISelect.html b/app/scripts/components/webUI/select/webUISelect.html new file mode 100644 index 00000000..76d1adb7 --- /dev/null +++ b/app/scripts/components/webUI/select/webUISelect.html @@ -0,0 +1,8 @@ +
+ + {{ $select.selected.name }} + +
+
+
+
\ No newline at end of file diff --git a/app/scripts/components/webUI/services/webUI.account.js b/app/scripts/components/webUI/services/webUI.account.js new file mode 100644 index 00000000..d492d038 --- /dev/null +++ b/app/scripts/components/webUI/services/webUI.account.js @@ -0,0 +1,22 @@ +'use strict'; + +class Account { + + constructor(name, host, port, user, password, prefix, role, current = false) { + this.name = name; + this.host = host; + this.port = port ? parseInt(port) : null; + this.user = user; + this.password = password; + this.prefix = (typeof prefix === 'string') ? (prefix === 'true') : prefix; + this.role = role; + this.current = current; + this.credentials = this.useCredentials; + } + + get useCredentials() { + return (!!this.user || (!!this.user && !!this.password)); + } +} + +export default Account; \ No newline at end of file diff --git a/app/scripts/components/webUI/services/webUI.service.js b/app/scripts/components/webUI/services/webUI.service.js new file mode 100644 index 00000000..d2a50ad4 --- /dev/null +++ b/app/scripts/components/webUI/services/webUI.service.js @@ -0,0 +1,131 @@ +'use strict'; + +import Account from './webUI.account'; + +function webUIService($rootScope, $location, $window, rolesFactory) { + 'ngInject'; + + let storage = $window.localStorage; + let accounts = []; + let current = null; + + let defaultHost = $location.host(); + let defaultPort = 18883; + let defaultRole = rolesFactory.ROLE_ONE; + + function load() { + accounts = storage.webUI ? JSON.parse(storage.webUI).map(createFromData) : []; + } + + function sync() { + storage.setItem('webUI', JSON.stringify(accounts)); + } + + function create() { + let account = new Account(); + account.role = parseInt(rolesFactory.current.role || defaultRole); + return account; + } + + function createFromData(data) { + return new Account(data.name, data.host, data.port, data.user, data.password, data.prefix, data.role, data.current); + } + + function save(account) { + if (!accounts.find(a => a === account)) { + accounts.push(account); + } + sync(); + } + + function getCurrent() { + return accounts.find(a => a.current === true); + } + + function setCurrent(account) { + accounts.forEach(a => a.current = a === account); + current = account; + sync(); + } + + function remove(account) { + let isCurrent = account === current; + + accounts.splice(accounts.indexOf(account), 1); + + if (!isCurrent) { + return; + } + + if (accounts.length) { + setCurrent(accounts[accounts.length - 1]); + } + + sync(); + + if (current) { + login(current); + } + else { + location.reload(); + } + } + + function login(account) { + setCurrent(account); + + storage.setItem('host', account.host); + storage.setItem('port', account.port); + storage.setItem('prefix', account.prefix); + + storage.setItem('user', (account.useCredentials ? account.user : '')); + storage.setItem('password', (account.useCredentials && account.password ? account.password : '')); + + let loginData = { + host: account.host, + port: account.port, + user: account.user, + password: account.password, + prefix: account.prefix + }; + + rolesFactory.setRole(account.role); + $rootScope.requestConfig(loginData); + + location.reload(); + } + + function init() { + load(); + + if (!accounts.length) { + let host = storage.host || defaultHost; + let port = storage.port || defaultPort; + let user = storage.user; + let password = storage.password; + let prefix = storage.prefix; + let role = rolesFactory.current.role || defaultRole; + + let account = new Account('Default', host, port, user, password, prefix, role, true); + save(account); + } + + current = getCurrent(); + } + + init(); + + return { + accounts: accounts, + current: current, + create: create, + save: save, + remove: remove, + getCurrent: getCurrent, + setCurrent: setCurrent, + login: login + }; +} + +export default webUIService; + diff --git a/app/scripts/components/webUI/webUI.scss b/app/scripts/components/webUI/webUI.scss new file mode 100644 index 00000000..64072421 --- /dev/null +++ b/app/scripts/components/webUI/webUI.scss @@ -0,0 +1,86 @@ +web-ui-manage { + +} + +web-ui-select { + display: inline-block; + vertical-align: middle; + + .ui-select-container { + position: relative; + + .ui-select-match { + + &.btn-default-focus { + background: none; + border: none; + color: #fff; + box-shadow: none; + } + + .ui-select-toggle { + background: transparent; + border: none; + color: #fff; + + &:hover, + &:focus { + background: transparent; + border: none; + } + } + } + + .ui-select-choices { + position: absolute; + z-index: 100; + top: 35px; + left: inherit; + right: -22px; + float: none; + + &.dropdown-menu { + background: #222; + border: 1px solid #222; + box-shadow: none; + padding: 0; + } + + .ui-select-choices-row { + > span { + background: #222; + color: #fff; + + &:hover { + color: rgba($color: #fff, $alpha: 0.7); + } + } + + &.active { + > span { + background: #fff; + color: #222; + } + } + } + } + + .form-control { + background: none; + border: none; + color: #fff; + + height: 19px; + padding: 0px 12px; + } + + .ui-select-search { + width: 1px; + + &.ui-select-search-hidden { + display: none; + } + } + } + +} \ No newline at end of file diff --git a/app/scripts/i18n/webUI/ru.json b/app/scripts/i18n/webUI/ru.json new file mode 100644 index 00000000..cc3a2272 --- /dev/null +++ b/app/scripts/i18n/webUI/ru.json @@ -0,0 +1,54 @@ +{ + "webUI": { + "manager": { + "field": { + "name": "Name", + "host": "Host", + "port": "Port", + "user": "User ID", + "password": "Password", + "prefix-header": "Use prefix", + "prefix": "Enable prefix (/client/user_id/)", + "credentials": "Use access credentials" + }, + "table": { + "header": { + "name": "Name", + "host": "Host", + "port": "Port", + "user": "User ID", + "prefix": "Use prefix" + } + }, + "button": { + "add": "Add account", + "edit": "Edit", + "remove": "Remove", + "login": "Login", + "save": "Save", + "cancel": "Cancel" + }, + "prompt": { + "remove": "Are you sure you want to delete {{name}} account?" + }, + "error": { + "name": { + "empty": "Empty name is not allowed" + }, + "host": { + "empty": "Empty host is not allowed" + }, + "port": { + "empty": "Empty port is not allowed", + "invalid": "Only number allowed" + }, + "user": { + "empty": "Empty user is not allowed" + }, + "password": { + "empty": "Empty password is not allowed" + } + } + } + } +} \ No newline at end of file diff --git a/app/views/web-ui.html b/app/views/web-ui.html index b1a95c36..273bdba6 100644 --- a/app/views/web-ui.html +++ b/app/views/web-ui.html @@ -2,7 +2,17 @@

Web UI

- + +
+
+
+

Accounts

+
+
+ +
+
+
diff --git a/package.json b/package.json index 3ef072d3..2da950a5 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,17 @@ "c3": "^0.4.11", "codemirror": "^5.25.0", "d3": "^4.7.4", + "dotenv": "^8.1.0", "jquery": "^3.2.1", "ng-file-upload": "^12.2.13", "ng-toast": "^2.0.0", + "ngbootbox": "^0.2.0", "node-sass": "^4.12.0", "oclazyload": "^1.1.0", "sass-loader": "^7.3.1", "spectrum-colorpicker": "^1.8.0", - "ui-select": "^0.19.6" + "ui-select": "^0.19.6", + "webpack-dotenv-plugin": "^2.1.0" }, "devDependencies": { "angular-mocks": "^1.5.0", diff --git a/webpack.config.js b/webpack.config.js index 4ca58c38..d9fe84a1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,9 +13,15 @@ const WebpackChunkHash = require("webpack-chunk-hash"); const InlineManifestWebpackPlugin = require("inline-manifest-webpack-plugin"); const InlineChunksManifestPlugin = require('./inline-chunks-manifest'); +const dotenv = require('dotenv').config({ + path: __dirname + '/.env' +}); +const DotenvPlugin = require('webpack-dotenv-plugin'); + const path = require('path'); process.traceDeprecation = true; +process.noDeprecation = true; /** * Env @@ -69,7 +75,8 @@ module.exports = function makeWebpackConfig() { 'ng-toast', 'angular-translate', - 'angular-translate-loader-partial' + 'angular-translate-loader-partial', + 'ngbootbox' ] }; /** @@ -241,6 +248,18 @@ module.exports = function makeWebpackConfig() { * List: http://webpack.github.io/docs/list-of-plugins.html */ config.plugins = [ + + /** + * Dotenv + * Reference: https://github.com/nwinch/webpack-dotenv-plugin + * Add dotenv support + */ + new DotenvPlugin({ + path: '.env', + sample: '.env.example', + allowEmptyValues: true, + }), + /** * Angular annotate * Reference: https://github.com/jeffling/ng-annotate-webpack-plugin From ae111a826a57a945f175b5cabf7d63c05a6fe630 Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Fri, 30 Aug 2019 22:40:12 +0300 Subject: [PATCH 2/8] Fix multiple view --- .env | 2 +- app/scripts/components/webUI/manage/webUIManage.controller.js | 2 +- app/scripts/components/webUI/select/webUISelect.controller.js | 2 ++ app/scripts/components/webUI/select/webUISelect.html | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 89191b8a..e4a708c0 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -WEBUI_MULTIPLE=true \ No newline at end of file +WEBUI_MULTIPLE=false \ No newline at end of file diff --git a/app/scripts/components/webUI/manage/webUIManage.controller.js b/app/scripts/components/webUI/manage/webUIManage.controller.js index dc01e29b..7c890107 100644 --- a/app/scripts/components/webUI/manage/webUIManage.controller.js +++ b/app/scripts/components/webUI/manage/webUIManage.controller.js @@ -16,7 +16,7 @@ class WebUIManageController { this.current = webUIService.current; this.editable = null; - this.isMultiple = process.env.WEBUI_MULTIPLE; + this.isMultiple = process.env.WEBUI_MULTIPLE === 'true'; if (!this.isMultiple) { this.editable = this.current; } diff --git a/app/scripts/components/webUI/select/webUISelect.controller.js b/app/scripts/components/webUI/select/webUISelect.controller.js index 7e05123c..f48aa736 100644 --- a/app/scripts/components/webUI/select/webUISelect.controller.js +++ b/app/scripts/components/webUI/select/webUISelect.controller.js @@ -13,6 +13,8 @@ class AccountSelectController { this.accounts = webUIService.accounts; this.current = webUIService.current; + this.isMultiple = process.env.WEBUI_MULTIPLE === 'true'; + $scope.$watch('$ctrl.current', (newValue, oldValue) => { if (newValue !== oldValue) { this.login(newValue); diff --git a/app/scripts/components/webUI/select/webUISelect.html b/app/scripts/components/webUI/select/webUISelect.html index 76d1adb7..2797d4b7 100644 --- a/app/scripts/components/webUI/select/webUISelect.html +++ b/app/scripts/components/webUI/select/webUISelect.html @@ -1,4 +1,4 @@ -
+
{{ $select.selected.name }} From 1fef519ded12d383b7bc7981eeec81dad9c93487 Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Sun, 1 Sep 2019 22:41:38 +0300 Subject: [PATCH 3/8] Fix webpack, copy i18n --- webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.js b/webpack.config.js index d9fe84a1..aaa988eb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -372,6 +372,7 @@ module.exports = function makeWebpackConfig() { // Reference: https://github.com/kevlened/copy-webpack-plugin new CopyWebpackPlugin([ {from: path.join(__dirname, 'app', 'images'), to: 'images'}, + {from: path.join(__dirname, 'app', 'scripts/i18n'), to: 'scripts/i18n'}, {from: path.join(__dirname, 'app', '404.html'), to: '404.html'}, {from: path.join(__dirname, 'app', 'favicon.ico'), to: 'favicon.ico'}, {from: path.join(__dirname, 'app', 'robots.txt'), to: 'robots.txt'} From 4ef24b646e462f6ddfc2d02c5c569111d0a6c2fe Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Mon, 2 Sep 2019 20:13:16 +0300 Subject: [PATCH 4/8] Add button in select account component Change name account to not required option --- app/scripts/app.routes.js | 7 +++++ .../webUI/manage/webUIManage.controller.js | 12 +++++++-- .../components/webUI/manage/webUIManage.html | 4 +-- .../webUI/select/webUISelect.controller.js | 27 +++++++++++++++++-- .../components/webUI/select/webUISelect.html | 6 ++--- .../webUI/services/webUI.service.js | 8 ++++-- app/scripts/components/webUI/webUI.scss | 12 ++++++++- app/scripts/i18n/webUI/ru.json | 8 ++++++ 8 files changed, 72 insertions(+), 12 deletions(-) diff --git a/app/scripts/app.routes.js b/app/scripts/app.routes.js index 104aa79c..29859bc0 100644 --- a/app/scripts/app.routes.js +++ b/app/scripts/app.routes.js @@ -1,3 +1,5 @@ +'use strict'; + import uiRouter from 'angular-ui-router'; import homeTemplateUrl from 'ngtemplate-loader?relativeTo=/app!../views/home.html'; @@ -43,6 +45,11 @@ function routing($stateProvider, $locationProvider, $urlRouterProvider) { templateUrl: webUITemplateUrl, controller: 'WebUICtrl as $ctrl' }) + .state('webUIAdd', { + url: '/web-ui/add', + templateUrl: webUITemplateUrl, + controller: 'WebUICtrl as $ctrl' + }) .state('system', { url: '/system', templateUrl: systemTemplateUrl, diff --git a/app/scripts/components/webUI/manage/webUIManage.controller.js b/app/scripts/components/webUI/manage/webUIManage.controller.js index 7c890107..5d1c46b5 100644 --- a/app/scripts/components/webUI/manage/webUIManage.controller.js +++ b/app/scripts/components/webUI/manage/webUIManage.controller.js @@ -2,11 +2,12 @@ class WebUIManageController { - constructor ($scope, $window, $translate, $ngBootbox, rolesFactory, webUIService) { + constructor ($scope, $window, $state, $translate, $ngBootbox, rolesFactory, webUIService) { 'ngInject'; this.$scope = $scope; this.$window = $window; + this.$state = $state; this.$translate = $translate; this.$ngBootbox = $ngBootbox; this.rolesFactory = rolesFactory; @@ -20,6 +21,9 @@ class WebUIManageController { if (!this.isMultiple) { this.editable = this.current; } + else if ($state.current.name === 'webUIAdd') { + this.create(); + } $scope.$watch('$ctrl.service.getCurrent()', (newValue, oldValue) => { if (newValue !== oldValue) { @@ -52,12 +56,16 @@ class WebUIManageController { } if (this.isMultiple) { - this.editable = false; + this.cancel(); } } cancel() { this.editable = null; + + if (this.$state.current.name === 'webUIAdd') { + this.$state.go('webUI'); + } } login(account) { diff --git a/app/scripts/components/webUI/manage/webUIManage.html b/app/scripts/components/webUI/manage/webUIManage.html index 18674b13..3fcc005a 100644 --- a/app/scripts/components/webUI/manage/webUIManage.html +++ b/app/scripts/components/webUI/manage/webUIManage.html @@ -41,9 +41,9 @@
-
+
- +
{{'webUI.manager.error.name.empty' | translate}}
diff --git a/app/scripts/components/webUI/select/webUISelect.controller.js b/app/scripts/components/webUI/select/webUISelect.controller.js index f48aa736..7943210e 100644 --- a/app/scripts/components/webUI/select/webUISelect.controller.js +++ b/app/scripts/components/webUI/select/webUISelect.controller.js @@ -2,24 +2,47 @@ class AccountSelectController { - constructor ($scope, $element, rolesFactory, webUIService) { + constructor ($scope, $element, $state, $location, $translate, rolesFactory, webUIService) { 'ngInject'; this.$scope = $scope; this.$element = $element; + this.$translate = $translate; + this.$state = $state; this.rolesFactory = rolesFactory; this.service = webUIService; this.accounts = webUIService.accounts; this.current = webUIService.current; + + this.accountAdd = { + 'name': 'Add service' + }; this.isMultiple = process.env.WEBUI_MULTIPLE === 'true'; $scope.$watch('$ctrl.current', (newValue, oldValue) => { if (newValue !== oldValue) { - this.login(newValue); + if (oldValue === this.accountAdd) { + return; + } + else if (newValue === this.accountAdd) { + this.current = webUIService.current; + $state.go('webUIAdd'); + } + else { + this.login(newValue); + } } }); + + this.$translate('webUI.select.button.add').then((translation) => { + this.accountAdd.name = translation; + }); + } + + items() { + return this.accounts.concat(this.accountAdd); } login(account) { diff --git a/app/scripts/components/webUI/select/webUISelect.html b/app/scripts/components/webUI/select/webUISelect.html index 2797d4b7..7cd30b0a 100644 --- a/app/scripts/components/webUI/select/webUISelect.html +++ b/app/scripts/components/webUI/select/webUISelect.html @@ -1,8 +1,8 @@
- + {{ $select.selected.name }} - -
+ +
\ No newline at end of file diff --git a/app/scripts/components/webUI/services/webUI.service.js b/app/scripts/components/webUI/services/webUI.service.js index d2a50ad4..8ed4fcc2 100644 --- a/app/scripts/components/webUI/services/webUI.service.js +++ b/app/scripts/components/webUI/services/webUI.service.js @@ -23,6 +23,7 @@ function webUIService($rootScope, $location, $window, rolesFactory) { function create() { let account = new Account(); + account.port = defaultPort; account.role = parseInt(rolesFactory.current.role || defaultRole); return account; } @@ -32,6 +33,10 @@ function webUIService($rootScope, $location, $window, rolesFactory) { } function save(account) { + if (!account.name) { + account.name = account.host; + } + if (!accounts.find(a => a === account)) { accounts.push(account); } @@ -52,6 +57,7 @@ function webUIService($rootScope, $location, $window, rolesFactory) { let isCurrent = account === current; accounts.splice(accounts.indexOf(account), 1); + sync(); if (!isCurrent) { return; @@ -61,8 +67,6 @@ function webUIService($rootScope, $location, $window, rolesFactory) { setCurrent(accounts[accounts.length - 1]); } - sync(); - if (current) { login(current); } diff --git a/app/scripts/components/webUI/webUI.scss b/app/scripts/components/webUI/webUI.scss index 64072421..c1a61477 100644 --- a/app/scripts/components/webUI/webUI.scss +++ b/app/scripts/components/webUI/webUI.scss @@ -1,5 +1,15 @@ web-ui-manage { - + .form-group { + .required { + .control-label { + &:after { + content: "*"; + color: red; + padding-left: 3px; + } + } + } + } } web-ui-select { diff --git a/app/scripts/i18n/webUI/ru.json b/app/scripts/i18n/webUI/ru.json index cc3a2272..9b8b688b 100644 --- a/app/scripts/i18n/webUI/ru.json +++ b/app/scripts/i18n/webUI/ru.json @@ -1,5 +1,13 @@ { "webUI": { + "select": { + "tip": { + "account": "Choose a account" + }, + "button": { + "add": "+ Add account" + } + }, "manager": { "field": { "name": "Name", From 5517013a44a11290675f6c19390e777a28333db3 Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Tue, 3 Sep 2019 15:09:11 +0300 Subject: [PATCH 5/8] Add responsive support --- app/index.ejs | 5 +- .../components/webUI/manage/webUIManage.html | 51 ++++++++++-------- .../webUI/select/webUISelect.controller.js | 4 ++ .../components/webUI/select/webUISelect.html | 2 +- app/scripts/components/webUI/webUI.scss | 54 +++++++++++++++++++ 5 files changed, 93 insertions(+), 23 deletions(-) diff --git a/app/index.ejs b/app/index.ejs index a95b5965..cfa47758 100644 --- a/app/index.ejs +++ b/app/index.ejs @@ -40,7 +40,7 @@ - +

@@ -49,6 +49,9 @@ \ No newline at end of file diff --git a/app/scripts/components/webUI/select/webUISelect.controller.js b/app/scripts/components/webUI/select/webUISelect.controller.js index 7943210e..62804301 100644 --- a/app/scripts/components/webUI/select/webUISelect.controller.js +++ b/app/scripts/components/webUI/select/webUISelect.controller.js @@ -48,6 +48,10 @@ class AccountSelectController { login(account) { this.service.login(account); } + + tagHelper(tag) { + return null; + } } export default AccountSelectController; \ No newline at end of file diff --git a/app/scripts/components/webUI/select/webUISelect.html b/app/scripts/components/webUI/select/webUISelect.html index 7cd30b0a..d2429f54 100644 --- a/app/scripts/components/webUI/select/webUISelect.html +++ b/app/scripts/components/webUI/select/webUISelect.html @@ -1,5 +1,5 @@
- + {{ $select.selected.name }}
diff --git a/app/scripts/components/webUI/webUI.scss b/app/scripts/components/webUI/webUI.scss index c1a61477..333a00ee 100644 --- a/app/scripts/components/webUI/webUI.scss +++ b/app/scripts/components/webUI/webUI.scss @@ -10,6 +10,60 @@ web-ui-manage { } } } + + .tap { + cursor: pointer; + } + + table { + tr:first-child { + td { + border-top: none; + } + } + } +} + +.visible-xs { + web-ui-select { + width: 100%; + margin: 10px 0px 5px 0px; + + .open { + > .dropdown-menu { + animation: none; + } + } + + .ui-select-container { + .ui-select-choices { + .ui-select-choices-row { + > span { + background: rgba(69, 69, 69, .6); + color:#999; + padding: 10px 15px 10px 38px; + font-size: 14px; + } + } + } + + .ui-select-match-text { + display: inline-block; + font-size: 14px; + font-weight: 400; + padding-bottom: 10px; + } + + .ui-select-choices { + position: relative !important; + top: 10px; + left: 0; + right: 0; + margin-bottom: 10px; + overflow: hidden; + } + } + } } web-ui-select { From 69bdc8af76071b6f4d73490c55e9b708566bc4e9 Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Mon, 9 Sep 2019 16:01:04 +0300 Subject: [PATCH 6/8] Add instructions to readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index ce05b594..6c0aab20 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,21 @@ Run `grunt` for building and `grunt serve` for preview. ## Testing Running `grunt test` will run the unit tests with karma. + +# Documentation + +## Multipe WebUI + +Change value in .env file + +**Multiple account disabled:** + +``` +WEBUI_MULTIPLE=false +``` + +**Multipe account enabled:** + +``` +WEBUI_MULTIPLE=true +``` \ No newline at end of file From bc1526d5bd58a21c6159adbbd319dca71f0f0e9b Mon Sep 17 00:00:00 2001 From: Sergey Safronov Date: Wed, 11 Sep 2019 15:45:23 +0300 Subject: [PATCH 7/8] Hide name field when multiple disabled --- app/scripts/components/webUI/manage/webUIManage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/components/webUI/manage/webUIManage.html b/app/scripts/components/webUI/manage/webUIManage.html index e65bc451..cf6259ca 100644 --- a/app/scripts/components/webUI/manage/webUIManage.html +++ b/app/scripts/components/webUI/manage/webUIManage.html @@ -44,7 +44,7 @@
-
+
{{'webUI.manager.error.name.empty' | translate}}
From 6b0ca4020f31268b4bc0b9a41e9e095318ada2c5 Mon Sep 17 00:00:00 2001 From: Evgeny Boger Date: Sun, 19 Apr 2020 22:51:06 +0300 Subject: [PATCH 8/8] fix broken merge --- webpack.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/webpack.config.js b/webpack.config.js index 0b092c8f..b76ec189 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -78,7 +78,6 @@ module.exports = function makeWebpackConfig() { 'angular-translate-loader-partial', 'ngbootbox', 'angular-spinkit', - 'ngbootbox' ] }; /**