Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
e3708bd5
Commit
e3708bd5
authored
Jan 30, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor headlines list to render everything with one view
parent
c55a2171
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
81 deletions
+45
-81
spec/headline.js
spec/headline.js
+2
-7
src/converse-headlines-view.js
src/converse-headlines-view.js
+32
-68
src/templates/headline_panel.html
src/templates/headline_panel.html
+0
-6
src/templates/headline_panel.js
src/templates/headline_panel.js
+11
-0
No files found.
spec/headline.js
View file @
e3708bd5
...
...
@@ -44,7 +44,7 @@
}));
it
(
"
will open and display headline messages
"
,
mock
.
initConverse
(
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
[
'
rosterGroupsFetched
'
],
{},
async
function
(
done
,
_converse
)
{
/* <message from='notify.example.com'
* to='romeo@im.example.com'
...
...
@@ -72,15 +72,10 @@
.
c
(
'
url
'
).
t
(
'
imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
expect
(
_
.
includes
(
_converse
.
chatboxviews
.
keys
(),
'
notify.example.com
'
)
).
toBeTruthy
();
await
u
.
waitUntil
(()
=>
_converse
.
chatboxviews
.
keys
().
includes
(
'
notify.example.com
'
));
expect
(
u
.
isHeadlineMessage
.
called
).
toBeTruthy
();
expect
(
u
.
isHeadlineMessage
.
returned
(
true
)).
toBeTruthy
();
u
.
isHeadlineMessage
.
restore
();
// unwraps
// Headlines boxes don't show an avatar
const
view
=
_converse
.
chatboxviews
.
get
(
'
notify.example.com
'
);
expect
(
view
.
model
.
get
(
'
show_avatar
'
)).
toBeFalsy
();
expect
(
view
.
el
.
querySelector
(
'
img.avatar
'
)).
toBe
(
null
);
...
...
src/converse-headlines-view.js
View file @
e3708bd5
...
...
@@ -8,8 +8,7 @@ import { View } from 'skeletor.js/src/view.js';
import
{
__
}
from
'
@converse/headless/i18n
'
;
import
converse
from
"
@converse/headless/converse-core
"
;
import
tpl_chatbox
from
"
templates/chatbox.html
"
;
import
tpl_headline_list
from
"
templates/headline_list.js
"
;
import
tpl_headline_panel
from
"
templates/headline_panel.html
"
;
import
tpl_headline_panel
from
"
templates/headline_panel.js
"
;
const
u
=
converse
.
env
.
utils
;
...
...
@@ -37,7 +36,7 @@ converse.plugins.add('converse-headlines-view', {
ControlBoxView
:
{
renderControlBoxPane
()
{
this
.
__super__
.
renderControlBoxPane
.
apply
(
this
,
arguments
);
this
.
renderHeadlinePanel
();
this
.
renderHeadline
s
Panel
();
},
},
},
...
...
@@ -50,15 +49,12 @@ converse.plugins.add('converse-headlines-view', {
const
{
_converse
}
=
this
;
const
viewWithHeadlinePanel
=
{
renderHeadlinePanel
()
{
const
viewWithHeadline
s
Panel
=
{
renderHeadline
s
Panel
()
{
if
(
this
.
headlinepanel
&&
u
.
isInDOM
(
this
.
headlinepanel
.
el
))
{
return
this
.
headlinepanel
;
}
this
.
headlinepanel
=
new
_converse
.
HeadlinePanel
();
this
.
el
.
querySelector
(
'
.controlbox-pane
'
).
insertAdjacentElement
(
'
beforeEnd
'
,
this
.
headlinepanel
.
render
().
el
);
this
.
headlinepanel
=
new
_converse
.
HeadlinesPanel
({
'
model
'
:
_converse
.
chatboxes
});
/**
* Triggered once the section of the { @link _converse.ControlBoxView }
* which shows announcements has been rendered.
...
...
@@ -71,17 +67,17 @@ converse.plugins.add('converse-headlines-view', {
}
if
(
_converse
.
ControlBoxView
)
{
Object
.
assign
(
_converse
.
ControlBoxView
.
prototype
,
viewWithHeadlinePanel
);
Object
.
assign
(
_converse
.
ControlBoxView
.
prototype
,
viewWithHeadline
s
Panel
);
}
/**
* View which renders headlines section of the control box.
* @class
* @namespace _converse.HeadlinePanel
* @namespace _converse.Headline
s
Panel
* @memberOf _converse
*/
_converse
.
HeadlinePanel
=
View
.
extend
({
_converse
.
Headline
s
Panel
=
View
.
extend
({
tagName
:
'
div
'
,
className
:
'
controlbox-section
'
,
id
:
'
headline
'
,
...
...
@@ -90,6 +86,26 @@ converse.plugins.add('converse-headlines-view', {
'
click .open-headline
'
:
'
openHeadline
'
},
initialize
()
{
this
.
listenTo
(
this
.
model
,
'
add
'
,
this
.
renderIfHeadline
)
this
.
listenTo
(
this
.
model
,
'
remove
'
,
this
.
renderIfHeadline
)
this
.
listenTo
(
this
.
model
,
'
destroy
'
,
this
.
renderIfHeadline
)
this
.
render
();
this
.
insertIntoDOM
();
},
toHTML
()
{
return
tpl_headline_panel
({
'
heading_headline
'
:
__
(
'
Announcements
'
),
'
headlineboxes
'
:
this
.
model
.
filter
(
m
=>
m
.
get
(
'
type
'
)
===
_converse
.
HEADLINES_TYPE
),
'
open_title
'
:
__
(
'
Click to open this server message
'
),
});
},
renderIfHeadline
(
model
)
{
return
(
model
&&
model
.
get
(
'
type
'
)
===
_converse
.
HEADLINES_TYPE
)
&&
this
.
render
();
},
openHeadline
(
ev
)
{
ev
.
preventDefault
();
const
jid
=
ev
.
target
.
getAttribute
(
'
data-headline-jid
'
);
...
...
@@ -97,9 +113,9 @@ converse.plugins.add('converse-headlines-view', {
chat
.
maybeShow
(
true
);
},
render
()
{
this
.
el
.
innerHTML
=
tpl_headline_panel
({
'
heading_headline
'
:
__
(
'
Announcements
'
)}
);
return
this
;
insertIntoDOM
()
{
const
view
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
);
view
&&
view
.
el
.
querySelector
(
'
.controlbox-pane
'
).
insertAdjacentElement
(
'
beforeEnd
'
,
this
.
el
)
;
}
});
...
...
@@ -155,49 +171,7 @@ converse.plugins.add('converse-headlines-view', {
});
_converse
.
HeadlinesListView
=
View
.
extend
({
tagName
:
'
span
'
,
initialize
()
{
this
.
listenTo
(
this
.
model
,
'
add
'
,
this
.
renderIfHeadline
)
this
.
listenTo
(
this
.
model
,
'
remove
'
,
this
.
renderIfHeadline
)
this
.
listenTo
(
this
.
model
,
'
destroy
'
,
this
.
renderIfHeadline
)
this
.
render
();
this
.
insertIntoControlBox
();
},
toHTML
()
{
return
tpl_headline_list
({
'
headlineboxes
'
:
this
.
model
.
filter
(
m
=>
m
.
get
(
'
type
'
)
===
_converse
.
HEADLINES_TYPE
),
'
open_title
'
:
__
(
'
Click to open this server message
'
),
});
},
renderIfHeadline
(
model
)
{
return
(
model
&&
model
.
get
(
'
type
'
)
===
_converse
.
HEADLINES_TYPE
)
&&
this
.
render
();
},
insertIntoControlBox
()
{
const
controlboxview
=
_converse
.
chatboxviews
.
get
(
'
controlbox
'
);
if
(
controlboxview
!==
undefined
&&
!
u
.
rootContains
(
_converse
.
root
,
this
.
el
))
{
const
el
=
controlboxview
.
el
.
querySelector
(
'
.list-container--headline
'
);
el
&&
el
.
parentNode
.
replaceChild
(
this
.
el
,
el
);
}
}
});
const
initHeadlinesListView
=
function
()
{
_converse
.
headlines_list
=
new
_converse
.
HeadlinesListView
({
'
model
'
:
_converse
.
chatboxes
});
/**
* Triggered once the _converse.HeadlinesListView has been created and initialized.
* @event _converse#roomsListInitialized
* @example _converse.api.listen.on('roomsListInitialized', status => { ... });
*/
_converse
.
api
.
trigger
(
'
headlinesListInitialized
'
);
};
/************************ BEGIN Event Handlers ************************/
_converse
.
api
.
listen
.
on
(
'
chatBoxViewsInitialized
'
,
()
=>
{
const
views
=
_converse
.
chatboxviews
;
_converse
.
chatboxes
.
on
(
'
add
'
,
item
=>
{
...
...
@@ -206,15 +180,5 @@ converse.plugins.add('converse-headlines-view', {
}
});
});
_converse
.
api
.
listen
.
on
(
'
connected
'
,
async
()
=>
{
await
Promise
.
all
([
_converse
.
api
.
waitUntil
(
'
chatBoxesFetched
'
),
_converse
.
api
.
waitUntil
(
'
headlinesPanelRendered
'
)
]);
initHeadlinesListView
();
});
_converse
.
api
.
listen
.
on
(
'
reconnected
'
,
initHeadlinesListView
);
}
});
src/templates/headline_panel.html
deleted
100644 → 0
View file @
c55a2171
<!-- <div id="headline"> -->
<div
class=
"d-flex controlbox-padded"
>
<span
class=
"w-100 controlbox-heading controlbox-heading--headline"
>
{{{o.heading_headline}}}
</span>
</div>
<div
class=
"list-container list-container--headline hidden"
></div>
<!-- </div> -->
src/templates/headline_panel.js
0 → 100644
View file @
e3708bd5
import
{
html
}
from
"
lit-html
"
;
import
{
__
}
from
'
@converse/headless/i18n
'
;
import
tpl_headline_list
from
"
templates/headline_list.js
"
;
export
default
(
o
)
=>
html
`
<div class="d-flex controlbox-padded
${
o
.
headlineboxes
.
length
?
''
:
'
hidden
'
}
">
<span class="w-100 controlbox-heading controlbox-heading--headline">
${
o
.
heading_headline
}
</span>
</div>
${
tpl_headline_list
(
o
)
}
`
;
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