Remove customized fields of add a server.

This commit is contained in:
Zhongyi Tong
2017-07-31 18:17:52 +08:00
parent c413a65f07
commit 0f6e48c65f
4 changed files with 26 additions and 54 deletions

View File

@@ -106,11 +106,9 @@ body {
}
img.server-info-icon {
background: #a4d3c4;
border-radius: 4px;
width: 28px;
height: 28px;
padding: 8px;
width: 36px;
height: 36px;
padding: 4px;
}
.server-info-left {
@@ -124,19 +122,14 @@ img.server-info-icon {
.server-info-row {
display: flex;
line-height: 27px;
margin: 8px 0;
height: 27px;
margin: 8px 0 0 0;
}
.server-info-key {
width: 40px;
margin-right: 20px;
.server-info-alias {
font-weight: bold;
text-align: right;
}
.server-info-value {
.server-info-url {
flex-grow: 1;
font-size: 14px;
height: 24px;
@@ -165,6 +158,7 @@ img.server-info-icon {
align-items: center;
padding: 0 10px;
border-radius: 2px;
margin-right: 10px;
}
.action i {

View File

@@ -17,19 +17,9 @@ class NewServerForm extends BaseComponent {
</div>
<div class="server-info-right">
<div class="server-info-row">
<span class="server-info-key">Url</span>
<input class="server-info-value" placeholder="(Required)"/>
<input class="server-info-url" placeholder="Enter the url of your Zulip server..."/>
</div>
<div class="server-info-row">
<span class="server-info-key">Label</span>
<input class="server-info-value" placeholder="(Optional)"/>
</div>
<div class="server-info-row">
<span class="server-info-key">Icon</span>
<input class="server-info-value" placeholder="(Optional)"/>
</div>
<div class="server-info-row">
<span class="server-info-key"></span>
<div class="action green server-save-action">
<i class="material-icons">check_box</i>
<span>Save</span>
@@ -51,20 +41,12 @@ class NewServerForm extends BaseComponent {
this.props.$root.innerHTML = '';
this.props.$root.appendChild(this.$newServerForm);
this.$newServerUrl = this.$newServerForm.querySelectorAll('input.server-info-value')[0];
this.$newServerAlias = this.$newServerForm.querySelectorAll('input.server-info-value')[1];
this.$newServerIcon = this.$newServerForm.querySelectorAll('input.server-info-value')[2];
this.$newServerUrl = this.$newServerForm.querySelectorAll('input.server-info-url')[0];
}
initActions() {
this.$saveServerButton.addEventListener('click', () => {
const newServerConf = {
alias: this.$newServerAlias.value,
url: this.$newServerUrl.value,
icon: this.$newServerIcon.value
};
DomainUtil.checkDomain(newServerConf).then(serverConf => {
DomainUtil.checkDomain(this.$newServerUrl.value).then(serverConf => {
DomainUtil.addDomain(serverConf).then(() => {
this.props.onChange(this.props.index);
});

View File

@@ -18,19 +18,12 @@ class ServerInfoForm extends BaseComponent {
</div>
<div class="server-info-right">
<div class="server-info-row">
<span class="server-info-key">Url</span>
<input class="server-info-value" disabled value="${this.props.server.url}"/>
<span class="server-info-alias">${this.props.server.alias}</span>
</div>
<div class="server-info-row">
<span class="server-info-key">Label</span>
<input class="server-info-value" disabled value="${this.props.server.alias}"/>
<input class="server-info-url" disabled value="${this.props.server.url}"/>
</div>
<div class="server-info-row">
<span class="server-info-key">Icon</span>
<input class="server-info-value" disabled value="${this.props.server.icon}"/>
</div>
<div class="server-info-row">
<span class="server-info-key"></span>
<div class="action red server-delete-action">
<i class="material-icons">indeterminate_check_box</i>
<span>Delete</span>

View File

@@ -73,10 +73,7 @@ class DomainUtil {
this.reloadDB();
}
checkDomain(server) {
let domain = server.url;
server.icon = server.icon || defaultIconUrl;
checkDomain(domain) {
const hasPrefix = (domain.indexOf('http') === 0);
if (!hasPrefix) {
domain = (domain.indexOf('localhost:') >= 0) ? `http://${domain}` : `https://${domain}`;
@@ -84,6 +81,12 @@ class DomainUtil {
const checkDomain = domain + '/static/audio/zulip.ogg';
const serverConf = {
icon: defaultIconUrl,
url: domain,
alias: domain
};
return new Promise((resolve, reject) => {
request(checkDomain, (error, response) => {
const certsError =
@@ -92,10 +95,10 @@ class DomainUtil {
];
if (!error && response.statusCode !== 404) {
// Correct
this.getServerSettings(domain, server).then(serverSettings => {
this.getServerSettings(domain).then(serverSettings => {
resolve(serverSettings);
}, () => {
resolve(server);
resolve(serverConf);
});
} else if (certsError.indexOf(error.toString()) >= 0) {
dialog.showMessageBox({
@@ -105,10 +108,10 @@ class DomainUtil {
message: `Do you trust certificate from ${domain}? \n ${error}`
}, response => {
if (response === 0) {
this.getServerSettings(domain, server).then(serverSettings => {
this.getServerSettings(domain).then(serverSettings => {
resolve(serverSettings);
}, () => {
resolve(server);
resolve(serverConf);
});
} else {
reject('Untrusted Certificate.');
@@ -121,7 +124,7 @@ class DomainUtil {
});
}
getServerSettings(domain, server) {
getServerSettings(domain) {
const serverSettingsUrl = domain + '/api/v1/server_settings';
return new Promise((resolve, reject) => {
request(serverSettingsUrl, (error, response) => {
@@ -129,9 +132,9 @@ class DomainUtil {
const data = JSON.parse(response.body);
if (data.hasOwnProperty('realm_icon') && data.realm_icon) {
resolve({
icon: (server.icon === defaultIconUrl) ? data.realm_uri + data.realm_icon : defaultIconUrl,
icon: data.realm_uri + data.realm_icon,
url: data.realm_uri,
alias: server.alias || data.realm_name
alias: data.realm_name
});
}
} else {