Skip to content
This repository has been archived by the owner on Mar 25, 2020. It is now read-only.

Develop with DNA

patrictyskwork edited this page Apr 12, 2019 · 4 revisions

How to use

V: 1.3.0

DNA as an handler instance:

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, {})
})

Send Notification:

this.DNA.add({
   uid: 503392020-32434-324234-434-34344,
   level: 'success',
    message: 'Your message',
})

DNA as an events:

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
    }		
})		

Basic Notifications

dashboard-dna-add-notification

Confirm Notifications

you can send a confirm notification with your DNA handler or an event notification or with a GUI.Button

Confirm item:

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
Confirm - Handler example:
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'
})
Confirm - Event example:
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'
	}
})
Confirm - GUI.Button example:
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

dashboard-dna-confirm-notification

Notification Parameters:

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.

Parameters to Remove-Notification

same "notification" object that you want to remove it. Be sure you pass the same "Notification" object with the same "uid"

Handler:

this.DNA.remove({
    uid: 503392020-32434-324234-434-34344,
    level: 'success',
    message: 'Your message',
})

Event:

this.send('Dashboard:removeNotification', {
    notification: {
        message: 'Your message',
        level: 'success',
        uid: 503392020-32434-324234-434-34344
    }
})
Clone this wiki locally