~qeef/damn-plugin

2804925ef4c6d539c0d5c08b7abc318f84a46ce5 — Jiri Vlasak 5 months ago a41959b + fe1e918
Merge branch 'upgrade-to-api-0.2.0'
M CHANGELOG.md => CHANGELOG.md +10 -0
@@ 13,6 13,16 @@ The format is based on [Keep a Changelog][] and this project adheres to
[Unreleased][]
==============

Added
-----

- Set default map/review actions by click on dialog window.

Changed
-------

- Update to API v0.2.0 (see https://server.damn-project.org/docs)


0.2.1 - 2020-12-17
==================

M src/main/java/org/openstreetmap/josm/plugins/damn/DamnDialog.java => src/main/java/org/openstreetmap/josm/plugins/damn/DamnDialog.java +9 -2
@@ 56,6 56,8 @@ import org.openstreetmap.josm.plugins.damn.actions.PostMapSquareAction;
import org.openstreetmap.josm.plugins.damn.actions.PostReviewAreaAction;
import org.openstreetmap.josm.plugins.damn.actions.PostReviewSquareAction;
import org.openstreetmap.josm.plugins.damn.actions.PostSplitSquareAction;
import org.openstreetmap.josm.plugins.damn.actions.SetMapAction;
import org.openstreetmap.josm.plugins.damn.actions.SetReviewAction;
import org.openstreetmap.josm.plugins.damn.callbacks.GetAreaCallback;
import org.openstreetmap.josm.plugins.damn.callbacks.GetAreasCallback;
import org.openstreetmap.josm.plugins.damn.callbacks.GetWorkingOnCallback;


@@ 106,7 108,13 @@ implements
        );
        JLabel intro = new JLabel("", 0);
        List<SideButton> buttons = new ArrayList<SideButton>();
        buttons.add(new SideButton(new AuthenticateAction()));
        buttons.add(new SideButton(new SetMapAction("map recent")));
        buttons.add(new SideButton(new SetMapAction("map random")));
        buttons.add(new SideButton(new SetMapAction("map nearest")));
        buttons.add(new SideButton(new SetReviewAction("review recent")));
        buttons.add(new SideButton(new SetReviewAction("review random")));
        buttons.add(new SideButton(new SetReviewAction("review nearest")));
        buttons.add(new SideButton(new SetReviewAction("review newbie")));
        createLayout(intro, true, buttons);
        authed();
    }


@@ 121,7 129,6 @@ implements
        try {
            JsonObject jwt = get_jwt(Config.getPref().get("damn.token"));
            String dn = jwt.getString("display_name");
            String tags = jwt.getString("tags");
            change1(new JLabel(tr("I am {0}.", dn), 0));
            change2(Arrays.asList(
                new SideButton(new GetAreasAction(this)),

M src/main/java/org/openstreetmap/josm/plugins/damn/DamnPlugin.java => src/main/java/org/openstreetmap/josm/plugins/damn/DamnPlugin.java +14 -0
@@ 42,6 42,20 @@ public class DamnPlugin extends Plugin
        } catch(Exception e) {
            Config.getPref().put("damn.token", "");
        }
        try {
            String damn_map_action = Config.getPref().get("damn.map_action");
            if (damn_map_action.equals(""))
                throw new Exception();
        } catch(Exception e) {
            Config.getPref().put("damn.map_action", "map random");
        }
        try {
            String damn_rev_act = Config.getPref().get("damn.review_action");
            if (damn_rev_act.equals(""))
                throw new Exception();
        } catch(Exception e) {
            Config.getPref().put("damn.review_action", "review recent");
        }
    }

    @Override

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/GetWorkingOnAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/GetWorkingOnAction.java +2 -1
@@ 54,7 54,8 @@ public class GetWorkingOnAction extends JosmAction {
                System.currentTimeMillis()
                - 1000 * 60 * 60 * 24 * 7 // week ago
            );
            SimpleDateFormat now_f = new SimpleDateFormat("yyyy-MM-dd");
            String now_fs = "yyyy-MM-dd'T'HH:mm:ss.S";
            SimpleDateFormat now_f = new SimpleDateFormat(now_fs);
            now_f.setTimeZone(TimeZone.getTimeZone("UTC"));
            JsonObject jwt = DamnDialog.get_jwt(damn_token);
            String dn = jwt.getString("display_name");

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostDoneSquareAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostDoneSquareAction.java +1 -6
@@ 56,23 56,18 @@ public class PostDoneSquareAction extends JosmAction {
                new URL(
                    damn_url
                    + "/area/" + doneSquare.getInt("aid")
                    + "/square/" + doneSquare.getInt("sid")
                    + "/commits"
                ),
                "POST"
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            JsonObject jwt = DamnDialog.get_jwt(damn_token);
            String dn = jwt.getString("display_name");
            String msg;
            msg = tr("This square is done.");
            msg = JOptionPane.showInputDialog("Post message", msg);
            JsonObject map_square = Json.createObjectBuilder()
                .add("aid", doneSquare.getInt("aid"))
                .add("sid", doneSquare.getInt("sid"))
                .add("author", dn)
                .add("type", "done")
                .add("type", "is done")
                .add("message", msg)
            .build();
            g.setRequestBody(map_square.toString().getBytes());

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostMapAreaAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostMapAreaAction.java +2 -3
@@ 59,10 59,9 @@ public class PostMapAreaAction extends JosmAction {
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            String ma = Config.getPref().get("damn.map_action");
            JsonObject map_area = Json.createObjectBuilder()
                .add("aid", mapArea.getInt("aid"))
                .add("type", "map")
                .add("what", "random")
                .add("type", ma)
            .build();
            g.setRequestBody(map_area.toString().getBytes());
            g.connect();

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostMapSquareAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostMapSquareAction.java +1 -6
@@ 56,23 56,18 @@ public class PostMapSquareAction extends JosmAction {
                new URL(
                    damn_url
                    + "/area/" + mapSquare.getInt("aid")
                    + "/square/" + mapSquare.getInt("sid")
                    + "/commits"
                ),
                "POST"
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            JsonObject jwt = DamnDialog.get_jwt(damn_token);
            String dn = jwt.getString("display_name");
            String msg;
            msg = "Map this square again as it is not mapped well yet.";
            msg = JOptionPane.showInputDialog("Post message", msg);
            JsonObject map_square = Json.createObjectBuilder()
                .add("aid", mapSquare.getInt("aid"))
                .add("sid", mapSquare.getInt("sid"))
                .add("author", dn)
                .add("type", "to map")
                .add("type", "needs mapping")
                .add("message", msg)
            .build();
            g.setRequestBody(map_square.toString().getBytes());

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostReviewAreaAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostReviewAreaAction.java +2 -3
@@ 59,10 59,9 @@ public class PostReviewAreaAction extends JosmAction {
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            String ra = Config.getPref().get("damn.review_action");
            JsonObject map_area = Json.createObjectBuilder()
                .add("aid", reviewArea.getInt("aid"))
                .add("type", "review")
                .add("what", "recent")
                .add("type", ra)
            .build();
            g.setRequestBody(map_area.toString().getBytes());
            g.connect();

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostReviewSquareAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostReviewSquareAction.java +1 -6
@@ 56,23 56,18 @@ public class PostReviewSquareAction extends JosmAction {
                new URL(
                    damn_url
                    + "/area/" + reviewSquare.getInt("aid")
                    + "/square/" + reviewSquare.getInt("sid")
                    + "/commits"
                ),
                "POST"
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            JsonObject jwt = DamnDialog.get_jwt(damn_token);
            String dn = jwt.getString("display_name");
            String msg;
            msg = "This square is mapped and ready to review.";
            msg = JOptionPane.showInputDialog("Post message", msg);
            JsonObject map_square = Json.createObjectBuilder()
                .add("aid", reviewSquare.getInt("aid"))
                .add("sid", reviewSquare.getInt("sid"))
                .add("author", dn)
                .add("type", "to review")
                .add("type", "needs review")
                .add("message", msg)
            .build();
            g.setRequestBody(map_square.toString().getBytes());

M src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostSplitSquareAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/PostSplitSquareAction.java +1 -6
@@ 54,22 54,17 @@ public class PostSplitSquareAction extends JosmAction {
                new URL(
                    damn_url
                    + "/area/" + splitSquare.getInt("aid")
                    + "/square/" + splitSquare.getInt("sid")
                    + "/commits"
                ),
                "POST"
            );
            g.setHeader("Content-Type", "application/json");
            g.setHeader("Authorization", "Bearer " + damn_token);
            JsonObject jwt = DamnDialog.get_jwt(damn_token);
            String dn = jwt.getString("display_name");
            String msg;
            msg = tr("It's time to divide. Now.");
            JsonObject map_square = Json.createObjectBuilder()
                .add("aid", splitSquare.getInt("aid"))
                .add("sid", splitSquare.getInt("sid"))
                .add("author", dn)
                .add("type", "splitted")
                .add("type", "split")
                .add("message", msg)
            .build();
            g.setRequestBody(map_square.toString().getBytes());

A src/main/java/org/openstreetmap/josm/plugins/damn/actions/SetMapAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/SetMapAction.java +40 -0
@@ 0,0 1,40 @@
package org.openstreetmap.josm.plugins.damn.actions;

import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.ActionEvent;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.spi.preferences.Config;

/**
 * Set default _map_ action (new lock action).
 *
 * @author qeef
 * @since xxx
 */
public class SetMapAction extends JosmAction {
    private String what;

    /**
     * Constructs a new {@code SetMapAction}.
     */
    public SetMapAction(String w)
    {
        super(
            tr("Set map action to " + w),
            "actions/map",
            tr("Set map action to " + w),
            null,
            true
        );
        what = w;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        Config.getPref().put("damn.map_action", what);
    }
}

A src/main/java/org/openstreetmap/josm/plugins/damn/actions/SetReviewAction.java => src/main/java/org/openstreetmap/josm/plugins/damn/actions/SetReviewAction.java +40 -0
@@ 0,0 1,40 @@
package org.openstreetmap.josm.plugins.damn.actions;

import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.ActionEvent;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.spi.preferences.Config;

/**
 * Set default _review_ action (new lock action).
 *
 * @author qeef
 * @since xxx
 */
public class SetReviewAction extends JosmAction {
    private String what;

    /**
     * Constructs a new {@code SetReviewAction}.
     */
    public SetReviewAction(String w)
    {
        super(
            tr("Set review action to " + w),
            "actions/review",
            tr("Set review action to " + w),
            null,
            true
        );
        what = w;
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        Config.getPref().put("damn.review_action", what);
    }
}