Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main/java/uk/co/neontribe/kimai/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,25 @@ public class Settings {
private static Settings kimaiSettings;

static {

Dotenv dotenv = Dotenv.configure().ignoreIfMalformed().ignoreIfMissing().load();
CONFIG_DIR = dotenv.get("CONFIG_DIR", ".config/neontribe/kimai-ui");
CONFIG_FILENAME = dotenv.get("CONFIG_FILENAME", "config.yml");
}

public static void reset() {
Settings.kimaiSettings = null;

}

/**
* Get a singleton instance of our settings object.
*
* @return Settings
* @throws ConfigNotInitialisedException Thrown when config location cannot be created.
* @throws IOException Thrown if we can't read from the file system
* @throws ConfigNotInitialisedException Thrown when config location cannot be
* created.
* @throws IOException Thrown if we can't read from the file
* system
*/
public static Settings getInstance() throws IOException, ConfigNotInitialisedException {
// If we have a (static) singleton instantiated then exit early, return it.
Expand All @@ -60,7 +64,8 @@ public static Settings getInstance() throws IOException, ConfigNotInitialisedExc
}
}

// If the config file does not exist throw a ConfigNotInitialisedException error, this can be caught and handled
// If the config file does not exist throw a ConfigNotInitialisedException
// error, this can be caught and handled
File settingsFile = Settings.getConfigFile();
if (!settingsFile.exists()) {
throw new ConfigNotInitialisedException("Config not initialised");
Expand Down Expand Up @@ -116,6 +121,7 @@ public static File getConfigFile() {
private String kimaiUri = "";
private String kimaiUsername = "";
private String kimaiPassword = "";
private Object kimaiFilteredCustomers = null;
private String[] customers = {};

public String getKimaiUri() {
Expand All @@ -140,6 +146,18 @@ public void setKimaiPassword(String kimaiPassword) {
this.kimaiPassword = kimaiPassword;
}

public void setFilteredCustomers(Object kimaiFilteredCustomers) {

this.kimaiFilteredCustomers = kimaiFilteredCustomers;
System.out.println("this has run");
System.out.println(this.kimaiFilteredCustomers);
}

public Object getFilteredCustomers() {
System.out.println(kimaiFilteredCustomers);
return kimaiFilteredCustomers;
}

public String[] getCustomers() {
return customers;
}
Expand All @@ -153,6 +171,8 @@ public static boolean save(Settings settings) throws FileNotFoundException, Secu
kimai.put("kimaiUri", settings.getKimaiUri());
kimai.put("kimaiUsername", settings.getKimaiUsername());
kimai.put("kimaiPassword", settings.getKimaiPassword());
kimai.put("filteredCustomers", settings.getFilteredCustomers());

kimai.put("customers", settings.getCustomers());

Yaml yaml = new Yaml();
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/uk/co/neontribe/kimai/desktop/ConfigPanel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package uk.co.neontribe.kimai.desktop;

import uk.co.neontribe.kimai.api.Customer;
import uk.co.neontribe.kimai.config.ConfigNotInitialisedException;
import uk.co.neontribe.kimai.config.Settings;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Array;

public class ConfigPanel extends JPanel implements ActionListener {

Expand All @@ -15,24 +21,34 @@ public class ConfigPanel extends JPanel implements ActionListener {
private final JTextField uri;
private final JTextField username;
private final JTextField password;
private final JList customer;

public ConfigPanel(Settings settings) {
public ConfigPanel(Settings settings) throws ConfigNotInitialisedException, IOException {
this.setLayout(new BorderLayout(5, 5));
this.setBorder(new EmptyBorder(5, 5, 5, 5));

this.add(new Header("Config Panel"), BorderLayout.NORTH);


JPanel gridRight = new JPanel(new GridLayout(0, 1, 5, 5));
customer = new JList<>(Customer.getCustomers());
customer.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
int start = 0;
int end = 1;
customer.setSelectionInterval(start, end);

gridRight.add(uri = new JTextField(settings.getKimaiUri(), 30));
gridRight.add(new JScrollPane(customer));
gridRight.add(username = new JTextField(settings.getKimaiUsername(), 30));
gridRight.add(password = new JTextField(settings.getKimaiPassword(), 30));
this.add(gridRight, BorderLayout.CENTER);

JPanel gridLeft = new JPanel(new GridLayout(0, 1, 5, 5));
gridLeft.add(new JLabel("Your Kimai Uri:"));
gridLeft.add(new JLabel("Select clients:"));
gridLeft.add(new JLabel("Username:"));
gridLeft.add(new JLabel("Password:"));

this.add(gridLeft, BorderLayout.WEST);

JButton save = new JButton("Save");
Expand All @@ -41,7 +57,8 @@ public ConfigPanel(Settings settings) {

}

public static JDialog makeFrame(Component parent, Settings settings) {
public static JDialog makeFrame(Component parent, Settings settings)
throws ConfigNotInitialisedException, IOException {
if (configFrame == null) {
Frame topWindow = ConfigPanel.getParentFrame(parent);
configFrame = new JDialog(topWindow, "Settings");
Expand All @@ -68,11 +85,16 @@ public static Frame getParentFrame(Component me) {
@Override
public void actionPerformed(ActionEvent e) {
try {

Object values = customer.getSelectedValuesList();

Settings settings = new Settings();
settings.setKimaiUri(this.uri.getText());
settings.setKimaiUsername(this.username.getText());
settings.setKimaiPassword(this.password.getText());
settings.setFilteredCustomers(values);
configFrame.setVisible(false);

} catch (Exception ex) {
System.err.println("Unreachable");
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/uk/co/neontribe/kimai/desktop/StatusPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.co.neontribe.kimai.desktop;

import uk.co.neontribe.kimai.config.ConfigNotInitialisedException;
import uk.co.neontribe.kimai.config.Settings;

import javax.swing.*;
Expand All @@ -25,7 +26,14 @@ public StatusPanel() {
ImageIcon newCogIcon = new ImageIcon(newCogImg);
settings.setIcon(newCogIcon);

settings.addActionListener(actionEvent -> openConfigDialog());
settings.addActionListener(actionEvent -> {
try {
openConfigDialog();
} catch (ConfigNotInitialisedException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
buttons.add(settings, BorderLayout.EAST);

try {
Expand Down Expand Up @@ -62,7 +70,7 @@ public void setText(String text) {
this.statusBar.setText(text);
}

private void openConfigDialog() {
private void openConfigDialog() throws ConfigNotInitialisedException, IOException {
try {
ConfigPanel.makeFrame(this, Settings.getInstance()).setVisible(true);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import uk.co.neontribe.kimai.api.*;
import uk.co.neontribe.kimai.config.ConfigNotInitialisedException;
import uk.co.neontribe.kimai.config.Settings;

import javax.swing.*;

Expand Down Expand Up @@ -39,6 +40,13 @@ public class TimeEntryPanel extends JPanel implements ActionListener {
private final StatusPanel statusPanel;

public TimeEntryPanel() throws IOException, ConfigNotInitialisedException {

Settings settings = Settings.getInstance();
Object filteredCustomers = settings.getFilteredCustomers();
String convertedToString = String.valueOf(filteredCustomers);

System.out.println(convertedToString);

this.setBackground(Color.WHITE);
this.setLayout(new GridBagLayout());

Expand Down