Database Reference
In-Depth Information
# add a status update
def add_content(neo,contentItem,username)
tagstr=trim_content_tags(contentItem["tagstr"])
tags=tagstr.split(",")
time = Time.now.to_i
cypher = " MATCH (user { username: {u}}) " +
" CREATE UNIQUE (user)-[:CURRENTPOST]->(newLP:Content { title:{title}, url:{url}, " +
" tagstr:{tagstr}, timestamp:{timestamp}, contentId:{contentId} }) " +
" WITH user, newLP" +
" FOREACH (tagName in {tags} | " +
" MERGE (t:Tag {wordPhrase:tagName}) " +
" MERGE (newLP)-[:HAS]->(t) " +
" )" +
" WITH user, newLP " +
" OPTIONAL MATCH (newLP)<-[:CURRENTPOST]-(user)-[oldRel:CURRENTPOST]->(oldLP)" +
" DELETE oldRel " +
" CREATE (newLP)-[:NEXTPOST]->(oldLP) " +
" RETURN newLP.contentId as contentId, newLP.title as title, newLP.tagstr as tagstr, " +
" newLP.timestamp as timestamp, newLP.url as url, {u} as username, true as owner "
results=neo.execute_query(cypher, { :u => username,
:title => contentItem["title"].strip,
:url => contentItem["url"].strip,
:tagstr => tagstr,
:timestamp => time,
:contentId => SecureRandom.uuid,
:tags => tags } )
r=results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
r.each do |e|
#convert the timestamp to readable date and time
e.merge!("timestampAsStr" => Time.at(e["timestamp"]).strftime("%m/%d/%Y") +
" at " +
Time.at(e["timestamp"]).strftime("%l:%M %p"))
end
r
end
Editing a Status Update
When status updates are displayed, the current user's status updates will contain a link to “Edit” the status. Once
clicked, it will open the form, similar to the “Add Content” link, but will populate the form with the status update
values as well as modify the form button to read “Edit Content”, as shown in Figure 10-11 . Clicking “Cancel” under the
heading will remove the values and return the form to its ready state.
 
Search WWH ::




Custom Search