Fix up network editing
This commit is contained in:
parent
8fa42c5c48
commit
c8b22b2df3
@ -12,9 +12,7 @@
|
|||||||
Edit {{ defaults.name }}
|
Edit {{ defaults.name }}
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<template v-if="config.public"
|
<template v-if="config.public">The Lounge - </template>
|
||||||
>The Lounge -
|
|
||||||
</template>
|
|
||||||
Connect
|
Connect
|
||||||
<template v-if="!config.displayNetwork">
|
<template v-if="!config.displayNetwork">
|
||||||
<template v-if="config.lockNetwork">
|
<template v-if="config.lockNetwork">
|
||||||
|
@ -34,6 +34,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
setNetworkData() {
|
setNetworkData() {
|
||||||
|
socket.emit("network:get", this.$route.params.uuid);
|
||||||
this.networkData = this.$root.findNetwork(this.$route.params.uuid);
|
this.networkData = this.$root.findNetwork(this.$route.params.uuid);
|
||||||
},
|
},
|
||||||
handleSubmit(data) {
|
handleSubmit(data) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const $ = require("jquery");
|
|
||||||
const socket = require("../socket");
|
const socket = require("../socket");
|
||||||
const {vueApp, initChannel, findChannel} = require("../vue");
|
const {vueApp, initChannel, findChannel, findNetwork} = require("../vue");
|
||||||
|
|
||||||
socket.on("network", function(data) {
|
socket.on("network", function(data) {
|
||||||
const network = data.networks[0];
|
const network = data.networks[0];
|
||||||
@ -13,10 +12,6 @@ socket.on("network", function(data) {
|
|||||||
|
|
||||||
vueApp.networks.push(network);
|
vueApp.networks.push(network);
|
||||||
vueApp.switchToChannel(network.channels[0]);
|
vueApp.switchToChannel(network.channels[0]);
|
||||||
|
|
||||||
$("#connect")
|
|
||||||
.find(".btn")
|
|
||||||
.prop("disabled", false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("network:options", function(data) {
|
socket.on("network:options", function(data) {
|
||||||
@ -50,7 +45,13 @@ socket.on("channel:state", function(data) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("network:info", function(data) {
|
socket.on("network:info", function(data) {
|
||||||
vueApp.$store.commit("currentNetworkConfig", data.defaults);
|
const network = findNetwork(data.uuid);
|
||||||
vueApp.$store.commit("activeWindow", "NetworkEdit");
|
|
||||||
vueApp.activeChannel = null;
|
if (!network) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in data) {
|
||||||
|
vueApp.$set(network, key, data[key]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -198,6 +198,10 @@ function findChannel(id) {
|
|||||||
return vueApp.findChannel(id);
|
return vueApp.findChannel(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findNetwork(uuid) {
|
||||||
|
return vueApp.findNetwork(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
function initChannel(channel) {
|
function initChannel(channel) {
|
||||||
channel.pendingMessage = "";
|
channel.pendingMessage = "";
|
||||||
channel.inputHistoryPosition = 0;
|
channel.inputHistoryPosition = 0;
|
||||||
@ -221,6 +225,7 @@ function getActiveWindowComponent() {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
vueApp,
|
vueApp,
|
||||||
findChannel,
|
findChannel,
|
||||||
|
findNetwork,
|
||||||
initChannel,
|
initChannel,
|
||||||
getActiveWindowComponent,
|
getActiveWindowComponent,
|
||||||
};
|
};
|
||||||
|
@ -10,21 +10,19 @@ const Helper = require("../helper");
|
|||||||
module.exports = Network;
|
module.exports = Network;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object} List of keys which should not be sent to the client.
|
* @type {Object} List of keys which should be sent to the client by default.
|
||||||
*/
|
*/
|
||||||
const filteredFromClient = {
|
const fieldsForClient = {
|
||||||
awayMessage: true,
|
uuid: true,
|
||||||
chanCache: true,
|
name: true,
|
||||||
highlightRegex: true,
|
nick: true,
|
||||||
irc: true,
|
serverOptions: true,
|
||||||
password: true,
|
|
||||||
ignoreList: true,
|
|
||||||
keepNick: true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function Network(attr) {
|
function Network(attr) {
|
||||||
_.defaults(this, attr, {
|
_.defaults(this, attr, {
|
||||||
name: "",
|
name: "",
|
||||||
|
nick: "",
|
||||||
host: "",
|
host: "",
|
||||||
port: 6667,
|
port: 6667,
|
||||||
tls: false,
|
tls: false,
|
||||||
@ -294,7 +292,7 @@ Network.prototype.getFilteredClone = function(lastActiveChannel, lastMessage) {
|
|||||||
newNetwork[prop] = this[prop].map((channel) =>
|
newNetwork[prop] = this[prop].map((channel) =>
|
||||||
channel.getFilteredClone(lastActiveChannel, lastMessage)
|
channel.getFilteredClone(lastActiveChannel, lastMessage)
|
||||||
);
|
);
|
||||||
} else if (!filteredFromClient[prop]) {
|
} else if (fieldsForClient[prop]) {
|
||||||
// Some properties that are not useful for the client are skipped
|
// Some properties that are not useful for the client are skipped
|
||||||
newNetwork[prop] = this[prop];
|
newNetwork[prop] = this[prop];
|
||||||
}
|
}
|
||||||
@ -352,6 +350,32 @@ Network.prototype.addChannel = function(newChan) {
|
|||||||
return index;
|
return index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Network.prototype.exportForEdit = function() {
|
||||||
|
let fieldsToReturn;
|
||||||
|
|
||||||
|
if (Helper.config.displayNetwork) {
|
||||||
|
// Return fields required to edit a network
|
||||||
|
fieldsToReturn = [
|
||||||
|
"uuid",
|
||||||
|
"nick",
|
||||||
|
"name",
|
||||||
|
"host",
|
||||||
|
"port",
|
||||||
|
"tls",
|
||||||
|
"rejectUnauthorized",
|
||||||
|
"password",
|
||||||
|
"username",
|
||||||
|
"realname",
|
||||||
|
"commands",
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// Same fields as in getClientConfiguration when network is hidden
|
||||||
|
fieldsToReturn = ["name", "nick", "username", "password", "realname"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return _.pick(this, fieldsToReturn);
|
||||||
|
};
|
||||||
|
|
||||||
Network.prototype.export = function() {
|
Network.prototype.export = function() {
|
||||||
const network = _.pick(this, [
|
const network = _.pick(this, [
|
||||||
"uuid",
|
"uuid",
|
||||||
|
@ -399,7 +399,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit("network:info", getClientConfiguration(network.export()));
|
socket.emit("network:info", network.exportForEdit());
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("network:edit", (data) => {
|
socket.on("network:edit", (data) => {
|
||||||
@ -657,7 +657,7 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClientConfiguration(network) {
|
function getClientConfiguration() {
|
||||||
const config = _.pick(Helper.config, [
|
const config = _.pick(Helper.config, [
|
||||||
"public",
|
"public",
|
||||||
"lockNetwork",
|
"lockNetwork",
|
||||||
@ -670,10 +670,10 @@ function getClientConfiguration(network) {
|
|||||||
config.ldapEnabled = Helper.config.ldap.enable;
|
config.ldapEnabled = Helper.config.ldap.enable;
|
||||||
|
|
||||||
if (config.displayNetwork) {
|
if (config.displayNetwork) {
|
||||||
config.defaults = _.clone(network || Helper.config.defaults);
|
config.defaults = _.clone(Helper.config.defaults);
|
||||||
} else {
|
} else {
|
||||||
// Only send defaults that are visible on the client
|
// Only send defaults that are visible on the client
|
||||||
config.defaults = _.pick(network || Helper.config.defaults, [
|
config.defaults = _.pick(Helper.config.defaults, [
|
||||||
"name",
|
"name",
|
||||||
"nick",
|
"nick",
|
||||||
"username",
|
"username",
|
||||||
@ -683,13 +683,11 @@ function getClientConfiguration(network) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!network) {
|
config.version = pkg.version;
|
||||||
config.version = pkg.version;
|
config.gitCommit = Helper.getGitCommit();
|
||||||
config.gitCommit = Helper.getGitCommit();
|
config.themes = themes.getAll();
|
||||||
config.themes = themes.getAll();
|
config.defaultTheme = Helper.config.theme;
|
||||||
config.defaultTheme = Helper.config.theme;
|
config.defaults.nick = Helper.getDefaultNick();
|
||||||
config.defaults.nick = Helper.getDefaultNick();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Uploader) {
|
if (Uploader) {
|
||||||
config.fileUploadMaxFileSize = Uploader.getMaxFileSize();
|
config.fileUploadMaxFileSize = Uploader.getMaxFileSize();
|
||||||
|
@ -227,21 +227,7 @@ describe("Network", function() {
|
|||||||
|
|
||||||
expect(clone)
|
expect(clone)
|
||||||
.to.be.an("object")
|
.to.be.an("object")
|
||||||
.that.has.all.keys(
|
.that.has.all.keys("channels", "status", "nick", "name", "serverOptions", "uuid");
|
||||||
"channels",
|
|
||||||
"commands",
|
|
||||||
"host",
|
|
||||||
"name",
|
|
||||||
"port",
|
|
||||||
"realname",
|
|
||||||
"serverOptions",
|
|
||||||
"status",
|
|
||||||
"tls",
|
|
||||||
"userDisconnected",
|
|
||||||
"rejectUnauthorized",
|
|
||||||
"uuid",
|
|
||||||
"username"
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(clone.status)
|
expect(clone.status)
|
||||||
.to.be.an("object")
|
.to.be.an("object")
|
||||||
|
@ -91,10 +91,12 @@ describe("Server", function() {
|
|||||||
client.on("network", (data) => {
|
client.on("network", (data) => {
|
||||||
expect(data.networks).to.be.an("array");
|
expect(data.networks).to.be.an("array");
|
||||||
expect(data.networks).to.have.lengthOf(1);
|
expect(data.networks).to.have.lengthOf(1);
|
||||||
expect(data.networks[0].realname).to.equal("The Lounge Test");
|
expect(data.networks[0].nick).to.equal("test-user");
|
||||||
|
expect(data.networks[0].name).to.equal("Test Network");
|
||||||
expect(data.networks[0].channels).to.have.lengthOf(3);
|
expect(data.networks[0].channels).to.have.lengthOf(3);
|
||||||
expect(data.networks[0].channels[0].name).to.equal("Test Network");
|
expect(data.networks[0].channels[0].name).to.equal("Test Network");
|
||||||
expect(data.networks[0].channels[1].name).to.equal("#thelounge");
|
expect(data.networks[0].channels[1].name).to.equal("#thelounge");
|
||||||
|
expect(data.networks[0].channels[2].name).to.equal("#spam");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user