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

Commit dc20aef

Browse files
author
Charles Marion
committed
ENH: Added assetstore management
BUG: fixed admin css
1 parent e912da7 commit dc20aef

File tree

10 files changed

+263
-23
lines changed

10 files changed

+263
-23
lines changed

core/controllers/AdminController.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ function init()
2121
/** index*/
2222
function indexAction()
2323
{
24-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
24+
if(!$this->logged)
25+
{
26+
$this->haveToBeLogged();
27+
return;
28+
}
29+
if(!$this->userSession->Dao->getAdmin() == 1)
2530
{
2631
throw new Zend_Exception("You should be an administrator");
2732
}
@@ -117,11 +122,13 @@ function indexAction()
117122
// get assetstore data
118123
$defaultAssetStoreId = Zend_Registry::get('configGlobal')->defaultassetstore->id;
119124
$assetstores = $this->Assetstore->getAll();
125+
$defaultSet = false;
120126
foreach($assetstores as $key => $assetstore)
121127
{
122128
if($assetstore->getKey() == $defaultAssetStoreId)
123129
{
124130
$assetstores[$key]->default = true;
131+
$defaultSet = true;
125132
}
126133
else
127134
{
@@ -132,6 +139,18 @@ function indexAction()
132139
$assetstores[$key]->freeSpace = disk_free_space($assetstore->getPath());
133140
$assetstores[$key]->freeSpaceText = $this->Component->Utility->formatSize($assetstores[$key]->freeSpace);
134141
}
142+
143+
if(!$defaultSet)
144+
{
145+
foreach($assetstores as $key => $assetstore)
146+
{
147+
$assetstores[$key]->default = true;
148+
$applicationConfig = parse_ini_file(BASE_PATH.'/core/configs/application.local.ini', true);
149+
$applicationConfig['global']['defaultassetstore.id'] = $assetstores[$key]->getKey();
150+
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
151+
break;
152+
}
153+
}
135154
$this->view->assetstores = $assetstores;
136155
$this->view->assetstoreForm = $this->Form->Assetstore->createAssetstoreForm();
137156

@@ -154,7 +173,6 @@ function indexAction()
154173
$this->view->modulesEnable = $modulesEnable;
155174
$this->view->databaseType = Zend_Registry::get('configDatabase')->database->adapter;
156175
}//end indexAction
157-
158176

159177
/** show logs*/
160178
function showlogAction()

core/controllers/AssetstoreController.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,96 @@ function indexAction()
3030

3131
}// end indexAction
3232

33+
34+
/** change default assetstore*/
35+
function defaultassetstoreAction()
36+
{
37+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
38+
{
39+
throw new Zend_Exception("You should be an administrator");
40+
}
41+
if(!$this->getRequest()->isXmlHttpRequest())
42+
{
43+
throw new Zend_Exception("Why are you here ? Should be ajax.");
44+
}
45+
$this->_helper->layout->disableLayout();
46+
$this->_helper->viewRenderer->setNoRender();
47+
$change = $this->_getParam("submitDefaultAssetstore");
48+
$element = $this->_getParam("element");
49+
if(isset($change))
50+
{
51+
$assetstore = $this->Assetstore->load($element);
52+
if($assetstore != false)
53+
{
54+
$applicationConfig = parse_ini_file(BASE_PATH.'/core/configs/application.local.ini', true);
55+
$applicationConfig['global']['defaultassetstore.id'] = $assetstore->getKey();
56+
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
57+
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
58+
return;
59+
}
60+
}
61+
echo JsonComponent::encode(array(false, $this->t('Error')));
62+
}//defaultassetstoreAction
63+
64+
65+
/** delete an assetstore assetstore*/
66+
function deleteAction()
67+
{
68+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
69+
{
70+
throw new Zend_Exception("You should be an administrator");
71+
}
72+
if(!$this->getRequest()->isXmlHttpRequest())
73+
{
74+
throw new Zend_Exception("Why are you here ? Should be ajax.");
75+
}
76+
$this->_helper->layout->disableLayout();
77+
$this->_helper->viewRenderer->setNoRender();
78+
$assetstoreId = $this->_getParam("assetstoreId");
79+
if(isset($assetstoreId))
80+
{
81+
$assetstore = $this->Assetstore->load($assetstoreId);
82+
if($assetstore != false)
83+
{
84+
$this->Assetstore->delete($assetstore);
85+
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
86+
return;
87+
}
88+
}
89+
echo JsonComponent::encode(array(false, $this->t('Error')));
90+
}//deleteAction
91+
92+
/** edit an assetstore assetstore*/
93+
function editAction()
94+
{
95+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
96+
{
97+
throw new Zend_Exception("You should be an administrator");
98+
}
99+
if(!$this->getRequest()->isXmlHttpRequest())
100+
{
101+
throw new Zend_Exception("Why are you here ? Should be ajax.");
102+
}
103+
$this->_helper->layout->disableLayout();
104+
$this->_helper->viewRenderer->setNoRender();
105+
$assetstoreId = $this->_getParam("assetstoreId");
106+
$assetstoreName = $this->_getParam("assetstoreName");
107+
$assetstorePath = $this->_getParam("assetstorePath");
108+
if(isset($assetstoreId) && !empty($assetstorePath) && file_exists($assetstorePath) && !empty($assetstoreName))
109+
{
110+
$assetstore = $this->Assetstore->load($assetstoreId);
111+
if($assetstore != false)
112+
{
113+
$assetstore->setName($assetstoreName);
114+
$assetstore->setPath($assetstorePath);
115+
$this->Assetstore->save($assetstore);
116+
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
117+
return;
118+
}
119+
}
120+
echo JsonComponent::encode(array(false, $this->t('Error')));
121+
}//editAction
122+
33123
/**
34124
* \fn indexAction()
35125
* \brief called from ajax

core/controllers/InstallController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,6 @@ function step2Action()
198198
$upgradeComponent->initUpgrade('core', $db, $dbtype);
199199
$upgradeComponent->upgrade(str_replace('.sql', '', basename($sqlFile)));
200200

201-
202-
203201
$this->User = new UserModel(); //reset Database adapter
204202
$this->userSession->Dao = $this->User->createUser($form->getValue('email'), $form->getValue('userpassword1'),
205203
$form->getValue('firstname'), $form->getValue('lastname'), 1);

core/controllers/components/UtilityComponent.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ static public function createInitFile($path, $data)
9494
$text .= "[".$delimiter."]\n";
9595
foreach($d as $field => $value)
9696
{
97-
$text .= $field."=".$value."\n";
97+
if($value == 'true' || $value == 'false')
98+
{
99+
$text .= $field."=".$value."\n";
100+
}
101+
else
102+
{
103+
$text .= $field."=\"".str_replace('"', "'", $value)."\"\n";
104+
}
98105
}
99106
$text .= "\n\n";
100107
}

core/models/base/AssetstoreModelBase.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,50 @@ public function __construct()
1212
$this->_mainData = array(
1313
'assetstore_id' => array('type' => MIDAS_DATA),
1414
'name' => array('type' => MIDAS_DATA),
15+
'itemrevision_id' => array('type' => MIDAS_DATA),
1516
'path' => array('type' => MIDAS_DATA),
1617
'type' => array('type' => MIDAS_DATA),
18+
'bitstreams' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Bitstream', 'parent_column' => 'assetstore_id', 'child_column' => 'assetstore_id'),
1719
);
1820
$this->initialize(); // required
1921
} // end __construct()
2022

2123
/** Abstract functions */
2224
abstract function getAll();
25+
26+
/** delete an assetstore (and all the items in it)*/
27+
public function delete($dao)
28+
{
29+
if(!$dao instanceof AssetstoreDao)
30+
{
31+
throw new Zend_Exception("Error param.");
32+
}
33+
$bitreams = $dao->getBitstreams();
34+
$items = array();
35+
foreach ($bitreams as $key => $bitstream)
36+
{
37+
$revision = $bitstream->getItemrevision();
38+
if(empty($revision))
39+
{
40+
continue;
41+
}
42+
$item = $revision->getItem();
43+
44+
if(empty($item))
45+
{
46+
continue;
47+
}
48+
49+
$items[$item->getKey()] = $item;
50+
}
51+
52+
$modelLoader = new MIDAS_ModelLoader();
53+
$item_model = $modelLoader->loadModel('Item');
54+
foreach ($items as $item)
55+
{
56+
$item_model->delete($item);
57+
}
58+
parent::delete($dao);
59+
}// delete
2360

2461
} // end class AssetstoreModelBase

core/models/base/BitstreamModelBase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct()
2020
'path' => array('type' => MIDAS_DATA),
2121
'assetstore_id' => array('type' => MIDAS_DATA),
2222
'date' => array('type' => MIDAS_DATA),
23-
//'itemrevision' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'ItemRevision', 'parent_column'=> 'itemrevision_id', 'child_column' => 'itemrevision_id'),
23+
'itemrevision' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'ItemRevision', 'parent_column'=> 'itemrevision_id', 'child_column' => 'itemrevision_id'),
2424
'assetstore' => array('type' => MIDAS_MANY_TO_ONE, 'model' => 'Assetstore', 'parent_column' => 'assetstore_id', 'child_column' => 'assetstore_id'),
2525
);
2626
$this->initialize(); // required
@@ -38,8 +38,9 @@ function delete($bitstream)
3838
}
3939
$checksum = $bitstream->getChecksum();
4040
$path = $bitstream->getFullPath();
41+
$assetstore = $bitstream->getAssetstore();
4142
parent::delete($bitstream);
42-
if($this->getByChecksum($checksum) == false)
43+
if($assetstore->getType() != MIDAS_ASSETSTORE_REMOTE && $this->getByChecksum($checksum) == false)
4344
{
4445
unlink($path);
4546
}

core/public/js/admin/admin.index.js

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,97 @@
66
});
77
$("#tabsGeneric").show();
88
$('img.tabsLoading').hide()
9+
10+
$('a.defaultAssetstoreLink').click(function(){
11+
$.post(json.global.webroot+'/assetstore/defaultassetstore', {submitDefaultAssetstore: true, element: $(this).attr('element')},
12+
function(data) {
13+
jsonResponse = jQuery.parseJSON(data);
14+
if(jsonResponse==null)
15+
{
16+
createNotive('Error',4000);
17+
return;
18+
}
19+
createNotive(jsonResponse[1],1500);
20+
window.location.replace(json.global.webroot+'/admin#tabs-assetstore');
21+
window.location.reload();
22+
});
23+
});
24+
25+
$('a.removeAssetstoreLink').click(function()
26+
{
27+
var element = $(this).attr('element');
28+
var html = '';
29+
html += 'Do you really want to remove the assetstore? All the items located in it will be delete.';
30+
html += '<br/>';
31+
html += '<br/>';
32+
html += '<input style="margin-left:140px;" class="globalButton deleteAssetstoreYes" element="'+element+'" type="button" value="'+json.global.Yes+'"/>';
33+
html += '<input style="margin-left:50px;" class="globalButton deleteAssetstoreNo" type="button" value="'+json.global.No+'"/>';
34+
showDialogWithContent('Remove Assetstore', html,false);
35+
36+
$('input.deleteAssetstoreYes').unbind('click').click(function()
37+
{
38+
ajaxSelectRequest = $.ajax({
39+
type: "POST",
40+
url: json.global.webroot+'/assetstore/delete',
41+
data: {assetstoreId: element},
42+
success: function(jsonContent){
43+
jsonResponse = jQuery.parseJSON(jsonContent);
44+
createNotive(jsonResponse[1],1500);
45+
if(jsonResponse[0])
46+
{
47+
window.location.replace(json.global.webroot+'/admin#tabs-assetstore');
48+
window.location.reload();
49+
}
50+
}
51+
});
52+
});
53+
$('input.deleteAssetstoreNo').unbind('click').click(function()
54+
{
55+
$( "div.MainDialog" ).dialog('close');
56+
});
57+
});
58+
59+
$('a.editAssetstoreLink').click(function()
60+
{
61+
var element = $(this).attr('element');
62+
var html = '';
63+
html += '<form class="genericForm" onsubmit="false;">';
64+
html += '<label>Name:</label> <input type="text" id="assetstoreName" value="'+$(this).parents('div').find('span.assetstoreName').html()+'"/><br/><br/>';
65+
html += '<label>Path:</label> <input type="text" id="assetstorePath" value="'+$(this).parents('div').find('span.assetstorePath').html()+'"/>';
66+
html += '<br/>';
67+
html += '<br/>';
68+
html += '<input type="submit" id="assetstoreSubmit" value="Save"/>';
69+
html += '</form>';
70+
html += '<br/>';
71+
showDialogWithContent('Edit Assetstore', html,false);
972

73+
$('input#assetstoreSubmit').unbind('click').click(function()
74+
{
75+
ajaxSelectRequest = $.ajax({
76+
type: "POST",
77+
url: json.global.webroot+'/assetstore/edit',
78+
data: {assetstoreId: element, assetstoreName: $('input#assetstoreName').val(), assetstorePath: $('input#assetstorePath').val()},
79+
success: function(jsonContent){
80+
jsonResponse = jQuery.parseJSON(jsonContent);
81+
createNotive(jsonResponse[1],1500);
82+
if(jsonResponse[0])
83+
{
84+
window.location.replace(json.global.webroot+'/admin#tabs-assetstore');
85+
window.location.reload();
86+
}
87+
}
88+
});
89+
});
90+
$('input.deleteAssetstoreNo').unbind('click').click(function()
91+
{
92+
$( "div.MainDialog" ).dialog('close');
93+
});
94+
});
1095

11-
$('#configForm').ajaxForm( {beforeSubmit: validateConfig, success: successConfig} );
96+
$('#configForm').ajaxForm( {beforeSubmit: validateConfig, success: successConfig} );
1297

1398
// Form for the new assetstore
14-
options = { success:assetstoreAddCallback, beforeSubmit: assetstoreSubmit, dataType:'json' };
99+
options = {success:assetstoreAddCallback, beforeSubmit: assetstoreSubmit, dataType:'json'};
15100
$('#assetstoreForm').ajaxForm(options);
16101

17102
$('a.load-newassetstore').cluetip({cluetipClass: 'jtip',
@@ -80,13 +165,8 @@ function assetstoreAddCallback(responseText, statusText, xhr, $form)
80165
// It worked, we add the assetstore to the list and we select it by default
81166
if(responseText.assetstore_id)
82167
{
83-
var html='';
84-
html+="<div class='assetstoreElement'> <span class='assetstoreName'><b>"+responseText.assetstore_name+"</b></span> <br/>";
85-
html+="Total space: "+responseText.totalSpaceText+"<br/>";
86-
html+="<b>Free space: "+responseText.freeSpaceText+"</b>";
87-
html+="</div>";
88-
$('div.assetstoreElement:last').after(html);
89-
console.log(html);
168+
window.location.replace(json.global.webroot+'/admin#tabs-assetstore');
169+
window.location.reload();
90170
}
91171

92172
createNotive(responseText.msg,4000);

core/public/js/admin/admin.upgrade.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function successUpgrade(responseText, statusText, xhr, form)
2222
if(jsonResponse[0])
2323
{
2424
createNotive(jsonResponse[1],4000);
25-
window.location.reload()
25+
window.location.replace(json.global.webroot+'/admin#ui-tabs-1');
26+
window.location.reload();
2627
}
2728
else
2829
{

0 commit comments

Comments
 (0)