Merge session list with document list
This commit is contained in:
parent
0d6d3a5d22
commit
922cdec6b8
@ -30,16 +30,16 @@ class Controller {
|
|||||||
|
|
||||||
public static function startSession($args){
|
public static function startSession($args){
|
||||||
$uid = self::getUser();
|
$uid = self::getUser();
|
||||||
$fileid = @$_POST['fileid'];
|
$fileId = @$_POST['fileid'];
|
||||||
$officeView = View::initOfficeView($uid);
|
$officeView = View::initOfficeView($uid);
|
||||||
$genesisPath = View::storeDocument($uid, $fileid);
|
$genesisPath = View::storeDocument($uid, $fileId);
|
||||||
|
|
||||||
if ($genesisPath){
|
if ($genesisPath){
|
||||||
$session = Session::getSessionByOwnerAndGenesis($uid, $genesisPath);
|
$session = Session::getSessionByFileId($fileId);
|
||||||
try {
|
try {
|
||||||
if (!$session){
|
if (!$session){
|
||||||
$hash = View::getHashByGenesis($uid, $genesisPath);
|
$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());
|
$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();
|
self::getUser();
|
||||||
$path = @$_POST['path'];
|
$items = @$_POST['items'];
|
||||||
$sessions = Session::getAll();
|
$info = array();
|
||||||
if (!is_array($sessions)){
|
|
||||||
$sessions = array();
|
if (is_array($items)){
|
||||||
|
$info = Session::getInfoByFileid($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
$preparedSessions = array_map(
|
|
||||||
function($x){return ($x['es_id']);},
|
|
||||||
$sessions
|
|
||||||
);
|
|
||||||
\OCP\JSON::success(array(
|
\OCP\JSON::success(array(
|
||||||
"session_list" => $preparedSessions
|
"info" => $info
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ $this->create('office_session_list', 'ajax/session/list')
|
|||||||
->action('\OCA\Office\Controller', 'listSessions')
|
->action('\OCA\Office\Controller', 'listSessions')
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->create('office_session_for', 'ajax/session/listFor')
|
$this->create('office_session_info', 'ajax/session/info')
|
||||||
->post()
|
->post()
|
||||||
->action('\OCA\Office\Controller', 'listSessions')
|
->action('\OCA\Office\Controller', 'sessionInfo')
|
||||||
;
|
;
|
||||||
|
|
||||||
$this->create('office_session_listhtml', 'ajax/session/listHtml')
|
$this->create('office_session_listhtml', 'ajax/session/listHtml')
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#office-content{
|
#office-content{
|
||||||
padding-top: 3em;
|
padding-top: 3em;
|
||||||
padding-left:160px;
|
|
||||||
}
|
}
|
||||||
#office-content.wide{
|
#office-content.wide{
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
@ -73,3 +72,12 @@ float:left;
|
|||||||
.claro #office-appsettings{
|
.claro #office-appsettings{
|
||||||
display:none;
|
display:none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.session-info{
|
||||||
|
float:right;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover .session-info{
|
||||||
|
display: inline;
|
||||||
|
}
|
27
index.php
27
index.php
@ -21,17 +21,26 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OCP\User::checkLoggedIn();
|
|
||||||
OCP\JSON::checkAppEnabled('office');
|
|
||||||
OCP\App::setActiveNavigationEntry( 'office_index' );
|
|
||||||
|
|
||||||
OCP\Util::addStyle( 'office', 'style' );
|
namespace OCA\Office;
|
||||||
OCP\Util::addStyle( 'office', 'dojo-app' );
|
|
||||||
OCP\Util::addStyle( 'office', 'editor' );
|
|
||||||
OCP\Util::addScript('office', '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->assign('list', $list);
|
||||||
$tmpl->printPage();
|
$tmpl->printPage();
|
||||||
|
39
js/office.js
39
js/office.js
@ -19,7 +19,7 @@ var officeMain = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setInterval(officeMain.updateSessions, 10000);
|
setInterval(officeMain.updateInfo, 10000);
|
||||||
},
|
},
|
||||||
initSession: function(response) {
|
initSession: function(response) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -84,6 +84,7 @@ var officeMain = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
startSession: function(filepath) {
|
startSession: function(filepath) {
|
||||||
"use strict";
|
"use strict";
|
||||||
if (officeMain.initialized === undefined) {
|
if (officeMain.initialized === undefined) {
|
||||||
@ -96,6 +97,7 @@ var officeMain = {
|
|||||||
officeMain.initSession
|
officeMain.initSession
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
joinSession: function(esId) {
|
joinSession: function(esId) {
|
||||||
$.post(OC.Router.generate('office_session_join') + '/' + esId,
|
$.post(OC.Router.generate('office_session_join') + '/' + esId,
|
||||||
{},
|
{},
|
||||||
@ -103,6 +105,28 @@ var officeMain = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
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;i<response.info.length;i++){
|
||||||
|
$('.documentslist tr[data-file='+ response.info[i].file_id +'] .session-info').text(
|
||||||
|
t('office', 'Users in session:')
|
||||||
|
+ response.info[i].users
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
updateSessions: function() {
|
updateSessions: function() {
|
||||||
$('#editing-sessions').load(OC.Router.generate('office_session_listhtml'), {});
|
$('#editing-sessions').load(OC.Router.generate('office_session_listhtml'), {});
|
||||||
},
|
},
|
||||||
@ -149,7 +173,12 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
$('.documentslist tr').click(function(event) {
|
$('.documentslist tr').click(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if ($(this).attr('data-esid')){
|
||||||
|
officeMain.joinSession($(this).attr('data-esid'));
|
||||||
|
}
|
||||||
|
if ($(this).attr('data-file')){
|
||||||
officeMain.startSession($(this).attr('data-file'));
|
officeMain.startSession($(this).attr('data-file'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$('#odf_close').live('click', officeMain.onClose);
|
$('#odf_close').live('click', officeMain.onClose);
|
||||||
$('#odf_invite').live('click', officeMain.onInvite);
|
$('#odf_invite').live('click', officeMain.onInvite);
|
||||||
@ -158,14 +187,6 @@ $(document).ready(function() {
|
|||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#editing-sessions a').live('click',
|
|
||||||
function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
officeMain.joinSession($(this).attr('data-esid'));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$('#inivite-input').autocomplete({
|
$('#inivite-input').autocomplete({
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
source: function(search, response) {
|
source: function(search, response) {
|
||||||
|
@ -43,12 +43,49 @@ class Session {
|
|||||||
return $result->fetchRow();
|
return $result->fetchRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSessionByOwnerAndGenesis($uid, $url){
|
public static function getInfo($esId){
|
||||||
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? ');
|
|
||||||
$result = $query->execute(array($url, $uid));
|
$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();
|
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(){
|
protected static function getUniqueSessionId(){
|
||||||
do {
|
do {
|
||||||
$id = \OC_Util::generate_random_bytes(30);
|
$id = \OC_Util::generate_random_bytes(30);
|
||||||
|
@ -14,24 +14,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="office-content">
|
<div id="office-content">
|
||||||
<div id="editing-sessions">
|
<?php if(empty($_['list']) && empty($_['sessions'])) { ?>
|
||||||
<?php \OCA\Office\Controller::listSessionsHtml() ?>
|
<div id="emptyfolder"><?php p('No documents are found. Please upload a document!');?></div>
|
||||||
</div>
|
|
||||||
<?php if(empty($_['list'])) { ?>
|
|
||||||
<div id="emptyfolder"><?php p('No documents are found. Please upload a document into your ownCloud');?></div>
|
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<div id="editor-content">
|
<div id="editor-content">
|
||||||
<table class="documentslist" >
|
<table class="documentslist" >
|
||||||
|
<?php foreach ($_['sessions'] as $session){ ?>
|
||||||
|
<?php $info = \OCA\Office\Session::getInfo($session['es_id']); ?>
|
||||||
|
<tr data-esid="<?php p($session['es_id']); ?>">
|
||||||
|
<td></td>
|
||||||
|
<td width="100%">Session: <?php p($session['file_id']); ?></td>
|
||||||
|
<td><?php p($l->t('Users:') . ' ' . $info['users']) ?></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
<?php foreach($_['list'] as $entry) { ?>
|
<?php foreach($_['list'] as $entry) { ?>
|
||||||
<tr data-file="<?php p($entry['fileid']) ?>">
|
<tr data-file="<?php p($entry['fileid']) ?>">
|
||||||
<td width="1">
|
<td>
|
||||||
<img align="left" src="<?php p(\OCP\Util::linkToAbsolute('office','ajax/thumbnail.php').'?filepath='.\OCP\Util::encodePath($entry['path'])) ?>" />
|
<img align="left" src="<?php p(\OCP\Util::linkToAbsolute('office','ajax/thumbnail.php').'?filepath='.\OCP\Util::encodePath($entry['path'])) ?>" />
|
||||||
</td>
|
</td>
|
||||||
<!-- <td width="1">
|
<!--<td>
|
||||||
<img align="left" src="<?php p( \OCP\Util::linkToAbsolute('office','img/office.png')) ?>" />
|
<img align="left" src="<?php p( \OCP\Util::linkToAbsolute('office','img/office.png')) ?>" />
|
||||||
</td> -->
|
</td> -->
|
||||||
<td width="100%">
|
<td width="100%">
|
||||||
<a target="_blank" href="<?php p(\OCP\Util::linkToRoute('download', array('file' => $entry['path']))) ?>"><?php p($entry['name'])?></a>
|
<a target="_blank" href="<?php p(\OCP\Util::linkToRoute('download', array('file' => $entry['path']))) ?>"><?php p($entry['name'])?></a>
|
||||||
|
<span class="session-info"></span>
|
||||||
</td>
|
</td>
|
||||||
<td><?php p(\OCP\Util::formatDate(intval($entry['mtime']))); ?></td>
|
<td><?php p(\OCP\Util::formatDate(intval($entry['mtime']))); ?></td>
|
||||||
<td><?php p(\OCP\Util::humanFileSize($entry['size'])); ?></td>
|
<td><?php p(\OCP\Util::humanFileSize($entry['size'])); ?></td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user