Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. var yo = require('yo-yo')
  2. var csjs = require('csjs-inject')
  3.  
  4. const styleguide = require('../ui/styles-guide/theme-chooser')
  5. const styles = styleguide.chooser()
  6.  
  7. const EventEmitter = require('events')
  8.  
  9. class PluginManagerComponent {
  10.  
  11. constructor () {
  12. this.event = new EventEmitter()
  13. this.views = {
  14. root: null,
  15. items: {}
  16. }
  17. }
  18.  
  19. profile () {
  20. return {
  21. name: 'plugin manager',
  22. methods: [],
  23. events: [],
  24. icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNzU1IDQ1M3EzNyAzOCAzNyA5MC41dC0zNyA5MC41bC00MDEgNDAwIDE1MCAxNTAtMTYwIDE2MHEtMTYzIDE2My0zODkuNSAxODYuNXQtNDExLjUtMTAwLjVsLTM2MiAzNjJoLTE4MXYtMTgxbDM2Mi0zNjJxLTEyNC0xODUtMTAwLjUtNDExLjV0MTg2LjUtMzg5LjVsMTYwLTE2MCAxNTAgMTUwIDQwMC00MDFxMzgtMzcgOTEtMzd0OTAgMzcgMzcgOTAuNS0zNyA5MC41bC00MDAgNDAxIDIzNCAyMzQgNDAxLTQwMHEzOC0zNyA5MS0zN3Q5MCAzN3oiLz48L3N2Zz4=',
  25. description: 'start/stop services, modules and plugins'
  26. }
  27. }
  28.  
  29. setApp (appManager) {
  30. this.appManager = appManager
  31. }
  32.  
  33. setStore (store) {
  34. this.store = store
  35. this.store.event.on('activate', (name) => { this.reRender() })
  36. this.store.event.on('deactivate', (name) => { this.reRender() })
  37. this.store.event.on('add', (name) => { this.reRender() })
  38. this.store.event.on('remove', (name) => { this.reRender() })
  39. }
  40.  
  41. render () {
  42. let activeMods = yo`
  43. <div id='activePlugs' class=${css.activePlugins}>
  44. <h3>Active Modules</h3>
  45. </div>
  46. `
  47. let inactiveMods = yo`
  48. <div class=${css.inactivePlugins}>
  49. <h3>Inactive Modules</h3>
  50. </div>
  51. `
  52. let searchbox = yo`
  53. <input id='filter_plugins' placeholder='Search'>
  54. `
  55. var rootView = yo`
  56. <div id='pluginManager' class=${css.plugins_settings} >
  57. <h2>Plugin Manager</h2>
  58. ${searchbox}
  59. ${activeMods}
  60. ${inactiveMods}
  61. </div>
  62. `
  63.  
  64. searchbox.addEventListener('keyup', (event) => { this.filterPlugins(event) })
  65.  
  66. var modulesActive = this.store.getActives()
  67. modulesActive.sort(function (a, b) {
  68. var textA = a.profile.name.toUpperCase()
  69. var textB = b.profile.name.toUpperCase()
  70. return (textA < textB) ? -1 : (textA > textB) ? 1 : 0
  71. })
  72.  
  73. modulesActive.forEach((mod) => {
  74. activeMods.appendChild(this.renderItem(mod.profile.name))
  75. })
  76.  
  77. var modulesAll = this.store.getAll()
  78. modulesAll.sort()
  79. modulesAll.forEach((mod) => {
  80. if (!modulesActive.includes(mod)) {
  81. inactiveMods.appendChild(this.renderItem(mod.profile.name))
  82. }
  83. })
  84. if (!this.views.root) {
  85. this.views.root = rootView
  86. }
  87. return rootView
  88. }
  89.  
  90. renderItem (item) {
  91. let ctrBtns
  92.  
  93. const mod = this.store.getOne(item)
  94. if (!mod) return
  95. let action = () => {
  96. if (this.store.isActive(item)) {
  97. this.appManager.deactivateOne(item)
  98. } else {
  99. this.appManager.activateOne(item)
  100. }
  101. }
  102.  
  103. ctrBtns = yo`<div id='${item}Activation'>
  104. <button onclick=${(event) => { action(event) }} >${this.store.isActive(item) ? 'deactivate' : 'activate'}</button>
  105. </div>`
  106.  
  107. return yo`
  108. <div id=${item} class=${css.plugin} >
  109. <h3>${mod.profile.name}</h3>
  110. ${mod.profile.description}
  111. ${ctrBtns}
  112. </div>
  113. `
  114. }
  115.  
  116. reRender () {
  117. if (this.views.root) {
  118. yo.update(this.views.root, this.render())
  119. }
  120. }
  121.  
  122. filterPlugins (event) {
  123. let filterOn = event.target.value.toUpperCase()
  124. var nodes = this.views.root.querySelectorAll(`.${css.plugin}`)
  125. nodes.forEach((node) => {
  126. let h = node.querySelector('h3')
  127. let txtValue = h.textContent || h.innerText
  128. if (txtValue.toLowerCase().indexOf(filterOn.toLowerCase()) !== -1) {
  129. node.style.display = 'block'
  130. } else {
  131. node.style.display = 'none'
  132. }
  133. })
  134. }
  135. }
  136.  
  137. module.exports = PluginManagerComponent
  138.  
  139. const css = csjs`
  140. .plugins_settings h2 {
  141. font-size: 1em;
  142. border-bottom: 1px ${styles.appProperties.solidBorderBox_BorderColor} solid;
  143. padding: 10px 20px;
  144. font-size: 10px;
  145. padding: 10px 20px;
  146. text-transform: uppercase;
  147. font-weight: normal;
  148. background-color: white;
  149. margin-bottom: 0;
  150. }
  151. .plugin {
  152. ${styles.rightPanel.compileTab.box_CompileContainer};
  153. margin: 0;
  154. margin-bottom: 2%;
  155. border-bottom: 1px ${styles.appProperties.solidBorderBox_BorderColor} solid;
  156. padding: 0px 20px 10px;
  157. }
  158. .plugin h3 {
  159. margin-bottom: 5px;
  160. font-size: 12px;
  161. margin-top: 9px;
  162. }
  163.  
  164. .plugin button {
  165. ${styles.rightPanel.settingsTab.button_LoadPlugin};
  166. cursor: pointer;
  167. font-size: 10px;
  168. }
  169. .activePlugins {
  170. }
  171.  
  172. .inactivePlugins {
  173. }
  174. .plugins_settings input {
  175. margin: 10px;
  176. }
  177. `
Add Comment
Please, Sign In to add comment