This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Develop with DNA
patrictyskwork edited this page Apr 12, 2019
·
4 revisions
V: 1.3.0
In your plugin you need to send an event to the DNA agent in order to get DNA-Handler instance
// Build your Notification handler once and use it in all your plugin's components
const DNA_BUNDLE = 'se.infomaker.DNA-Agent'
const DNA_GET_LIB = `${DNA_BUNDLE}:getDNALib`
const DNA_LIB = `${DNA_BUNDLE}:DNALib`
this.DNA = undefined
this.ready(DNA_BUNDLE, () => {
this.on(DNA_LIB, userData => {
let _dna = userData.DNA
this.DNA = new _dna()
})
this.send(DNA_GET_LIB, {})
})
this.DNA.add({
uid: 503392020-32434-324234-434-34344,
level: 'success',
message: 'Your message',
})
To send a notification in DNA use the event name Dashboard:addNotification
this.send('Dashboard:addNotification', {
notification: {
message: 'Your message',
level: 'success',
uid: 4546547-23124-1234567-9899865-764
}
})
you can send a confirm notification with your DNA handler or an event notification or with a GUI.Button
const confirm = {
message: 'My confirm message',
buttonTexts: [CANCEL_BUTTON_TEXT, CONFIRM_BUTTON_TEXT],
onConfirm: () => {},
onCancel: () => {}
}
Attr | Type | Default | Description |
---|---|---|---|
message |
string | null | Message of the notification |
buttonTexts |
array | ['cancel', 'ok'] |
Confirm buttons texts, first item take the cancel text and the second takes the confirm text |
onConfirm |
function | null | callback function will be called on confirm |
onCancel |
function | null | callback function will be called on cancel |
this.DNA.confirm({
uid: 4546547-23124-1234567-9899865-764,
confirm: {
message: `My first event confirm notification 😎`,
onConfirm: () => console.log('Confirmed 😄'),
onCancel: () => console.log('Canceled 🙁')
},
level: 'warning'
})
this.send('Dashboard:addNotification', {
notification: {
uid: 4546547-23124-1234567-9899865-764,
confirm: {
message: `My first event confirm notification 😎`,
onConfirm: () => console.log('Confirmed 😄'),
onCancel: () => console.log('Canceled 🙁')
},
level: 'warning'
}
})
const myConfirmObj = {
message: `My first button confirm notification 😎`,
buttonTexts: ['Deny', 'Confirm'],
onConfirm: () => console.log('Confirmed 😄'),
onCancel: () => console.log('Canceled 🙁')
}
<GUI.Button confirm={myConfirmObj}/>
with GUI.Button if the confirm object doesn't include onConfirm callback function GUI.Button will takes the onClick callback as an onConfirm callback
Attr | Type | Default | Description |
---|---|---|---|
message |
string | "" | Message of the notification |
level |
string | "info" | Level of the notification. Available: success, error, warning and info |
autoDismiss |
int | 0 | Delay in seconds for the notification go away. 0 for not auto-dismiss the notification |
uid |
int/string | null | Notification won't be display without the uid. Notifications with same uid won't be displayed. |
same "notification" object that you want to remove it. Be sure you pass the same "Notification" object with the same "uid"
this.DNA.remove({
uid: 503392020-32434-324234-434-34344,
level: 'success',
message: 'Your message',
})
this.send('Dashboard:removeNotification', {
notification: {
message: 'Your message',
level: 'success',
uid: 503392020-32434-324234-434-34344
}
})