@things-factory/notification 6.1.18 → 6.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/client/{bootstrap.js → bootstrap.ts} +13 -9
  2. package/client/pages/notification/notification-list-page.ts +267 -0
  3. package/client/pages/notification-rule/notification-rule-importer.ts +93 -0
  4. package/client/pages/notification-rule/notification-rule-list-page.ts +395 -0
  5. package/client/route.ts +10 -0
  6. package/client/tsconfig.json +13 -0
  7. package/client/viewparts/notification-badge.ts +58 -0
  8. package/client/viewparts/notification-item.ts +242 -0
  9. package/client/viewparts/notification-list.ts +171 -0
  10. package/client/viewparts/notification-sender.ts +126 -0
  11. package/client/viewparts/{notification-setting-let.js → notification-setting-let.ts} +48 -52
  12. package/dist-client/actions/notification-fcm.d.ts +7 -0
  13. package/dist-client/actions/notification-fcm.js +125 -0
  14. package/dist-client/actions/notification-fcm.js.map +1 -0
  15. package/dist-client/bootstrap.d.ts +1 -0
  16. package/dist-client/bootstrap.js +112 -0
  17. package/dist-client/bootstrap.js.map +1 -0
  18. package/dist-client/index.d.ts +5 -0
  19. package/dist-client/index.js +6 -0
  20. package/dist-client/index.js.map +1 -0
  21. package/dist-client/pages/notification/notification-list-page.d.ts +49 -0
  22. package/dist-client/pages/notification/notification-list-page.js +262 -0
  23. package/dist-client/pages/notification/notification-list-page.js.map +1 -0
  24. package/dist-client/pages/notification-rule/notification-rule-importer.d.ts +22 -0
  25. package/dist-client/pages/notification-rule/notification-rule-importer.js +100 -0
  26. package/dist-client/pages/notification-rule/notification-rule-importer.js.map +1 -0
  27. package/dist-client/pages/notification-rule/notification-rule-list-page.d.ts +62 -0
  28. package/dist-client/pages/notification-rule/notification-rule-list-page.js +380 -0
  29. package/dist-client/pages/notification-rule/notification-rule-list-page.js.map +1 -0
  30. package/dist-client/reducers/notification.d.ts +8 -0
  31. package/dist-client/reducers/notification.js +22 -0
  32. package/dist-client/reducers/notification.js.map +1 -0
  33. package/dist-client/route.d.ts +1 -0
  34. package/dist-client/route.js +11 -0
  35. package/dist-client/route.js.map +1 -0
  36. package/dist-client/tsconfig.tsbuildinfo +1 -0
  37. package/dist-client/viewparts/notification-badge.d.ts +15 -0
  38. package/dist-client/viewparts/notification-badge.js +61 -0
  39. package/dist-client/viewparts/notification-badge.js.map +1 -0
  40. package/dist-client/viewparts/notification-item.d.ts +16 -0
  41. package/dist-client/viewparts/notification-item.js +249 -0
  42. package/dist-client/viewparts/notification-item.js.map +1 -0
  43. package/dist-client/viewparts/notification-list.d.ts +20 -0
  44. package/dist-client/viewparts/notification-list.js +160 -0
  45. package/dist-client/viewparts/notification-list.js.map +1 -0
  46. package/dist-client/viewparts/notification-sender.d.ts +13 -0
  47. package/dist-client/viewparts/notification-sender.js +122 -0
  48. package/dist-client/viewparts/notification-sender.js.map +1 -0
  49. package/dist-client/viewparts/notification-setting-let.d.ts +20 -0
  50. package/dist-client/viewparts/notification-setting-let.js +193 -0
  51. package/dist-client/viewparts/notification-setting-let.js.map +1 -0
  52. package/dist-server/service/index.js +10 -1
  53. package/dist-server/service/index.js.map +1 -1
  54. package/dist-server/service/notification/index.js +6 -3
  55. package/dist-server/service/notification/index.js.map +1 -1
  56. package/dist-server/service/notification/notification-mutation.js +110 -0
  57. package/dist-server/service/notification/notification-mutation.js.map +1 -0
  58. package/dist-server/service/notification/notification-query.js +109 -0
  59. package/dist-server/service/notification/notification-query.js.map +1 -0
  60. package/dist-server/service/notification/notification-subscription.js +45 -0
  61. package/dist-server/service/notification/notification-subscription.js.map +1 -0
  62. package/dist-server/service/notification/notification-type.js +82 -0
  63. package/dist-server/service/notification/notification-type.js.map +1 -0
  64. package/dist-server/service/notification/notification.js +81 -8
  65. package/dist-server/service/notification/notification.js.map +1 -1
  66. package/dist-server/service/notification-rule/event-subscriber.js +21 -0
  67. package/dist-server/service/notification-rule/event-subscriber.js.map +1 -0
  68. package/dist-server/service/notification-rule/index.js +12 -0
  69. package/dist-server/service/notification-rule/index.js.map +1 -0
  70. package/dist-server/service/notification-rule/notification-rule-history.js +146 -0
  71. package/dist-server/service/notification-rule/notification-rule-history.js.map +1 -0
  72. package/dist-server/service/notification-rule/notification-rule-mutation.js +170 -0
  73. package/dist-server/service/notification-rule/notification-rule-mutation.js.map +1 -0
  74. package/dist-server/service/notification-rule/notification-rule-query.js +97 -0
  75. package/dist-server/service/notification-rule/notification-rule-query.js.map +1 -0
  76. package/dist-server/service/notification-rule/notification-rule-type.js +102 -0
  77. package/dist-server/service/notification-rule/notification-rule-type.js.map +1 -0
  78. package/dist-server/service/notification-rule/notification-rule.js +146 -0
  79. package/dist-server/service/notification-rule/notification-rule.js.map +1 -0
  80. package/dist-server/tsconfig.tsbuildinfo +1 -1
  81. package/helps/notification/noti-box.md +160 -0
  82. package/helps/notification/noti-rule.md +160 -0
  83. package/helps/notification/notibox.md +160 -0
  84. package/package.json +15 -12
  85. package/server/service/index.ts +14 -0
  86. package/server/service/notification/index.ts +6 -3
  87. package/server/service/notification/notification-mutation.ts +119 -0
  88. package/server/service/notification/notification-query.ts +70 -0
  89. package/server/service/notification/{notification-resolver.ts → notification-subscription.ts} +4 -4
  90. package/server/service/notification/notification-type.ts +55 -0
  91. package/server/service/notification/notification.ts +87 -14
  92. package/server/service/notification-rule/event-subscriber.ts +20 -0
  93. package/server/service/notification-rule/index.ts +9 -0
  94. package/server/service/notification-rule/notification-rule-history.ts +130 -0
  95. package/server/service/notification-rule/notification-rule-mutation.ts +203 -0
  96. package/server/service/notification-rule/notification-rule-query.ts +62 -0
  97. package/server/service/notification-rule/notification-rule-type.ts +71 -0
  98. package/server/service/notification-rule/notification-rule.ts +125 -0
  99. package/server/tsconfig.json +9 -0
  100. package/things-factory.config.js +7 -1
  101. package/client/viewparts/notification-badge.js +0 -63
  102. package/client/viewparts/notification-item.js +0 -250
  103. package/client/viewparts/notification-list.js +0 -177
  104. package/client/viewparts/notification-sender.js +0 -128
  105. package/tsconfig.json +0 -9
  106. /package/client/actions/{notification-fcm.js → notification-fcm.ts} +0 -0
  107. /package/client/{index.js → index.ts} +0 -0
  108. /package/client/reducers/{notification.js → notification.ts} +0 -0
@@ -0,0 +1,71 @@
1
+ import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
2
+ import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
3
+ import { ObjectType, Field, InputType, Int, ID } from 'type-graphql'
4
+
5
+ import { NotificationRule, NotificationRuleStatus } from './notification-rule'
6
+
7
+ @InputType()
8
+ export class NewNotificationRule {
9
+ @Field()
10
+ name: string
11
+
12
+ @Field({ nullable: true })
13
+ description?: string
14
+
15
+ @Field(type => NotificationRuleStatus, { nullable: true })
16
+ state?: NotificationRuleStatus
17
+
18
+ @Field({ nullable: true })
19
+ active?: boolean
20
+
21
+ @Field({ nullable: true })
22
+ title: string
23
+
24
+ @Field({ nullable: true })
25
+ body: string
26
+
27
+ @Field({ nullable: true })
28
+ url: string
29
+
30
+ @Field(type => GraphQLUpload, { nullable: true })
31
+ thumbnail?: FileUpload
32
+ }
33
+
34
+ @InputType()
35
+ export class NotificationRulePatch {
36
+ @Field(type => ID, { nullable: true })
37
+ id?: string
38
+
39
+ @Field({ nullable: true })
40
+ name?: string
41
+
42
+ @Field({ nullable: true })
43
+ description?: string
44
+
45
+ @Field(type => NotificationRuleStatus, { nullable: true })
46
+ state?: NotificationRuleStatus
47
+
48
+ @Field({ nullable: true })
49
+ title: string
50
+
51
+ @Field({ nullable: true })
52
+ body: string
53
+
54
+ @Field({ nullable: true })
55
+ url: string
56
+
57
+ @Field(type => GraphQLUpload, { nullable: true })
58
+ thumbnail?: FileUpload
59
+
60
+ @Field({ nullable: true })
61
+ cuFlag?: string
62
+ }
63
+
64
+ @ObjectType()
65
+ export class NotificationRuleList {
66
+ @Field(type => [NotificationRule])
67
+ items: NotificationRule[]
68
+
69
+ @Field(type => Int)
70
+ total: number
71
+ }
@@ -0,0 +1,125 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ DeleteDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ PrimaryGeneratedColumn,
11
+ VersionColumn
12
+ } from 'typeorm'
13
+ import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
14
+
15
+ import { Domain } from '@things-factory/shell'
16
+ import { User } from '@things-factory/auth-base'
17
+ import { OrgMemberTargetType, OrgMemberTarget } from '@things-factory/organization'
18
+
19
+ export enum NotificationRuleStatus {
20
+ DRAFT = 'DRAFT',
21
+ RELEASED = 'RELEASED'
22
+ }
23
+
24
+ registerEnumType(NotificationRuleStatus, {
25
+ name: 'NotificationRuleStatus',
26
+ description: 'state enumeration of a notificationRule'
27
+ })
28
+
29
+ @ObjectType()
30
+ export class RecipientItem {
31
+ @Field(type => OrgMemberTargetType, { nullable: true })
32
+ type?: OrgMemberTargetType
33
+
34
+ @Field({ nullable: true })
35
+ value?: string
36
+
37
+ @Field(type => OrgMemberTarget, { nullable: true })
38
+ recipient?: OrgMemberTarget
39
+ }
40
+
41
+ @Entity()
42
+ @Index(
43
+ 'ix_notification_rule_0',
44
+ (notificationRule: NotificationRule) => [notificationRule.domain, notificationRule.name, notificationRule.deletedAt],
45
+ { unique: true }
46
+ )
47
+ @ObjectType({ description: 'Entity for NotificationRule' })
48
+ export class NotificationRule {
49
+ @PrimaryGeneratedColumn('uuid')
50
+ @Field(type => ID)
51
+ readonly id: string
52
+
53
+ @VersionColumn()
54
+ @Field({ nullable: true })
55
+ version?: number = 1
56
+
57
+ @ManyToOne(type => Domain)
58
+ @Field({ nullable: true })
59
+ domain?: Domain
60
+
61
+ @RelationId((notificationRule: NotificationRule) => notificationRule.domain)
62
+ domainId?: string
63
+
64
+ @Column()
65
+ @Field({ nullable: true })
66
+ name?: string
67
+
68
+ @Column({ nullable: true })
69
+ @Field({ nullable: true })
70
+ description?: string
71
+
72
+ @Column({ nullable: true })
73
+ @Field({ nullable: true })
74
+ state?: NotificationRuleStatus
75
+
76
+ @Column({ nullable: true })
77
+ @Field({ nullable: true })
78
+ title: string
79
+
80
+ @Column({ nullable: true })
81
+ @Field({ nullable: true })
82
+ body: string
83
+
84
+ @Column({ nullable: true })
85
+ @Field({ nullable: true })
86
+ url: string
87
+
88
+ @Column({ nullable: true })
89
+ @Field({ nullable: true })
90
+ thumbnail: string
91
+
92
+ @Column({ nullable: true })
93
+ @Field({ nullable: true })
94
+ channels: string
95
+
96
+ @Column('simple-json', { nullable: true })
97
+ @Field(type => [RecipientItem], { nullable: true, description: 'notification recipients.' })
98
+ recipients: string
99
+
100
+ @CreateDateColumn()
101
+ @Field({ nullable: true })
102
+ createdAt?: Date
103
+
104
+ @UpdateDateColumn()
105
+ @Field({ nullable: true })
106
+ updatedAt?: Date
107
+
108
+ @DeleteDateColumn()
109
+ @Field({ nullable: true })
110
+ deletedAt?: Date
111
+
112
+ @ManyToOne(type => User, { nullable: true })
113
+ @Field(type => User, { nullable: true })
114
+ creator?: User
115
+
116
+ @RelationId((notificationRule: NotificationRule) => notificationRule.creator)
117
+ creatorId?: string
118
+
119
+ @ManyToOne(type => User, { nullable: true })
120
+ @Field(type => User, { nullable: true })
121
+ updater?: User
122
+
123
+ @RelationId((notificationRule: NotificationRule) => notificationRule.updater)
124
+ updaterId?: string
125
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "outDir": "../dist-server",
5
+ "baseUrl": "./"
6
+ },
7
+ "include": ["./**/*"],
8
+ "exclude": ["**/*.spec.ts"]
9
+ }
@@ -1,5 +1,11 @@
1
- import bootstrap from './client/bootstrap'
1
+ import bootstrap from './dist-client/bootstrap'
2
+ import route from './dist-client/route'
2
3
 
3
4
  export default {
5
+ route,
6
+ routes: [
7
+ { tagname: 'notification-rule-list', page: 'notification-rule-list' },
8
+ { tagname: 'notification-list', page: 'notification-list' }
9
+ ],
4
10
  bootstrap
5
11
  }
@@ -1,63 +0,0 @@
1
- import { LitElement, html, css } from 'lit'
2
- import { connect } from 'pwa-helpers/connect-mixin.js'
3
- import { store } from '@things-factory/shell'
4
-
5
- export class NotificationBadge extends connect(store)(LitElement) {
6
- static get styles() {
7
- return [
8
- css`
9
- :host {
10
- font-size: 2em;
11
- margin: 0 5px 0 0;
12
- --badge-size: 14px;
13
- }
14
-
15
- mwc-icon {
16
- display: block;
17
- }
18
-
19
- [data-badge] {
20
- position: relative;
21
- }
22
-
23
- [data-badge]::after {
24
- content: attr(data-badge);
25
- position: absolute;
26
- top: 0px;
27
- right: -6px;
28
- font-family: var(--theme-font);
29
- font-size: 0.4em;
30
- background: var(--paper-deep-orange-a400);
31
- color: var(--theme-white-color);
32
- width: var(--badge-size);
33
- height: var(--badge-size);
34
- text-align: center;
35
- line-height: var(--badge-size);
36
- border-radius: 50%;
37
- box-shadow: var(--box-shadow);
38
- }
39
-
40
- [data-badge='0']::after {
41
- display: none;
42
- }
43
- `
44
- ]
45
- }
46
-
47
- static get properties() {
48
- return {
49
- badge: Number
50
- }
51
- }
52
-
53
- render() {
54
- var badge = this.badge || 0
55
- return html` <mwc-icon data-badge=${badge} class="badge">notifications_none</mwc-icon> `
56
- }
57
-
58
- stateChanged(state) {
59
- this.badge = state.notification.badge
60
- }
61
- }
62
-
63
- customElements.define('notification-badge', NotificationBadge)
@@ -1,250 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { LitElement, html, css } from 'lit'
3
- import '@material/mwc-icon'
4
- import { client } from '@operato/graphql'
5
-
6
- function isOriginSameAsLocation(url) {
7
- function defaultPort(protocol) {
8
- return { 'http:': 80, 'https:': 443 }[protocol]
9
- }
10
-
11
- function portOf(location) {
12
- return location.port || defaultPort(location.protocol || pageLocation.protocol)
13
- }
14
-
15
- try {
16
- var pageLocation = window.location
17
- var urlparts = new URL(url, pageLocation)
18
-
19
- return !!(
20
- urlparts.protocol &&
21
- urlparts.protocol == pageLocation.protocol &&
22
- urlparts.host &&
23
- urlparts.host == pageLocation.host &&
24
- urlparts.host &&
25
- portOf(urlparts) == portOf(pageLocation)
26
- )
27
- } catch (err) {
28
- console.warn(err, url)
29
- }
30
- }
31
-
32
- export class NotificationItem extends LitElement {
33
- static get styles() {
34
- return [
35
- css`
36
- :host {
37
- position: relative;
38
- background-color: var(--theme-white-color);
39
- padding: var(--padding-default);
40
- border-left: 0 solid transparent;
41
- border-bottom: var(--border-dark-color) !important;
42
- transition: border-left 300ms ease-in-out, padding-left 300ms ease-in-out;
43
- color: var(--scondary-color);
44
-
45
- --type-dot-size: 9px;
46
- }
47
-
48
- :host([newbie]) {
49
- background-color: var(--paper-light-green-50);
50
- }
51
-
52
- :host(:hover) {
53
- padding-left: 0.5rem;
54
- border-left: 0.5rem solid var(--status-info-color);
55
- }
56
-
57
- [titler] {
58
- white-space: nowrap;
59
- overflow: hidden;
60
- text-overflow: ellipsis;
61
- font-size: var(--fontsize-large);
62
- font-weight: bold;
63
- color: var(--secondary-color);
64
- }
65
-
66
- [titler] span {
67
- display: inline-block;
68
- width: var(--type-dot-size);
69
- height: var(--type-dot-size);
70
- border-radius: 50%;
71
- margin-right: var(--margin-narrow);
72
- }
73
- [titler] * {
74
- vertical-align: middle;
75
- }
76
-
77
- [close] {
78
- position: absolute;
79
- top: 13px;
80
- right: 0;
81
- font-size: var(--fontsize-large);
82
- opacity: 0.5;
83
- cursor: pointer;
84
- }
85
- [close]:hover {
86
- opacity: 1;
87
- }
88
- [detail]{
89
- padding:var(--padding-narrow) var(--padding-default);
90
- border-radius:var(--border-radius);
91
- font-size:.85em
92
- }
93
- span.more{
94
- margin-left: 16px;
95
- float:right;
96
- padding:0px var(--padding-narrow) 2px var(--padding-narrow);
97
- border-radius:var(--border-radius);
98
- font-size: 0.8em;
99
- color:var(--theme-white-color);
100
- --mdc-icon-size:14px;
101
- }
102
- span.more *{
103
- vertical-align:middle
104
- }
105
-
106
- :host([type='ERROR']) span {
107
- background-color: var(--status-danger-color);
108
- }
109
- :host([type='ERROR']) {
110
- border-color: var(--status-danger-color);
111
- }
112
- :host([type='ERROR']) [detail]{
113
- border:1px solid rgba(241,53,63,.5);
114
- background-color: rgba(241,53,63,.1);
115
- }
116
- :host([type='WARN']) span {
117
- background-color: var(--status-warning-color);
118
- }
119
- :host([type='WARN']) {
120
- border-color: var(--status-warning-color);
121
- }
122
- :host([type='SUCCESS']) span {
123
- background-color: var(--status-success-color);
124
- }
125
- :host([type='SUCCESS']) {
126
- border-color: var(--status-success-color);
127
- }
128
- :host([type='INFO']) span,
129
- :host span {
130
- background-color: var(--status-info-color);
131
- }
132
- :host([type='INFO']) {
133
- border-color: var(--status-info-color);
134
- }
135
-
136
- img {
137
- display: block;
138
- max-width: 100%;
139
- margin: auto;
140
- }
141
-
142
- [message] {
143
- font-size: var(--fontsize-default);
144
- color: var(--secondary-color);
145
- }
146
-
147
- [timestamp] {
148
- white-space: nowrap;
149
- font-size: var(--fontsize-small);
150
- color: var(--secondary-text-color);
151
- }
152
- `
153
- ]
154
- }
155
-
156
- static get properties() {
157
- return {
158
- type: {
159
- type: String,
160
- reflect: true
161
- },
162
- notification: Object,
163
- target: String,
164
- detail: String
165
- }
166
- }
167
-
168
- render() {
169
- const { title, url, image, timestamp, body } = this.notification
170
- const target = this.target
171
- const detail = this.detail
172
- const type = this.type
173
-
174
- return html`
175
- <div titler>
176
- <span></span>
177
- ${url
178
- ? target
179
- ? html`<a href=${url} target=${target}>${title}</a>`
180
- : html`<a href=${url}>${title}</a>`
181
- : title}
182
- </div>
183
- <mwc-icon close @click=${e => this.dispatchEvent(new CustomEvent('close'))}>close</mwc-icon>
184
-
185
- ${image
186
- ? url
187
- ? target
188
- ? html`<a href=${url} target=${target}><img src=${image} /></a>`
189
- : html`<a href=${url}><img src=${image} /></a>`
190
- : html`<img src=${image} />`
191
- : html``}
192
- <div message>${body}</div>
193
- ${type == 'ERROR'
194
- ? html`<div
195
- @click=${() => {
196
- this.decipherErrorCode()
197
- }}
198
- >
199
- <span class='more'><mwc-icon>expand_circle_down</mwc-icon> more</span>
200
- </div>`
201
- : html``}
202
- ${detail ? html`<div detail>${detail.message}</div>` : html``}
203
-
204
- <div timestamp>${new Date(Number(timestamp)).toLocaleString()}</div>
205
- `
206
- }
207
-
208
- updated(changed) {
209
- if (!this.notification?.confirmed) {
210
- this.setAttribute('newbie', true)
211
- } else {
212
- this.removeAttribute('newbie')
213
- }
214
-
215
- const url = this.notification?.url
216
- this.target = url && !isOriginSameAsLocation(url) && '_blank'
217
- }
218
-
219
- async decipherErrorCode() {
220
- if (this.type != 'ERROR' || !this.notification) {
221
- return
222
- }
223
-
224
- const { title, body } = this.notification
225
- var code = `${title}`
226
- if (body) {
227
- code += `: ${body}`
228
- }
229
-
230
- const response = await client.query({
231
- query: gql`
232
- query ($input: CodeDecipherInput!) {
233
- decipherErrorCode(input: $input) {
234
- message
235
- }
236
- }
237
- `,
238
- variables: {
239
- input: {
240
- code,
241
- system: ''
242
- }
243
- }
244
- })
245
-
246
- this.detail = response.data.decipherErrorCode
247
- }
248
- }
249
-
250
- customElements.define('notification-item', NotificationItem)
@@ -1,177 +0,0 @@
1
- import { LitElement, html, css } from 'lit'
2
- import { connect } from 'pwa-helpers'
3
- import { store, notificationStore } from '@things-factory/shell'
4
- import { UPDATE_NOTIFICATION } from '../actions/notification-fcm'
5
- import { i18next, localize } from '@things-factory/i18n-base'
6
-
7
- import '@material/mwc-icon'
8
- import './notification-item'
9
-
10
- export class NotificationList extends connect(store)(localize(i18next)(LitElement)) {
11
- static get styles() {
12
- return [
13
- css`
14
- :host {
15
- display: block;
16
- background-color: var(--theme-white-color);
17
- box-shadow: var(--box-shadow);
18
- margin-right: var(--margin-wide);
19
- padding: var(--padding-default);
20
- max-height: 100%;
21
- overflow-x: hidden;
22
- overflow-y: auto;
23
- }
24
- :host::before {
25
- content: '';
26
- width: 0px;
27
- height: 0px;
28
- border-left: 7px solid transparent;
29
- border-right: 7px solid transparent;
30
- border-bottom: 7px solid var(--theme-white-color);
31
- position: absolute;
32
- margin-top: -7px;
33
- right: 50px;
34
- }
35
-
36
- [notifications-wrap] {
37
- display: flex;
38
- flex-direction: column;
39
- justify-content: flex-start;
40
- }
41
- [notifications-wrap] div {
42
- align-items: stretch;
43
- border-bottom: 1px solid var(--primary-color);
44
- }
45
- [notifications-wrap] strong {
46
- color: var(--primary-color);
47
- text-transform: capitalize;
48
- line-height: 2;
49
- }
50
- [notifications-wrap] mwc-button {
51
- float: right;
52
- --mdc-button-horizontal-padding: var(--padding-narrow);
53
- --mdc-typography-button-font-size: 0.75em;
54
- }
55
- [no-notifications] {
56
- margin: 0;
57
- padding: var(--padding-wide);
58
- text-align: center;
59
- font-size: var(--fontsize-default);
60
- font-weight: bold;
61
- color: var(--secondary-color);
62
- }
63
- div mwc-icon {
64
- display: block;
65
- opacity: 0.3;
66
- }
67
- @media screen and (max-width: 480px) {
68
- :host {
69
- height: 100%;
70
- width: 100vw;
71
- }
72
- }
73
- `
74
- ]
75
- }
76
-
77
- static get properties() {
78
- return {
79
- history: Array
80
- }
81
- }
82
-
83
- render() {
84
- var history = this.history.reverse()
85
-
86
- return history.length > 0
87
- ? html`
88
- <div notifications-wrap>
89
- <div>
90
- <strong>${i18next.t('label.notification list')}</strong>
91
- <mwc-button
92
- outlined
93
- dense
94
- label=${i18next.t('label.clear all')}
95
- icon="delete_outline"
96
- @click=${e => this.onclearall()}
97
- ></mwc-button>
98
- </div>
99
- ${history.map(
100
- notification => html`
101
- <notification-item
102
- @close=${e => {
103
- this.onclose(notification)
104
- }}
105
- .type=${notification.type}
106
- .notification=${notification}
107
- ></notification-item>
108
- `
109
- )}
110
- </div>
111
- `
112
- : html`
113
- <div no-notifications @click=${e => window.history.back()}>
114
- <mwc-icon>notifications_off</mwc-icon>${i18next.t('text.no notification available')}
115
- </div>
116
- `
117
- }
118
-
119
- onclose(notification) {
120
- const { id } = notification
121
-
122
- store.dispatch(async dispatch => {
123
- if (notification) {
124
- await notificationStore.delete(id)
125
- }
126
-
127
- const history = await notificationStore.getAll()
128
-
129
- dispatch({
130
- type: UPDATE_NOTIFICATION,
131
- history: [...history]
132
- })
133
- })
134
- }
135
-
136
- onclearall() {
137
- store.dispatch(async dispatch => {
138
- await notificationStore.clear()
139
- const history = await notificationStore.getAll()
140
-
141
- dispatch({
142
- type: UPDATE_NOTIFICATION,
143
- history: [...history]
144
- })
145
- })
146
- }
147
-
148
- stateChanged(state) {
149
- this.history = state.notification.history
150
- }
151
-
152
- async disconnectedCallback() {
153
- super.disconnectedCallback()
154
-
155
- await Promise.all(
156
- this.history
157
- .filter(noti => !noti.confirmed)
158
- .map(async noti => {
159
- return await notificationStore.put({
160
- ...noti,
161
- confirmed: true
162
- })
163
- })
164
- )
165
-
166
- store.dispatch(async dispatch => {
167
- const history = await notificationStore.getAll()
168
-
169
- dispatch({
170
- type: UPDATE_NOTIFICATION,
171
- history: [...history]
172
- })
173
- })
174
- }
175
- }
176
-
177
- customElements.define('notification-list', NotificationList)