mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-74652 Time tracking features. Serialization problems. Correct counting time for jira. And fix for empty comment.
This commit is contained in:
+11
-3
@@ -4,6 +4,7 @@ import com.atlassian.connector.commons.jira.soap.axis.JiraSoapService;
|
||||
import com.atlassian.connector.commons.jira.soap.axis.JiraSoapServiceServiceLocator;
|
||||
import com.atlassian.theplugin.jira.api.JIRAIssueBean;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.Task;
|
||||
import com.intellij.tasks.TaskRepository;
|
||||
@@ -215,18 +216,25 @@ public class JiraRepository extends BaseRepositoryImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpent, final String comment) throws Exception {
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpentInMinutes, final String comment) throws Exception {
|
||||
final HttpClient client = login();
|
||||
checkVersion(client);
|
||||
PostMethod method = new PostMethod(getUrl() + "/rest/api/2/issue/" + task.getId() + "/worklog");
|
||||
method.setRequestEntity(new StringRequestEntity("{\"timeSpentSeconds\" : " + String.valueOf(timeSpent * 60) +
|
||||
", \"comment\" : " + comment + "}", "application/json", "UTF-8"));
|
||||
method.setRequestEntity(
|
||||
new StringRequestEntity("{\"timeSpentSeconds\" : " + String.valueOf(calculateTimeSpent(timeSpentInMinutes)) +
|
||||
(StringUtil.isNotEmpty(comment) ? ", \"comment\" : " + comment : "")
|
||||
+ " }", "application/json", "UTF-8"));
|
||||
client.executeMethod(method);
|
||||
if (method.getStatusCode() != 201) {
|
||||
throw new Exception(method.getResponseBodyAsString());
|
||||
}
|
||||
}
|
||||
|
||||
private static long calculateTimeSpent(final int timeSpentInMinutes) {
|
||||
int days = timeSpentInMinutes / 60 / 24;
|
||||
return (days * 8 * 60 + timeSpentInMinutes % (60 * 24)) * 60;
|
||||
}
|
||||
|
||||
private void checkVersion(final HttpClient client) throws Exception {
|
||||
GetMethod method = new GetMethod(getUrl() + "/rest/api/2/project");
|
||||
client.executeMethod(method);
|
||||
|
||||
@@ -194,7 +194,7 @@ public abstract class TaskRepository {
|
||||
return "{id} (e.g. FOO-001), {summary}, {number} (e.g. 001), {project} (e.g. FOO)";
|
||||
}
|
||||
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpent, final String comment) throws Exception {
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpentInMinutes, final String comment) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class LocalTaskImpl extends LocalTask {
|
||||
private List<ChangeListInfo> myChangeLists = new ArrayList<ChangeListInfo>();
|
||||
private boolean myRunning = false;
|
||||
private List<WorkItem> myWorkItems = new ArrayList<WorkItem>();
|
||||
private Date myLastPost = null;
|
||||
private Date myLastPost;
|
||||
|
||||
|
||||
/** for serialization */
|
||||
@@ -86,6 +86,7 @@ public class LocalTaskImpl extends LocalTask {
|
||||
myActive = ((LocalTaskImpl)origin).isActive();
|
||||
myWorkItems = ((LocalTaskImpl)origin).getWorkItems();
|
||||
myRunning = ((LocalTaskImpl)origin).isRunning();
|
||||
myLastPost = ((LocalTaskImpl)origin).getLastPost();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +303,7 @@ public class LocalTaskImpl extends LocalTask {
|
||||
myWorkItems.add(workItem);
|
||||
}
|
||||
|
||||
@Tag("lastWorkItemPostingDate")
|
||||
@Tag("lastPost")
|
||||
@Override
|
||||
public Date getLastPost() {
|
||||
return myLastPost;
|
||||
|
||||
@@ -282,9 +282,9 @@ public class YouTrackRepository extends BaseRepositoryImpl {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.tasks.youtrack.YouTrackRepository");
|
||||
|
||||
@Override
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpent, final String comment) throws Exception {
|
||||
public void updateTimeSpent(final LocalTask task, final int timeSpentInMinutes, final String comment) throws Exception {
|
||||
checkVersion();
|
||||
final HttpMethod method = doREST("/rest/issue/execute/" + task.getId() + "?command=work+Today+" + timeSpent + "m+" + comment, true);
|
||||
final HttpMethod method = doREST("/rest/issue/execute/" + task.getId() + "?command=work+Today+" + timeSpentInMinutes + "m+" + comment, true);
|
||||
if (method.getStatusCode() != 200) {
|
||||
InputStream stream = method.getResponseBodyAsStream();
|
||||
String message = new SAXBuilder(false).build(stream).getRootElement().getText();
|
||||
|
||||
+21
-25
@@ -1,14 +1,9 @@
|
||||
package com.intellij.tasks.timeTracking;
|
||||
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.NonDefaultProjectConfigurable;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.options.binding.BindControl;
|
||||
import com.intellij.openapi.options.binding.BindableConfigurable;
|
||||
import com.intellij.openapi.options.binding.ControlBinder;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,22 +17,12 @@ import java.awt.event.ActionListener;
|
||||
* User: Evgeny.Zakrevsky
|
||||
* Date: 11/19/12
|
||||
*/
|
||||
public class TimeTrackingConfigurable extends BindableConfigurable implements SearchableConfigurable,
|
||||
NonDefaultProjectConfigurable, Configurable.NoScroll {
|
||||
@BindControl("enabled")
|
||||
public class TimeTrackingConfigurable implements SearchableConfigurable, NonDefaultProjectConfigurable, Configurable.NoScroll {
|
||||
private JCheckBox myEnableTimeTrackingCheckBox;
|
||||
@BindControl("suspendDelayInSeconds")
|
||||
private JTextField myTimeTrackingSuspendDelay;
|
||||
private JPanel myTimeTrackingSettings;
|
||||
private JPanel myPanel;
|
||||
private Project myProject;
|
||||
private final NotNullLazyValue<ControlBinder> myControlBinder = new NotNullLazyValue<ControlBinder>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected ControlBinder compute() {
|
||||
return new ControlBinder(getConfig());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public TimeTrackingConfigurable(Project project) {
|
||||
@@ -57,24 +42,36 @@ public class TimeTrackingConfigurable extends BindableConfigurable implements Se
|
||||
return TimeTrackingManager.getInstance(myProject).getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ControlBinder getBinder() {
|
||||
return myControlBinder.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
myEnableTimeTrackingCheckBox.setSelected(getConfig().enabled);
|
||||
myTimeTrackingSuspendDelay.setText(String.valueOf(getConfig().suspendDelayInSeconds));
|
||||
enableTimeTrackingPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() throws ConfigurationException {
|
||||
public void disposeUIResources() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return myEnableTimeTrackingCheckBox.isSelected() != getConfig().enabled ||
|
||||
!myTimeTrackingSuspendDelay.getText().equals(String.valueOf(getConfig().suspendDelayInSeconds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
boolean oldTimeTrackingEnabled = getConfig().enabled;
|
||||
super.apply();
|
||||
getConfig().enabled = myEnableTimeTrackingCheckBox.isSelected();
|
||||
if (getConfig().enabled != oldTimeTrackingEnabled) {
|
||||
TimeTrackingManager.getInstance(myProject).updateTimeTrackingToolWindow();
|
||||
}
|
||||
try{
|
||||
getConfig().suspendDelayInSeconds = Integer.parseInt(myTimeTrackingSuspendDelay.getText());
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -105,7 +102,6 @@ public class TimeTrackingConfigurable extends BindableConfigurable implements Se
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
bindAnnotations();
|
||||
return myPanel;
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import com.intellij.tasks.TaskManager;
|
||||
import com.intellij.tasks.timeTracking.model.WorkItem;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -196,6 +197,7 @@ public class TimeTrackingManager implements ProjectComponent, PersistentStateCom
|
||||
|
||||
@Override
|
||||
public void loadState(final TimeTrackingManager.Config state) {
|
||||
XmlSerializerUtil.copyBean(state, myConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user