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

Commit

Permalink
Use FeedStore instead of MetaStore to have recursive meta. Could be e…
Browse files Browse the repository at this point in the history
…xpanded to a more generic SQL-based metastore.
  • Loading branch information
cdujeu committed Sep 26, 2013
1 parent 93ee206 commit 18dc884
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 26 deletions.
74 changes: 65 additions & 9 deletions core/src/plugins/meta.comments/class.CommentsMetaManager.php
Expand Up @@ -19,15 +19,28 @@ class CommentsMetaManager extends AJXP_Plugin
* @var MetaStoreProvider
*/
private $metaStore;
/**
* @var AJXP_FeedStore
*/
private $feedStore;

private $storageMode;

public function initMeta($accessDriver)
{
$this->accessDriver = $accessDriver;
$store = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("metastore");
if ($store === false) {
throw new Exception("The 'meta.comments' plugin requires at least one active 'metastore' plugin");
$feed = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("feed");
if($feed){
$this->storageMode = "FEED";
$this->feedStore = $feed;
}else{
$store = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("metastore");
if ($store === false) {
throw new Exception("The 'meta.comments' plugin requires at least one active 'metastore' plugin");
}
$this->metaStore = $store;
$this->storageMode = "METASTORE";
}
$this->metaStore = $store;
}
/**
* @param AJXP_Node $ajxpNode
Expand All @@ -49,6 +62,11 @@ public function mergeMeta($ajxpNode)
public function moveMeta($oldFile, $newFile = null, $copy = false)
{
if($oldFile == null) return;
$feedStore = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("feed");
if($feedStore !== false) {
$feedStore->updateMetaObject(ConfService::getRepository()->getId(), $oldFile->getPath(), ($newFile!=null?$newFile->getPath():null), $copy);
return;
}

if(!$copy && $this->metaStore->inherentMetaMove()) return;

Expand Down Expand Up @@ -77,6 +95,7 @@ public function switchActions($actionName, $httpVars, $fileVars)
$userSelection = new UserSelection();
$userSelection->initFromHttpVars($httpVars);
$uniqNode = $userSelection->getUniqueNode($this->accessDriver);
$feedStore = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("feed");
$existingFeed = $uniqNode->retrieveMetadata(AJXP_META_SPACE_COMMENTS, false);
if ($existingFeed == null) {
$existingFeed = array();
Expand All @@ -93,8 +112,19 @@ public function switchActions($actionName, $httpVars, $fileVars)
"content" => $httpVars["content"]
);
$existingFeed[] = $com;
$uniqNode->removeMetadata(AJXP_META_SPACE_COMMENTS, false);
$uniqNode->setMetadata(AJXP_META_SPACE_COMMENTS, $existingFeed, false);
if($feedStore!== false){
$feedStore->persistMetaObject(
$uniqNode->getPath(),
base64_encode($com["content"]),
$uniqNode->getRepositoryId(),
$uniqNode->getRepository()->securityScope(),
$uniqNode->getRepository()->getOwner(),
AuthService::getLoggedUser()->getId(),
AuthService::getLoggedUser()->getGroupPath());
}else{
$uniqNode->removeMetadata(AJXP_META_SPACE_COMMENTS, false);
$uniqNode->setMetadata(AJXP_META_SPACE_COMMENTS, $existingFeed, false);
}
HTMLWriter::charsetHeader("application/json");
$com["hdate"] = AJXP_Utils::relativeDate($com["date"], $mess);
echo json_encode($com);
Expand All @@ -104,10 +134,36 @@ public function switchActions($actionName, $httpVars, $fileVars)
case "load_comments_feed":

HTMLWriter::charsetHeader("application/json");
foreach ($existingFeed as &$item) {
$item["hdate"] = AJXP_Utils::relativeDate($item["date"], $mess);
if($feedStore !== false){
$data = $feedStore->findMetaObjectsByIndexPath(ConfService::getRepository()->getId(), $uniqNode->getPath(), AuthService::getLoggedUser()->getId(), AuthService::getLoggedUser()->getGroupPath(), 0, 20, "date", "asc");
$theFeed = array();
foreach($data as $stdObject){
$rPath = substr($stdObject->path, strlen($uniqNode->getPath()));
if($rPath == false && $stdObject->path == $uniqNode->getPath()) $rPath = "";
$rPath = ltrim($rPath, "/");
$newItem = array(
"date" =>$stdObject->date,
"hdate" => AJXP_Utils::relativeDate($stdObject->date, $mess),
"author" => $stdObject->author,
"content" => base64_decode($stdObject->content),
"path" => $stdObject->path,
"rpath" => $rPath
);
if(isSet($previous) && $previous["author"] == $newItem["author"] && $previous["path"] == $newItem["path"] && $previous["hdate"] == $newItem["hdate"] ){
$theFeed[count($theFeed) - 1]["content"].= $newItem["content"];

}else{
$theFeed[] = $newItem;
}
$previous = $newItem;
}
echo json_encode($theFeed);
}else{
foreach ($existingFeed as &$item) {
$item["hdate"] = AJXP_Utils::relativeDate($item["date"], $mess);
}
echo json_encode($existingFeed);
}
echo json_encode($existingFeed);

break;

Expand Down
21 changes: 18 additions & 3 deletions core/src/plugins/meta.comments/class.CommentsPanel.js
Expand Up @@ -51,12 +51,13 @@ Class.create("CommentsPanel", {
});
conn.discrete = true;
conn.onComplete = function(transport){
container.down("#comments_container").update('');
container.down("#comments_container").select('.comment_content').invoke("remove");
var feed = transport.responseJSON;
for(var i=0;i<feed.length;i++){
CommentsPanel.prototype.commentObjectToDOM($H(feed[i]), container, node, pe?true:false);
}
CommentsPanel.prototype.refreshScroller(container);
$("comments_container").scrollTop = 10000;
};

conn.sendAsync();
Expand All @@ -67,7 +68,7 @@ Class.create("CommentsPanel", {

}

container.down("#comments_submit").observe("click", function(){
var submitComment = function(){

if(!container.down('textarea').getValue()) {
return;
Expand All @@ -83,18 +84,32 @@ Class.create("CommentsPanel", {
CommentsPanel.prototype.commentObjectToDOM($H(transport.responseJSON), container, node);
container.down('textarea').setValue("");
CommentsPanel.prototype.refreshScroller(container);
$("comments_container").scrollTop = 10000;
};

conn.sendAsync();

}.bind(this);

container.down("#comments_submit").observe("click", function(){
submitComment();
});

container.down('textarea').observe("keydown", function(e){
if(e.keyCode == Event.KEY_RETURN && e.ctrlKey){
submitComment();
return false;
}
return true;
});

},

commentObjectToDOM: function(hash, container, node, skipAnim){

var tpl = new Template('<div class="comment_legend"><span class="icon-remove comment_delete"></span>#{author}, #{hdate}</div><div class="comment_text">#{content}</div>');
var tpl = new Template('<div class="comment_legend"><span class="icon-remove comment_delete"></span>#{author}, #{hdate}</div><div class="comment_text"><span class="comment_text_content">#{content}</span><span class="comment_file_path" ajxp-goto="#{path}">#{rpath}</span></div>');
var el = new Element("div", {className:'comment_content'}).update(tpl.evaluate(hash._object));
if(!hash.get('rpath')) el.down('.comment_file_path').hide();

if(!skipAnim) el.setStyle({opacity:0, display:'block'});
container.down("#comments_container").insert(el);
Expand Down
51 changes: 37 additions & 14 deletions core/src/plugins/meta.comments/comments_feed.css
@@ -1,11 +1,18 @@
#comments_container{
padding: 5px 0;
color: #555555;
max-height: 300px;
overflow-y: auto;
}

.scrolling #comments_container{
margin-right: 10px;
}

#comments_form{
padding: 5px 0;
position: relative;
clear: both;
}

#comments_form textarea{
Expand Down Expand Up @@ -36,46 +43,62 @@ div.double #comments_form textarea, div.triple #comments_form textarea{
}

.comment_delete {
float: right;
cursor: pointer;
font-size: 10px;
color: rgb(174, 183, 192);
display: inline-block !important;
padding-top: 3px;
padding-left: 5px;
padding: 5px;
}

.comment_legend {
color: rgba(184, 184, 184, 0.6);
font-size: 11px;
text-transform: lowercase;
text-align: center;
top: -10px;
background-color: #ebedf0;
display: inline-block;
position: absolute;
padding: 0 6px;
left: 27%;
display: block;
padding: 2%;
float: left;
width: 28%;
}
.comment_text{
float:right;
width: 65%;
background-color: rgba(138,149,160,0.40);
border-radius: 10px;
padding: 0;
}

.comment_file_path{
display: block;
font-size: 11px;
text-align: center;
border-top: 1px solid rgba(255,255,255,0.4);
padding: 1px;
color: rgba(255,255,255,1);
}

.comment_text_content{
display: block;
padding: 5px;
}

.foldedPanel_tooltip .comment_legend{
display: none;
}

.comment_content {
border-top: 1px solid #ffffff;
font-size: 13px;
padding: 10px 5px 0 5px;
margin: 10px 0;
position: relative;
clear: both;
}

.comment_content:nth-child(even) .comment_text {
text-align: right;
float: left;
}

.scrolling div.comment_text{
padding-right: 10px;
.comment_content:nth-child(even) .comment_legend {
float: right;
}

.foldedPanel_tooltip .comment_text{
Expand Down

0 comments on commit 18dc884

Please sign in to comment.