Commit 2884485a authored by Henning Leutz's avatar Henning Leutz 🥋

refactor: permissions are 1000x faster, rewrite of permission sitemap building

parent 12960541
......@@ -40,9 +40,7 @@ QUI::$Ajax->registerFunction(
break;
}
$result = $Manager->getCompletePermissionList($Bind);
return $result;
return $Manager->getCompletePermissionList($Bind);
},
['params', 'btype'],
[
......
......@@ -46,7 +46,7 @@ define('controls/permissions/Edit', [
this.$Status.set(
'html',
QUILocale.get('quiqqer/system', 'permission.control.editcreate.title')
QUILocale.get('quiqqer/quiqqer', 'permission.control.editcreate.title')
);
resolve();
......@@ -59,8 +59,8 @@ define('controls/permissions/Edit', [
*/
$onOpen: function () {
new QUIButton({
text : QUILocale.get('quiqqer/system', 'permission.control.btn.add.permission'),
title : QUILocale.get('quiqqer/system', 'permission.control.btn.add.permission'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.add.permission'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.add.permission'),
textimage: 'fa fa-plus',
styles : {
'float': 'right'
......@@ -78,10 +78,10 @@ define('controls/permissions/Edit', [
var self = this;
new QUIPrompt({
title : QUILocale.get('quiqqer/system', 'permissions.panel.window.add.title'),
title : QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.title'),
icon : 'fa fa-add',
text : QUILocale.get('quiqqer/system', 'permissions.panel.window.add.text'),
information: QUILocale.get('quiqqer/system', 'permissions.panel.window.add.information'),
text : QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.text'),
information: QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.information'),
autoclose : false,
maxWidth : 600,
maxHeight : 400,
......@@ -101,16 +101,16 @@ define('controls/permissions/Edit', [
var Area = new Element('select', {
name : 'area',
html : '<option value="">' +
QUILocale.get('quiqqer/system', 'permissions.panel.window.add.select.user') +
'</option>' +
'<option value="site">' +
QUILocale.get('quiqqer/system', 'permissions.panel.window.add.select.site') +
'</option>' +
'<option value="project">' +
QUILocale.get('quiqqer/system', 'permissions.panel.window.add.select.project') +
'</option>',
QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.select.user') +
'</option>' +
'<option value="site">' +
QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.select.site') +
'</option>' +
'<option value="project">' +
QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.select.project') +
'</option>',
// '<option value="media">'+
// QUILocale.get('quiqqer/system', 'permissions.panel.window.add.select.media') +
// QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.add.select.media') +
// '</option>',
styles: {
width : 190,
......@@ -121,13 +121,13 @@ define('controls/permissions/Edit', [
new Element('select', {
name : 'type',
html : '<option value="bool" selected="selected">bool</option>' +
'<option value="string">string</option>' +
'<option value="int">int</option>' +
'<option value="group">group</option>' +
'<option value="groups">groups</option>' +
'<option value="user">user</option>' +
'<option value="users">users</option>' +
'<option value="array">array</option>',
'<option value="string">string</option>' +
'<option value="int">int</option>' +
'<option value="group">group</option>' +
'<option value="groups">groups</option>' +
'<option value="user">user</option>' +
'<option value="users">users</option>' +
'<option value="array">array</option>',
styles: {
width : 100,
margin: '10px 0 0 0'
......
......@@ -16,7 +16,7 @@ define('controls/permissions/Group', [
], function (Permission, QUIButton, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -101,15 +101,24 @@ define('controls/permissions/Group', [
require(['controls/groups/Select'], function (Select) {
Container.set(
'html',
'<h2>' + QUILocale.get(lg, 'permissions.panel.select.group.title') + '</h2>'
'<span class="controls-permissions-panel-headerIcon fa fa-users"></span>' +
'<h2>' + QUILocale.get(lg, 'permissions.panel.select.group.title') + '</h2>' +
QUILocale.get(lg, 'permissions.panel.select.group.description')
);
var size = Container.getSize(),
width = Math.round(size.x / 3);
if (width < 500) {
width = 500;
}
self.$Input = new Select({
max : 1,
multiple: false,
styles : {
margin: '0 auto',
width : 300
marginTop: 40,
width : width
},
events : {
onAddItem: function (GroupSearch, groupid) {
......@@ -143,8 +152,8 @@ define('controls/permissions/Group', [
*/
$onOpen: function () {
new QUIButton({
text : QUILocale.get('quiqqer/system', 'permission.control.btn.group.save'),
title : QUILocale.get('quiqqer/system', 'permission.control.btn.group.save'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.group.save'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.group.save'),
textimage: 'fa fa-save',
styles : {
'float': 'right'
......
......@@ -14,7 +14,7 @@ define('controls/permissions/Media', [
], function (Permission, QUIButton, QUIConfirm, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -78,33 +78,33 @@ define('controls/permissions/Media', [
*/
$openBindSelect: function () {
var self = this;
console.log('$openBindSelect');
return Promise.resolve();
return new Promise(function (resolve, reject) {
require([
'controls/projects/Popup',
'controls/projects/project/media/Popup',
'Projects'
], function (Popup, Projects) {
new Popup({
events: {
onSubmit: function (Popup, data) {
var Project = Projects.get(data.project, data.lang);
console.log(data);
if (!data.ids.length) {
var Project = Projects.get(data.project);
if (!parseInt(data.id)) {
reject();
return;
}
self.$Bind = Project.getMedia().get(data.ids[0]);
self.refresh();
Project.getMedia().get(data.id).then(function (Item) {
self.$Bind = Item;
self.refresh();
resolve();
resolve();
});
},
onCancel: function () {
reject();
}
onCancel: reject
}
}).open();
}, function (err) {
......@@ -119,7 +119,7 @@ define('controls/permissions/Media', [
*/
$onOpen: function () {
new QUIButton({
title : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save.recursive'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save.recursive'),
textimage: 'fa fa-reply-all',
styles : {
'float': 'right'
......@@ -132,8 +132,8 @@ define('controls/permissions/Media', [
}).inject(this.$Buttons);
new QUIButton({
text : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save'),
title : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save.text'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save.text'),
textimage: 'fa fa-save',
styles : {
'float': 'right'
......@@ -162,20 +162,20 @@ define('controls/permissions/Media', [
var self = this;
new QUIConfirm({
title : QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.title'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.title'),
icon : 'fa fa-reply-all',
maxHeight : 300,
maxWidth : 450,
texticon : false,
text : QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.text'),
information: QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.information'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.text'),
information: QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.information'),
cancel_button: {
text : QUILocale.get('quiqqer/system', 'cancel'),
text : QUILocale.get('quiqqer/quiqqer', 'cancel'),
textimage: 'fa fa-remove'
},
ok_button : {
text : QUILocale.get('quiqqer/system', 'accept'),
text : QUILocale.get('quiqqer/quiqqer', 'accept'),
textimage: 'fa fa-check'
},
......
.controls-permissions-panel-welcome {
align-items: center;
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
opacity: 0;
padding: 20px;
width: 100%;
}
.controls-permissions-panel-welcome img {
margin-top: 20px;
}
.controls-permissions-select .quiqqer-user-select .qui-elements-select-list {
display: none;
}
.controls-permissions-panel-headerIcon {
color: #efefef;
font-size: 120px;
margin-bottom: 40px;
}
......@@ -8,7 +8,9 @@ define('controls/permissions/Panel', [
'qui/QUI',
'qui/controls/desktop/Panel',
'Locale'
'Locale',
'css!controls/permissions/Panel.css'
], function (QUI, QUIPanel, QUILocale) {
"use strict";
......@@ -22,6 +24,7 @@ define('controls/permissions/Panel', [
Binds: [
'$onCreate',
'$onShow',
'openUserPermissions',
'openGroupPermissions',
'openSitePermissions',
......@@ -43,11 +46,11 @@ define('controls/permissions/Panel', [
);
this.setAttribute('icon', 'fa fa-shield');
this.$PermissionControl = null;
this.addEvents({
onCreate : this.$onCreate,
onShow : this.$onShow,
onDestroy: function () {
if (this.$PermissionControl) {
this.$PermissionControl.destroy();
......@@ -123,7 +126,12 @@ define('controls/permissions/Panel', [
this.getContent().setStyles({
padding: 0
});
},
/**
* event: on open
*/
$onShow: function () {
if (this.getAttribute('Object')) {
switch (typeOf(this.getAttribute('Object'))) {
case 'classes/users/User':
......@@ -146,13 +154,15 @@ define('controls/permissions/Panel', [
}
}
this.openWelcomeMessage().catch(function (err) {
console.error(err);
});
(function () {
this.openWelcomeMessage().catch(function (err) {
console.error(err);
});
}).delay(200, this);
},
/**
* Shows the welcom message and close all permissions contrls
* Shows the welcome message and close all permissions controls
*
* @returns {Promise}
*/
......@@ -162,25 +172,22 @@ define('controls/permissions/Panel', [
return new Promise(function (resolve) {
self.$closeLastPermissionControl().then(function () {
var Container = new Element('div', {
'class': 'controls-prmissions-panel-welcome',
html : QUILocale.get(lg, 'permissions.panel.welcome.message'),
styles : {
left : '-100',
opacity : 0,
padding : 20,
position: 'absolute',
top : 0
}
'class': 'controls-permissions-panel-welcome',
html : QUILocale.get(lg, 'permissions.panel.welcome.message')
}).inject(self.getContent());
new Element('img', {
src : URL_OPT_DIR + 'quiqqer/quiqqer/bin/images/QMan/security.svg',
styles: {
width: 250
}
}).inject(Container);
moofx(Container).animate({
left : 0,
opacity: 1
}, {
duration: 250,
equation: 'ease-in-out',
callback: function () {
self.getCategoryBar()
.getChildren()
.each(function (Category) {
......@@ -262,7 +269,6 @@ define('controls/permissions/Panel', [
self.$closeLastPermissionControl().then(function () {
return new Promise(function (resolve, reject) {
self.Loader.show();
var Button = false,
......@@ -323,7 +329,9 @@ define('controls/permissions/Panel', [
});
});
}).catch(function () {
self.openWelcomeMessage();
self.openWelcomeMessage().catch(function (e) {
console.error(e);
});
});
},
......@@ -338,13 +346,10 @@ define('controls/permissions/Panel', [
if (Welcome) {
return new Promise(function (resolved) {
moofx(Welcome).animate({
left : '-100%',
opacity: 0
}, {
duration: 250,
equation: 'ease-in-out',
callback: function () {
Welcome.destroy();
this.$PermissionControl = null;
......
......@@ -62,8 +62,12 @@
}
.controls-permissions-select {
align-items: center;
background: #fff;
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
left: 0;
padding: 20px;
position: absolute;
......
......@@ -27,8 +27,7 @@ define('controls/permissions/Permission', [
], function (QUI, QUIControl, QUIButton, QUIConfirm, QUIObjectUtils, PermissionMap, ControlUtils, PermissionUtils, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -133,14 +132,12 @@ define('controls/permissions/Permission', [
opacity: 0
}, {
duration: duration,
equation: 'cubic-bezier(.42,.4,.46,1.29)',
callback: function () {
moofx(self.$MapContainer).animate({
opacity: 0,
left : '-100%'
left : '-10%'
}, {
duration: duration,
equation: 'cubic-bezier(.42,.4,.46,1.29)',
callback: function () {
if (!SelectSheet) {
......@@ -150,10 +147,9 @@ define('controls/permissions/Permission', [
moofx(SelectSheet).animate({
opacity: 0,
left : '-100%'
left : '-10%'
}, {
duration: 250,
equation: 'ease-in-out',
callback: function () {
SelectSheet.destroy();
response();
......@@ -179,7 +175,6 @@ define('controls/permissions/Permission', [
var self = this;
return new Promise(function (response, reject) {
if (!self.$Bind) {
self.$openBindSelect().then(function () {
return self.open();
......@@ -211,14 +206,12 @@ define('controls/permissions/Permission', [
width : 240
}, {
duration: 250,
equation: 'cubic-bezier(.42,.4,.46,1.29)',
callback: function () {
moofx(self.$ContentContainer).animate({
left : 0,
opacity: 1
}, {
duration: 250,
equation: 'cubic-bezier(.42,.4,.46,1.29)',
callback: function () {
moofx(self.$Buttons).animate({
opacity: 1
......@@ -543,11 +536,11 @@ define('controls/permissions/Permission', [
new QUIConfirm({
maxWidth : 450,
maxHeight : 300,
title : QUILocale.get('quiqqer/system', 'permissions.panel.window.delete.title'),
text : QUILocale.get('quiqqer/system', 'permissions.panel.window.delete.text', {
title : QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.delete.title'),
text : QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.delete.text', {
right: permission
}),
information: QUILocale.get('quiqqer/system', 'permissions.panel.window.delete.information', {
information: QUILocale.get('quiqqer/quiqqer', 'permissions.panel.window.delete.information', {
right: permission
}),
autoclose : false,
......
......@@ -13,7 +13,7 @@ define('controls/permissions/Project', [
], function (Permission, QUIButton, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -93,8 +93,8 @@ define('controls/permissions/Project', [
*/
$onOpen: function () {
new QUIButton({
text : QUILocale.get('quiqqer/system', 'permission.control.btn.project.save'),
title : QUILocale.get('quiqqer/system', 'permission.control.btn.project.save'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.project.save'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.project.save'),
textimage: 'fa fa-save',
styles : {
'float': 'right'
......
......@@ -14,7 +14,7 @@ define('controls/permissions/Site', [
], function (Permission, QUIButton, QUIConfirm, QUILocale) {
"use strict";
var lg = 'quiqqer/system';
var lg = 'quiqqer/quiqqer';
return new Class({
......@@ -112,7 +112,7 @@ define('controls/permissions/Site', [
*/
$onOpen: function () {
new QUIButton({
title : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save.recursive'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save.recursive'),
textimage: 'fa fa-reply-all',
styles : {
'float': 'right'
......@@ -125,8 +125,8 @@ define('controls/permissions/Site', [
}).inject(this.$Buttons);
new QUIButton({
text : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save'),
title : QUILocale.get('quiqqer/system', 'permission.control.btn.site.save.text'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.btn.site.save.text'),
textimage: 'fa fa-save',
styles : {
'float': 'right'
......@@ -155,20 +155,20 @@ define('controls/permissions/Site', [
var self = this;
new QUIConfirm({
title : QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.title'),
title : QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.title'),
icon : 'fa fa-reply-all',
maxHeight : 300,
maxWidth : 450,
texticon : false,
text : QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.text'),
information: QUILocale.get('quiqqer/system', 'permission.control.site.recursive.win.information'),
text : QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.text'),
information: QUILocale.get('quiqqer/quiqqer', 'permission.control.site.recursive.win.information'),
cancel_button: {
text : QUILocale.get('quiqqer/system', 'cancel'),
text : QUILocale.get('quiqqer/quiqqer', 'cancel'),
textimage: 'fa fa-remove'
},
ok_button : {
text : QUILocale.get('quiqqer/system', 'accept'),
text : QUILocale.get('quiqqer/quiqqer', 'accept'),
textimage: 'fa fa-check'
},
......
......@@ -28,7 +28,8 @@ define('controls/permissions/Sitemap', [
Binds: [
'$onInject',
'$onItemClick',
'$createMap'
'$createMap',
'$onItemOpen'
],
initialize: function (Object, options) {
......@@ -71,7 +72,7 @@ define('controls/permissions/Sitemap', [
this.$Map.appendChild(
new QUISitemapItem({
text : 'Rechte',
text : 'Rechte', // #locale
icon : 'fa fa-gears',
value : '',
events: {
......@@ -128,8 +129,13 @@ define('controls/permissions/Sitemap', [
* @param {Object} permissions - list of permissions
*/
$createMap: function (permissions) {
var arr, permission;
var permissionList = {};
var i, len, arr, parent, permission, startParent;
var permissionList = {
items : {},
length: 0
};
parent = permissionList;
for (permission in permissions) {
if (!permissions.hasOwnProperty(permission)) {
......@@ -139,11 +145,26 @@ define('controls/permissions/Sitemap', [
arr = permission.split('.');
arr.pop(); // drop the last element
if (arr.length) {
ObjectUtils.namespace(arr.join('.'), permissionList);
startParent = parent;
for (i = 0, len = arr.length; i < len; i++) {
if (typeof parent.items[arr[i]] === 'undefined') {
parent.items[arr[i]] = {
items : {},
length: 0
};
}
parent.length = Object.getLength(parent.items);
parent = parent.items[arr[i]];
}
parent = startParent;
parent.length = Object.getLength(parent.items);
}
this.$permissionsList = permissionList;
this.$appendSitemapItemTo(
this.$Map.firstChild(),
'',
......@@ -169,19 +190,123 @@ define('controls/permissions/Sitemap', [
* @param {Object} params
*/
$appendSitemapItemTo: function (Parent, name, params) {
var i, len, text, right, Item, permission;
if (!params.length) {
return;
}
var groups = QUILocale.getGroups(),
list = [];
var list = this.$parseItemEntries(params, name);
for (var i = 0, len = list.length; i < len; i++) {
Parent.appendChild(
new QUISitemapItem({
icon : 'fa fa-gears',
value : list[i].permission,
text : list[i].translation,
hasChildren: list[i].hasChildren,
events : {
onClick: this.$onItemClick,
onOpen : this.$onItemOpen
}
})
);
}
},
/**
* event : item on click
*
* @param {Object} Item - qui/controls/sitemap/Item
*/
$onItemClick: function (Item) {
this.fireEvent('itemClick', [
Item,
Item.getAttribute('permission')
]);
},
/**
* event: item on open
*/
$onItemOpen: function (Item) {
var children = Item.getChildren();
if (children.length) {
return;
}
var i, len, perm, parent;
var permission = Item.getAttribute('value'),
items = this.$permissionsList.items;
permission = permission.split('.');
parent = items;
for (i = 0, len = permission.length; i < len; i++) {
perm = permission[i];
// first entry
if (typeof parent[perm] !== 'undefined') {
parent = parent[perm];
continue;
}
if (typeof parent.items[perm] !== 'undefined') {
parent = parent.items[perm];