From 922cdec6b8237fd5693bbef82d7e58cd94715549 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Sun, 18 Aug 2013 17:11:22 +0300 Subject: [PATCH] Merge session list with document list --- ajax/controller.php | 25 +++++++++++------------- appinfo/routes.php | 4 ++-- css/style.css | 10 +++++++++- index.php | 27 +++++++++++++++++--------- js/office.js | 41 +++++++++++++++++++++++++++++---------- lib/session.php | 43 ++++++++++++++++++++++++++++++++++++++--- templates/documents.php | 21 +++++++++++++------- 7 files changed, 125 insertions(+), 46 deletions(-) diff --git a/ajax/controller.php b/ajax/controller.php index 3d43497d..51417746 100644 --- a/ajax/controller.php +++ b/ajax/controller.php @@ -30,16 +30,16 @@ class Controller { public static function startSession($args){ $uid = self::getUser(); - $fileid = @$_POST['fileid']; + $fileId = @$_POST['fileid']; $officeView = View::initOfficeView($uid); - $genesisPath = View::storeDocument($uid, $fileid); + $genesisPath = View::storeDocument($uid, $fileId); if ($genesisPath){ - $session = Session::getSessionByOwnerAndGenesis($uid, $genesisPath); + $session = Session::getSessionByFileId($fileId); try { if (!$session){ $hash = View::getHashByGenesis($uid, $genesisPath); - $session = Session::add($genesisPath, $hash, $fileid); + $session = Session::add($genesisPath, $hash, $fileId); } $session['member_id'] = (string) Member::add($session['es_id'], \OCP\User::getUser(), self::getRandomColor()); @@ -90,20 +90,17 @@ class Controller { )); } - public static function listSessionFor(){ + public static function sessionInfo(){ self::getUser(); - $path = @$_POST['path']; - $sessions = Session::getAll(); - if (!is_array($sessions)){ - $sessions = array(); + $items = @$_POST['items']; + $info = array(); + + if (is_array($items)){ + $info = Session::getInfoByFileid($items); } - $preparedSessions = array_map( - function($x){return ($x['es_id']);}, - $sessions - ); \OCP\JSON::success(array( - "session_list" => $preparedSessions + "info" => $info )); } diff --git a/appinfo/routes.php b/appinfo/routes.php index 58fdb2c8..3638c35f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -36,9 +36,9 @@ $this->create('office_session_list', 'ajax/session/list') ->action('\OCA\Office\Controller', 'listSessions') ; -$this->create('office_session_for', 'ajax/session/listFor') +$this->create('office_session_info', 'ajax/session/info') ->post() - ->action('\OCA\Office\Controller', 'listSessions') + ->action('\OCA\Office\Controller', 'sessionInfo') ; $this->create('office_session_listhtml', 'ajax/session/listHtml') diff --git a/css/style.css b/css/style.css index 5bcc4673..420bb857 100755 --- a/css/style.css +++ b/css/style.css @@ -6,7 +6,6 @@ #office-content{ padding-top: 3em; -padding-left:160px; } #office-content.wide{ padding-left: 0; @@ -72,4 +71,13 @@ float:left; .claro .office-settings-btn, .claro #office-appsettings{ display:none; +} + +.session-info{ + float:right; + display: none; +} + +tr:hover .session-info{ + display: inline; } \ No newline at end of file diff --git a/index.php b/index.php index a5d9796a..d7938db6 100755 --- a/index.php +++ b/index.php @@ -21,17 +21,26 @@ * */ -OCP\User::checkLoggedIn(); -OCP\JSON::checkAppEnabled('office'); -OCP\App::setActiveNavigationEntry( 'office_index' ); -OCP\Util::addStyle( 'office', 'style' ); -OCP\Util::addStyle( 'office', 'dojo-app' ); -OCP\Util::addStyle( 'office', 'editor' ); -OCP\Util::addScript('office', 'office'); +namespace OCA\Office; -$list=\OCA\Office\Storage::getDocuments(); +\OCP\User::checkLoggedIn(); +\OCP\JSON::checkAppEnabled('office'); +\OCP\App::setActiveNavigationEntry( 'office_index' ); -$tmpl = new OCP\Template('office', 'documents', 'user'); +\OCP\Util::addStyle( 'office', 'style' ); +\OCP\Util::addStyle( 'office', 'dojo-app' ); +\OCP\Util::addStyle( 'office', 'editor' ); +\OCP\Util::addScript('office', 'office'); + +$list=Storage::getDocuments(); + +$tmpl = new \OCP\Template('office', 'documents', 'user'); +$sessions = Session::getAll(); +if (!is_array($sessions)){ + $sessions = array(); +} + +$tmpl->assign('sessions', $sessions); $tmpl->assign('list', $list); $tmpl->printPage(); diff --git a/js/office.js b/js/office.js index 65d31bb1..8a3a5891 100644 --- a/js/office.js +++ b/js/office.js @@ -19,7 +19,7 @@ var officeMain = { }); }); }); - setInterval(officeMain.updateSessions, 10000); + setInterval(officeMain.updateInfo, 10000); }, initSession: function(response) { "use strict"; @@ -84,6 +84,7 @@ var officeMain = { }); }); }, + startSession: function(filepath) { "use strict"; if (officeMain.initialized === undefined) { @@ -96,12 +97,35 @@ var officeMain = { officeMain.initSession ); }, + joinSession: function(esId) { $.post(OC.Router.generate('office_session_join') + '/' + esId, {}, officeMain.initSession ); }, + + + updateInfo : function(){ + var fileIds = []; + $('.documentslist tr').each(function(i, e){ + fileIds.push($(e).attr('data-file')); + }); + $.post( + OC.Router.generate('office_session_info'), + {items: fileIds}, + function (response){ + if (response && response.info && response.info.length){ + for (var i=0;ifetchRow(); } - public static function getSessionByOwnerAndGenesis($uid, $url){ - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? '); - $result = $query->execute(array($url, $uid)); + public static function getInfo($esId){ + + $query = \OCP\DB::prepare('SELECT s.*, COUNT(`m`.`member_id`) AS users FROM `*PREFIX*office_session` AS s LEFT JOIN `*PREFIX*office_member` AS m ON `s`.`es_id`=`m`.`es_id` AND `m`.`status`='. Member::MEMBER_STATUS_ACTIVE .' AND `m`.`uid` != ? WHERE `s`.`es_id` = ? GROUP BY `m`.`es_id`'); + $result = $query->execute( + array( + \OCP\User::getUser(), + $esId + ) + ); + + $info = $result->fetchRow(); + if (!is_array($info)){ + $info = array(); + } + return $info; + } + + public static function getSessionByFileId($fileId){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `file_id`= ?'); + $result = $query->execute(array($fileId)); return $result->fetchRow(); } + public static function getInfoByFileid($fileIds){ + $fileIdCount = count($fileIds); + if (!$fileIdCount || !is_array($fileIds)){ + return array(); + } + + $placeholders = array_fill(0, $fileIdCount, '?'); + $stmt = implode(', ', $placeholders); + $query = \OCP\DB::prepare('SELECT s.*, COUNT(`m`.`member_id`) AS users FROM `*PREFIX*office_session` AS s LEFT JOIN `*PREFIX*office_member` AS m ON `s`.`es_id`=`m`.`es_id` AND `m`.`status`='. Member::MEMBER_STATUS_ACTIVE .' AND `m`.`uid` != ? WHERE `s`.`file_id` IN (' . $stmt .') GROUP BY `m`.`es_id`'); + $result = $query->execute( + array_merge(array(\OCP\User::getUser()), $fileIds) + ); + + $info = $result->fetchAll(); + if (!is_array($info)){ + $info = array(); + } + return $info; + } + protected static function getUniqueSessionId(){ do { $id = \OC_Util::generate_random_bytes(30); diff --git a/templates/documents.php b/templates/documents.php index 0515ab67..e179f9c5 100755 --- a/templates/documents.php +++ b/templates/documents.php @@ -14,24 +14,31 @@
-
- -
- -
+ +
+ + + + + + + + + - -
Session: t('Users:') . ' ' . $info['users']) ?>
+ +