Top | Previous | Next |
Comments Panel |
The database-powered Comments Panel Description The comments panel is used to power a blog-style comments system within your project. This can be useful for ad-hoc collaboration and communication between shifts, remote users, etc. This component is driven by a dataset that should be bound to a SQL query. Unlike most components, this component has built-in functionality to alter an external database. This is how the Add Note functionality works. You have the opportunity to alter the queries that the components uses by changing their properties.
The schema that typically drives this component involves up to two tables. One table (by default: Notes) stores all of the notes across the board. The second table (by default, ItemNotes) is used to associate notes with other things. This allows you to have different sets of notes for different screens/objects. Typically you'd bind the data to a query that joined these tables together restricting the second identifier in the ItemNotes table to the value appropriate for the window you're on. You'll also need to alter Insert Query 2's "YOURID" placeholder so that new notes get put in the right spot. You can opt out of this two-table system by simply clearing out Insert Query 2.
Users can be given the choice to remove their own comments, and comments can have files attached. To allow attachments, make sure you have a BLOB field in your notes table.
This component expects that its dataset is populated with the following columns. The names do not need to be exact, but the data type in your notes table must match.
The comments panel also has a set of default queries to handle adding, deleting, and unsticking comments. The default queries expect certain database tables and columns to be set up. If your database is set up differently, or your dataset is different than the default, remember to change the default queries.
Table: Notes
Table: ItemNotes
Table: Users
Insert Query 1: INSERT INTO Notes (Note, WhoID, TStamp, Attachment, Filename, Sticky) VALUES (?, (SELECT Id FROM Users WHERE Username='%s'), CURRENT_TIMESTAMP, ?, ?, ?) This query will insert into your note table using the runPrepStmtGetKey() function and will be given four variables in the following order: note text, attachment blob, attachment filename, and sticky value. Also, it will pass in one string denoted by the %s. This is the name of the user that entered the note and does not need to be placed in any specific spot. If you WhoID field is a string, you can replace (SELECT Id FROM Users WHERE Username='%s') with '%s' to pass the username in directly. Insert Query 2: INSERT INTO ItemNotes (AccountId, NoteId) VALUES (YOURID, %d) This query is optional and will insert the note id from Insert Query 1 into a mapping table of your choice. You must replace YOURID with something meaningful for your mapping table. This is most commonly done by binding this query to an expression. The reason for this second query is to have a mapping table to be joined to the note table to filter out which notes belong to a particular Comment Panel component. Delete Query: DELETE FROM Notes WHERE Id=%d This query will use the note id from the component to delete the selected note. Unstick Query: UPDATE Notes SET Sticky=0 WHERE Id=%d This query will use the note id from the component to set the sticky value to 0. Download Attachment Query: SELECT Attachment FROM Notes WHERE Id=%d This query will use the note id from the component to download the attachment blob from the database.
Sample queries for the Data property binding: Note that the data types in the database must be correct and the columns must be in this order
Assuming WhoID is a string that contains the username: SELECT ID, WhoID as 'Username', TStamp as 'Timestamp', Note as 'NoteText', Filename as 'AttachmentFilename', Sticky as 'Sticky' FROM notes ORDER BY TStamp DESC
If WhoID is a foreign key linked to the Users Table: SELECT n.ID, u.Username, n.TStamp, n.Note, n.Filename, n.Sticky FROM notes n INNER JOIN users u ON u.ID = n.WhoID ORDER BY TStamp DESC
If WhoID is a string and your ItemNotes table links AccountId to NoteId SELECT n.ID, n.WhoID, n.TStamp, n.Note, n.Filename, n.Sticky FROM notes n INNER JOIN ItemNotes i ON i.NoteId = n.ID WHERE i.AccountID = 5 ORDER BY TStamp DESC
Properties
Scripting Events The following event sets are fired by this component. See Component Event Handlers to learn more.
Scripting Functions This component has no special scripting functions. |