From 6f3fb507450e7e80d42bde87d4a437b6d7cd8935 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Feb 2024 15:07:07 +0100 Subject: [PATCH] Add new admin page --- www/common/common-constants.js | 2 +- www/common/inner/sidebar-layout.js | 4 +- www/newadmin/app-admin.less | 23 ++++++ www/newadmin/index.html | 21 +++++ www/newadmin/inner.html | 22 ++++++ www/newadmin/inner.js | 123 +++++++++++++++++++++++++++++ www/newadmin/main.js | 47 +++++++++++ www/sidebar/inner.js | 26 +----- 8 files changed, 243 insertions(+), 25 deletions(-) create mode 100644 www/newadmin/app-admin.less create mode 100644 www/newadmin/index.html create mode 100644 www/newadmin/inner.html create mode 100644 www/newadmin/inner.js create mode 100644 www/newadmin/main.js diff --git a/www/common/common-constants.js b/www/common/common-constants.js index 148ea8e43..05ca5d092 100644 --- a/www/common/common-constants.js +++ b/www/common/common-constants.js @@ -26,7 +26,7 @@ define(['/customize/application_config.js'], function (AppConfig) { MAX_PREMIUM_TEAMS_SLOTS: Math.max(AppConfig.maxTeamsSlots || 0, AppConfig.maxPremiumTeamsSlots || 0) || 5, MAX_PREMIUM_TEAMS_OWNED: Math.max(AppConfig.maxTeamsOwned || 0, AppConfig.maxPremiumTeamsOwned || 0) || 5, // Apps - criticalApps: ['profile', 'settings', 'debug', 'admin', 'support', 'notifications', 'calendar'], + criticalApps: ['profile', 'settings', 'debug', 'admin', 'support', 'notifications', 'calendar', 'newadmin'], // XXX earlyAccessApps: ['doc', 'presentation'] }; }); diff --git a/www/common/inner/sidebar-layout.js b/www/common/inner/sidebar-layout.js index b31dcf747..8090f8f0c 100644 --- a/www/common/inner/sidebar-layout.js +++ b/www/common/inner/sidebar-layout.js @@ -24,7 +24,9 @@ define([ const Sidebar = {}; - Sidebar.create = function (common, app, $leftside, $rightside) { + Sidebar.create = function (common, app, $container) { + const $leftside = $(h('div#cp-sidebarlayout-leftside')).appendTo($container); + const $rightside = $(h('div#cp-sidebarlayout-rightside')).appendTo($container); const sidebar = {}; const items = {}; diff --git a/www/newadmin/app-admin.less b/www/newadmin/app-admin.less new file mode 100644 index 000000000..242f368a2 --- /dev/null +++ b/www/newadmin/app-admin.less @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +@import (reference) '../../customize/src/less2/include/sidebar-layout.less'; +@import (reference) "../../customize/src/less2/include/limit-bar.less"; +@import (reference) "../../customize/src/less2/include/creation.less"; +@import (reference) '../../customize/src/less2/include/framework.less'; +@import (reference) '../../customize/src/less2/include/export.less'; + +&.cp-app-admin { + .framework_min_main(); + .sidebar-layout_main(); + .limit-bar_main(); + .creation_main(); + + display: flex; + flex-flow: column; + font: @colortheme_app-font; +} + diff --git a/www/newadmin/index.html b/www/newadmin/index.html new file mode 100644 index 000000000..c8c6384bb --- /dev/null +++ b/www/newadmin/index.html @@ -0,0 +1,21 @@ + + + + + + CryptPad + + + + + + + + + + + diff --git a/www/newadmin/inner.html b/www/newadmin/inner.html new file mode 100644 index 000000000..8eacb34ac --- /dev/null +++ b/www/newadmin/inner.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + +
+
+ + diff --git a/www/newadmin/inner.js b/www/newadmin/inner.js new file mode 100644 index 000000000..5f08f71ac --- /dev/null +++ b/www/newadmin/inner.js @@ -0,0 +1,123 @@ +// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +define([ + 'jquery', + '/common/toolbar.js', + '/components/nthen/index.js', + '/common/sframe-common.js', + '/common/common-interface.js', + '/common/common-ui-elements.js', + '/common/common-util.js', + '/common/common-hash.js', + '/common/inner/sidebar-layout.js', + '/customize/messages.js', + '/common/hyperscript.js', + '/customize/application_config.js', + '/api/config', + + 'css!/components/bootstrap/dist/css/bootstrap.min.css', + 'css!/components/components-font-awesome/css/font-awesome.min.css', + 'less!/newadmin/app-admin.less', +], function( + $, + Toolbar, + nThen, + SFCommon, + UI, + UIElements, + Util, + Hash, + Sidebar, + Messages, + h, + AppConfig, + ApiConfig, +) { + var APP = window.APP = {}; + + var common; + var metadataMgr; + var privateData; + var sframeChan; + + var andThen = function (common, $container) { + const sidebar = Sidebar.create(common, 'sidebar', $container); + var categories = { + 'users': { + icon: 'fa fa-users', + content: [ + 'invitations', + 'directory' + ] + }, + 'test': { + icon: 'fa fa-bell', + content: [ + ] + }, + 'click': { + icon: 'fa fa-file', + onClick: () => { + common.openUnsafeURL('https://cryptpad.fr'); + } + } + }; + + const blocks = sidebar.blocks; + sidebar.addItem('invitations', function (cb) { + var input = h('input', {type:'number'}); + var label = blocks.labelledInput('Test Input label', input); + var button = blocks.button('secondary', 'fa-question', "My Button text"); + var content = blocks.form(label, blocks.nav(button)); + cb(content); + }); + + sidebar.makeLeftside(categories); + }; + + + var createToolbar = function () { + var displayed = ['useradmin', 'newpad', 'limit', 'pageTitle', 'notifications']; + var configTb = { + displayed: displayed, + sfCommon: common, + $container: APP.$toolbar, + pageTitle: Messages.adminPage || 'Admin', + metadataMgr: common.getMetadataMgr(), + }; + APP.toolbar = Toolbar.create(configTb); + APP.toolbar.$rightside.hide(); + }; + + nThen(function(waitFor) { + $(waitFor(UI.addLoadingScreen)); + SFCommon.create(waitFor(function(c) { APP.common = common = c; })); + }).nThen(function(waitFor) { + APP.$container = $('#cp-sidebarlayout-container'); + APP.$toolbar = $('#cp-toolbar'); + sframeChan = common.getSframeChannel(); + sframeChan.onReady(waitFor()); + }).nThen(function (waitFor) { + if (!common.isAdmin()) { return; } + //updateStatus(waitFor()); // TODO re-add this + }).nThen(function( /*waitFor*/ ) { + metadataMgr = common.getMetadataMgr(); + privateData = metadataMgr.getPrivateData(); + common.setTabTitle(Messages.adminPage || 'Administration'); + + if (!common.isAdmin()) { + return void UI.errorLoadingScreen(Messages.admin_authError || '403 Forbidden'); + } + + // Add toolbar + createToolbar(); + + // Content + andThen(common, APP.$container); + + common.setTabTitle(Messages.settings_title); + UI.removeLoadingScreen(); + }); +}); diff --git a/www/newadmin/main.js b/www/newadmin/main.js new file mode 100644 index 000000000..f12995861 --- /dev/null +++ b/www/newadmin/main.js @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +// Load #1, load as little as possible because we are in a race to get the loading screen up. +define([ + '/components/nthen/index.js', + '/api/config', + '/common/dom-ready.js', + '/common/sframe-common-outer.js' +], function (nThen, ApiConfig, DomReady, SFCommonO) { + + // Loaded in load #2 + nThen(function (waitFor) { + DomReady.onReady(waitFor()); + }).nThen(function (waitFor) { + SFCommonO.initIframe(waitFor); + }).nThen(function (/*waitFor*/) { + var addRpc = function (sframeChan, Cryptpad/*, Utils*/) { + // Adding a new avatar from the profile: pin it and store it in the object + sframeChan.on('Q_ADMIN_MAILBOX', function (data, cb) { + Cryptpad.addAdminMailbox(data, cb); + }); + sframeChan.on('Q_ADMIN_RPC', function (data, cb) { + Cryptpad.adminRpc(data, cb); + }); + sframeChan.on('Q_UPDATE_LIMIT', function (data, cb) { + Cryptpad.updatePinLimit(function (e) { + cb({error: e}); + }); + }); + }; + var category; + if (window.location.hash) { + category = window.location.hash.slice(1); + window.location.hash = ''; + } + var addData = function (obj, Cryptpad, user, Utils) { + if (category) { obj.category = category; } + }; + SFCommonO.start({ + noRealtime: true, + addRpc: addRpc, + addData: addData + }); + }); +}); diff --git a/www/sidebar/inner.js b/www/sidebar/inner.js index 87caf54f2..c596d2e37 100644 --- a/www/sidebar/inner.js +++ b/www/sidebar/inner.js @@ -42,8 +42,8 @@ define([ var privateData; var sframeChan; - var andThen = function (common, $leftside, $rightside) { - const sidebar = Sidebar.create(common, 'sidebar', $leftside, $rightside); + var andThen = function (common, $container) { + const sidebar = Sidebar.create(common, 'sidebar', $container); var categories = { 'users': { icon: 'fa fa-users', @@ -84,8 +84,6 @@ define([ }).nThen(function(waitFor) { APP.$container = $('#cp-sidebarlayout-container'); APP.$toolbar = $('#cp-toolbar'); - APP.$leftside = $('
', { id: 'cp-sidebarlayout-leftside' }).appendTo(APP.$container); - APP.$rightside = $('
', { id: 'cp-sidebarlayout-rightside' }).appendTo(APP.$container); sframeChan = common.getSframeChannel(); sframeChan.onReady(waitFor()); }).nThen(function( /*waitFor*/ ) { @@ -103,27 +101,9 @@ define([ }; APP.toolbar = Toolbar.create(configTb); APP.toolbar.$rightside.hide(); - APP.history = common.makeUniversal('history'); // Content - var $rightside = APP.$rightside; - /* - var addItem = function(cssClass) { - var item = cssClass.slice(12); // remove 'cp-settings-' - if (typeof(create[item]) === "function") { - $rightside.append(create[item]()); - } - }; - for (var cat in categories) { - if (!Array.isArray(categories[cat])) { continue; } - categories[cat].forEach(addItem); - } - - - createLeftside(); - createUsageButton(); - */ - andThen(common, APP.$leftside, APP.$rightside); + andThen(common, APP.$container); common.setTabTitle(Messages.settings_title); UI.removeLoadingScreen();