Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1db3c63

Browse files
committed
ENH: refs #223. Added drag-and-drop feature to move data between user folders and community folders.
1 parent 1fc0272 commit 1db3c63

File tree

10 files changed

+260
-24
lines changed

10 files changed

+260
-24
lines changed

core/constant/user.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
define("MIDAS_USER_PUBLIC", 0);
1414
define("MIDAS_USER_PRIVATE", 1);
15+
define("MIDAS_MAXIMUM_FOLDER_NUMBERS_PER_LEVEL", 1000);
1516
?>

core/controllers/CommunityController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ function manageAction()
202202
$this->view->header = $this->t("Manage Community");
203203
$this->view->communityDao = $communityDao;
204204

205+
// User's personal data, used for drag-and-drop feature
206+
$this->view->userPersonalmainFolder = $this->userSession->Dao->getFolder();
207+
$this->view->userPersonalFolders = $this->Folder->getChildrenFoldersFiltered($this->view->userPersonalmainFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
208+
$this->view->userPersonalItems = $this->Folder->getItemsFiltered($this->view->userPersonalmainFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
209+
205210
$this->view->isAdmin = $this->Community->policyCheck($communityDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN);
206211
$this->view->json['community'] = $communityDao->toArray();
207212
$this->view->json['community']['moderatorGroup'] = $moderator_group->toArray();

core/controllers/UserController.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/** User Controller */
1414
class UserController extends AppController
1515
{
16-
public $_models = array('User', 'Folder', 'Folderpolicygroup', 'Folderpolicyuser', 'Group', 'Feed', 'Feedpolicygroup', 'Feedpolicyuser', 'Group', 'Item' );
16+
public $_models = array('User', 'Folder', 'Folderpolicygroup', 'Folderpolicyuser', 'Group', 'Feed', 'Feedpolicygroup', 'Feedpolicyuser', 'Group', 'Item', 'Community' );
1717
public $_daos = array('User', 'Folder', 'Folderpolicygroup', 'Folderpolicyuser', 'Group' );
1818
public $_components = array('Date', 'Filter', 'Sortdao');
1919
public $_forms = array('User');
@@ -704,9 +704,30 @@ public function manageAction()
704704
throw new Zend_Exception("Unable to find user");
705705
}
706706

707+
// Get all the communities this user can see
708+
$communities = array();
709+
if($userDao->isAdmin())
710+
{
711+
$communities = $this->Community->getAll();
712+
}
713+
else
714+
{
715+
$communities = $this->Community->getPublicCommunities();
716+
}
717+
// Get community folders this user can at least read
718+
$communityFolders = array();
719+
foreach($communities as $communityDao)
720+
{
721+
$tmpfolders = $this->Folder->getChildrenFoldersFiltered($communityDao->getFolder(), $userDao, MIDAS_POLICY_READ);
722+
$communityID = $communityDao->getKey();
723+
$communityFolders[$communityID] = $tmpfolders;
724+
}
725+
707726
$this->view->user = $userDao;
708727
$this->view->mainFolder = $userDao->getFolder();
709728
$this->view->folders = $this->Folder->getChildrenFoldersFiltered($this->view->mainFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
710729
$this->view->items = $this->Folder->getItemsFiltered($this->view->mainFolder, $this->userSession->Dao, MIDAS_POLICY_READ);
730+
$this->view->userCommunities = $communities;
731+
$this->view->userCommunityFolders = $communityFolders;
711732
}
712733
}//end class

core/public/css/community/community.manage.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,18 @@ img.folderLoading{
2828
#products { float:left; width: 500px; margin-right: 2em; }
2929
#cart { width: 200px; float: left; }
3030
/* style the list to maximize the droppable hitarea */
31-
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
31+
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
32+
33+
span.userDataTitle{
34+
font-size: 14px;
35+
text-shadow: white 0px 1px 1px;
36+
font-weight: bold;
37+
line-height:150%;
38+
}
39+
40+
.notdraggable { cursor: default; }
41+
.ui-draggable { cursor: pointer; }
42+
43+
div.userPersonalData{
44+
opacity: .85;
45+
}

core/public/css/user/user.manage.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,22 @@ img.folderLoading{
2828
#products { float:left; width: 500px; margin-right: 2em; }
2929
#cart { width: 200px; float: left; }
3030
/* style the list to maximize the droppable hitarea */
31-
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
31+
#cart ol { margin: 0; padding: 1em 0 1em 3em; }
32+
33+
span.communityTitle{
34+
font-size: 14px;
35+
text-shadow: white 0px 1px 1px;
36+
font-weight: bold;
37+
line-height:150%;
38+
}
39+
40+
.notdraggable { cursor: default; }
41+
.draggable { cursor: pointer; }
42+
43+
div.communityList{
44+
opacity: .85;
45+
}
46+
47+
div.communityList span.communityShortDescription{
48+
padding-left: 15px;
49+
}

core/public/js/community/community.manage.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ $(document).ready(function() {
7373
$('img.tabsLoading').hide()
7474

7575

76-
$("#browseTable").treeTable();
76+
$('table')
77+
.filter(function() {
78+
return this.id.match(/browseTable*/);
79+
})
80+
.treeTable();
81+
;
7782
$("img.tableLoading").hide();
7883
$("table#browseTable").show();
7984

85+
$('div.userPersonalData').hide();
86+
8087
initDragAndDrop();
8188
$('td.tdUser input').removeAttr('checked');
8289
});
@@ -112,11 +119,15 @@ function initDragAndDrop()
112119
{
113120
$("#browseTable .file, #browseTable .folder:not(.notdraggable)").draggable({
114121
helper: "clone",
122+
cursor: "move",
115123
opacity: .75,
116124
refreshPositions: true, // Performance?
117125
revert: "invalid",
118126
revertDuration: 300,
119-
scroll: true
127+
scroll: true,
128+
start: function() {
129+
$('div.userPersonalData').show();
130+
}
120131
});
121132

122133
// Configure droppable rows

core/public/js/layout/jquery.treeTable.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@
334334
var j = 1;
335335
var sliceValue = 42 - (id.split('-').length - 1)*3;
336336

337+
var drag_option = "";
338+
337339
$.each(elements['folders'], function(index, value) {
338340
if(j > 70)
339341
{
@@ -344,8 +346,16 @@
344346
{
345347
return;
346348
}
347-
html+= "<tr id='"+id+"-"+i+"' deletable='"+value['deletable']+"' privacy='"+value['privacy_status']+"' class='parent child-of-"+id+"' ajax='"+value['folder_id']+"'type='folder' policy='"+value['policy']+"' element='"+value['folder_id']+"'>";
348-
html+= " <td><span class='folder'>"+sliceFileName(value['name'],sliceValue)+"</span></td>";
349+
if (value['policy'] == 0)
350+
{
351+
drag_option = " notdraggable"
352+
}
353+
else
354+
{
355+
drag_option = ""
356+
}
357+
html+= "<tr id='"+id+"-"+i+"' deletable='"+value['deletable']+"' privacy='"+value['privacy_status']+"' class='parent child-of-"+id+"' ajax='"+value['folder_id']+"'type='folder' policy='"+value['policy']+"' element='"+value['folder_id']+"'>";
358+
html+= " <td><span class='folder"+drag_option+"'>"+sliceFileName(value['name'],sliceValue)+"</span></td>";
349359
html+= " <td>"+'<img class="folderLoading" element="'+value['folder_id']+'" alt="" src="'+json.global.coreWebroot+'/public/images/icons/loading.gif"/>'+"</td>";
350360
html+= " <td>"+value['date_update']+"</td>";
351361
html+= " <td><input type='checkbox' class='treeCheckbox' type='folder' element='"+value['folder_id']+"'/></td>";
@@ -365,8 +375,16 @@
365375
{
366376
return;
367377
}
378+
if (value['policy'] == 0)
379+
{
380+
drag_option = " notdraggable"
381+
}
382+
else
383+
{
384+
drag_option = ""
385+
}
368386
html+= "<tr id='"+id+"-"+i+"' class='child-of-"+id+"' privacy='"+value['privacy_status']+"' type='item' policy='"+value['policy']+"' element='"+value['item_id']+"'>";
369-
html+= " <td><span class='file'>"+sliceFileName(value['name'],sliceValue)+"</span></td>";
387+
html+= " <td><span class='file"+drag_option+"'>"+sliceFileName(value['name'],sliceValue)+"</span></td>";
370388
html+= " <td>"+value['size']+"</td>";
371389
html+= " <td>"+value['date_update']+"</td>";
372390
html+= " <td><input type='checkbox' class='treeCheckbox' type='item' element='"+value['item_id']+"'/></td>";

core/public/js/user/user.manage.js

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ $(document).ready(function() {
88
$('div.sideElementFirst').show();
99

1010

11-
$("#browseTable").treeTable();
11+
$('table')
12+
.filter(function() {
13+
return this.id.match(/browseTable*/);
14+
})
15+
.treeTable();
16+
;
17+
1218
$("img.tableLoading").hide();
1319
$("table#browseTable").show();
1420

15-
initDragAndDrop();
21+
$('div.communityList').hide();
22+
23+
initDragAndDrop();
1624

1725
});
1826

@@ -24,8 +32,15 @@ $(document).ready(function() {
2432
$('div.genericAction').hide();
2533
$('div.genericCommunities').hide();
2634
$('div.genericStats').hide();
27-
$('div.viewInfo').show();
28-
$('div.viewAction').show()
35+
36+
// user need to have at least written permission to see specific Actions
37+
//(edit, delete, etc...)
38+
if (node.attr('type')!= 0 )
39+
{
40+
$('div.viewInfo').show();
41+
$('div.viewAction').show();
42+
}
43+
2944
genericCallbackSelect(node);
3045
}
3146

@@ -45,18 +60,24 @@ $(document).ready(function() {
4560

4661
function initDragAndDrop()
4762
{
48-
$("#browseTable .file, #browseTable .folder:not(.notdraggable)").draggable({
49-
helper: "clone",
50-
opacity: .75,
51-
refreshPositions: true, // Performance?
52-
revert: "invalid",
53-
revertDuration: 300,
54-
scroll: true
63+
$("#browseTable .file:not(.notdraggable), #browseTable .folder:not(.notdraggable)").draggable({
64+
helper: "clone",
65+
cursor: "move",
66+
opacity: .75,
67+
refreshPositions: true, // Performance?
68+
revert: "invalid",
69+
revertDuration: 300,
70+
scroll: true,
71+
// Show communities when user starts to drag items
72+
start: function() {
73+
$('div.communityList').show();
74+
}
5575
});
5676

57-
// Configure droppable rows
77+
5878
$("#browseTable .folder").each(function() {
59-
$(this).parents("tr").droppable({
79+
// Configure droppable folders/items
80+
$(this).parents("tr:[policy!=0]").droppable({
6081
accept: ".file, .folder",
6182
drop: function(e, ui) {
6283
// Call jQuery treeTable plugin to move the branch
@@ -107,5 +128,31 @@ function initDragAndDrop()
107128
}
108129
}
109130
});
131+
132+
// Configure non-drappable folders/items
133+
$(this).parents("tr:[policy=0]").droppable({
134+
revert: true,
135+
// Make the droppable branch expand when a draggable node is moved over it.
136+
over: function(e, ui) {
137+
if(!$(this).is(".expanded")) {
138+
$(this).expand();
139+
}
140+
}
141+
});
142+
143+
$(this).parents("tr:[policy=0]").qtip({
144+
content: 'You do not have write permission on this folder and cannot drop items to it !',
145+
show: 'mouseover',
146+
hide: 'mouseout',
147+
position: {
148+
at: 'center',
149+
my: 'bottom left',
150+
viewport: $(window), // Keep the qtip on-screen at all times
151+
effect: true // Disable positioning animation
152+
}
153+
});
154+
110155
});
156+
157+
111158
}

core/views/community/manage.phtml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.bro
234234
</thead>
235235
<tbody>
236236
<?php
237-
$node=1;
237+
$communityId = $this->communityDao->getKey();
238+
$node = MIDAS_MAXIMUM_FOLDER_NUMBERS_PER_LEVEL * $communityId;
238239

239240
foreach($this->folders as $folder)
240241
{
@@ -261,7 +262,47 @@ $this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.bro
261262

262263
</tbody>
263264
</table>
265+
<br/>
266+
<div class="userPersonalData">
267+
<span class="userDataTitle">
268+
<?php echo 'Your personal data'?></span>
269+
<br/>
270+
<table id="browseTable" class="midasTree">
271+
<thead>
272+
<th class="thData"><?php echo $this->t('Name');?></th>
273+
<th class="thSize"><?php echo $this->t('Size');?></th>
274+
<th class="thDate"><?php echo $this->t('Modified');?></th>
275+
<th class="thCheckbox"></th>
276+
</thead>
277+
<tbody>
278+
<?php
279+
$node=1;
264280

281+
foreach($this->userPersonalFolders as $folder)
282+
{
283+
echo "<tr id='node--$node' class='parent' privacy='{$folder->getPrivacyStatus()}' policy='".MIDAS_POLICY_ADMIN."' type='folder' element='{$folder->getFolderId()}' ajax='{$folder->getFolderId()}'>";
284+
echo " <td class='treeBrowseElement'><span class='notdraggable folder'>{$folder->getName()}</span></td>";
285+
echo " <td><img class='folderLoading' element='{$folder->getFolderId()}' alt='' src='{$this->coreWebroot}/public/images/icons/loading.gif'/></td>";
286+
echo " <td>{$this->Date->ago($folder->getDateUpdate(),true)}</td>";
287+
echo " <td><input type='checkbox' class='treeCheckbox' type='folder' element='{$folder->getFolderId()}' /></td>";
288+
echo "</tr>";
289+
$node++;
290+
}
291+
292+
foreach($this->userPersonalItems as $item)
293+
{
294+
echo "<tr id='node--$node' policy='{$item->policy}' privacy='{$item->getPrivacyStatus()}' class='' type='item' element='{$item->getItemId()}' >";
295+
echo " <td class='treeBrowseElement'><span class='file'>{$this->slicename($item->getName(),40)}</span></td>";
296+
echo " <td>{$item->size}</td>";
297+
echo " <td>{$this->Date->ago($item->getDateUpdate(),true)}</td>";
298+
echo " <td><input type='checkbox' class='treeCheckbox' type='item' element='{$item->getItemId()}' /></td>";
299+
echo "</tr>";
300+
$node++;
301+
}
302+
?>
303+
</tbody>
304+
</table>
305+
</div>
265306
</div>
266307
</div>
267308
</div>

0 commit comments

Comments
 (0)