Browse Source

Merge branch 'HPCC-16774' into candidate-6.2.0

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 years ago
parent
commit
407b1916fd

+ 124 - 33
esp/src/eclwatch/MemberOfWidget.js

@@ -18,30 +18,36 @@ define([
     "dojo/_base/lang",
     "dojo/i18n",
     "dojo/i18n!./nls/hpcc",
+    "dojo/_base/array",
+    "dojo/promise/all",
 
     "dijit/registry",
+    "dijit/form/Button",
+    "dijit/ToolbarSeparator",
+    "dijit/Dialog",
 
-    "dgrid/editor",
+    "dgrid/selector",
 
     "hpcc/GridDetailsWidget",
     "hpcc/ws_access",
     "hpcc/ws_account",
-    "hpcc/ESPUtil"
+    "hpcc/ESPUtil",
+    "hpcc/TargetSelectWidget"
 
-], function (declare, lang, i18n, nlsHPCC,
-                registry,
-                editor,
-                GridDetailsWidget, WsAccess, WsAccount, ESPUtil) {
+], function (declare, lang, i18n, nlsHPCC, arrayUtil, all,
+                registry, Button, ToolbarSeparator, Dialog,
+                selector,
+                GridDetailsWidget, WsAccess, WsAccount, ESPUtil, TargetSelectWidget) {
     return declare("MemberOfWidget", [GridDetailsWidget], {
         i18n: nlsHPCC,
 
         gridTitle: nlsHPCC.title_MemberOf,
-        idProperty: "__hpcc_id",
+        idProperty: "name",
         currentUser: null,
 
         //  Hitched Actions  ---
         _onRefresh: function (args) {
-            this.grid.refresh();
+            this.refreshGrid();
         },
 
         //  Implementation  ---
@@ -50,40 +56,56 @@ define([
             if (this.inherited(arguments))
                 return;
 
-            WsAccount.MyAccount({
-            }).then(function (response) {
-                if (lang.exists("MyAccountResponse.username", response)) {
-                    context.currentUser = response.MyAccountResponse.username;
-                }
+            this.refreshGrid();
+            this.memberDropDown = new TargetSelectWidget({});
+            this.memberDropDown.init({
+                loadUsersNotAMemberOfAGroup: true,
+                username: params.username
             });
+            this.dialog.addChild(this.memberDropDown);
+            
+        },
 
-            this.store = WsAccess.CreateGroupsStore(params.username, false);
-            this.grid.setStore(this.store);
-            this.grid.on("dgrid-datachange", function(event){
-                if (dojoConfig.isAdmin && params.username === context.currentUser && event.oldValue === true) {
-                    var msg = confirm(context.i18n.RemoveUser + " " + event.rowId + ". " + context.i18n.ConfirmRemoval);
-                    if (msg) {
-                        location.hash = "";
-                        location.reload();
-                    } else {
-                        event.preventDefault();
-                    }
+        createGrid: function (domID) {
+            var context = this;
+            this.openButton = registry.byId(this.id + "Open");
+            this.refreshButton = registry.byId(this.id + "Refresh");
+            this.addButton = new Button({
+                id: this.id + "Add",
+                label: this.i18n.Add,
+                onClick: function (event) {
+                    context._onAddMember(event);
+                }
+            }).placeAt(this.openButton.domNode, "after");
+            this.deleteButton = new Button({
+                id: this.id + "Delete",
+                label: this.i18n.Delete,
+                disabled: true,
+                onClick: function (event) {
+                    context._onDeleteMember(event);
                 }
+            }).placeAt(this.addButton.domNode, "after");
+            tmpSplitter = new ToolbarSeparator().placeAt(this.addButton.domNode, "before");
+            this.dialog = new Dialog({
+                title: this.i18n.PleaseSelectAGroupToAddUser,
+                style: "width: 320px;"
             });
-            this._refreshActionState();
-        },
+            this.dialogBtn = new Button({
+                label: this.i18n.Add,
+                style: "float:right;",
+                onClick: function (event) {
+                    context._onSubmitAddMember(event);
+                }
+            }).placeAt(this.dialog.domNode);
 
-        createGrid: function (domID) {
-            var retVal = new declare([ESPUtil.Grid(true, false)])({
+            var retVal = new declare([ESPUtil.Grid(true, true)])({
                 sort: [{ attribute: "name" }],
                 store: this.store,
                 columns: {
-                    isMember: editor({
-                        label: "",
+                    check: selector({
                         width: 27,
-                        editor: "checkbox",
-                        autoSave: true
-                    }),
+                        label: " "
+                    }, "checkbox"),
                     name: {
                         label: this.i18n.GroupName,
                         sortable: true
@@ -91,11 +113,80 @@ define([
                 }
             }, domID);
 
+            retVal.onSelectionChanged(function (event) {
+                context.refreshActionState();
+            });
+
             return retVal;
         },
 
+        _onAddMember: function (event) {
+            this.dialog.show();
+        },
+
+        _onSubmitAddMember: function (event) {
+            var context = this;
+            WsAccess.UserGroupEdit({
+                request: {
+                    groupnames_i1:context.memberDropDown.get("value"),
+                    username:context.params.username,
+                    action: "Add"
+                }
+            }).then(function (response) {
+               context.dialog.hide();
+               context._onRefresh();
+            });
+        },
+
+        _onDeleteMember: function (event) {
+            var context = this;
+            var selections = this.grid.getSelected();
+            if (confirm(this.i18n.YouAreAboutToRemoveUserFrom)) {
+                var promises = [];
+                arrayUtil.forEach(selections, function (row, idx) {
+                    promises.push(WsAccess.UserGroupEdit({
+                        request: {
+                            groupnames_i6: row.name,
+                            username:context.params.username,
+                            action: "Delete"
+                        }
+                    }));
+                });
+                all(promises).then(function() {
+                    context._onRefresh();
+                });
+            }
+        },
+
+        refreshGrid: function () {
+            var context = this;
+            WsAccess.UserEdit({
+                request: {
+                    username: context.params.username
+                }
+            }).then(function (response) {
+                var results = [];
+
+                if (lang.exists("UserEditResponse.Groups.Group", response)) {
+                    results = response.UserEditResponse.Groups.Group;
+                    arrayUtil.forEach(results, function (row, idx) {
+                        lang.mixin(row, {
+                            name: row.name
+                        });
+                    });
+                }
+
+                context.store.setData(results);
+                context.grid.set("query", {});
+            });
+        },
+
         refreshActionState: function (selection) {
             registry.byId(this.id + "Open").set("disabled", true);
+            var selection = this.grid.getSelected();
+            var hasUserSelection = selection.length;
+
+            this.deleteButton.set("disabled", !hasUserSelection);
         }
     });
 });

+ 129 - 29
esp/src/eclwatch/MembersWidget.js

@@ -18,69 +18,169 @@ define([
     "dojo/_base/lang",
     "dojo/i18n",
     "dojo/i18n!./nls/hpcc",
+    "dojo/_base/array",
+    "dojo/promise/all",
 
     "dijit/registry",
+    "dijit/form/Button",
+    "dijit/ToolbarSeparator",
+    "dijit/Dialog",
 
-    "dgrid/editor",
+    "dgrid/selector",
 
     "hpcc/GridDetailsWidget",
     "hpcc/ws_access",
-    "hpcc/ESPUtil"
+    "hpcc/ESPUtil",
+    "hpcc/TargetSelectWidget"
 
-], function (declare, lang, i18n, nlsHPCC,
-                registry,
-                editor,
-                GridDetailsWidget, WsAccess, ESPUtil) {
+], function (declare, lang, i18n, nlsHPCC, arrayUtil, all,
+                registry, Button, ToolbarSeparator, Dialog,
+                selector,
+                GridDetailsWidget, WsAccess, ESPUtil, TargetSelectWidget) {
     return declare("MembersWidget", [GridDetailsWidget], {
         i18n: nlsHPCC,
 
         gridTitle: nlsHPCC.title_Members,
-        idProperty: "__hpcc_id",
-
-        //  Hitched Actions  ---
-        _onRefresh: function (args) {
-            this.grid.refresh();
-        },
+        idProperty: "username",
 
         //  Implementation  ---
         init: function (params) {
             if (this.inherited(arguments))
                 return;
 
-            this.store = WsAccess.CreateUsersStore(params.groupname, false);
-            this.grid.setStore(this.store);
-            this._refreshActionState();
+            this.refreshGrid();
+            this.memberDropDown = new TargetSelectWidget({});
+            this.memberDropDown.init({
+                loadUsersNotInGroup: true,
+                groupname: params.groupname
+            });
+            this.dialog.addChild(this.memberDropDown);
         },
 
         createGrid: function (domID) {
-            var retVal = new declare([ESPUtil.Grid(true, false)])({
+            var context = this;
+            this.openButton = registry.byId(this.id + "Open");
+            this.refreshButton = registry.byId(this.id + "Refresh");
+            this.addButton = new Button({
+                id: this.id + "Add",
+                label: this.i18n.Add,
+                onClick: function (event) {
+                    context._onAddMember(event);
+                }
+            }).placeAt(this.openButton.domNode, "after");
+            this.deleteButton = new Button({
+                id: this.id + "Delete",
+                label: this.i18n.Delete,
+                disabled: true,
+                onClick: function (event) {
+                    context._onDeleteMember(event);
+                }
+            }).placeAt(this.addButton.domNode, "after");
+            tmpSplitter = new ToolbarSeparator().placeAt(this.addButton.domNode, "before");
+
+            this.dialog = new Dialog({
+                title: this.i18n.PleaseSelectAUserToAdd,
+                style: "width: 300px;"
+            });
+            this.dialogBtn = new Button({
+                label: this.i18n.Add,
+                style: "float:right;",
+                onClick: function (event) {
+                    context._onSubmitAddMember(event);
+                }
+            }).placeAt(this.dialog.domNode);
+            
+            var retVal = new declare([ESPUtil.Grid(true, true)])({
                 store: this.store,
                 columns: {
-                    isMember: editor({
-                        label: "",
+                    check: selector({
                         width: 27,
-                        editor: "checkbox",
-                        autoSave: true
-                    }),
+                        label: " "
+                    }, "checkbox"),
                     username: {
-                        width: 180,
                         label: this.i18n.Username
-                    },
-                    fullname: {
-                        label: this.i18n.FullName
-                    },
-                    passwordexpiration: {
-                        width: 180,
-                        label: this.i18n.PasswordExpiration
                     }
                 }
             }, domID);
 
+             retVal.onSelectionChanged(function (event) {
+                context.refreshActionState();
+            });
+
             return retVal;
         },
 
+        _onAddMember: function (event) {
+            this.dialog.show();
+        },
+
+        _onSubmitAddMember: function (event) {
+            var context = this;
+            WsAccess.GroupMemberEdit({
+                request: {
+                    groupname:context.params.groupname,
+                    usernames_i7:context.memberDropDown.get("value"),
+                    action: "Add"
+                }
+            }).then(function (response) {
+               context.dialog.hide();
+               context._onRefresh();
+            });
+        },
+
+        _onDeleteMember: function (event) {
+            var context = this;
+            var selections = this.grid.getSelected();
+            if (confirm(this.i18n.YouAreAboutToRemoveUserFrom)) {
+                var promises = [];
+                arrayUtil.forEach(selections, function (row, idx) {
+                    promises.push(WsAccess.GroupMemberEdit({
+                        request: {
+                            groupname: context.params.groupname,
+                            usernames_i1:row.username,
+                            action: "Delete"
+                        }
+                    }));
+                });
+                all(promises).then(function() {
+                    context._onRefresh();
+                });
+            }
+        },
+
+        _onRefresh: function () {
+            this.refreshGrid();
+        },
+
         refreshActionState: function (selection) {
             registry.byId(this.id + "Open").set("disabled", true);
+            var selection = this.grid.getSelected();
+            var hasUserSelection = selection.length;
+
+            this.deleteButton.set("disabled", !hasUserSelection);
+        },
+
+        refreshGrid: function () {
+            var context = this;
+            WsAccess.Members({
+                request: {
+                    groupname: context.params.groupname
+                }
+            }).then(function (response) {
+                var results = [];
+
+                if (lang.exists("GroupEditResponse.Users.User", response)) {
+                    results = response.GroupEditResponse.Users.User;
+                    arrayUtil.forEach(results, function (row, idx) {
+                        lang.mixin(row, {
+                            username: row.username
+                        });
+                    });
+                }
+
+                context.store.setData(results);
+                context.grid.set("query", {});
+            });
         }
     });
 });

+ 44 - 0
esp/src/eclwatch/TargetSelectClass.js

@@ -78,6 +78,10 @@ define([
                 this.loadDropZones();
             } else if (params.Users === true) {
                 this.loadUsers();
+            } else if (params.loadUsersNotInGroup === true) {
+                this.loadUsersNotInGroup(params.groupname);
+            } else if (params.loadUsersNotAMemberOfAGroup === true) {
+                this.loadUsersNotAMemberOfAGroup(params.username);
             } else if (params.UserGroups === true) {
                 this.loadUserGroups();
             } else if (params.DropZoneFolders === true) {
@@ -178,6 +182,46 @@ define([
             });
         },
 
+        loadUsersNotAMemberOfAGroup: function (username) {
+            var context = this;
+            WsAccess.UserGroupEditInput({
+                request: {
+                    username: username
+                }
+            }).then(function (response) {
+                    if (lang.exists("UserGroupEditInputResponse.Groups.Group", response)) {
+                        var targetData = response.UserGroupEditInputResponse.Groups.Group;
+                        for (var i = 0; i < targetData.length; ++i) {
+                            context.options.push({
+                                label: targetData[i].name,
+                                value: targetData[i].name
+                            });
+                        }
+                        context._postLoad();
+                    }
+            });
+        },
+
+        loadUsersNotInGroup: function (groupname) {
+            var context = this;
+            WsAccess.GroupMemberEditInput({
+                request: {
+                    groupname: groupname
+                }
+            }).then(function (response) {
+                    if (lang.exists("GroupMemberEditInputResponse.Users.User", response)) {
+                        var targetData = response.GroupMemberEditInputResponse.Users.User;
+                        for (var i = 0; i < targetData.length; ++i) {
+                            context.options.push({
+                                label: targetData[i].username,
+                                value: targetData[i].username
+                            });
+                        }
+                        context._postLoad();
+                    }
+            });
+        },
+
         loadDropZones: function () {
             var context = this;
             WsTopology.TpServiceQuery({

+ 3 - 0
esp/src/eclwatch/nls/hpcc.js

@@ -437,7 +437,9 @@ define({root:
     PlaceholderLastName: "Smith",
     Playground: "Playground",
     PleasePickADefinition: "Please pick a definition",
+    PleaseSelectAGroupToAddUser: "Please select a group to add the user to",
     PleaseSelectAUserOrGroup: "Please select a user or a group along with a file name",
+    PleaseSelectAUserToAdd: "Please select a user to add",
     PleaseSelectADynamicESDLService: "Please select a dynamic ESDL service",
     PleaseSelectATopologyItem: "Please select a target, service or machine.",
     Plugins: "Plugins",
@@ -755,6 +757,7 @@ define({root:
     XML: "XML",
     XRef: "XRef",
     Year: "Year",
+    YouAreAboutToRemoveUserFrom: "You are about to remove a user(s) from this group. Do you wish to continue?",
     YouAreAboutToDeleteBinding: "You are about to delete this binding. Are you sure you want to do this?",
     YourBrowserMayNotSupport: "Your browser may not support file(s) of this size",
     ZAP: "Z.A.P",

+ 18 - 88
esp/src/eclwatch/ws_access.js

@@ -38,53 +38,7 @@ define([
         responseTotalQualifier: "UserQueryResponse.TotalUsers",
         idProperty: "username",
         startProperty: "PageStartFrom",
-        countProperty: "PageSize",
-
-        constructor: function () {
-            this.idProperty = "username";
-        },
-
-        put: function (object, options) {
-            var retVal = this.inherited(arguments);
-            self.UserGroupEdit({
-                request: {
-                    username: this.username,
-                    action: object.isMember ? "add" : "delete",
-                    groupnames_i1: object.__hpcc_groupname
-                }
-            });
-            return retVal;
-        },
-
-        refreshUsers: function (query) {
-            var context = this;
-            return self.Users({
-                request: query
-            }).then(function (response) {
-                if (lang.exists("UserQueryResponse.Users.User", response)) {
-                    return response.UserQueryResponse.Users.User;
-                }
-                return [];
-            });
-        },
-
-        refreshGroupUsers: function (query) {
-            if (!this.groupname) {
-                var deferred = new Deferred;
-                deferred.resolve([]);
-                return deferred.promise;
-            }
-            return self.GroupEdit({
-                request: {
-                    groupname: this.groupname
-                }
-            }).then(function (response) {
-                if (lang.exists("GroupEditResponse.Users.User", response)) {
-                    return response.GroupEditResponse.Users.User;
-                }
-                return [];
-            });
-        }
+        countProperty: "PageSize"
     });
 
     var GroupsStore = declare([ESPRequest.Store], {
@@ -94,47 +48,7 @@ define([
         responseTotalQualifier: "GroupQueryResponse.TotalGroups",
         idProperty: "name",
         startProperty: "PageStartFrom",
-        countProperty: "PageSize",
-
-        constructor: function () {
-            this.idProperty = "name";
-            this.startProperty = "PageStartFrom";
-            this.countProperty = "PageSize";
-        },
-
-        put: function (object, options) {
-            var retVal = this.inherited(arguments);
-            self.UserGroupEdit({
-                request: {
-                    username: this.username,
-                    action: object.isMember ? "add" : "delete",
-                    groupnames_i1: object.name
-                }
-            });
-            return retVal;
-        },
-
-        refreshGroups: function () {
-            return self.Groups().then(function (response) {
-                if (lang.exists("GroupQueryResponse.Groups.Group", response)) {
-                    return response.GroupQueryResponse.Groups.Group;
-                }
-                return [];
-            });
-        },
-
-        refreshUserGroups: function (query) {
-            return self.UserEdit({
-                request: {
-                    username: this.username
-                }
-            }).then(function (response) {
-                if (lang.exists("UserEditResponse.Groups.Group", response)) {
-                    return response.UserEditResponse.Groups.Group;
-                }
-                return [];
-            });
-        }
+        countProperty: "PageSize"
     });
 
     var CONCAT_SYMBOL = ":";
@@ -592,6 +506,10 @@ define([
             return this._doCall("UserGroupEdit", params);
         },
 
+        UserGroupEditInput: function (params) {
+            return this._doCall("UserGroupEditInput", params);
+        },
+
         GroupAdd: function (params) {
             return this._doCall("GroupAdd", params);
         },
@@ -604,10 +522,22 @@ define([
             return this._doCall("GroupEdit", params);
         },
 
+        GroupMemberEdit: function (params) {
+            return this._doCall("GroupMemberEdit", params);
+        },
+
         Groups: function (params) {
             return this._doCall("GroupQuery", params);
         },
 
+        Members: function (params) {
+            return this._doCall("GroupEdit", params);
+        },
+
+        GroupMemberEditInput: function (params) {
+            return this._doCall("GroupMemberEditInput", params);
+        },
+
         Permissions: function (params) {
             return this._doCall("Permissions", params);
         },