-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #377 from shamoon/unified-infowidget-settings
Feature: Unified info widget settings
- Loading branch information
Showing
7 changed files
with
99 additions
and
41 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
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 |
---|---|---|
|
@@ -165,4 +165,4 @@ export default async function getServiceWidget(group, service) { | |
} | ||
|
||
return false; | ||
} | ||
} |
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,73 @@ | ||
import { promises as fs } from "fs"; | ||
import path from "path"; | ||
|
||
import yaml from "js-yaml"; | ||
|
||
import checkAndCopyConfig from "utils/config/config"; | ||
|
||
export async function widgetsFromConfig() { | ||
checkAndCopyConfig("widgets.yaml"); | ||
|
||
const widgetsYaml = path.join(process.cwd(), "config", "widgets.yaml"); | ||
const fileContents = await fs.readFile(widgetsYaml, "utf8"); | ||
const widgets = yaml.load(fileContents); | ||
|
||
if (!widgets) return []; | ||
|
||
// map easy to write YAML objects into easy to consume JS arrays | ||
const widgetsArray = widgets.map((group, index) => ({ | ||
type: Object.keys(group)[0], | ||
options: { | ||
index, | ||
...group[Object.keys(group)[0]] | ||
}, | ||
})); | ||
return widgetsArray; | ||
} | ||
|
||
export async function cleanWidgetGroups(widgets) { | ||
return widgets.map((widget, index) => { | ||
const sanitizedOptions = widget.options; | ||
const optionKeys = Object.keys(sanitizedOptions); | ||
["url", "username", "password", "key"].forEach((pO) => { | ||
if (optionKeys.includes(pO)) { | ||
delete sanitizedOptions[pO]; | ||
} | ||
}); | ||
|
||
return { | ||
type: widget.type, | ||
options: { | ||
index, | ||
...sanitizedOptions | ||
}, | ||
} | ||
}); | ||
} | ||
|
||
export async function getPrivateWidgetOptions(type, widgetIndex) { | ||
const widgets = await widgetsFromConfig(); | ||
|
||
const privateOptions = widgets.map((widget) => { | ||
const { | ||
index, | ||
url, | ||
username, | ||
password, | ||
key | ||
} = widget.options; | ||
|
||
return { | ||
type: widget.type, | ||
options: { | ||
index, | ||
url, | ||
username, | ||
password, | ||
key | ||
}, | ||
} | ||
}); | ||
|
||
return (type !== undefined && widgetIndex !== undefined) ? privateOptions.find(o => o.type === type && o.options.index === parseInt(widgetIndex, 10))?.options : privateOptions; | ||
} |
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