From eaba9b716519dd2d1a2df34fd644be4fcb07eb50 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Tue, 19 Feb 2019 15:12:48 +0100 Subject: [PATCH] Plugin Manager with checkboxes and reactive filter --- .../components/plugin-manager-component.js | 214 ++++++------------ src/app/ui/styles-guide/theme-chooser.js | 2 +- 2 files changed, 70 insertions(+), 146 deletions(-) diff --git a/src/app/components/plugin-manager-component.js b/src/app/components/plugin-manager-component.js index fcadba7aaa..6c659691ff 100644 --- a/src/app/components/plugin-manager-component.js +++ b/src/app/components/plugin-manager-component.js @@ -1,11 +1,14 @@ -var yo = require('yo-yo') -var csjs = require('csjs-inject') - -// const styleguide = require('../ui/styles-guide/theme-chooser') -// const styles = styleguide.chooser() +const yo = require('yo-yo') +const csjs = require('csjs-inject') const EventEmitter = require('events') +const css = csjs` + .pluginManager { + padding: 10px; + } +` + class PluginManagerComponent { constructor () { @@ -14,6 +17,7 @@ class PluginManagerComponent { root: null, items: {} } + this.filter = '' } profile () { @@ -40,103 +44,72 @@ class PluginManagerComponent { this.store.event.on('remove', (entity) => { this.reRender() }) } - render () { - let activeMods = yo` -
-

Active Modules

-
- ` - let inactiveMods = yo` -
-

Inactive Modules

-
- ` - let searchbox = yo` - - ` - var rootView = yo` -
-

Plugin Manager

- ${searchbox} - ${activeMods} - ${inactiveMods} -
- ` - - searchbox.addEventListener('keyup', (event) => { this.filterPlugins(event.target) }) - - var modulesActiveNotReq = this.store.getActives().filter(({profile}) => !profile.required) - this.sortObject(modulesActiveNotReq) - - if (modulesActiveNotReq.length > 0) { - modulesActiveNotReq.forEach((mod) => { - activeMods.appendChild(this.renderItem(mod.profile.name)) - }) - activeMods.style.display = 'block' - } else { - activeMods.style.display = 'none' - } - - var modulesAllNotReq = this.store.getAll().filter(({profile}) => !profile.required) - this.sortObject(modulesAllNotReq) - modulesAllNotReq.forEach((mod) => { - if (!modulesActiveNotReq.includes(mod)) { - inactiveMods.appendChild(this.renderItem(mod.profile.name)) - } - }) - if (!this.views.root) { - this.views.root = rootView - } - return rootView - } - - searchBox () { - if (this.views.root) { - return this.views.root.querySelector('#filter_plugins') - } - return null - } - - sortObject (obj) { - obj.sort((a, b) => { - var textA = a.profile.name.toUpperCase() - var textB = b.profile.name.toUpperCase() - return (textA < textB) ? -1 : (textA > textB) ? 1 : 0 - }) - } - renderItem (item) { - let ctrBtns - const mod = this.store.getOne(item) if (!mod) return - let displayName = (mod.profile.displayName) ? mod.profile.displayName : mod.profile.name - let action = () => { - if (this.store.isActive(item)) { - this.appManager.deactivateOne(item) - } else { - this.appManager.activateOne(item) - } - } - - ctrBtns = yo`
- -
` + const isActive = this.store.actives.includes(mod.profile.name) + const displayName = (mod.profile.displayName) ? mod.profile.displayName : mod.profile.name - //
- // - // - //
+ const input = isActive + ? yo`` + : yo`` return yo` -
-

${displayName}

- ${mod.profile.description} - ${ctrBtns} -
+
+
+ ${input} +
${displayName}
+
+

${mod.profile.description}

+
` } + render () { + // Filtering helpers + const isFiltered = ({profile}) => profile.name.toLowerCase().includes(this.filter) + const isNotRequired = ({profile}) => !profile.required + const sortByName = (a, b) => { + const nameA = a.profile.name.toUpperCase() + const nameB = b.profile.name.toUpperCase() + return (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0 + } + + // Filter all active and inactive modules that are not required + const { actives, inactives } = this.store.getAll() + .filter(isFiltered) + .filter(isNotRequired) + .sort(sortByName) + .reduce(({actives, inactives}, {profile}) => { + return this.store.actives.includes(profile.name) + ? { actives: [...actives, profile.name], inactives } + : { inactives: [...inactives, profile.name], actives } + }, { actives: [], inactives: [] }) + + const activeTile = actives.length !== 0 + ? yo`

Active Modules

` + : '' + const inactiveTile = inactives.length !== 0 + ? yo`

Inactive Modules

` + : '' + + const rootView = yo` +
+

Plugin Manager

+
+
+ +
+ ${activeTile} + ${actives.map(name => this.renderItem(name))} + ${inactiveTile} + ${inactives.map(name => this.renderItem(name))} +
+ ` + if (!this.views.root) this.views.root = rootView + return rootView + } + reRender () { if (this.views.root) { yo.update(this.views.root, this.render()) @@ -144,59 +117,10 @@ class PluginManagerComponent { } } - filterPlugins (target) { - if (!target) return - let filterOn = target.value.toUpperCase() - var nodes = this.views.root.querySelectorAll(`.${css.plugin}`) - nodes.forEach((node) => { - let h = node.querySelector('h3') - let txtValue = h.textContent || h.innerText - if (txtValue.toLowerCase().indexOf(filterOn.toLowerCase()) !== -1) { - node.style.display = 'block' - } else { - node.style.display = 'none' - } - }) + filterPlugins ({ target }) { + this.filter = target.value.toLowerCase() + this.reRender() } } module.exports = PluginManagerComponent - -const css = csjs` - .plugins_settings h2 { - font-size: 1em; - border-bottom: 1px red solid; - padding: 10px 20px; - font-size: 10px; - padding: 10px 20px; - text-transform: uppercase; - font-weight: normal; - background-color: white; - margin-bottom: 0; - } - .plugin { - margin: 0; - margin-bottom: 2%; - padding: 0px 20px 10px; - } - .plugin h3 { - margin-bottom: 5px; - font-size: 12px; - margin-top: 9px; - } - - .plugin button { - font-size: 10px; - } - .activePlugins { - } - - .inactivePlugins { - } - .plugins_settings input { - margin: 10px; - } - .hideIt { - display: none; - } -` diff --git a/src/app/ui/styles-guide/theme-chooser.js b/src/app/ui/styles-guide/theme-chooser.js index 25ce70405f..9ede538992 100644 --- a/src/app/ui/styles-guide/theme-chooser.js +++ b/src/app/ui/styles-guide/theme-chooser.js @@ -36,7 +36,7 @@ module.exports = { themeStorage.set('theme', theme) if (themes[theme]) { document.getElementById('theme-link').setAttribute('href', themes[theme]) - } + } // if (theme === 'dark') { // return styleGuideDark() // } else if (theme === 'light') {