Skip to content

Commit a119510

Browse files
author
Mario David
committed
added information to README; updated messages UI
1 parent 629a8d6 commit a119510

File tree

10 files changed

+170
-5
lines changed

10 files changed

+170
-5
lines changed

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,65 @@ Add custom application component to your project:
4444

4545
## Using the inbox as a user
4646

47-
A user
48-
![Screenshot health check overview](https://github.com/mariodavid/cuba-component-health-check/blob/master/img/health-check-overview.png)
47+
As a logged in user you'll see a menu entry called "Messages" which will show the incoming messages that are either
48+
from another user of the system or from the system itself, which has send a message
49+
to the system in order to notify the user about something changed in the system.
50+
51+
![Screenshot overview of incoming messages](https://github.com/mariodavid/cuba-component-user-inbox/blob/master/img/messages-overview.png)
52+
53+
54+
55+
## Sending messages
56+
57+
To send messages to a particular user, there are two options available:
58+
59+
* manually sending message to a user
60+
* system messages that are send programmatically
61+
62+
63+
### Send manual messages
64+
65+
In order to send a message to a particular user, there is a button "Send message" in the users inbox.
66+
67+
This screen allows to manually send a message. A message contains a subject and a body, just like a regular Email.
68+
69+
![Screenshot of sending a new message](https://github.com/mariodavid/cuba-component-user-inbox/blob/master/img/send-messages.png)
70+
71+
72+
This feature can sometimes be helpful but oftentimes sending a regular email is not worse.
73+
74+
##### Context-based messages
75+
76+
Therefore there is another option to send a Message. In this case it is a message that is send through the context of a particular entity.
77+
78+
This is comparable of sending a email with a link that points to a particular customer / order etc. in your application together with the information from the sender.
79+
80+
81+
### Send system messages (programmatically)
82+
83+
The other way to send a message to a user is that the developer defines points in the application, where it is useful to notify some user
84+
about a particular thing happend. This can be various actions, like:
85+
86+
* a new Customer has been created
87+
* an order was placed with a total amount > 10k
88+
* an import of data through an API was successful
89+
* ...
90+
91+
There are lot of things that might happen in the lifecycle of an application that are worth to notify.
92+
93+
To send a message to user programmatically, there is a [MessageService]() which will allow exactly this. The interface of this service
94+
looks liks this:
95+
96+
````
97+
public interface MessageService {
98+
99+
void sendSystemMessage(User receiver, String subject, String messageText);
100+
101+
void sendSystemMessage(User receiver, String subject, String messageText, Entity entityReference);
102+
103+
}
104+
````
105+
106+
`sendSystemMessage` will add a message in the given receivers inbox with a subject, a text and an optional entity reference.
107+
49108

img/messages-overview.png

257 KB
Loading

img/new-messages-badge.png

181 KB
Loading

img/send-message.png

237 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
alter table DDCUI_MESSAGE add column ENTITY_CAPTION varchar(255) ;
2+
alter table DDCUI_MESSAGE add column RECEIVED_AT timestamp ^
3+
update DDCUI_MESSAGE set RECEIVED_AT = current_timestamp where RECEIVED_AT is null ;
4+
alter table DDCUI_MESSAGE alter column RECEIVED_AT set not null ;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
4+
<persistence-unit name="cuba-component-user-inbox" transaction-type="RESOURCE_LOCAL">
5+
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
6+
<class>com.haulmont.cuba.core.entity.BaseGenericIdEntity</class>
7+
<class>com.haulmont.cuba.core.entity.BaseUuidEntity</class>
8+
<class>com.haulmont.cuba.core.entity.BaseLongIdEntity</class>
9+
<class>com.haulmont.cuba.core.entity.BaseIntegerIdEntity</class>
10+
<class>com.haulmont.cuba.core.entity.BaseStringIdEntity</class>
11+
<class>com.haulmont.cuba.core.entity.BaseDbGeneratedIdEntity</class>
12+
<class>com.haulmont.cuba.core.entity.BaseIdentityIdEntity</class>
13+
<class>com.haulmont.cuba.core.entity.BaseIntIdentityIdEntity</class>
14+
<class>com.haulmont.cuba.core.entity.StandardEntity</class>
15+
<class>com.haulmont.cuba.core.entity.EmbeddableEntity</class>
16+
<class>com.haulmont.cuba.core.entity.Server</class>
17+
<class>com.haulmont.cuba.core.entity.Config</class>
18+
<class>com.haulmont.cuba.core.entity.FileDescriptor</class>
19+
<class>com.haulmont.cuba.core.entity.LockDescriptor</class>
20+
<class>com.haulmont.cuba.core.entity.Folder</class>
21+
<class>com.haulmont.cuba.core.entity.AbstractSearchFolder</class>
22+
<class>com.haulmont.cuba.core.entity.AppFolder</class>
23+
<class>com.haulmont.cuba.core.entity.FtsQueue</class>
24+
<class>com.haulmont.cuba.core.entity.EntityStatistics</class>
25+
<class>com.haulmont.cuba.core.entity.SendingMessage</class>
26+
<class>com.haulmont.cuba.core.entity.SendingAttachment</class>
27+
<class>com.haulmont.cuba.core.entity.EntitySnapshot</class>
28+
<class>com.haulmont.cuba.core.entity.ScheduledTask</class>
29+
<class>com.haulmont.cuba.core.entity.ScheduledExecution</class>
30+
<class>com.haulmont.cuba.core.entity.QueryResult</class>
31+
<class>com.haulmont.cuba.core.entity.RestApiToken</class>
32+
<class>com.haulmont.cuba.security.entity.User</class>
33+
<class>com.haulmont.cuba.security.entity.Role</class>
34+
<class>com.haulmont.cuba.security.entity.UserRole</class>
35+
<class>com.haulmont.cuba.security.entity.Group</class>
36+
<class>com.haulmont.cuba.security.entity.GroupHierarchy</class>
37+
<class>com.haulmont.cuba.security.entity.Permission</class>
38+
<class>com.haulmont.cuba.security.entity.Constraint</class>
39+
<class>com.haulmont.cuba.security.entity.LocalizedConstraintMessage</class>
40+
<class>com.haulmont.cuba.security.entity.SessionAttribute</class>
41+
<class>com.haulmont.cuba.security.entity.UserSetting</class>
42+
<class>com.haulmont.cuba.security.entity.UserSubstitution</class>
43+
<class>com.haulmont.cuba.security.entity.LoggedEntity</class>
44+
<class>com.haulmont.cuba.security.entity.LoggedAttribute</class>
45+
<class>com.haulmont.cuba.security.entity.EntityLogItem</class>
46+
<class>com.haulmont.cuba.security.entity.FilterEntity</class>
47+
<class>com.haulmont.cuba.security.entity.SearchFolder</class>
48+
<class>com.haulmont.cuba.security.entity.Presentation</class>
49+
<class>com.haulmont.cuba.security.entity.ScreenHistoryEntity</class>
50+
<class>com.haulmont.cuba.security.entity.SessionLogEntry</class>
51+
<class>com.haulmont.cuba.core.entity.CategorizedEntity</class>
52+
<class>com.haulmont.cuba.core.entity.Category</class>
53+
<class>com.haulmont.cuba.core.entity.CategoryAttribute</class>
54+
<class>com.haulmont.cuba.core.entity.CategoryAttributeValue</class>
55+
<class>com.haulmont.cuba.core.entity.JmxInstance</class>
56+
<class>com.haulmont.cuba.security.entity.RememberMeToken</class>
57+
<class>com.haulmont.cuba.core.entity.ReferenceToEntity</class>
58+
<class>de.diedavids.cuba.userinbox.entity.Message</class>
59+
<exclude-unlisted-classes/>
60+
<properties>
61+
<property name="eclipselink.cache.coordination.propagate-asynchronously" value="false"/>
62+
<property name="eclipselink.session-event-listener" value="com.haulmont.cuba.core.sys.persistence.EclipseLinkSessionEventListener"/>
63+
<property name="eclipselink.logging.logger" value="com.haulmont.cuba.core.sys.logging.EclipseLinkLog"/>
64+
<property name="eclipselink.cache.shared.default" value="false"/>
65+
<property name="eclipselink.target-database" value="com.haulmont.cuba.core.sys.persistence.CubaHSQLPlatform"/>
66+
<property name="javax.persistence.validation.mode" value="NONE"/>
67+
<property name="eclipselink.cache.coordination.protocol" value="com.haulmont.cuba.core.sys.entitycache.EntityCacheTransportManager"/>
68+
<property name="eclipselink.weaving" value="static"/>
69+
</properties>
70+
</persistence-unit>
71+
</persistence>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package de.diedavids.cuba.userinbox.web.message
22

33
import com.haulmont.cuba.gui.components.AbstractEditor
4+
import com.haulmont.cuba.security.global.UserSession
45
import de.diedavids.cuba.userinbox.entity.Message
56

7+
import javax.inject.Inject
8+
69
class SendMessage extends AbstractEditor<Message> {
10+
11+
12+
@Inject
13+
UserSession userSession
14+
15+
@Override
16+
protected boolean preCommit() {
17+
item.sender = userSession.currentOrSubstitutedUser
18+
return super.preCommit()
19+
}
720
}

modules/web/src/de/diedavids/cuba/userinbox/web/message/UserInbox.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.haulmont.cuba.core.global.Metadata
77
import com.haulmont.cuba.gui.WindowManager
88
import com.haulmont.cuba.gui.components.AbstractLookup
99
import com.haulmont.cuba.gui.components.Component
10+
import com.haulmont.cuba.gui.components.Frame
1011
import com.haulmont.cuba.gui.components.Table
1112
import com.haulmont.cuba.gui.components.actions.BaseAction
1213
import com.haulmont.cuba.gui.components.actions.CreateAction
@@ -21,6 +22,8 @@ class UserInbox extends AbstractLookup {
2122

2223
@Named("messagesTable.create")
2324
CreateAction createAction
25+
26+
2427
@Named("messagesTable.edit")
2528
EditAction editAction
2629

@@ -40,6 +43,18 @@ class UserInbox extends AbstractLookup {
4043
void init(Map<String, Object> params) {
4144
super.init(params)
4245
createAction.windowId = 'send-message'
46+
createAction.afterCommitHandler = new CreateAction.AfterCommitHandler() {
47+
@Override
48+
void handle(Entity entity) {
49+
messagesDs.refresh()
50+
showMessageSendNotification()
51+
}
52+
}
53+
}
54+
55+
56+
private showMessageSendNotification() {
57+
showNotification(messages.formatMessage(getClass(), 'messageSend'), Frame.NotificationType.TRAY)
4358
}
4459

4560
void openEntity(Message item, String columnId) {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
browseCaption = Messages
2-
newMessage=New Message
2+
newMessage= Send Message
33
editorCaption = Message Details
4+
5+
messageSend = Message successful send

modules/web/src/de/diedavids/cuba/userinbox/web/message/user-inbox.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class="de.diedavids.cuba.userinbox.entity.Message"
1111
view="message-with-users-view">
1212
<query>
13-
<![CDATA[select e from ddcui$Message e where e.receiver.id = :session$userId]]>
13+
<![CDATA[select e from ddcui$Message e where e.receiver.id = :session$userId order by e.receivedAt desc]]>
1414
</query>
1515
</groupDatasource>
1616
</dsContext>
@@ -24,6 +24,7 @@
2424
<properties include=".*"/>
2525
</filter>
2626
<groupTable id="messagesTable"
27+
multiselect="true"
2728
width="100%">
2829
<actions>
2930
<action id="create"
@@ -34,8 +35,8 @@
3435
<columns>
3536
<column id="sender"/>
3637
<column id="subject"/>
37-
<column id="read"/>
3838
<column id="entityCaption" link="true" linkInvoke="openEntity"/>
39+
<column id="read"/>
3940
<column id="receivedAt"/>
4041
</columns>
4142
<rows datasource="messagesDs"/>

0 commit comments

Comments
 (0)