Skip to content

Commit c8ec6ff

Browse files
committed
#178: add heimat settings in settings layout. add heimat settings to database. started external mapping db-table (wip)
1 parent 0abf2de commit c8ec6ff

File tree

11 files changed

+438
-26
lines changed

11 files changed

+438
-26
lines changed

src/main/java/de/doubleslash/keeptime/controller/Controller.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.List;
2424

25+
import de.doubleslash.keeptime.model.settings.HeimatSettings;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728
import org.springframework.stereotype.Service;
@@ -41,16 +42,18 @@ public class Controller {
4142
private static final Logger LOG = LoggerFactory.getLogger(Controller.class);
4243

4344
private final long AUTO_SAVE_INTERVAL_SECONDS = 60;
45+
private final HeimatSettings heimatSettings;
4446
private Interval autoSaveInterval;
4547

4648
private final Model model;
4749
private final Settings settings;
4850

4951
private final DateProvider dateProvider;
5052

51-
public Controller(final Model model, Settings settings, final DateProvider dateProvider) {
53+
public Controller(final Model model, Settings settings, HeimatSettings heimatSettings, final DateProvider dateProvider) {
5254
this.model = model;
5355
this.settings = settings;
56+
this.heimatSettings = heimatSettings;
5457
this.dateProvider = dateProvider;
5558
}
5659

@@ -119,8 +122,14 @@ public void addNewProject(final Project project) {
119122
model.getProjectRepository().saveAll(changedProjects);
120123
}
121124

125+
public void updateHeimatSettings(final boolean active, String url, String pat){
126+
heimatSettings.setHeimatActive(active);
127+
heimatSettings.setHeimatUrl(url);
128+
heimatSettings.setHeimatPat(pat);
129+
heimatSettings.save();
130+
}
131+
122132
public void updateSettings(final Settings newValuedSettings) {
123-
124133
settings.setTaskBarColor(newValuedSettings.getTaskBarColor());
125134
settings.setDefaultBackgroundColor(newValuedSettings.getDefaultBackgroundColor());
126135
settings.setDefaultFontColor(newValuedSettings.getDefaultFontColor());
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2019 doubleSlash Net Business GmbH
2+
//
3+
// This file is part of KeepTime.
4+
// KeepTime is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package de.doubleslash.keeptime.model;
18+
19+
import de.doubleslash.keeptime.model.persistenceconverter.ColorConverter;
20+
import jakarta.persistence.*;
21+
import javafx.scene.paint.Color;
22+
23+
@Entity
24+
@Table(name = "ExternalProjectMapping")
25+
public class ExternalProjectMapping {
26+
27+
@Id
28+
@GeneratedValue(strategy = GenerationType.IDENTITY)
29+
@Column(name = "id", updatable = false, nullable = false)
30+
private long id;
31+
32+
// TODO maybe add a externalSystem Identifier
33+
34+
@Lob
35+
private String externalProjectData;
36+
37+
@ManyToOne
38+
private Project project;
39+
40+
public ExternalProjectMapping() {
41+
// Needed for jpa
42+
}
43+
44+
public ExternalProjectMapping(final String externalProjectData, final Project project) {
45+
this.externalProjectData = externalProjectData;
46+
this.project = project;
47+
}
48+
49+
public String getExternalProjectData() {
50+
return externalProjectData;
51+
}
52+
53+
public void setExternalProjectData(final String externalProjectData) {
54+
this.externalProjectData = externalProjectData;
55+
}
56+
57+
public Project getProject() {
58+
return project;
59+
}
60+
61+
public void setProject(final Project project) {
62+
this.project = project;
63+
}
64+
}

src/main/java/de/doubleslash/keeptime/model/Model.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import de.doubleslash.keeptime.model.repos.ProjectRepository;
2020
import de.doubleslash.keeptime.model.repos.SettingsRepository;
2121
import de.doubleslash.keeptime.model.repos.WorkRepository;
22+
import de.doubleslash.keeptime.model.settings.HeimatSettings;
2223
import javafx.beans.property.ObjectProperty;
2324
import javafx.beans.property.SimpleObjectProperty;
2425
import javafx.collections.FXCollections;
@@ -35,14 +36,19 @@
3536
public class Model {
3637
private ProjectRepository projectRepository;
3738
private WorkRepository workRepository;
38-
private SettingsRepository settingsRepository;
39+
40+
public HeimatSettings getHeimatSettings() {
41+
return heimatSettings;
42+
}
43+
44+
private HeimatSettings heimatSettings;
3945
@Autowired
4046
public Model(final ProjectRepository projectRepository, final WorkRepository workRepository,
41-
final SettingsRepository settingsRepository) {
47+
final HeimatSettings heimatSettings) {
4248
super();
4349
this.projectRepository = projectRepository;
4450
this.workRepository = workRepository;
45-
this.settingsRepository = settingsRepository;
51+
this.heimatSettings = heimatSettings;
4652
}
4753

4854
public static final Color ORIGINAL_HOVER_BACKGROUND_COLOR = new Color(54 / 255., 143 / 255., 179 / 255., .7);
@@ -96,10 +102,6 @@ public void setProjectRepository(final ProjectRepository projectRepository) {
96102
this.projectRepository = projectRepository;
97103
}
98104

99-
public void setSettingsRepository(final SettingsRepository settingsRepository) {
100-
this.settingsRepository = settingsRepository;
101-
}
102-
103105
public void setIdleProject(final Project idleProject) {
104106
this.idleProject = idleProject;
105107
}
@@ -120,10 +122,6 @@ public ProjectRepository getProjectRepository() {
120122
return projectRepository;
121123
}
122124

123-
public SettingsRepository getSettingsRepository() {
124-
return settingsRepository;
125-
}
126-
127125
public ObservableList<Work> getPastWorkItems() {
128126
return pastWorkItems;
129127
}

src/main/java/de/doubleslash/keeptime/model/Settings.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ public Settings(SettingsRepository settingsRepository) {
3636
this.settingsRepository = settingsRepository;
3737
}
3838

39+
// TODO add default values
40+
3941
public boolean isRemindIfNotesAreEmptyOnlyForWorkEntry() {
40-
return getBoolean("remind_if_notes_are_empty_only_for_work_entry");
42+
return getBoolean("remind_if_notes_are_empty_only_for_work_entry", false);
4143
}
4244

4345
public void setRemindIfNotesAreEmptyOnlyForWorkEntry(boolean emptyNoteReminderCheckBoxIsWork) {
4446
setBoolean( "remind_if_notes_are_empty_only_for_work_entry", emptyNoteReminderCheckBoxIsWork);
4547
}
4648

4749
public boolean isConfirmClose() {
48-
return getBoolean("confirm_close");
50+
return getBoolean("confirm_close", false);
4951
}
5052

5153
public void setConfirmClose(boolean confirmClose) {
@@ -93,23 +95,23 @@ public void setTaskBarColor(final Color taskBarColor) {
9395
}
9496

9597
public boolean isUseHotkey() {
96-
return getBoolean("use_hotkey");
98+
return getBoolean("use_hotkey", false);
9799
}
98100

99101
public void setUseHotkey(final boolean useHotkey) {
100102
setBoolean("use_hotkey", useHotkey);
101103
}
102104

103105
public boolean isDisplayProjectsRight() {
104-
return getBoolean("display_projects_right");
106+
return getBoolean("display_projects_right", true);
105107
}
106108

107109
public void setDisplayProjectsRight(final boolean displayProjectsRight) {
108110
setBoolean("display_projects_right", displayProjectsRight);
109111
}
110112

111113
public boolean isHideProjectsOnMouseExit() {
112-
return getBoolean("hide_projects_on_mouse_exit");
114+
return getBoolean("hide_projects_on_mouse_exit", true);
113115
}
114116

115117
public void setHideProjectsOnMouseExit(final boolean hideProjectsOnMouseExit) {
@@ -141,27 +143,32 @@ public void setScreenHash(final int screenHash) {
141143
}
142144

143145
public boolean isSaveWindowPosition() {
144-
return getBoolean("save_window_position");
146+
return getBoolean("save_window_position", false);
145147
}
146148

147149
public void setSaveWindowPosition(final boolean saveWindowPosition) {
148150
setBoolean("save_window_position", saveWindowPosition);
149151
}
150152

151153
public boolean isRemindIfNotesAreEmpty() {
152-
return getBoolean("remind_if_notes_are_empty");
154+
return getBoolean("remind_if_notes_are_empty", false);
153155
}
154156

155157
public void setRemindIfNotesAreEmpty(final boolean emptyNoteReminder) {
156158
setBoolean("remind_if_notes_are_empty", emptyNoteReminder);
157159
}
158160

159-
private boolean getBoolean(String key) {
160-
return Boolean.getBoolean(settingsRepository.findBySetting(key).getSettingValue());
161+
private boolean getBoolean(String key, boolean orDefault) {
162+
final Setting bySetting = settingsRepository.findBySetting(key);
163+
if (bySetting == null)
164+
return orDefault;
165+
return Boolean.parseBoolean(bySetting.getSettingValue());
161166
}
162167

163168
public void setBoolean(String key, boolean value) {
164-
final Setting setting = settingsRepository.findBySetting(key);
169+
Setting setting = settingsRepository.findBySetting(key);
170+
if (setting == null)
171+
setting = new Setting(key, "");
165172
setting.setSettingValue(String.valueOf(value));
166173
settingsRepository.save(setting);
167174
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019 doubleSlash Net Business GmbH
2+
//
3+
// This file is part of KeepTime.
4+
// KeepTime is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
18+
package de.doubleslash.keeptime.model.repos;
19+
20+
import de.doubleslash.keeptime.model.ExternalProjectMapping;
21+
import de.doubleslash.keeptime.model.Project;
22+
import org.springframework.data.jpa.repository.JpaRepository;
23+
import org.springframework.stereotype.Repository;
24+
25+
@Repository
26+
public interface ExternalProjectsMappingsRepository extends JpaRepository<ExternalProjectMapping, Long> {
27+
28+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2019 doubleSlash Net Business GmbH
2+
//
3+
// This file is part of KeepTime.
4+
// KeepTime is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package de.doubleslash.keeptime.model.settings;
18+
19+
import org.springframework.stereotype.Service;
20+
21+
import java.util.Arrays;
22+
23+
@Service
24+
public class HeimatSettings {
25+
26+
private final SettingsBase settingsBase;
27+
28+
public HeimatSettings(SettingsBase settingsBase) {
29+
this.settingsBase = settingsBase;
30+
}
31+
32+
public boolean isHeimatActive() {
33+
return settingsBase.getBoolean("heimat_active", false);
34+
}
35+
36+
public void setHeimatActive(boolean heimatActive) {
37+
settingsBase.setBoolean("heimat_active", heimatActive);
38+
}
39+
40+
public String getHeimatUrl() {
41+
return settingsBase.getString("heimat_url", "");
42+
}
43+
44+
public void setHeimatUrl(String heimatUrl) {
45+
settingsBase.setString("heimat_url", heimatUrl);
46+
}
47+
48+
public String getHeimatPat() {
49+
return settingsBase.getString("heimat_pat", "");
50+
}
51+
52+
public void setHeimatPat(String heimatPat) {
53+
settingsBase.setString("heimat_pat", heimatPat);
54+
}
55+
56+
public void save() {
57+
settingsBase.save(Arrays.asList("heimat_active", "heimat_url", "heimat_pat"));
58+
}
59+
}

0 commit comments

Comments
 (0)