-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed layout when multiple servers are reporting metrics for one project to a tabbed layout. This allows for easier navigation between the different servers. By default, the tabs will rotate every 10 seconds. This can be changed by setting `?interval=4` in the URL. This will change the interval to 4 seconds between tab changes.
- Loading branch information
Showing
10 changed files
with
154 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/javascript/mission_control/servers/controllers/tabs_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["link", "content"] | ||
static values = { refreshInterval: 10000 } | ||
index = 0; | ||
|
||
connect() { | ||
this.showInitialTab(); | ||
this.loopThroughTabs(); | ||
console.log(this.refreshIntervalValue); | ||
} | ||
|
||
showInitialTab() { | ||
const initialTab = this.linkTargets[0]; | ||
if (initialTab) { | ||
this.showTab(initialTab.dataset.target); | ||
} | ||
} | ||
|
||
loopThroughTabs() { | ||
this.showTab(this.linkTargets[this.index].dataset.target); | ||
|
||
this.interval = setInterval(() => { | ||
this.index = (this.index + 1) % this.linkTargets.length; | ||
this.showTab(this.linkTargets[this.index].dataset.target); | ||
}, this.refreshIntervalValue); | ||
} | ||
|
||
showTab(targetId) { | ||
this.resetTabs(); | ||
const activeTab = this.linkTargets.find(link => link.dataset.target === targetId); | ||
const activeContent = this.contentTargets.find(content => content.dataset.target === targetId); | ||
|
||
if (activeTab && activeContent) { | ||
activeTab.classList.add("text-xl", "text-gray-100", 'bg-indigo-500', 'transition', 'duration-300', 'ease-in-out'); | ||
|
||
activeContent.classList.remove('absolute', 'top-0', 'left-full', 'w-0', 'h-0'); | ||
activeContent.classList.add('relative'); | ||
} | ||
} | ||
|
||
resetTabs() { | ||
this.linkTargets.forEach(link => { | ||
link.classList.add('transition', 'duration-300', 'ease-in-out'); | ||
link.classList.remove("text-xl", "text-gray-100", 'bg-indigo-500'); | ||
}); | ||
this.contentTargets.forEach(content => { | ||
content.classList.add('absolute', 'top-0', 'left-full', 'w-0', 'h-0'); | ||
content.classList.remove('relative'); | ||
}); | ||
} | ||
|
||
|
||
changeTab(event) { | ||
event.preventDefault(); | ||
const targetId = event.target.dataset.target; | ||
const newIndex = this.linkTargets.findIndex(link => link.dataset.target === targetId); | ||
if (newIndex >= 0) { | ||
this.index = newIndex; | ||
} | ||
this.showTab(targetId); | ||
|
||
clearInterval(this.interval); | ||
this.loopThroughTabs(); | ||
} | ||
|
||
disconnect() { | ||
clearInterval(this.interval); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module MissionControl | ||
module Servers | ||
VERSION = "0.1.6" | ||
VERSION = "0.2.0" | ||
end | ||
end |