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

Commit fc85b39

Browse files
author
Charles Marion
committed
ENH: fixed bug #146 Added demo mode
1 parent 3393492 commit fc85b39

File tree

9 files changed

+177
-17
lines changed

9 files changed

+177
-17
lines changed

core/AppController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function preDispatch()
3838
$this->view->webroot = $fc->getBaseUrl();
3939
$this->coreWebroot = $this->view->webroot.'/core';
4040
$this->view->coreWebroot = $this->coreWebroot;
41+
42+
$this->view->demoMode = $this->isDemoMode();
4143

4244
$this->view->title = Zend_Registry::get('configGlobal')->application->name;
4345
$this->view->metaDescription = Zend_Registry::get('configGlobal')->application->description;
@@ -276,6 +278,12 @@ public function isTestingEnv()
276278
return Zend_Registry::get('configGlobal')->environment == 'testing';
277279
}
278280

281+
/** check if demo mode is set */
282+
public function isDemoMode()
283+
{
284+
return Zend_Registry::get('configGlobal')->demomode == 1;
285+
}
286+
279287
/** disable layout */
280288
public function disableLayout()
281289
{

core/configs/application.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ default.timezone=America/New_York
2525
processing=onthefly
2626
;Default license
2727
defaultlicense=1
28+
;Demo Mode (only works with MySql)
29+
demomode=0
2830

2931
[module]
3032

core/controllers/AdminController.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AdminController extends AppController
1717
{
1818
public $_models = array('Errorlog', 'Assetstore');
1919
public $_daos = array();
20-
public $_components = array('Upgrade', 'Utility', 'MIDAS2Migration');
20+
public $_components = array('Upgrade', 'Utility', 'MIDAS2Migration', 'Demo');
2121
public $_forms = array('Admin', 'Assetstore', 'Migrate');
2222

2323
/** init the controller */
@@ -28,6 +28,18 @@ function init()
2828
Zend_Registry::get('configGlobal', $config);
2929
}
3030

31+
/** reset Demo*/
32+
function resetdemoAction()
33+
{
34+
if(!$this->isDemoMode())
35+
{
36+
throw new Zend_Exception("Please enable demo mode");
37+
}
38+
$this->Component->Demo->reset();
39+
$this->disableLayout();
40+
$this->disableView();
41+
}
42+
3143
/** index*/
3244
function indexAction()
3345
{
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
/** Demo management Componenet */
14+
class DemoComponent extends AppComponent
15+
{
16+
/** reset database (only works with mysql)*/
17+
public function reset()
18+
{
19+
if(Zend_Registry::get('configGlobal')->demomode != 1)
20+
{
21+
throw new Zend_Exception("Please enable demo mode");
22+
}
23+
24+
$db = Zend_Registry::get('dbAdapter');
25+
$dbname = Zend_Registry::get('configDatabase')->database->params->dbname;
26+
27+
$stmt = $db->query("SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = '$dbname'");
28+
while ($row = $stmt->fetch())
29+
{
30+
$db->query("DELETE FROM `".$row['TABLE_NAME']."`");
31+
}
32+
33+
$path = BASE_PATH.'/data/assetstore';
34+
$dir = opendir($path);
35+
while($entry = readdir($dir))
36+
{
37+
if(is_dir($path.'/'.$entry) && !in_array($entry, array('.','..')))
38+
{
39+
$this->rrmdir($path.'/'.$entry);
40+
}
41+
}
42+
43+
$path = BASE_PATH.'/data/thumbnail';
44+
$dir = opendir($path);
45+
while($entry = readdir($dir))
46+
{
47+
if(is_dir($path.'/'.$entry) && !in_array($entry, array('.','..')))
48+
{
49+
$this->rrmdir($path.'/'.$entry);
50+
}
51+
}
52+
53+
if(file_exists(BASE_PATH.'/core/configs/ldap.local.ini'))
54+
{
55+
unlink(BASE_PATH.'/core/configs/ldap.local.ini');
56+
}
57+
58+
$modelLoad = new MIDAS_ModelLoader();
59+
$userModel = $modelLoad->loadModel('User');
60+
$communityModel = $modelLoad->loadModel('Community');
61+
$assetstoreModel = $modelLoad->loadModel('Assetstore');
62+
$admin = $userModel->createUser('admin@kitware.com', 'admin', 'Demo', 'Administrator', 1);
63+
$user = $userModel->createUser('user@kitware.com', 'user', 'Demo', 'User', 0);
64+
65+
$communityDao = $communityModel->createCommunity('Demo', "This is a Demo Community", MIDAS_COMMUNITY_PUBLIC, $admin, MIDAS_COMMUNITY_CAN_JOIN);
66+
67+
$assetstoreDao = new AssetstoreDao();
68+
$assetstoreDao->setName('Default');
69+
$assetstoreDao->setPath(BASE_PATH.'/data/assetstore');
70+
$assetstoreDao->setType(MIDAS_ASSETSTORE_LOCAL);
71+
$assetstoreModel->save($assetstoreDao);
72+
73+
$applicationConfig = parse_ini_file(BASE_PATH.'/core/configs/application.ini', true);
74+
$applicationConfig['global']['defaultassetstore.id'] = $assetstoreDao->getKey();
75+
$applicationConfig['global']['demomode'] = true;
76+
77+
if(file_exists(BASE_PATH.'/core/configs/visualize.demo.local.ini'))
78+
{
79+
copy(BASE_PATH.'/core/configs/visualize.demo.local.ini', BASE_PATH.'/core/configs/visualize.local.ini');
80+
$applicationConfig['module']['visualize'] = true;
81+
}
82+
83+
require_once BASE_PATH.'/core/controllers/components/UtilityComponent.php';
84+
$utilityComponent = new UtilityComponent();
85+
$utilityComponent->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
86+
87+
$configGlobal = new Zend_Config_Ini(APPLICATION_CONFIG, 'global', true);
88+
Zend_Registry::set('configGlobal', $configGlobal);
89+
90+
require_once BASE_PATH.'/core/controllers/components/UploadComponent.php';
91+
$uploadCompoenent = new UploadComponent();
92+
$item = $uploadCompoenent->createUploadedItem($admin, 'midasLogo.gif', BASE_PATH.'/core/public/images/midasLogo.gif', $communityDao->getPublicFolder());
93+
}
94+
95+
/** recursively delete a folder*/
96+
private function rrmdir($dir)
97+
{
98+
if(!file_exists($dir))
99+
{
100+
return;
101+
}
102+
if(is_dir($dir))
103+
{
104+
$objects = scandir($dir);
105+
}
106+
107+
foreach($objects as $object)
108+
{
109+
if($object != "." && $object != "..")
110+
{
111+
if(filetype($dir."/".$object) == "dir")
112+
{
113+
$this->rrmdir($dir."/".$object);
114+
}
115+
else
116+
{
117+
unlink($dir."/".$object);
118+
}
119+
}
120+
}
121+
reset($objects);
122+
rmdir($dir);
123+
}
124+
} // end class

core/controllers/components/UploadComponent.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public function createUploadedItem($userDao, $name, $path, $parent = null, $lice
288288
$defaultAssetStoreId = Zend_Registry::get('configGlobal')->defaultassetstore->id;
289289
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
290290
$assetstoreDao = $assetstoreModel->load($defaultAssetStoreId);
291+
292+
if($assetstoreDao == false)
293+
{
294+
throw new Zend_Exception("Unable to load default assetstore");
295+
}
291296

292297
// Upload the bitstream ifnecessary (based on the assetstore type)
293298
$this->uploadBitstream($bitstreamDao, $assetstoreDao);

core/layouts/layout.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ echo $this->doctype()
148148
<div class="HeaderContent">
149149

150150
<div class="HeaderLogo" onclick="window.location='<?php echo $this->webroot?>';">
151+
<?php
152+
if($this->demoMode)
153+
echo 'Demo'
154+
?>
151155
</div>
152156
<div class="HeaderSearch">
153157
<input type="text" id="live_search" value="<?= $this->t('Jump to a data, folder...') ?>" autocomplete="off" autocorrect="off" autocapitalize="off" />

core/views/item/view.phtml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ PURPOSE. See the above copyright notices for more information.
1818
$this->headScript()->appendFile($this->coreWebroot . '/public/js/item/item.view.js');
1919
if($this->preview) // module visualize
2020
{
21+
$this->headScript()->appendFile($this->coreWebroot.'/public/js/common/common.browser.js');
2122
$this->headScript()->appendFile($this->webroot . '/modules/visualize/public/js/main.js');
2223
}
2324
?>
2425
<div class="viewMain">
25-
<div class="genericThumbnail">
26-
<?php
27-
echo "<img src='{$this->coreWebroot}/public/images/icons/document-big.png' alt=''/>";
28-
?>
29-
</div>
30-
<div class="genericInfo">
31-
<div class ="genericWrapperTopRight">
26+
27+
<div class ="genericWrapperTopRight">
3228
<div style="float:right;" class="genericBigButton ">
3329
<?php
3430
echo "<a href='{$this->webroot}/download/?items={$this->itemDao->getKey()}'><img style='float:left;margin-right:2px;' alt='' src='{$this->coreWebroot}/public/images/icons/download.png'/>";
@@ -67,19 +63,21 @@ if($this->preview) // module visualize
6763
<div class="itemStats">
6864
<?php echo $this->itemDao->getView()?> <?php echo $this->t('views'); ?>,
6965
<?php echo $this->itemDao->getDownload()?> <?php echo $this->t('downloads');?></div>
66+
</div>
67+
<div style='width:400px;' class="genericInfo">
68+
<div class="genericThumbnail">
69+
<?php
70+
echo "<img src='{$this->coreWebroot}/public/images/icons/document-big.png' alt=''/>";
71+
?>
7072
</div>
7173
<div class="genericName <?php if(strlen($this->itemDao->getName()) > 30) echo "tips";?>" <?php if(strlen($this->itemDao->getName()) > 30) echo "style='cursor:help;' title='".$this->itemDao->getName()."'";?> ><?php echo $this->slicename($this->itemDao->getName(),30); ?></div>
7274
<div class="genericSubtitle" style="color:grey;"><?php echo $this->itemSize;?></div>
7375

7476
</div>
7577

76-
<table id="browseTable" class="midasTree">
7778
<table style='display:block;' class="midasTree">
7879
<thead>
7980
<tr>
80-
<th ><?php echo $this->t('Revision');?></th>
81-
<th ><?php echo $this->t('Uploaded');?></th>
82-
<th ><?php echo $this->t('Changes');?></th>
8381
<th style="width:100px;" ><?php echo $this->t('Revision');?></th>
8482
<th style="width:240px;" ><?php echo $this->t('Uploaded');?></th>
8583
<th style="width:250px;"><?php echo $this->t('Changes');?></th>
@@ -110,7 +108,7 @@ if($this->preview) // module visualize
110108
else
111109
{
112110
?>
113-
<table id="metadataTable" class="midasTree">
111+
<table style='display:block;' id="metadataTable" class="midasTree">
114112
<thead>
115113
<tr>
116114
<th ><?php echo $this->t('Element');?></th>
@@ -141,7 +139,7 @@ if($this->preview) // module visualize
141139

142140
<h4 style="margin-top: 0px;margin-bottom: 5px;"><?php echo $this->t('Latest revision content')?>:</h4>
143141

144-
<table id="browseTable" class="midasTree">
142+
<table style='display:block;' id="browseTable" class="midasTree">
145143
<thead>
146144
<tr>
147145
<th ><?php echo $this->t('Name');?></th>
@@ -167,7 +165,11 @@ if($this->preview) // module visualize
167165

168166
</div>
169167
<div class="viewSideBar">
168+
<?php
169+
if($this->preview || $this->isModerator ||$this->isAdmin)
170+
{?>
170171
<div class="sideElementFirst viewAction">
172+
171173
<h1>Actions</h1>
172174
<ul>
173175
<?php
@@ -208,7 +210,9 @@ if($this->preview) // module visualize
208210
?>
209211
</ul>
210212
</div>
211-
<div class="sideElement<?php if(count($this->sameLocation) > 1) echo "Last"?> viewInfo">
213+
<?php
214+
}?>
215+
<div class="<?php echo (!$this->preview && !$this->isModerator && !$this->isAdmin)?'sideElementFirst':''; ?>sideElement<?php if(count($this->sameLocation) > 1) echo "Last"?> viewInfo">
212216
<h1>Info</h1>
213217
<table>
214218
<tbody>

modules/visualize/public/js/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
var height = $(window).height()-100;
1414
var width = 800;
1515
var url = json.global.webroot+"/visualize/?itemId="+json.item.item_id+'&height='+height+'&width='+width;
16-
var html = '<div id="fullscreenVisualize" >';
16+
var html = '<div id="fullscreenVisualize" style="min-width:1200px">';
1717
html += '<div id="fullscreenPanel">';
1818
html += '<div style="float:left;margin-right:2px;" class="genericBigButton ">';
1919
html += '<a style="float:left;" class="closeVisuButton"><img style="float:left;margin-right:2px;" alt="" src="'+json.global.coreWebroot+'/public/images/icons/back.png">Back</a></div>';
@@ -108,7 +108,7 @@
108108
$('.MainDialog').hide();
109109
$('.TopDynamicBar').hide();
110110
$('.Topbar').show();
111-
$('.Header').hide();
111+
//$('.Header').hide();
112112
$('.SubWrapper').hide();
113113
$('#fullscreenVisualize a.closeVisuButton').click(function(){
114114
$('#fullscreenVisualize').remove();

modules/visualize/public/js/paraview/paraview.index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ var serverUrl = "/PWService";
110110
{
111111
if(renderers.webgl == undefined)
112112
{
113+
paraview.updateConfiguration(true, "JPEG", "WebGL");
113114
renderers.webgl = new WebGLRenderer("webglRenderer", serverUrl);
114115
renderers.webgl.init(paraview.sessionId, activeView.__selfid__);
115116
$('img.toolButton').hide();

0 commit comments

Comments
 (0)