@@ -9,25 +9,48 @@ export default {
99 },
1010 data () {
1111 return {
12+ loaded: false ,
1213 opened: false ,
1314 notifications: [],
1415 lastNotification: null ,
1516 };
1617 },
17- ready () {
18+ created () {
1819 this .$logger (this , ' NotificationCenter' );
1920 },
21+ watch: {
22+ ' notifications.length' (new_value, old_value) {
23+ if (! this .loaded ) return ;
24+ this .save ();
25+ }
26+ },
2027 mounted () {
2128 this .$bus .on (' notification' , this .onNotification );
2229 document .addEventListener (' click' , (evt ) => {
2330 if (! evt .target .closest (' #notification-center' )) {
2431 this .close ();
2532 }
2633 });
34+ this .load ();
2735 },
2836 methods: {
37+ load () {
38+ let existingNotifications = this .$localStorage .get (' notifications' , []);
39+ for (let n of existingNotifications) {
40+ this .notifications .push (n);
41+ }
42+ this .loaded = true ;
43+ this .$debug (' loaded' );
44+ },
45+ save () {
46+ this .$localStorage .set (' notifications' , this .notifications );
47+ this .$debug (' saved' );
48+ },
2949 onNotification (notification ) {
30- let notif = Object .assign ({id: new Date ().getTime ()}, notification);
50+ let now = new Date ().getTime ();
51+ let idSuffix = (Math .random () + 1 ).toString (36 ).substring (7 );
52+ let id = ` ${ now} -${ idSuffix} ` ;
53+ let notif = Object .assign ({id: id, timestamp: now}, notification);
3154 this .notifications .splice (0 , 0 , notif);
3255 this .lastNotification = Object .assign ({}, notif);
3356 },
@@ -78,7 +101,7 @@ export default {
78101 <Badge v-if =" hasNotifications " :value =" notificationCount " :severity =" maxSeverity " size="small" class="local-badge" />
79102 </a >
80103 <div class =" notification-container" >
81- <Message v-if =" lastNotification " severity="info" life="10000 " @lifeEnd =" dismissLastNotification ()" >
104+ <Message v-if =" lastNotification " severity="info" : life =" 3000 " @lifeEnd =" dismissLastNotification ()" closable >
82105 <strong class =" notification-msg" >{{lastNotification.msg}}</strong >
83106 <div v-if =" lastNotification.detail" class =" notification-detail" >{{lastNotification.detail}}</div >
84107 </Message >
@@ -90,6 +113,10 @@ export default {
90113 closable @close =" ack (index )" >
91114 <strong class =" notification-msg" >{{notif.msg}}</strong >
92115 <div v-if =" notif.detail" class =" notification-detail" >{{notif.detail}}</div >
116+ <a v-if =" notif.url" class =" notification-url link-secondary" :href =" notif.url" >
117+ <i class =" fa fa-eye" ></i >
118+ Open
119+ </a >
93120 </Message >
94121 </div >
95122 <div v-else >
@@ -122,10 +149,17 @@ a.activable.active
122149 z-index : 10 ;
123150
124151 .p-message {
152+ position : relative ;
125153 margin : 1rem ;
126154 box-shadow : 0 0 1rem white ;
127155 }
128156
157+ .p-message-close-button {
158+ position : absolute ;
159+ right : 0.25rem ;
160+ top : 0.25rem ;
161+ }
162+
129163 .notification-msg {}
130164 .notification-detail {}
131165}
0 commit comments