Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
8c4de202
Commit
8c4de202
authored
May 09, 2019
by
Grandschtroumpf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create abstract panel
parent
a30d4dd7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
112 additions
and
0 deletions
+112
-0
panel.js
src/app/components/panel.js
+112
-0
No files found.
src/app/components/panel.js
0 → 100644
View file @
8c4de202
import
{
EventEmitter
}
from
'events'
const
registry
=
require
(
'../../global/registry'
)
const
csjs
=
require
(
'csjs-inject'
)
const
yo
=
require
(
'yo-yo'
)
const
css
=
csjs
`
.plugins {
height: 100%;
}
.plugItIn {
display : none;
height : 100%;
}
.plugItIn > div {
overflow-y : auto;
height : 100%;
width : 100%;
}
.plugItIn.active {
display : block;
}
.pluginsContainer {
height: 100%;
overflow-y: hidden;
}
`
// Events are : 'toggle' | 'showing'
/** Abstract class used for hosting the view of a plugin */
export
class
AbstractPanel
{
constructor
(
panelName
,
appStore
,
opts
)
{
this
.
events
=
new
EventEmitter
()
this
.
contents
=
{}
this
.
active
=
undefined
// View where the plugin HTMLElement leaves
this
.
view
=
yo
`<div id="plugins" class="
${
css
.
plugins
}
"></div>`
appStore
.
event
.
on
(
'activate'
,
(
name
)
=>
{
const
api
=
appStore
.
getOne
(
name
)
const
profile
=
api
.
profile
if
(
profile
.
location
!==
panelName
)
return
if
(
!
profile
.
location
&&
!
opts
.
default
)
return
if
(
profile
.
icon
&&
api
.
render
&&
typeof
api
.
render
===
'function'
)
{
this
.
add
(
name
,
api
.
render
())
}
})
appStore
.
event
.
on
(
'deactivate'
,
(
name
)
=>
{
if
(
this
.
contents
[
name
])
this
.
remove
(
name
)
})
const
verticalIcon
=
registry
.
get
(
'verticalicon'
).
api
// Toggle content
verticalIcon
.
events
.
on
(
'toggleContent'
,
(
name
)
=>
{
if
(
!
this
.
contents
[
name
])
return
if
(
this
.
active
===
name
)
{
this
.
events
.
emit
(
'toggle'
,
name
)
}
this
.
showContent
(
name
)
this
.
events
.
emit
(
'showing'
,
name
)
})
// Force opening
verticalIcon
.
events
.
on
(
'showContent'
,
(
name
)
=>
{
if
(
!
this
.
contents
[
name
])
return
this
.
showContent
(
name
)
this
.
events
.
emit
(
'showing'
,
name
)
})
}
/**
* Add the plugin to the panel
* @param {String} name the name of the plugin
* @param {HTMLElement} content the HTMLContent of the plugin
*/
add
(
name
,
content
)
{
if
(
!!
this
.
contents
[
name
])
throw
new
Error
(
`Plugin
${
name
}
already rendered`
)
content
.
style
.
height
=
'100%'
content
.
style
.
width
=
'100%'
content
.
style
.
border
=
'0'
this
.
contents
[
name
]
=
yo
`<div class="
${
css
.
plugItIn
}
" >
${
content
}
</div>`
this
.
view
.
appendChild
(
this
.
contents
[
name
])
}
/**
* Remove a plugin from the panel
* @param {String} name The name of the plugin to remove
*/
remove
(
name
)
{
const
el
=
this
.
contents
[
name
]
delete
this
.
contents
[
name
]
if
(
el
)
el
.
parentElement
.
removeChild
(
el
)
}
/**
* Display the content of this specific plugin
* @param {String} name The name of the plugin to display the content
*/
showContent
(
name
)
{
if
(
!
this
.
contents
[
name
])
throw
new
Error
(
`Plugin
${
name
}
is not yet activated`
)
// hiding the current view and display the `moduleName`
if
(
this
.
active
)
{
this
.
contents
[
this
.
active
].
style
.
display
=
'none'
}
this
.
contents
[
name
].
style
.
display
=
'block'
this
.
active
=
name
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment