Skip to content

Commit

Permalink
Bump version to 0.7.0
Browse files Browse the repository at this point in the history
Changes:

- Add input to select number of shown issues to custom box dialogs.
- Bugfixes for custom box creation (displaying and preventing creation of same box)
  • Loading branch information
paulgoetze committed Sep 29, 2014
2 parents 483d379 + 5378d8f commit 31cc386
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 57 deletions.
6 changes: 5 additions & 1 deletion Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function register()
$this->description = plugin_lang_get('description'); #description text
$this->page = 'config_page'; #configure page file

$this->version = '0.6.0'; # Plugin version string
$this->version = '0.7.0'; # Plugin version string
$this->requires = array( # Plugin dependencies, array of basename => version pairs
'MantisCore' => '1.2.0', # Should always depend on an appropriate version of MantisBT
'jQuery' => '1.9.1', # jQuery for AJAX calls (including jQueryUI v1.10.3)
Expand Down Expand Up @@ -106,6 +106,10 @@ public function schema()
array('AddColumnSQL', array(plugin_table('boxes'), "
project_id I NOTNULL UNSIGNED DEFAULT 0
")
),
array('AddColumnSQL', array(plugin_table('custom_boxes'), "
issues_count I NOTNULL UNSIGNED DEFAULT 10
")
)
);
}
Expand Down
96 changes: 72 additions & 24 deletions Dashboard/api/dashboard_db_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ static function dashoard_data_exists()
$t_column_project_id = 'project_id';

$t_dashboard_table = '';

if($t_default_boxes_view){
$t_dashboard_table = plugin_table(self::TABLE_BOXES);
} else if($t_custom_boxes_view){
$t_dashboard_table = plugin_table(self::TABLE_CUSTOM_BOXES_POSITIONS);
}

$t_query = "SELECT id FROM $t_dashboard_table
WHERE user_id=".db_param() . " AND $t_column_project_id = " . db_param();
WHERE user_id=".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));

Expand Down Expand Up @@ -82,18 +85,26 @@ static function custom_box_exists($p_title = "", $p_filter_id = 0)
}

$t_current_user_id = auth_get_current_user_id();

$t_current_project_id = helper_get_current_project();

$t_column_filter_id = 'filter_id';
$t_column_user_id = 'user_id';
$t_column_title = 'title';
$t_column_project_id = 'project_id';

$t_dashboard_table = plugin_table(self::TABLE_CUSTOM_BOXES);
$t_query = "SELECT id FROM $t_dashboard_table
WHERE $t_column_user_id=" . db_param() .
" AND $t_column_title=".db_param() .
" AND $t_column_filter_id=" . db_param();
" AND $t_column_filter_id=" . db_param() .
" AND ($t_column_project_id=" . db_param() .
" OR $t_column_project_id=0)";

$t_result = db_query_bound($t_query, array($t_current_user_id, $p_title, $p_filter_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$p_title,
$p_filter_id,
$t_current_project_id));

return (db_num_rows($t_result) > 0);
}
Expand Down Expand Up @@ -627,16 +638,22 @@ static function get_positioned_custom_boxes_data()
if (self::user_has_custom_boxes()) {
$t_query = "SELECT $t_column_positions
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id = " . db_param();
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$t_current_project_id));

if ($t_result != false) {
$t_result_array = db_fetch_array($t_result);

# If there is no project-specific position, we use the global one instead.
if (!$t_result_array) {
$t_query = "SELECT $t_column_positions
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id = " . db_param();
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id = " . db_param();

$t_result = db_query_bound($t_query, array($t_current_user_id, 0));
if ($t_result)
Expand All @@ -655,9 +672,12 @@ static function get_positioned_custom_boxes_data()

$t_query = "SELECT $t_column_title, $t_column_id
FROM $t_dashboard_table
WHERE $t_column_user_id = ".db_param() . " AND $t_column_project_id IN(" . db_param() . ", 0) ";
WHERE $t_column_user_id = ".db_param() .
" AND $t_column_project_id IN(" . db_param() . ", 0) ";

$t_result = db_query_bound($t_query, array($t_current_user_id, $t_current_project_id));
$t_result = db_query_bound($t_query, array(
$t_current_user_id,
$t_current_project_id));

if ($t_result != false) {
$t_count = 0;
Expand All @@ -671,7 +691,10 @@ static function get_positioned_custom_boxes_data()
$t_column = (($t_count % 3) == 0) ? 3 : ($t_count % 3);
$t_title = $t_box['title'];
$t_id = $t_box['id'];
array_push($t_boxes, array('id' => $t_id, 'title' => $t_title, 'column' => $t_column));
array_push($t_boxes, array(
'id' => $t_id,
'title' => $t_title,
'column' => $t_column));
}
}
}
Expand Down Expand Up @@ -722,31 +745,48 @@ static function _boxes_data_from_position_string($p_string, $p_default_column =
*
* @return Array
*/
static function save_custom_box($p_title, $p_filter_id, $p_box_id = 0, $p_visible = 1, $p_project_id = null)
static function save_custom_box($p_title, $p_filter_id, $p_box_id = 0, $p_visible = 1, $p_project_id = null, $p_issues_count)
{
$t_result = "";
$t_saved = false;

$t_current_user_id = auth_get_current_user_id();
$t_current_project_id = (is_null($p_project_id) ? helper_get_current_project() : $p_project_id);

$t_max_count = DashboardPrintAPI::DEFAULT_ISSUES_COUNT;

$t_issues_count = $p_issues_count;

if ($p_issues_count > $t_max_count) {
$t_issues_count = $t_max_count;
} elseif ($p_issues_count < 1) {
$t_issues_count = 1;
}

$t_dashboard_table = plugin_table(self::TABLE_CUSTOM_BOXES);

$t_column_id = 'id';
$t_column_user_id = 'user_id';
$t_column_filter_id = 'filter_id';
$t_column_project_id = 'project_id';
$t_column_title = 'title';
$t_column_visible= 'visible';

$t_column_visible = 'visible';
$t_column_issues_count = 'issues_count';

# box does not exist so far for current user
if ($p_box_id == 0 && $p_filter_id != null && !self::custom_box_exists($p_title . $t_column_project_id, $p_filter_id)) {
if ($p_box_id == 0 && $p_filter_id != null && !self::custom_box_exists($p_title, $p_filter_id)) {
# save box
$t_query = "INSERT INTO $t_dashboard_table
($t_column_user_id, $t_column_filter_id, $t_column_title, $t_column_project_id)
VALUES (" . db_param() . ',' . db_param() . ','. db_param() . ", " . db_param() . ")";

$t_query_result = db_query_bound($t_query, array($t_current_user_id, $p_filter_id, $p_title, $t_current_project_id));
$t_query = "INSERT INTO $t_dashboard_table " .
"($t_column_user_id, $t_column_filter_id, $t_column_title," .
" $t_column_project_id, $t_column_issues_count)" .
" VALUES (" . db_param() . ',' . db_param() . ','. db_param() .
", " . db_param() . ", " . db_param() . ")";

$t_query_result = db_query_bound($t_query, array(
$t_current_user_id,
$p_filter_id,
$p_title,
$t_current_project_id,
$t_issues_count));

if ($t_query_result != false) {
$t_saved = true;
Expand Down Expand Up @@ -787,13 +827,21 @@ static function save_custom_box($p_title, $p_filter_id, $p_box_id = 0, $p_visibl
}
}
} else if ($p_box_id != 0 && $p_filter_id != null && self::custom_box_exists_with_id($p_box_id)) {
#box exists for current user and should be changed
# box exists for current user and should be changed
# update box
$t_query = "UPDATE $t_dashboard_table
SET $t_column_filter_id=".db_param().", $t_column_title=" . db_param() . ", $t_column_visible=" . db_param() .
SET $t_column_filter_id=".db_param().", $t_column_title=" . db_param() .
", $t_column_visible=" . db_param() . ", $t_column_issues_count=" . db_param() .
" WHERE $t_column_user_id=".db_param() . " AND $t_column_id=". db_param();

$t_query_result = db_query_bound($t_query, array($p_filter_id, $p_title, $p_visible, $t_current_user_id, $p_box_id));
$t_query_result = db_query_bound($t_query, array(
$p_filter_id,
$p_title,
$p_visible,
$t_issues_count,
$t_current_user_id,
$p_box_id));

$t_updated = (db_num_rows($t_query_result) > 0 || $t_query_result != false);

DashboardDbAPI::set_custom_box_visibility($p_box_id, $p_visible);
Expand All @@ -818,7 +866,7 @@ static function save_custom_box($p_title, $p_filter_id, $p_box_id = 0, $p_visibl
$t_result = DashboardPrintAPI::get_already_available_box_message_html($p_title, $p_filter_id);
}

return array('saved' => $t_saved, 'html' => $t_result);
return array('saved' => $t_saved, 'html' => $t_result, 'box_id' => $t_box_id);
}

/**
Expand Down
54 changes: 39 additions & 15 deletions Dashboard/api/dashboard_print_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DashboardPrintAPI
const ICON_DELETE = "delete.png";
const ICON_ADD = "plus.png";

const DEFAULT_ISSUES_COUNT = 10;

/**
* Gets the url links parameters for a current user
*
Expand Down Expand Up @@ -861,6 +863,7 @@ static function get_custom_box_html($p_box)
$t_box_title = $p_box['title'];
$t_visible = $p_box['visible'];
$t_box_id = $p_box['id'];
$t_issues_count = $p_box['issues_count'];

$f_page_number = gpc_get_int('page_number', 1);
$t_per_page = config_get('my_view_bug_count');
Expand Down Expand Up @@ -901,12 +904,15 @@ static function get_custom_box_html($p_box)
$t_rows = filter_get_bug_rows($f_page_number, $t_per_page, $t_page_count, $t_bug_count,
$t_unserialized_filter, helper_get_current_project());

$t_array = self::get_custom_filtered_projects_html($t_filter, $t_rows);
$t_original_count = count($t_rows);
$t_count = ($t_original_count <= $t_issues_count ? $t_original_count : $t_issues_count);

$t_array = self::get_custom_filtered_projects_html($t_filter, $t_rows, $t_count);
$t_projects_html = $t_array['projects'];

if (count($t_rows) > 0) {
if ($t_count > 0) {
$v_start = $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] * ($f_page_number - 1) + 1;
$v_end = $v_start + count($t_rows) - 1;
$v_end = $t_count;
} else {
$v_start = 0;
$v_end = 0;
Expand Down Expand Up @@ -939,21 +945,20 @@ static function get_custom_box_html($p_box)
*
* @return Array
*/
static function get_custom_filtered_projects_html($p_filter, $p_rows)
static function get_custom_filtered_projects_html($p_filter, $p_rows, $p_count = self::DEFAULT_ISSUES_COUNT)
{
$t_rows = $p_rows;
$t_filter = $p_filter;

$t_update_bug_threshold = config_get('update_bug_threshold');
$t_icon_path = config_get('icon_path');

# print project table rows
$t_html = "";

# Loop over bug rows and create $v_* variables
$t_count = count($t_rows);
$t_original_count = count($t_rows);
$t_count = ($t_original_count <= $p_count ? $t_original_count : $p_count);

for ($i = 0;$i < $t_count; $i++) {
for ($i = 0;$i < $t_count; $i++) {
$t_bug = $t_rows[$i];

$t_summary = string_display_line_links($t_bug->summary);
Expand Down Expand Up @@ -1045,9 +1050,9 @@ static function get_custom_filtered_projects_html($p_filter, $p_rows)
}

# create projects count html
if (count($t_rows) > 0) {
if ($t_count > 0) {
$v_start = $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] * ($f_page_number - 1) + 1;
$v_end = $v_start + count($t_rows) - 1;
$v_end = $t_count;
} else {
$v_start = 0;
$v_end = 0;
Expand Down Expand Up @@ -1328,9 +1333,11 @@ static function get_form_html($p_type, $p_box_id, $p_icon, $p_title, $p_text)
$t_box = DashboardDbAPI::get_custom_box_data($p_box_id);
$t_box_title = $t_box['title'];
$t_box_filter_id = $t_box['filter_id'];
$t_issues_count = $t_box['issues_count'];

$t_html .= '<input type="hidden" name="orig_box_title" value="'. $t_box_title.'">';
$t_html .= '<input type="hidden" name="orig_box_filter_id" value="'. $t_box_filter_id.'">';
$t_html .= '<input type="hidden" name="orig_issues_count" value="' .$t_issues_count . '">';
}

$t_html .= "</form>";
Expand Down Expand Up @@ -1549,6 +1556,14 @@ static function print_create_new_box_dialog()
# filter select
self::print_custom_filter_select_box("create");

# number of issues select
echo '<div class="dialog-form-field">';
$t_issues_count = plugin_lang_get('issues_count');
echo "<label class='dashboard-label' for='issue-number'>$t_issues_count</label>";
echo "<input id='create-box-issues-count' name='issues-count' type='number' " .
"min='1' max='10' value='10' title='$t_issues_count' class='dashboard-input'>";
echo '</div>';

echo "</form>";
echo '</div>';
}
Expand Down Expand Up @@ -1578,21 +1593,30 @@ static function print_create_edit_box_dialog()
echo '<div class="dialog-form-field">';
$t_box_title = plugin_lang_get('box_title');
echo "<label class='dashboard-label' for='box-title'>$t_box_title</label>";
echo "<input id='edit-box-title' name='box-title' type='text' title='$t_box_title' class='dashboard-input'>";
echo "<input id='edit-box-title' name='box-title' type='text' " .
"title='$t_box_title' class='dashboard-input'>";
echo '</div>';

# filter select
self::print_custom_filter_select_box("edit");

# number of issues select
echo '<div class="dialog-form-field">';
$t_issues_count = plugin_lang_get('issues_count');
echo "<label class='dashboard-label' for='issue-number'>$t_issues_count</label>";
echo "<input id='edit-box-issues-count' name='issues-count' type='number' " .
"min='1' max='10' value='10' title='$t_issues_count' class='dashboard-input'>";
echo '</div>';

# visibility checkbox
echo '<div class="dialog-form-field">';
$t_text_show_box = plugin_lang_get('show_box');
echo "<label class='dashboard-label' for='box-visible'>$t_text_show_box</label>";
#self::print_icon(self::ICON_LINK_SHOW);
echo "<input id='edit-box-visible-checkbox' name='box-visible' type='checkbox' title='$t_text_show_box' class='dashboard-input' checked>";
echo "<input id='edit-box-visible-checkbox' name='box-visible' type='checkbox' " .
"title='$t_text_show_box' class='dashboard-input' checked>";
echo '</div>';

# visibility checkbox
# delete link
echo '<div id="delete-box-link" class="dialog-form-field">';
self::print_icon_link(self::ICON_LINK_DELETE);
echo '</div>';
Expand Down
Loading

0 comments on commit 31cc386

Please sign in to comment.