mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-26 04:24:53 +00:00
98_todoist: new command reorderTasks/widget reorder repaired
git-svn-id: https://svn.fhem.de/fhem/trunk@20965 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
30230329c0
commit
22a885b3ae
fhem
@ -1,5 +1,6 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
# Do not insert empty lines here, update check depends on it.
|
||||
- change: 98_todoist: reorder tasks - widget reorder
|
||||
- change: 73_NUKIBridge: 74_NUKIDevice use packages
|
||||
- change: 98_Heating_Control: move to contrib
|
||||
- bugfix: 98_livetracking: DoTrigger after readingsEndUpdate, decimals
|
||||
|
@ -17,7 +17,7 @@ eval "use Date::Parse;1" or $missingModule .= "Date::Parse ";
|
||||
|
||||
#######################
|
||||
# Global variables
|
||||
my $version = "1.2.13";
|
||||
my $version = "1.3.0";
|
||||
|
||||
my $srandUsed;
|
||||
|
||||
@ -250,6 +250,111 @@ sub todoist_ErrorReadings($;$$) {
|
||||
}
|
||||
|
||||
|
||||
# reorderTasks
|
||||
sub todoist_ReorderTasks ($$) {
|
||||
my ($hash,$cmd) = @_;
|
||||
|
||||
my $name=$hash->{NAME};
|
||||
|
||||
Log3 $name,4, "$name: cmd: ".$cmd;
|
||||
|
||||
my $pwd="";
|
||||
|
||||
my $param;
|
||||
|
||||
my %commands=();
|
||||
|
||||
# some random string for UUID
|
||||
my $uuid = todoist_genUUID();
|
||||
|
||||
# JSON String start- and endpoint
|
||||
my $commandsStart="[{";
|
||||
my $commandsEnd="}]";
|
||||
|
||||
my $tType;
|
||||
|
||||
my $argsStart = "{\"items\": [";
|
||||
my $argsEnd = "]}";
|
||||
|
||||
my $args = "";
|
||||
|
||||
## if no token is needed and device is not disabled, check token and get list vom todoist
|
||||
if (!$hash->{helper}{PWD_NEEDED} && !IsDisabled($name)) {
|
||||
|
||||
## get password
|
||||
$pwd=todoist_GetPwd($hash);
|
||||
|
||||
if ($pwd) {
|
||||
Log3 $name,5, "$name: hash: ".Dumper($hash);
|
||||
|
||||
# get Task - IDs in order
|
||||
my $tids = $cmd;
|
||||
my @taskIds = split(",",$tids);
|
||||
|
||||
$tType = "item_reorder";
|
||||
|
||||
my $i=0;
|
||||
|
||||
foreach my $taskId (@taskIds) {
|
||||
$i++;
|
||||
$args .= "," if ($i>1);
|
||||
$args .= "{\"id\":".$taskId.",\"child_order\":".$i."}";
|
||||
}
|
||||
|
||||
$args = $argsStart.$args.$argsEnd;
|
||||
|
||||
Log3 $name,5, "todoist ($name): Data sent to todoist API: ".$args;
|
||||
|
||||
my $dataArr=$commandsStart.'"type":"'.$tType.'","uuid":"'.$uuid.'","args":'.$args.$commandsEnd;
|
||||
|
||||
Log3 $name,4, "todoist ($name): Data Array sent to todoist API: ".$dataArr;
|
||||
|
||||
my $data= {
|
||||
token => $pwd,
|
||||
commands => $dataArr
|
||||
};
|
||||
|
||||
Log3 $name,4, "todoist ($name): JSON sent to todoist API: ".Dumper($data);
|
||||
|
||||
my $method="POST";
|
||||
|
||||
$param = {
|
||||
url => "https://api.todoist.com/sync/v8/sync",
|
||||
data => $data,
|
||||
method => $method,
|
||||
wType => "reorder",
|
||||
timeout => 7,
|
||||
header => "Content-Type: application/x-www-form-urlencoded",
|
||||
hash => $hash,
|
||||
callback => \&todoist_HandleTaskCallback, ## call callback sub to work with the data we get
|
||||
};
|
||||
|
||||
Log3 $name,5, "todoist ($name): Param: ".Dumper($param);
|
||||
|
||||
## non-blocking access to todoist API
|
||||
InternalTimer(gettimeofday()+0.1, "HttpUtils_NonblockingGet", $param, 0);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
todoist_ErrorReadings($hash,"access token empty");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!IsDisabled($name)) {
|
||||
todoist_ErrorReadings($hash,"no access token set");
|
||||
}
|
||||
else {
|
||||
todoist_ErrorReadings($hash,"device is disabled");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
# update Task
|
||||
sub todoist_UpdateTask($$$) {
|
||||
my ($hash,$cmd, $type) = @_;
|
||||
@ -1679,6 +1784,7 @@ sub todoist_Set ($@) {
|
||||
push @sets, "getTasks:noArg";
|
||||
push @sets, "cChildProjects:noArg";
|
||||
push @sets, "getUsers:noArg";
|
||||
push @sets, "reorderTasks";
|
||||
}
|
||||
push @sets, "accessToken" if ($hash->{helper}{PWD_NEEDED});
|
||||
push @sets, "newAccessToken" if (!$hash->{helper}{PWD_NEEDED});
|
||||
@ -1753,6 +1859,14 @@ sub todoist_Set ($@) {
|
||||
}
|
||||
return "in order to complete a task, we need it's ID" if ($count==0);
|
||||
}
|
||||
elsif ($cmd eq "reorderTasks") {
|
||||
my $count=@args;
|
||||
if ($count!=0) {
|
||||
my $exp=$args[0];
|
||||
todoist_ReorderTasks ($hash,$exp);
|
||||
}
|
||||
return "in order to delete a task, we need it's ID" if ($count==0);
|
||||
}
|
||||
elsif ($cmd eq "deleteTask") {
|
||||
my $count=@args;
|
||||
if ($count!=0) {
|
||||
@ -2366,6 +2480,18 @@ sub todoist_genUUID() {
|
||||
<li>1: show order number</li>
|
||||
</ul></li>
|
||||
<br />
|
||||
<li>showParent
|
||||
<ul>
|
||||
<li>0: don't show parent_id of the task</li>
|
||||
<li>1: show parent_id (default)</li>
|
||||
</ul></li>
|
||||
<br />
|
||||
<li>showSection
|
||||
<ul>
|
||||
<li>0: don't show section_id of the task</li>
|
||||
<li>1: show section_id (default)</li>
|
||||
</ul></li>
|
||||
<br />
|
||||
<li>showChecked
|
||||
<ul>
|
||||
<li>0: don't show if a task is checked (for tasks with parent_id)</li>
|
||||
|
@ -53,15 +53,21 @@ if (typeof todoist_checkVar === 'undefined') {
|
||||
|
||||
function todoist_refreshTable(name,sortit) {
|
||||
var i=1;
|
||||
var order = "";
|
||||
$('#todoistTable_' + name).find('tr.todoist_data').each(function() {
|
||||
// order
|
||||
var tid = $(this).attr("data-line-id");
|
||||
$(this).removeClass("odd even");
|
||||
if (i%2==0) $(this).addClass("even");
|
||||
else $(this).addClass("odd");
|
||||
if (typeof sortit != 'undefined') todoist_sendCommand('set ' + name + ' updateTask ID:'+ tid + ' order="' + i + '"');
|
||||
|
||||
if (typeof sortit != 'undefined') {
|
||||
if (i>1) order = order + ",";
|
||||
order = order + tid;
|
||||
}
|
||||
i++;
|
||||
});
|
||||
if (order!="") todoist_sendCommand('set ' + name + ' reorderTasks '+ order);
|
||||
if (i!=1) $('#todoistTable_' + name).find("tr.todoist_ph").hide();
|
||||
if (i==1) $('#todoistTable_' + name).find("tr.todoist_ph").show();
|
||||
refreshInput(name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user