Skip to content

Commit

Permalink
sidebar: Update domains on tab drag.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishk98 committed Aug 14, 2019
1 parent f9857c6 commit 1c1fa47
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class ServerManagerView {
$fullscreenEscapeKey: string;
loading: AnyObject;
activeTabIndex: number;
servers: ServerOrFunctionalTab[];
tabs: ServerOrFunctionalTab[];
functionalTabs: AnyObject;
tabIndex: number;
Expand Down Expand Up @@ -134,6 +135,7 @@ class ServerManagerView {

this.loading = {};
this.activeTabIndex = -1;
this.servers = [];
this.tabs = [];
this.presetOrgs = [];
this.functionalTabs = {};
Expand Down Expand Up @@ -241,10 +243,32 @@ class ServerManagerView {
}
}

onEnd(): void {
const newServers: any[] | ServerOrFunctionalTab[] = [];
const tabMap: any = {};
const tabElements = document.querySelectorAll('#tabs-container .tab');
tabElements.forEach((el, index) => {
const oldIndex = Number(el.getAttribute('data-tab-id')) % this.servers.length;
tabMap[index] = oldIndex;
newServers.push(this.servers[index]);
el.setAttribute('data-tab-id', index.toString());
});

for (let server = 0; server < newServers.length; ++server) {
DomainUtil.updateDomain(server, newServers[tabMap[server]]);
}

this.reloadView();
}

initSidebar(): void {
const showSidebar = ConfigUtil.getConfigItem('showSidebar', true);
this.toggleSidebar(showSidebar);
this.$sortable = sortable.create(this.$drag, {});
// Allow dragging of server tabs and update the data-tab-id
this.$sortable = sortable.create(this.$drag, {
dataIdAttr: 'data-sortable-id',
onEnd: this.onEnd.bind(this)
});
}

async queueDomain(domain: any): Promise<boolean> {
Expand Down Expand Up @@ -314,6 +338,7 @@ class ServerManagerView {

initTabs(): void {
const servers = DomainUtil.getDomains();
this.servers = servers;
if (servers.length > 0) {
for (let i = 0; i < servers.length; i++) {
this.initServer(servers[i], i);
Expand Down

0 comments on commit 1c1fa47

Please sign in to comment.