Skip to content

Commit

Permalink
Merge pull request #9 from odeimaiz/pcrespov-is239+304+188/users
Browse files Browse the repository at this point in the history
modification on front-end
  • Loading branch information
pcrespov authored Nov 22, 2018
2 parents 9d1d9d5 + 91da29b commit 2854023
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 79 deletions.
186 changes: 110 additions & 76 deletions services/web/client/source/class/qxapp/Preferences.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint no-warning-comments: "off" */

qx.Class.define("qxapp.Preferences", {
extend: qx.ui.window.Window,

Expand Down Expand Up @@ -41,7 +40,7 @@ qx.Class.define("qxapp.Preferences", {

members: {
__tokenResources: null,
__validTokens: null,
__tokensList: null,

__createPage: function(name, iconSrc = null) {
let page = new qx.ui.tabview.Page(name, iconSrc);
Expand All @@ -51,7 +50,7 @@ qx.Class.define("qxapp.Preferences", {
}));

// title
page.add(new qx.ui.basic.Label("<h3>" + name + " Settings</h3>").set({
page.add(new qx.ui.basic.Label("<h3>" + name + " " + this.tr("Settings") + "</h3>").set({
rich: true
}));

Expand All @@ -61,18 +60,19 @@ qx.Class.define("qxapp.Preferences", {
},

__getGeneral: function() {
const iconUrl = qxapp.dev.Placeholders.getIcon("ion-ios-settings", 32);
let page = this.__createPage("General", iconUrl);
const iconUrl = "@FontAwesome5Solid/sliders-h/24";
let page = this.__createPage(this.tr("General"), iconUrl);

const userEmail = qxapp.auth.Data.getInstance().getEmail();

let form = new qx.ui.form.Form();
// content
let username = new qx.ui.form.TextField().set({
value: userEmail.split("@")[0],
placeholder: "User Name",
readOnly: true
});
page.add(username);
form.add(username, "Username");

// let fullname = new qx.ui.form.TextField().set({
// placeholder: "Full Name"
Expand All @@ -85,7 +85,9 @@ qx.Class.define("qxapp.Preferences", {
placeholder: "Email",
readOnly: true
});
page.add(email);
form.add(email, this.tr("Email"));

page.add(new qx.ui.form.renderer.Single(form));

let img = new qx.ui.basic.Image().set({
source: qxapp.utils.Avatar.getUrl(email.getValue(), 200)
Expand All @@ -96,87 +98,36 @@ qx.Class.define("qxapp.Preferences", {
},

__getSecurity: function() {
const iconUrl = qxapp.dev.Placeholders.getIcon("fa-lock", 32);
let page = this.__createPage("Security", iconUrl);

// content
// page.add(new qx.ui.form.PasswordField().set({
// placeholder: "Password"
// }));

// page.add(new qx.ui.form.PasswordField().set({
// placeholder: "Re-type Password"
// }));
const iconUrl = "@FontAwesome5Solid/shield-alt/24";
let page = this.__createPage(this.tr("Security"), iconUrl);

page.add(new qx.ui.basic.Atom("<h3>DAT-CORE</h3>").set({
rich: true
}));

let newTokenGrp = new qx.ui.container.Composite(new qx.ui.layout.HBox());
let newTokenPass = new qx.ui.form.PasswordField();
newTokenPass.set({
placeholder: "Personal Access Token",
alignY: "bottom"
});
newTokenGrp.add(newTokenPass, {
flex: 1
});
const iconSize = 12;
let newTokenBtn = new qx.ui.toolbar.Button(null, "@FontAwesome5Solid/plus/"+iconSize);
newTokenBtn.addListener("execute", e => {
let tokens = this.__tokenResources.tokens;
tokens.addListenerOnce("postSuccess", ev => {
newTokenPass.resetValue();
let tokensList = ev.getRequest().getResponse().data;
console.log(tokensList);
this.__reloadTokens();
}, this);
tokens.addListenerOnce("getError", ev => {
console.log(ev);
});
tokens.post(newTokenPass.getValue());
}, this);
newTokenGrp.add(newTokenBtn);
page.add(newTokenGrp);
this.__tokensList = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
page.add(this.__tokensList);

this.__validTokens = new qx.ui.container.Composite(new qx.ui.layout.VBox());
page.add(this.__validTokens);
this.__reloadTokens();

return page;
},

__reloadTokens: function() {
this.__validTokens.removeAll();
this.__tokensList.removeAll();

let tokens = this.__tokenResources.tokens;
tokens.addListenerOnce("getSuccess", e => {
let tokensList = e.getRequest().getResponse().data;
for (let i=0; i<tokensList.length; i++) {
let validTokenGrp = new qx.ui.container.Composite(new qx.ui.layout.HBox());
let validToken = new qx.ui.form.TextField();
validToken.set({
value: tokensList[i]["service"] + ": " + tokensList[i]["token_key"],
enable: false,
alignY: "bottom"
});
validTokenGrp.add(validToken, {
flex: 1
});
const iconSize = 12;
let newTokenBtn = new qx.ui.toolbar.Button(null, "@FontAwesome5Solid/trash/"+iconSize);
newTokenBtn.addListener("execute", ev => {
let token = this.__tokenResources.token;
token.addListenerOnce("delSuccess", eve => {
this.__reloadTokens();
}, this);
token.addListenerOnce("delError", eve => {
console.log(eve);
});
token.del();
}, this);
validTokenGrp.add(newTokenBtn);
this.__validTokens.add(validTokenGrp);
if (tokensList.length === 0) {
let emptyForm = this.__getEmptyTokenForm();
this.__tokensList.add(new qx.ui.form.renderer.Single(emptyForm));
} else {
for (let i=0; i<tokensList.length; i++) {
const token = tokensList[i];
let tokenForm = this.__getValidTokenForm(token["service"], token["token_key"], token["token_secret"]);
this.__tokensList.add(tokenForm);
}
}
}, this);
tokens.addListenerOnce("getError", e => {
Expand All @@ -185,9 +136,92 @@ qx.Class.define("qxapp.Preferences", {
tokens.get();
},

__getEmptyTokenForm: function() {
let form = new qx.ui.form.Form();

let newTokenKey = new qx.ui.form.TextField();
newTokenKey.set({
placeholder: "Key"
});
form.add(newTokenKey, this.tr("Key"));

let newTokenSecret = new qx.ui.form.TextField();
newTokenSecret.set({
placeholder: "Secret"
});
form.add(newTokenSecret, this.tr("Secret"));

let addTokenBtn = new qx.ui.form.Button(this.tr("Add token"));
addTokenBtn.setWidth(100);
addTokenBtn.setTextColor("black");
addTokenBtn.addListener("execute", e => {
let tokens = this.__tokenResources.tokens;
tokens.addListenerOnce("postSuccess", ev => {
this.__reloadTokens();
}, this);
tokens.addListenerOnce("getError", ev => {
console.log(ev);
});
const newTokenInfo = {
"service": "dat-core",
"token_key": newTokenKey.getValue(),
"token_secret": newTokenSecret.getValue()
};
tokens.post(newTokenInfo);
}, this);
form.addButton(addTokenBtn);

return form;
},

__getValidTokenForm: function(service, key, secret) {
let form = new qx.ui.form.Form();

let tokenService = new qx.ui.form.TextField().set({
value: service,
readOnly: true
});
form.add(tokenService, this.tr("Service"));

let tokenKey = new qx.ui.form.TextField();
tokenKey.set({
value: key,
readOnly: true
});
form.add(tokenKey, this.tr("Key"));

if (secret) {
let tokenSecret = new qx.ui.form.TextField();
tokenSecret.set({
value: secret,
readOnly: true
});
form.add(tokenSecret, this.tr("Secret"));
}

let delTokenBtn = new qx.ui.form.Button(this.tr("Delete token"));
delTokenBtn.setWidth(100);
delTokenBtn.setTextColor("black");
delTokenBtn.addListener("execute", e => {
let token = this.__tokenResources.token;
token.addListenerOnce("delSuccess", eve => {
this.__reloadTokens();
}, this);
token.addListenerOnce("delError", eve => {
console.log(eve);
});
token.del({
"service": service
});
}, this);
form.addButton(delTokenBtn);

return form;
},

__getDisplay: function() {
const iconUrl = qxapp.dev.Placeholders.getIcon("fa-eye", 32);
let page = this.__createPage("Display", iconUrl);
const iconUrl = "@FontAwesome5Solid/eye/24";
let page = this.__createPage(this.tr("Display"), iconUrl);
let themes = qx.Theme.getAll();

let select = new qx.ui.form.SelectBox("Theme");
Expand Down Expand Up @@ -220,8 +254,8 @@ qx.Class.define("qxapp.Preferences", {
},

__getAdvanced: function() {
const iconUrl = qxapp.dev.Placeholders.getIcon("fa-rebel", 32);
let page = this.__createPage("Advanced", iconUrl);
const iconUrl = "@FontAwesome5Solid/flask/24";
let page = this.__createPage(this.tr("Experimental"), iconUrl);

return page;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ qx.Class.define("qxapp.io.rest.ResourceFactory", {
// Get token
get: {
method: "GET",
url: basePath+"/my/tokens/{token_id}"
url: basePath+"/my/tokens/{service}"
},

// Update token
put: {
method: "PUT",
url: basePath+"/my/tokens/{token_id}"
url: basePath+"/my/tokens/{service}"
},

// Delete token
del: {
method: "DELETE",
url: basePath+"/my/tokens/{token_id}"
url: basePath+"/my/tokens/{service}"
}
});

Expand Down

0 comments on commit 2854023

Please sign in to comment.