summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-10-21 14:38:22 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-10-31 11:51:20 (GMT)
commit5c4530245713dab4d7ed38f273dacc31f4699365 (patch)
tree209af82501f638970618b07f2bd85fd19a05a918
parentee52d6e52f1c85c35f85faebb73b05b0c8210741 (diff)
downloadroundcubemail-plugins-kolab-5c4530245713dab4d7ed38f273dacc31f4699365.tar.gz
Refresh tasks list periodically with changes from the server (#2369)
-rw-r--r--plugins/tasklist/drivers/database/tasklist_database_driver.php6
-rw-r--r--plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php6
-rw-r--r--plugins/tasklist/tasklist.js14
-rw-r--r--plugins/tasklist/tasklist.php36
4 files changed, 58 insertions, 4 deletions
diff --git a/plugins/tasklist/drivers/database/tasklist_database_driver.php b/plugins/tasklist/drivers/database/tasklist_database_driver.php
index 8ad776a..3c5ad38 100644
--- a/plugins/tasklist/drivers/database/tasklist_database_driver.php
+++ b/plugins/tasklist/drivers/database/tasklist_database_driver.php
@@ -286,7 +286,7 @@ class tasklist_database_driver extends tasklist_driver
if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE)
$sql_add .= ' AND complete=1';
- else // don't show complete tasks by default
+ else if (empty($filter['since'])) // don't show complete tasks by default
$sql_add .= ' AND complete<1';
if ($filter['mask'] & tasklist::FILTER_MASK_FLAGGED)
@@ -301,6 +301,10 @@ class tasklist_database_driver extends tasklist_driver
$sql_add = 'AND (' . join(' OR ', $sql_query) . ')';
}
+ if ($filter['since'] && is_numeric($filter['since'])) {
+ $sql_add .= ' AND changed >= ' . $this->rc->db->quote(date('Y-m-d H:i:s', $filter['since']));
+ }
+
$tasks = array();
if (!empty($list_ids)) {
$result = $this->rc->db->query(sprintf(
diff --git a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
index c630a41..fd3e5c3 100644
--- a/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
+++ b/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
@@ -371,7 +371,7 @@ class tasklist_kolab_driver extends tasklist_driver
$query = array();
if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE)
$query[] = array('tags','~','x-complete');
- else
+ else if (empty($filter['since']))
$query[] = array('tags','!~','x-complete');
// full text search (only works with cache enabled)
@@ -382,6 +382,10 @@ class tasklist_kolab_driver extends tasklist_driver
}
}
+ if ($filter['since']) {
+ $query[] = array('changed', '>=', $filter['since']);
+ }
+
foreach ($lists as $list_id) {
$folder = $this->folders[$list_id];
foreach ((array)$folder->select($query) as $record) {
diff --git a/plugins/tasklist/tasklist.js b/plugins/tasklist/tasklist.js
index 19db0fe..631494c 100644
--- a/plugins/tasklist/tasklist.js
+++ b/plugins/tasklist/tasklist.js
@@ -132,6 +132,7 @@ function rcube_tasklist_ui(settings)
rcmail.addEventListener('plugin.destroy_tasklist', destroy_list);
rcmail.addEventListener('plugin.reload_data', function(){ list_tasks(null); });
rcmail.addEventListener('plugin.unlock_saving', unlock_saving);
+ rcmail.addEventListener('requestrefresh', before_refresh);
// start loading tasks
fetch_counts();
@@ -439,6 +440,19 @@ function rcube_tasklist_ui(settings)
}
/**
+ * Modify query parameters for refresh requests
+ */
+ function before_refresh(query)
+ {
+ query.filter = filtermask == FILTER_MASK_COMPLETE ? FILTER_MASK_COMPLETE : FILTER_MASK_ALL;
+ query.lists = active_lists().join(',');
+ if (search_query)
+ query.q = search_query;
+
+ return query;
+ }
+
+ /**
* Callback if task data from server is ready
*/
function data_ready(response)
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index 9d5544c..e6b5d1c 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -90,6 +90,7 @@ class tasklist extends rcube_plugin
$this->register_action('mail2task', array($this, 'mail_message2task'));
$this->register_action('get-attachment', array($this, 'attachment_get'));
$this->register_action('upload', array($this, 'attachment_upload'));
+ $this->add_hook('refresh', array($this, 'refresh'));
$this->collapsed_tasks = array_filter(explode(',', $this->rc->config->get('tasklist_collapsed_tasks', '')));
}
@@ -540,8 +541,17 @@ class tasklist extends rcube_plugin
}
*/
+ $data = $this->tasks_data($this->driver->list_tasks($filter, $lists), $f, $tags);
+ $this->rc->output->command('plugin.data_ready', array('filter' => $f, 'lists' => $lists, 'search' => $search, 'data' => $data, 'tags' => array_values(array_unique($tags))));
+ }
+
+ /**
+ * Prepare and sort the given task records to be sent to the client
+ */
+ private function tasks_data($records, $f, &$tags)
+ {
$data = $tags = $this->task_tree = $this->task_titles = array();
- foreach ($this->driver->list_tasks($filter, $lists) as $rec) {
+ foreach ($records as $rec) {
if ($rec['parent_id']) {
$this->task_tree[$rec['id']] = $rec['parent_id'];
}
@@ -558,7 +568,7 @@ class tasklist extends rcube_plugin
array_walk($data, array($this, 'task_walk_tree'));
usort($data, array($this, 'task_sort_cmp'));
- $this->rc->output->command('plugin.data_ready', array('filter' => $f, 'lists' => $lists, 'search' => $search, 'data' => $data, 'tags' => array_values(array_unique($tags))));
+ return $data;
}
/**
@@ -724,6 +734,28 @@ class tasklist extends rcube_plugin
exit;
}
+ /**
+ * Handler for keep-alive requests
+ * This will check for updated data in active lists and sync them to the client
+ */
+ public function refresh($attr)
+ {
+ $filter = array(
+ 'since' => $attr['last'],
+ 'search' => get_input_value('q', RCUBE_INPUT_GPC),
+ 'mask' => intval(get_input_value('filter', RCUBE_INPUT_GPC)) & self::FILTER_MASK_COMPLETE,
+ );
+ $lists = get_input_value('lists', RCUBE_INPUT_GPC);;
+
+ $updates = $this->driver->list_tasks($filter, $lists);
+ if (!empty($updates)) {
+ $this->rc->output->command('plugin.refresh_task', $this->tasks_data($updates, 255, $tags));
+
+ // update counts
+ $counts = $this->driver->count_tasks($lists);
+ $this->rc->output->command('plugin.update_counts', $counts);
+ }
+ }
/**
* Handler for pending_alarms plugin hook triggered by the calendar module on keep-alive requests.