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

Commit d427f2d

Browse files
author
Charles Ma
committed
ENH: Added dependencies and categories (see helloworld module.ini)
fixed bug #157
1 parent 1c654e2 commit d427f2d

File tree

9 files changed

+235
-34
lines changed

9 files changed

+235
-34
lines changed

core/controllers/AdminController.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function indexAction()
191191

192192
// get modules
193193
$modulesEnable = Zend_Registry::get('modulesEnable');
194-
194+
$adapter = Zend_Registry::get('configDatabase')->database->adapter;
195195
foreach($allModules as $key => $module)
196196
{
197197
if(file_exists(BASE_PATH."/modules/".$key."/controllers/ConfigController.php"))
@@ -202,9 +202,68 @@ function indexAction()
202202
{
203203
$allModules[$key]->configPage = false;
204204
}
205+
206+
if(isset($module->db->$adapter))
207+
{
208+
$allModules[$key]->dbOk = true;
209+
}
210+
else
211+
{
212+
$allModules[$key]->dbOk = false;
213+
}
214+
215+
$allModules[$key]->dependenciesArray = array();
216+
$allModules[$key]->dependenciesExist = true;
217+
// check if dependencies exit
218+
if(isset($allModules[$key]->dependencies) && !empty($allModules[$key]->dependencies))
219+
{
220+
$allModules[$key]->dependenciesArray = explode(',', trim($allModules[$key]->dependencies));
221+
foreach($allModules[$key]->dependenciesArray as $dependency)
222+
{
223+
if(!isset($allModules[$dependency]))
224+
{
225+
$allModules[$key]->dependenciesExist = false;
226+
}
227+
}
228+
}
205229
}
206230

207-
$this->view->modulesList = $allModules;
231+
$modulesList = array();
232+
$countModules = array();
233+
foreach($allModules as $k => $module)
234+
{
235+
if(!isset($module->category) || empty($module->category))
236+
{
237+
$category = "Misc";
238+
}
239+
else
240+
{
241+
$category = ucfirst(strtolower($module->category));
242+
}
243+
if(!isset($modulesList[$category]))
244+
{
245+
$modulesList[$category] = array();
246+
$countModules[$category] = array('visible' => 0, 'hidden' => 0);
247+
}
248+
$modulesList[$category][$k] = $module;
249+
if($module->dbOk && $module->dependenciesExist)
250+
{
251+
$countModules[$category]['visible']++;
252+
}
253+
else
254+
{
255+
$countModules[$category]['hidden']++;
256+
}
257+
}
258+
259+
foreach($modulesList as $k => $l)
260+
{
261+
ksort($modulesList[$k]);
262+
}
263+
264+
ksort($modulesList);
265+
$this->view->countModules = $countModules;
266+
$this->view->modulesList = $modulesList;
208267
$this->view->modulesEnable = $modulesEnable;
209268
$this->view->databaseType = Zend_Registry::get('configDatabase')->database->adapter;
210269
}//end indexAction

core/public/css/admin/admin.index.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ div.viewWrapper {
99

1010
div.assetstoreElement{
1111
margin-bottom: 10px;
12-
}
12+
}
13+
14+
tr.moduleElementError td{
15+
color:grey;
16+
font-size: 11px;
17+
}
18+
19+
a.moduleVisibleCategoryLink, a.moduleHiddenCategoryLink{
20+
font-weight: bold!important;
21+
font-size: 13px!important;
22+
}
23+

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,53 @@
113113
if($(this).is(':checked'))
114114
{
115115
modulevalue='true';
116+
var dependencies = $(this).attr('dependencies');
117+
dependencies=dependencies.split(',');
118+
$.each(dependencies, function(i, l){
119+
if(l != '')
120+
{
121+
if(!$('input[module='+l+']').is(':checked'))
122+
{
123+
$.post(json.global.webroot+'/admin/index', {submitModule: true, modulename: l , modulevalue:modulevalue});
124+
createNotive("Dependancy: Enabling module "+l,1500);
125+
}
126+
$('input[module='+l+']').attr('checked',true);
127+
}
128+
});
116129
}
117130
else
118131
{
119132
modulevalue='false';
133+
var moduleDependencies = new Array();
134+
$.each($('input[dependencies='+$(this).attr('module')+']:checked'),function(){
135+
moduleDependencies.push($(this).attr('module'));
136+
});
137+
$.each($('input[dependencies*=",'+$(this).attr('module')+'"]:checked'),function(){
138+
moduleDependencies.push($(this).attr('module'));
139+
});
140+
$.each($('input[dependencies*="'+$(this).attr('module')+',"]:checked'),function(){
141+
moduleDependencies.push($(this).attr('module'));
142+
});
143+
var found = false;
144+
145+
var mainModule = $(this).attr('module');
146+
147+
$.each(moduleDependencies, function(i, l){
148+
var module = l;
149+
if(module != '')
150+
{
151+
found =true;
152+
createNotive("Dependancy: The module "+module+" requires "+mainModule+". Please, disable it first.",3500);
153+
}
154+
});
155+
if(found)
156+
{
157+
$(this).attr('checked',true);
158+
return;
159+
}
120160
}
161+
162+
121163
$.post(json.global.webroot+'/admin/index', {submitModule: true, modulename: $(this).attr('module') , modulevalue:modulevalue},
122164
function(data) {
123165
jsonResponse = jQuery.parseJSON(data);
@@ -126,10 +168,36 @@
126168
createNotive('Error',4000);
127169
return;
128170
}
129-
createNotive(jsonResponse[1],1500);
171+
createNotive(jsonResponse[1],3500);
130172
initModulesConfigLinks();
131173
});
132174
});
175+
176+
$('a.moduleVisibleCategoryLink').click(function(){
177+
if($(this).prev('span').html() == '>')
178+
{
179+
$(this).prev('span').html('v');
180+
$('.'+$(this).html()+'VisibleElement').show();
181+
}
182+
else
183+
{
184+
$(this).prev('span').html('>');
185+
$('.'+$(this).html()+'VisibleElement').hide();
186+
}
187+
});
188+
189+
$('a.moduleHiddenCategoryLink').click(function(){
190+
if($(this).prev('span').html() == '>')
191+
{
192+
$(this).prev('span').html('v');
193+
$('.'+$(this).html()+'HiddenElement').show();
194+
}
195+
else
196+
{
197+
$(this).prev('span').html('>');
198+
$('.'+$(this).html()+'HiddenElement').hide();
199+
}
200+
});
133201
initModulesConfigLinks();
134202
});
135203

core/views/admin/index.phtml

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,91 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/admin/admin.ind
134134
</div>
135135

136136
<div id="tabs-modules">
137-
<table>
137+
<table style='width:100%;'>
138138
<?php
139-
foreach($this->modulesList as $key=>$module)
139+
$hidden = 0;
140+
foreach($this->modulesList as $category => $list)
140141
{
141-
if(isset($module->db->{$this->databaseType}))
142-
{
143-
echo "
144-
<tr class='moduleElement'>
145-
<td>
146-
<input type='checkbox' class='moduleCheckbox' module='{$key}' name='module[{$key}]' ".((in_array($key, $this->modulesEnable))?'checked':'')."/>
147-
</td>
148-
<td>
149-
<b>{$module->fullname}</b><br/>
150-
{$module->description}
151-
</td>";
152-
if($module->configPage)
153-
{
154-
echo "
155-
<td class='configLink' style='display:none;'>
156-
<a href='{$this->webroot}/$key/config'>View configuration</a>
157-
</td>";
158-
}
159-
echo "
160-
</tr>
161-
";
162-
}
142+
echo "<tr><td colspan=3><span class='moduleCategoryArrow'>></span> <a class='moduleVisibleCategoryLink'>".$category."</a> (".$this->countModules[$category]['visible'].")</td></tr>";
143+
echo "<div class='categoryWrapper' style='display:none;'>";
144+
foreach($list as $key => $module)
145+
{
146+
if($module->dbOk && $module->dependenciesExist)
147+
{
148+
echo "
149+
<tr class='moduleElement {$category}VisibleElement' style='display:none;'>
150+
<td style='width:30px;'>
151+
<input type='checkbox' dependencies='".trim($module->dependencies)."' class='moduleCheckbox' module='{$key}' name='module[{$key}]' ".((in_array($key, $this->modulesEnable))?'checked':'')."/>
152+
</td>
153+
<td>
154+
<b>{$module->fullname}</b><br/>
155+
{$module->description}
156+
</td>";
157+
if($module->configPage)
158+
{
159+
echo "
160+
<td class='configLink' style='display:none;width:300px;'>
161+
<a href='{$this->webroot}/$key/config'>View configuration</a>
162+
</td>";
163+
}
164+
echo "
165+
</tr>
166+
";
167+
}
168+
}
169+
echo "</div>";
163170
}
164171
?>
165172
</table>
173+
174+
<table class="tableElementError" style="display:none;width:100%;">
175+
<?php
176+
$hidden = 0;
177+
echo "<tr><td colspan=3><h4 style='margin-bottom:2px;'>Hidden modules</h4></td></tr>";
178+
foreach($this->modulesList as $category => $list)
179+
{
180+
echo "<tr><td colspan=3><span class='moduleCategoryArrow'>></span> <a class='moduleHiddenCategoryLink'>".$category."</a> (".$this->countModules[$category]['hidden'].")</td></tr>";
181+
echo "<div class='categoryWrapper' style='display:none;'>";
182+
foreach($list as $key => $module)
183+
{
184+
if(!$module->dbOk || !$module->dependenciesExist)
185+
{
186+
$hidden++ ;
187+
echo "
188+
<tr class='moduleElementError {$category}HiddenElement' style='display:none;'>
189+
<td style='width:30px;'></td>
190+
<td>
191+
<b>{$module->fullname}</b><br/>
192+
{$module->description}
193+
</td>";
194+
if(!$module->dbOk)
195+
{
196+
echo "
197+
<td style='width:300px;'>
198+
Not available with you database type
199+
</td>";
200+
}
201+
elseif(!$module->dependenciesExist)
202+
{
203+
echo "
204+
<td style='width:300px;'>
205+
Missing dependencies
206+
</td>";
207+
}
208+
echo "
209+
</tr>
210+
";
211+
}
212+
}
213+
echo "</div>";
214+
}
215+
?>
216+
</table>
217+
218+
<?php if($hidden != 0)
219+
{
220+
echo "<br/><br/><a onclick=\"$('.tableElementError').show();$(this).remove();\">Show $hidden hidden modules</a>";
221+
}?>
166222
</div>
167223
</div>
168224

modules/api/configs/module.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ version = 1.0.0
55
fullname= Web Api
66
; description
77
description=
8+
;Category
9+
category= Core
810

911
;Specify the prefix of the method exposed to the client API
1012
;For example: By setting 'midas', the method signature will be 'midas.something.get'

modules/helloworld/configs/module.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ version = 1.0.0
55
fullname= Hello World
66
; description
77
description= Test Module
8-
; if true, only an admini can enable the addon and it will be activated for everyone
9-
system = true
8+
;Category
9+
category= Demo
10+
;Dependencies
11+
dependencies= api,ldap

modules/ldap/configs/module.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ version = 1.0.0
55
fullname= Ldap
66
; description
77
description=
8-
; if true, only an admini can enable the addon and it will be activated for everyone
9-
system = true
8+
;Category
9+
category= Athentification
10+
1011

1112

1213
ldap.hostname = localhost

modules/visualize/configs/module.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ version = 1.0.0
55
fullname= Visualization
66
; description
77
description= "Preview online various types of document (Beta version)"
8+
;Category
9+
category= Visualization
810

911
useparaview = "false"
1012
userwebgl = "true"

modules/webdav/configs/module.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ version = 1.0.0
55
fullname= WebDav
66
; description
77
description= "Browse Midas files using SabreDab (Alpha version)"
8-
; if true, only an admini can enable the addon and it will be activated for everyone
9-
system = true
8+
;Category
9+
category= Core

0 commit comments

Comments
 (0)