Permalink
Browse files

This patch add the notion of groups to the project

A group is just a container of dashboards.
This new notion introduce the possibility of filter the dashboards
by group, linking a dashboard with the others in the group, etc...
Those features will be commited later.
In this commit :
	- Add a group
	- Edit a group
	- Delete a group
There is also the script that create the new sql table and, if the base
is already created, a script that add the column "group_id"
in the dashboard table.
  • Loading branch information...
Florent Couffe
Florent Couffe committed May 31, 2013
1 parent 95c7c5f commit 580c7d86788feb6976138748099393278c7818db
@@ -30,6 +30,7 @@ CREATE TABLE `dashboards` (
`graph_height` int(11) NOT NULL DEFAULT '300',
`graph_width` int(11) NOT NULL DEFAULT '300',
`refresh_rate` int(11) NOT NULL DEFAULT 0,
`group_id` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`dashboard_id`),
UNIQUE KEY `user_id` (`user_id`,`name`)
) CHARSET=utf8;
@@ -105,3 +106,12 @@ CREATE TABLE `subscriptions` (
KEY `check_id` (`check_id`),
KEY `user_id` (`user_id`)
) CHARSET=utf8;
CREATE TABLE `groups` (
`group_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`description` varchar(1000) NOT NULL,
PRIMARY KEY (`group_id`),
KEY `name` (`name`)
) CHARSET=utf8;
INSERT INTO groups VALUES (1, 'Default group', 'This group is the default group. It can\'t be deleted nor edited.');
@@ -0,0 +1,90 @@
<?php
include 'inc/init.php';
fAuthorization::requireLoggedIn();
fRequest::overrideAction();
$action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete'));
$breadcrumbs[] = array('name' => 'Groups', 'url' => Group::makeURL('list'),'active'=> true);
$group_id = fRequest::get('group_id', 'integer');
if ('delete' == $action) {
if ($group_id == $GLOBALS['DEFAULT_GROUP_ID']) {
fURL::redirect(Group::makeUrl('list'));
} else {
$class_name = 'Group';
try {
$obj = new Group($group_id);
$delete_text = 'Are you sure you want to delete the group : <strong>' . $obj->getName() . '</strong>?';
if (fRequest::isPost()) {
fRequest::validateCSRFToken(fRequest::get('token'));
$obj->delete();
fMessaging::create('success', "/".Group::makeUrl('list'),
'The group "' . $obj->getName() . '" was successfully deleted');
fURL::redirect(Group::makeUrl('list'));
}
} catch (fNotFoundException $e) {
fMessaging::create('error', "/".Group::makeUrl('list'),
'The group requested could not be found');
fURL::redirect(Group::makeUrl('list'));
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/delete.php';
}
// --------------------------------- //
} elseif ('edit' == $action) {
if ($group_id == $GLOBALS['DEFAULT_GROUP_ID']) {
fURL::redirect(Group::makeUrl('list'));
} else {
try {
$group = new Group($group_id);
if (fRequest::isPost()) {
$group->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$group->store();
fMessaging::create('success', "/".Group::makeURL("list"),
'The Group ' . $group->getName(). ' was successfully updated');
fURL::redirect(Group::makeUrl('list'));
}
} catch (fNotFoundException $e) {
fMessaging::create('error', "/".Group::makeUrl('list'),
'The Group requested, ' . fHTML::encode($group_id) . ', could not be found');
fURL::redirect(Group::makeUrl('list'));
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
include VIEW_PATH . '/add_edit_group.php';
}
// --------------------------------- //
} elseif ('add' == $action) {
$group = new Group();
if (fRequest::isPost()) {
try {
$group->populate();
fRequest::validateCSRFToken(fRequest::get('token'));
$group->store();
$group_url = fURL::redirect(Group::makeUrl('list'));
fMessaging::create('affected', "/".$group_url, $group->getName());
fMessaging::create('success', "/".$group_url,
'The Group ' . $group->getName() . ' was successfully created');
fURL::redirect($group_url);
echo "";
} catch (fExpectedException $e) {
fMessaging::create('error', fURL::get(), $e->getMessage());
}
}
include VIEW_PATH . '/add_edit_group.php';
} else {
$groups = Group::findAll();
include VIEW_PATH . '/list_groups.php';
}
@@ -0,0 +1,44 @@
<?
class Group extends fActiveRecord
{
protected function configure()
{
}
/**
* Returns all meetups on the system
*
* @return fRecordSet An object containing all meetups
*/
static function findAll($group_id=NULL)
{
if (!is_null($group_id) && is_numeric($group_id)){
$filter = array('group_id=' => $group_id);
} else {
$filter = array();
}
return fRecordSet::build(
__CLASS__,
$filter,
array()
);
}
static public function makeURL($type, $obj=NULL)
{
switch ($type)
{
case 'list':
return 'groups.php';
case 'add':
return 'groups.php?action=add';
case 'edit':
return 'groups.php?action=edit&group_id=' . (int)$obj->getGroupId();
case 'delete':
return 'groups.php?action=delete&group_id=' . (int)$obj->getGroupId();
case 'list':
return 'groups.php?action=list&group_id=' . (int)$obj->getGroupId();
}
}
}
@@ -40,6 +40,9 @@
// Number of elements per page (checks, alerts, subscriptions)
$GLOBALS['PAGE_SIZE'] = 15;
// Global variable for groups
$GLOBALS['DEFAULT_GROUP_ID'] = 1;
// Locale settings
$GLOBALS['TIMEZONE'] = 'America/New_York';
@@ -79,4 +79,5 @@
include($classes . 'Dashboard.php');
include($classes . 'Line.php');
include($classes . 'Graph.php');
include($classes . 'Group.php');
include($classes . 'Setting.php');
@@ -0,0 +1,46 @@
<?
$page_title = ($action == 'add' ? 'Add a Group' : 'Edit Group');
$tmpl->set('title', $page_title);
$breadcrumbs[] = array('name' => $page_title, 'url' => '?'.fURL::getQueryString(),'active'=> true);
$tmpl->set('breadcrumbs',$breadcrumbs);
$tmpl->place('header');
$query_string = '';
if (isset($group_id)) {
$query_string = "&group_id=$group_id";
}
?>
<div class="row">
<div class="span6">
<form action="?action=<?=$action.$query_string; ?>" method="post">
<div class="main" id="main">
<fieldset>
<div class="clearfix">
<label for="group-name">Name<em>*</em></label>
<div class="input">
<input id="group-name" class="span3" type="text" size="30" name="name" value="<?=$group->encodeName(); ?>" />
</div>
</div><!-- /clearfix -->
<div class="clearfix">
<label for="group-description">Description<em>*</em></label>
<div class="input">
<textarea class="span3" id="group-description" name="description" rows="3"><?=$group->encodeDescription(); ?></textarea>
</div>
</div>
<div class="actions">
<input class="btn primary" type="submit" value="Save" />
<input class="btn" type="submit" name="action::delete" value="Delete" />
<div class="required"><em>*</em> Required field</div>
<input type="hidden" name="token" value="<?=fRequest::generateCSRFToken(); ?>" />
</div>
</fieldset>
</div>
</form>
</div>
<div class="span10">
</div>
</div>
</div>
<?php
$tmpl->place('footer');
@@ -85,7 +85,7 @@
<?
$current_url = '?'.fURL::getQueryString();
echo '<li' . ($current_url == '' ? ' class="active"' : '') . '><a href="index.php">Alerts</a></li>'. "\n";
echo '<li' . (fActiveRecord::is_menu_active('index') ? ' class="active"' : '') . '><a href="index.php">Alerts</a></li>'. "\n";
$threshold_check_list = Check::makeURL('list', 'threshold');
echo '<li' . (fActiveRecord::is_menu_active('check','type=threshold') ? ' class="active"' : '') . '><a href="' . $threshold_check_list . '" >Threshold Checks</a></li>' . "\n";
$predictive_check_list = Check::makeURL('list', 'predictive');
@@ -94,6 +94,8 @@
echo '<li' . (fActiveRecord::is_menu_active('subscription') ? ' class="active"' : '') .'><a href="' . $subscription_list . '" >Subscriptions</a></li>' . "\n";
$dashboard_list = Dashboard::makeURL('list');
echo '<li' . (fActiveRecord::is_menu_active('dashboard') ? ' class="active"' : '') . '><a href="' . $dashboard_list . '">Dashboards</a></li>';
$group_list = Group::makeURL('list');
echo '<li' . (fActiveRecord::is_menu_active('group') ? ' class="active"' : '') . '><a href="' . $group_list . '">Groups</a></li>';
$setting_list = Setting::makeURL('list','user');
echo '<li' . (fActiveRecord::is_menu_active('setting','type=user') ? ' class="active"' : '') . '><a href="' . $setting_list . '" >Settings</a></li>' . "\n";
if (fAuthorization::checkAuthLevel('admin')) {
@@ -0,0 +1,48 @@
<?php
$tmpl->set('title', 'Tattle : Self Service Alerts based on Graphite metrics');
$tmpl->set('breadcrumbs',$breadcrumbs);
$tmpl->place('header');
try {
$groups->tossIfEmpty();
$affected = fMessaging::retrieve('affected', fURL::get());
?><a href="<?=Group::makeURL('add'); ?>" class="btn primary">Add Group</a>
<table class="zebra-striped">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$first = TRUE;
foreach ($groups as $group) {
?>
<tr>
<td><?=$group->prepareName(); ?></td>
<td><?=$group->prepareDescription(); ?></td>
<td>
<?php
if ($group->getGroupId() != $GLOBALS['DEFAULT_GROUP_ID']) {
?>
<a href="<?=Group::makeURL('edit', $group); ?>">Edit</a> |
<a href="<?=Group::makeURL('delete', $group); ?>">Delete</a>
<?php
}
?>
</td>
</tr>
<?php } ?>
</tbody></table>
<?
} catch (fEmptySetException $e) {
?>
<p class="info">There are currently no Tattle Groups available. <a href="<?=Group::makeURL('add'); ?>">Add one now</a></p>
<?php
}
?>
</div>
<?php $tmpl->place('footer') ?>
@@ -0,0 +1,4 @@
ALTER TABLE eagle_tattle.dashboards ADD COLUMN `group_id` int(11) NOT NULL DEFAULT '1';
INSERT INTO groups VALUES (1, 'Default group', 'This group is the default group. It can\'t be deleted nor edited.');

0 comments on commit 580c7d8

Please sign in to comment.