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

Commit

Permalink
New method load_repository_info to feed the home page blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jul 30, 2014
1 parent 66b0e0b commit 8053aa6
Show file tree
Hide file tree
Showing 43 changed files with 401 additions and 31 deletions.
12 changes: 10 additions & 2 deletions core/src/core/classes/class.AJXP_Utils.php
Expand Up @@ -718,8 +718,9 @@ public static function convertBytes($value)

//Relative Date Function

public static function relativeDate($time, $messages)
public static function relativeDate($time, $messages, $shortestForm = false)
{
$crtYear = date('Y');
$today = strtotime(date('M j, Y'));
$reldays = ($time - $today)/86400;
$relTime = date($messages['date_relative_time_format'], $time);
Expand All @@ -746,7 +747,14 @@ public static function relativeDate($time, $messages)

}

return str_replace("DATE", date($messages["date_relative_date_format"], $time ? $time : time()), $messages["date_relative_date"]);
$finalDate = date($messages["date_relative_date_format"], $time ? $time : time());
if(!$shortestForm || strpos($finalDate, $crtYear) !== false){
$finalDate = str_replace($crtYear, '', $finalDate);
return str_replace("DATE", $finalDate, $messages["date_relative_date"]);
}else{
return $finalDate = date("M Y", $time ? $time : time());
}
//return str_replace("DATE", $finalDate, $messages["date_relative_date"]);

}

Expand Down
4 changes: 2 additions & 2 deletions core/src/core/classes/class.AuthService.php
Expand Up @@ -898,9 +898,9 @@ public static function getUsersForRepository($repositoryId)
return ConfService::getConfStorageImpl()->getUsersForRepository($repositoryId);
}

public static function countUsersForRepository($repositoryId)
public static function countUsersForRepository($repositoryId, $details = false)
{
return ConfService::getConfStorageImpl()->countUsersForRepository($repositoryId);
return ConfService::getConfStorageImpl()->countUsersForRepository($repositoryId, $details);
}

/**
Expand Down
57 changes: 54 additions & 3 deletions core/src/plugins/access.ajxp_home/class.UserDashboardHome.js
Expand Up @@ -21,11 +21,14 @@
Class.create("UserDashboardHome", AjxpPane, {

_formManager: null,
_repoInfos: null,
_repoInfosLoading:null,

initialize: function($super, oFormObject, editorOptions){

$super(oFormObject, editorOptions);

this._repoInfos = $H();
this._repoInfosLoading = $H();
var dashLogo = ajaxplorer.getPluginConfigs("guidriver").get("CUSTOM_DASH_LOGO");
if(dashLogo){
var url;
Expand Down Expand Up @@ -60,6 +63,27 @@ Class.create("UserDashboardHome", AjxpPane, {
ajaxplorer.triggerRepositoryChange(repoId);
};

var updateRepoInfo = function(block, repoId){
var data = this._repoInfos.get(repoId);
var blocks = 0;
if(data['core.users'] && data['core.users']['internal'] != undefined && data['core.users']['external'] != undefined){
blocks++;
block.insert('<div class="repoInfoBadge"><div class="repoInfoTitle">'+MessageHash[527]+'</div><span class="icon-group"></span>'+MessageHash[531]+' ' + data['core.users']['internal'] + ' <br>'+MessageHash[532]+' ' + data['core.users']['external']+"</div>");
}
if(data['meta.quota']){
blocks++;
block.insert('<div class="repoInfoBadge"><div class="repoInfoTitle">'+MessageHash['meta.quota.4']+'</div><span class="icon-dashboard"></span>' + parseInt(100*data['meta.quota']['usage']/data['meta.quota']['total']) + '% <br><small>' + roundSize(data['meta.quota']['total'], MessageHash["byte_unit_symbol"]) +"</small></div>");
}
if(data['core.notifications'] && data['core.notifications'][0]){
var date = data['core.notifications'][0]['short_date'];
blocks++;
block.insert('<div class="repoInfoBadge"><div class="repoInfoTitle">'+MessageHash[4]+'</div><span class="icon-calendar"></span>' + date + "</div>");
}
if(!blocks){
block.previous('small').addClassName('show_description');
}
}.bind(this);

var updateWsLegend = function(repoObject){
var legendBlock = this.htmlElement.down('#ws_legend');
if(!repoObject && this.htmlElement.down('#go_to_ws').CURRENT_REPO_OBJECT){
Expand All @@ -73,16 +97,43 @@ Class.create("UserDashboardHome", AjxpPane, {
this.timer = window.setTimeout(function(){
if(! legendBlock.up('#home_center_panel') ) return;
legendBlock.update('');
legendBlock.writeAttribute("data-repoId", "");
legendBlock.up('#home_center_panel').removeClassName('legend_visible');
}, 3500);
return;
}
legendBlock.update(repoObject.getLabel() + '<small>' + repoObject.getDescription() + '</small>');
var repoId = repoObject.getId();
legendBlock.writeAttribute("data-repoId", repoId);
legendBlock.update(repoObject.getLabel() + '<small>' + repoObject.getDescription() + '</small><div class="repoInfo"></div>');
legendBlock.insert('<a>'+MessageHash['user_home.42']+'</a>');
legendBlock.down('a').observe('click', function(){
switchToRepo(repoObject.getId());
switchToRepo(repoId);
});
legendBlock.up('#home_center_panel').addClassName('legend_visible');
if(!this._repoInfosLoading.get(repoId) && !this._repoInfos.get(repoId)){
var conn = new Connexion();
this._repoInfosLoading.set(repoId, 'loading');
conn.setParameters({
get_action:'load_repository_info',
tmp_repository_id:repoObject.getId(),
collect:'true'
});
conn.onComplete = function(transport){
this._repoInfosLoading.unset(repoId);
if(transport.responseJSON){
var data = transport.responseJSON;
this._repoInfos.set(repoId, data);
if(legendBlock.readAttribute("data-repoId") == repoId){
updateRepoInfo(legendBlock.down(".repoInfo"), repoId);
}else{

}
}
}.bind(this);
conn.sendAsync();
}else if(this._repoInfos.get(repoId)){
updateRepoInfo(legendBlock.down(".repoInfo"), repoId);
}
}.bind(this);

var renderElement = function(repoObject){
Expand Down
42 changes: 40 additions & 2 deletions core/src/plugins/access.ajxp_home/home.css
Expand Up @@ -32,6 +32,37 @@
float: left;
}

.repoInfoBadge {
display: inline-block;
font-size: 30px;
width: 190px;
line-height: 30px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 8px;
margin: 10px 16px;
height: 116px;
font-family: "Open sans Regular", Arial, sans-serif;
vertical-align: top;
padding: 3px 8px;
text-align: left;
}

.repoInfoTitle {
text-transform: uppercase;
font-family: "Open sans Light", Arial, sans-serif;
font-size: 18px;
text-align: center;
margin-bottom: 9px;
}

.repoInfoBadge span {
display: block;
font-size: 50px;
float: left;
margin: 6px 16px 0 14px;
opacity: 0.9;
}

#home_account_pane #close-icon{
position: absolute;
margin-left: 2px;
Expand Down Expand Up @@ -181,9 +212,16 @@ div.legend_visible div#logo_div{
margin: 0 20px;
}

#home_account_pane div#ws_legend small{
#home_account_pane div#ws_legend > small {
display: block;
font-size: 0.7em;
font-size: 0.6em;
line-height: 1em;
visibility: hidden;
}

#home_account_pane div#ws_legend > small.show_description {
line-height: 1.9em;
visibility: visible;
}

#home_account_pane div#ws_legend a{
Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/boot.conf/class.BootConfLoader.php
Expand Up @@ -618,9 +618,10 @@ public function getUsersForRepository($repositoryId)

/**
* @param string $repositoryId
* @return array('INTERNAL' => count, 'SHARED' => count)
* @param boolean $details
* @return array('internal' => count, 'external' => count)
*/
public function countUsersForRepository($repositoryId){
public function countUsersForRepository($repositoryId, $details = false){

}

Expand Down
9 changes: 6 additions & 3 deletions core/src/plugins/conf.serial/class.serialConfDriver.php
Expand Up @@ -371,10 +371,13 @@ public function getUsersForRepository($repositoryId)

/**
* @param string $repositoryId
* @return array('INTERNAL' => count, 'SHARED' => count)
* @param boolean $details
* @return array('internal' => count, 'external' => count)
*/
public function countUsersForRepository($repositoryId){
return count($this->getUsersForRepository($repositoryId));
public function countUsersForRepository($repositoryId, $details = false){
$c = count($this->getUsersForRepository($repositoryId));
if($details) return array("internal" => $c);
else return $c;
}


Expand Down
46 changes: 40 additions & 6 deletions core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -510,24 +510,58 @@ public function getUsersForRepository($repositoryId)

/**
* @param string $repositoryId
* @return Integer
* @param boolean $details
* @return Integer|Array
*/
public function countUsersForRepository($repositoryId){
public function countUsersForRepository($repositoryId, $details = false){
$object = ConfService::getRepositoryById($repositoryId);
if($object->securityScope() == "USER"){
if($details) return array('internal' => 1);
else return 1;
}else if($object->securityScope() == "GROUP"){
// Count users from current group
$groupUsers = AuthService::authCountUsers(AuthService::getLoggedUser()->getGroupPath());
if($details) return array('internal' => $groupUsers);
else return $groupUsers;
}
// NEW METHOD : SEARCH PERSONAL ROLE
if(is_numeric($repositoryId)){
$likeValue = "i:$repositoryId;s:";
}else{
$likeValue = '"'.$repositoryId.'";s:';
}
switch ($this->sqlDriver["driver"]) {
case "sqlite":
case "sqlite3":
case "postgre":
$res = dibi::query('SELECT count([role_id]) FROM [ajxp_roles] WHERE [searchable_repositories] LIKE %~like~', '"'.$repositoryId.'";s:');
$q = 'SELECT count([role_id]) FROM [ajxp_roles] WHERE [role_id] LIKE \'AJXP_USR_/%\' AND [searchable_repositories] LIKE %~like~';
break;
case "mysql":
$res = dibi::query('SELECT count([role_id]) as c FROM [ajxp_roles] WHERE [serial_role] LIKE %~like~', '"'.$repositoryId.'";s:');
$q = 'SELECT count([role_id]) as c FROM [ajxp_roles] WHERE [role_id] LIKE \'AJXP_USR_/%\' AND [serial_role] LIKE %~like~';
break;
default:
return "ERROR!, DB driver "+ $this->sqlDriver["driver"] +" not supported yet in __FUNCTION__";
}
$all = $res->fetchAll();
return intval($all[0]['c']);
if($details){
if($this->sqlDriver["driver"] == "sqlite" || $this->sqlDriver["driver"] == "sqlite3"){
$internalClause = " AND NOT EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]='AJXP_USR_/'||[ajxp_user_rights].[login] AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
$externalClause = " AND EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]='AJXP_USR_/'||[ajxp_user_rights].[login] AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
}else{
$internalClause = " AND NOT EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]=CONCAT('AJXP_USR_/',[ajxp_user_rights].[login]) AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
$externalClause = " AND EXISTS (SELECT * FROM [ajxp_user_rights] WHERE [ajxp_roles].[role_id]=CONCAT('AJXP_USR_/',[ajxp_user_rights].[login]) AND [ajxp_user_rights].[repo_uuid] = 'ajxp.parent_user')";
}
$intRes = dibi::query($q.$internalClause, $likeValue);
$extRes = dibi::query($q.$externalClause, $likeValue);
return array(
'internal' => $intRes->fetchSingle(),
'external' => $extRes->fetchSingle()
);
}else{
$res = dibi::query($q, $likeValue);
return $res->fetchSingle();

}
//$all = $res->fetchAll();
}


Expand Down
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/ca.php
Expand Up @@ -582,5 +582,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/cs.php
Expand Up @@ -580,5 +580,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/da.php
Expand Up @@ -585,5 +585,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/de.php
Expand Up @@ -594,5 +594,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/en.php
Expand Up @@ -582,4 +582,9 @@
"524"=> "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/es.php
Expand Up @@ -586,5 +586,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
6 changes: 5 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/et.php
Expand Up @@ -583,6 +583,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",

"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
6 changes: 5 additions & 1 deletion core/src/plugins/core.ajaxplorer/i18n/eus.php
Expand Up @@ -581,6 +581,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
/* END SENTENCE */
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);
5 changes: 5 additions & 0 deletions core/src/plugins/core.ajaxplorer/i18n/fi.php
Expand Up @@ -583,5 +583,10 @@
"524" => "Update Password",
"525"=> "Show original picture",
"526"=> "Low-resolution version",
"527"=> "Shared with",
"528"=> "Internal users",
"530"=> "External users",
"531"=> "Int.",
"532"=> "Ext.",
/* END SENTENCE */
);

0 comments on commit 8053aa6

Please sign in to comment.