Skip to content

Commit 5333bbf

Browse files
committed
__searchDelayer
1 parent 873c879 commit 5333bbf

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
4444
__resourceData: null,
4545
__showOrganizations: null,
4646
__textFilter: null,
47-
__searchButton: null,
4847
__collabButtonsContainer: null,
48+
__searchingCollaborators: null,
49+
__searchDelayer: null,
4950
__shareButton: null,
5051
__selectedCollaborators: null,
5152
__potentialCollaborators: null,
@@ -72,17 +73,25 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
7273
}));
7374
const filter = this.__textFilter = new osparc.filter.TextFilter("name", "collaboratorsManager");
7475
filter.setCompact(true);
75-
this.addListener("appear", () => filter.getChildControl("textfield").focus());
76+
const filterTextField = filter.getChildControl("textfield");
77+
filterTextField.setPlaceholder(this.tr("Search"));
78+
this.addListener("appear", () => filterTextField.focus());
7679
toolbar.add(filter, {
7780
flex: 1
7881
});
79-
const searchButton = this.__searchButton = new osparc.ui.form.FetchButton(this.tr("Search"), "@FontAwesome5Solid/search/12").set({
80-
maxHeight: 30,
82+
filterTextField.addListener("input", e => {
83+
const filterValue = e.getData();
84+
if (this.__searchDelayer) {
85+
clearTimeout(this.__searchDelayer);
86+
}
87+
if (filterValue.length > 3) {
88+
this.__searchingCollaborators.show();
89+
this.__searchDelayer = setTimeout(() => {
90+
this.__searchingCollaborators.show();
91+
this.__searchUsers();
92+
}, 1000);
93+
}
8194
});
82-
const command = new qx.ui.command.Command("Enter");
83-
searchButton.setCommand(command);
84-
searchButton.addListener("execute", () => this.__searchUsers(), this);
85-
toolbar.add(searchButton);
8695
this.add(toolbar);
8796

8897
const collabButtonsContainer = this.__collabButtonsContainer = new qx.ui.container.Composite(new qx.ui.layout.VBox());
@@ -92,6 +101,10 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
92101
flex: 1
93102
});
94103

104+
const searchingCollaborators = this.__searchingCollaborators = new osparc.filter.SearchingCollaborators();
105+
searchingCollaborators.exclude();
106+
this.__collabButtonsContainer.add(searchingCollaborators);
107+
95108
const buttons = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({
96109
alignX: "right"
97110
}));
@@ -106,7 +119,6 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
106119

107120
__searchUsers: function() {
108121
const text = this.__textFilter.getChildControl("textfield").getValue();
109-
this.__searchButton.setFetching(true);
110122
osparc.store.Users.getInstance().searchUsers(text)
111123
.then(users => {
112124
users.forEach(user => user["collabType"] = 2);
@@ -116,7 +128,9 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
116128
console.error(err);
117129
osparc.FlashMessenger.getInstance().logAs(err.message, "ERROR");
118130
})
119-
.finally(() => this.__searchButton.setFetching(false));
131+
.finally(() => {
132+
this.__searchingCollaborators.exclude();
133+
});
120134
},
121135

122136
__showProductEveryone: function() {
@@ -208,6 +222,10 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
208222
}
209223
this.__collabButtonsContainer.add(this.__collaboratorButton(potentialCollaborator));
210224
});
225+
226+
// move it to last position
227+
this.__collabButtonsContainer.remove(this.__searchingCollaborators);
228+
this.__collabButtonsContainer.add(this.__searchingCollaborators);
211229
},
212230

213231
__shareClicked: function() {

0 commit comments

Comments
 (0)