diff --git a/doc/developper/Doxyfile b/doc/developper/Doxyfile index 63ef35284..3571e04c5 100644 --- a/doc/developper/Doxyfile +++ b/doc/developper/Doxyfile @@ -673,7 +673,6 @@ EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = a?.php \ b?.php \ ?.php \ - test*.php \ calendar-*.js \ richtext.js \ builder.js \ diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 38e2332f4..c77c74cb3 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -46,6 +46,7 @@ require_once NOALYSS_INCLUDE.'/lib/ac_common.php'; require_once NOALYSS_INCLUDE.'/class/user.class.php'; require_once NOALYSS_INCLUDE.'/lib/http_input.class.php'; require_once NOALYSS_INCLUDE.'/lib/icon_action.class.php'; +require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php'; $http=new HttpInput(); mb_internal_encoding("UTF-8"); @@ -86,6 +87,16 @@ else $g_user = new User($cn); $g_user->check(true); } + +// For progress bar, for saving time , we check and answer directly +if ($op == "progressBar") { + $task_id=$http->request("task_id"); + $task=new Progress_Bar($task_id); + $task->answer(); + return; +} + + $html = var_export($_REQUEST, true); set_language(); if ( LOGINPUT) diff --git a/html/js/scripts.js b/html/js/scripts.js index 633427941..a212591b9 100644 --- a/html/js/scripts.js +++ b/html/js/scripts.js @@ -3394,3 +3394,70 @@ Periode.filter_exercice=function (p_table_id) { } }; + +// keep track of progress bar +var progressBar = []; +// idx of progress bar +var progressIdx = 0; + +/** + * Start the progress bar + * @param {string} p_taskid id to monitor + * @param {int} p_dossier + */ +function progress_bar_start(p_taskid) +{ + try { + progressIdx++; + // Create a div + add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '0'}); + // Check status every sec. + progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000); + } catch (e) { + console.error(e.message); + } +} + +/** + * Check every second the status + * @param {integer} p_idx idx of progressbar + * @param {string} p_taskid id to monitor + */ +function progress_bar_check(p_idx, p_taskid) +{ + try { + + new Ajax.Request("ajax_misc.php", { + parameters: {gDossier: 0, task_id: p_taskid,op:"progressBar"}, + onSuccess: function (req) { + try + { + var answer=req.responseText.evalJSON(); + + var progressValue = $('progressValue'); + var progress = parseFloat(progressValue.innerHTML); + if ( answer.value <= progress ) { + return; + } + + progressValue.innerHTML = answer.value; + progressValue.setStyle("width:" + answer.value + "%"); + if (answer.value== 100) { + clearInterval(progressBar[p_idx]); + progressValue.innerHTML="Success"; + Effect.BlindUp("progressDiv"+progressIdx,{duration:1.0,scaleContent:false}) + } + } catch (e) { + clearInterval(progressBar[p_idx]); + document.getElementById("progressValue").innerHTML=req.responseText; + console.error(e.message); + } + } + }); + } catch (e) { + clearInterval(progressBar[p_idx]); + console.error(e.message); + } +} + + diff --git a/html/style-light.css b/html/style-light.css index 8875abe15..7e291e8bb 100644 --- a/html/style-light.css +++ b/html/style-light.css @@ -2200,4 +2200,30 @@ div.bxbutton .icon:hover { background-color: white; color: blue; +} +/** + * progressBar + */ +div.progressbar { + width:300px; + height:30px; + position:fixed; + top:5px; + left:40%; + background-color: white; + color:blue; + z-index:800; + border-color: #596a72; + border-width: 1px; + border-style: solid; +} +#progressValue { + display:block; + width: 0px; + height: 100%; + margin:0px; + padding: 0px; + background-color:darkblue; + color:antiquewhite; + font-weight: bolder; } \ No newline at end of file diff --git a/html/style-r692.css b/html/style-r692.css index 5e2efd9b8..ad8b18d3b 100644 --- a/html/style-r692.css +++ b/html/style-r692.css @@ -2227,4 +2227,30 @@ div.bxbutton .icon:hover { background-color: white; color: blue; +} +/** + * progressBar + */ +div.progressbar { + width:300px; + height:30px; + position:fixed; + top:5px; + left:40%; + background-color: white; + color:blue; + z-index:800; + border-color: #596a72; + border-width: 1px; + border-style: solid; +} +#progressValue { + display:block; + width: 0px; + height: 100%; + margin:0px; + padding: 0px; + background-color:darkblue; + color:antiquewhite; + font-weight: bolder; } \ No newline at end of file diff --git a/html/test.php b/html/test.php index d5a467e75..e45ddc264 100644 --- a/html/test.php +++ b/html/test.php @@ -23,7 +23,7 @@ * It is only a quick and dirty testing. You should use a tool as PHPUNIT for the unit testing * * - first do not forget to create the authorized_debug file in the html folder - * - secund the test must adapted to this page : if you do a post (or get) from a test, you won't get any result + * - secund the test must be adapted to this page : if you do a post (or get) from a test, you won't get any result * if the $_REQUEST[test_select] is not set, so set it . */ diff --git a/include/lib/progress_bar.class.php b/include/lib/progress_bar.class.php new file mode 100644 index 000000000..04e6f2416 --- /dev/null +++ b/include/lib/progress_bar.class.php @@ -0,0 +1,115 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +/** + * @file + * @brief Manage the progress bar and display it with javascript + * + */ + +/** + * @brief Use one db for tracking progress bar value, the task id must be unique + * and let you follow the progress of a task. + * how it works : when calling an ajax , you have to create the task id and start + * the monitoring of it (js function = progress_bar_start). + * In your php script called by ajax you call Progress_Bar->set_value to show + * the progress. The timer created by progress_bar_start will check regularly the + * progress in the db. + * The ajax parameter for following the task is task_id + * + *@note you have to use session_write_close(); in the ajax file , otherwise, + * the function progress_bar_check will be blocked and won't update the progress + * bar + * + *@see progress_bar_start + *@see progress_bar_check + * + * + */ +class Progress_Bar +{ + private $db ; //!< database connexion + private $task_id ; //! task id (progress_bar.p_id) + private $value; //!< value of progress (between 0 & 100) + /** + * @example progress-bar.test.php test of this class + * @param type $p_task_id + */ + function __construct($p_task_id) + { + $this->db=new Database(); + $this->task_id=$p_task_id; + // Find value from db + $this->value = $this->db->exec_sql("select p_value from progress where p_id=$1", + [$p_task_id]); + + // if task doesn't exists, create it + if ( $this->db->size()==0) + { + $this->value=0; + $this->db->exec_sql("insert into progress(p_id,p_value) values ($1,0)", + [$p_task_id]); + } + } + /** + * Store the progress value into the db + * @param integer $p_value value of the progress between 0 & 100 + *@exceptions code 1005 - if p_value is not in between 0 & 100 + */ + function set_value($p_value) + { + if ( $p_value > 100 || $p_value < 0 ) { + throw new Exception("Invalid value",EXC_PARAM_VALUE); + } + $this->value=$p_value; + $this->db->start(); + $this->db->exec_sql("update progress set p_value=$1 where p_id=$2", + [$this->value,$this->task_id]); + $this->db->commit(); + } + /** + * Get the progress value from db + * @return integer between 0 & 100 + */ + function get_value() + { + $this->value = $this->db->get_value("select p_value from progress where p_id=$1", + [$this->task_id]); + + return $this->value; + } + /** + * Json answer of the task progressing + * if value is equal or greater than 100 , delete the row + * @return type + */ + function answer() + { + $this->get_value(); + + header('Content-Type: application/json'); + echo json_encode(["value"=>$this->value]); + if ($this->value>=100) { + $this->db->exec_sql("delete from progress where p_id=$1",[$this->task_id]) + } + return; + } +} diff --git a/scenario/progress-bar.test.php b/scenario/progress-bar.test.php new file mode 100644 index 000000000..f7fdb68e6 --- /dev/null +++ b/scenario/progress-bar.test.php @@ -0,0 +1,65 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/** + * @file + * @brief Example about Progress_Bar, the most important is the + * session_write_close in the ajax script to unblock the PHP script. + * Each time a step is reached , you use Progress_Bar->set_value + * @see Progress_Bar + * @see progress_bar_start + * @see progress_bar_check + */ +require_once NOALYSS_INCLUDE.'/lib/progress_bar.class.php'; + +$ajax=$http->request("TestAjaxFile","string","no"); + +// $ajax != no if we are in ajax mode +if ( $ajax != "no") +{ + session_write_close(); + $task=$http->request("task_id"); + $progress=new Progress_Bar($task); + sleep(1); + $progress->set_value(10); + sleep(2); + $progress->set_value(20); + sleep(1); + $progress->set_value(90); + sleep(2); + $progress->set_value(91); + sleep(5); + $progress->set_value(95); + sleep(6); + $progress->set_value(100); + return; +} +?> + + + \ No newline at end of file diff --git a/sql/upgrade.sql b/sql/upgrade.sql index eebd1343d..21af50a23 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -9,6 +9,14 @@ delete from theme where the_filestyle in ('style-mandarine.css','style-mobile.cs update user_global_pref set parameter_value='style-classic7.css' where parameter_value in ('style-mandarine.css','style-mobile.css'); -- add constraint alter table jnt_use_dos add CONSTRAINT use_id_dos_id_uniq UNIQUE (use_id,dos_id); +-- create table to check progress +create table progress +( + p_id varchar(16) primary key, + p_value integer not null , + p_created timestamp default now() +); + */ create sequence tmp_pcmn_id_seq; ALTER TABLE tmp_pcmn ADD COLUMN id bigint; @@ -107,3 +115,5 @@ ALTER TABLE tags ADD CONSTRAINT tags_check CHECK (t_actif in ('N','Y')) ; alter table tags alter t_actif set default 'Y'; COMMENT ON COLUMN tags.t_actif is 'Y if the tag is activate and can be used '; + +-- in repo