Skip to content

Commit d8e6f0d

Browse files
committed
fixed comments :removed unwanted test and fixed settings file
1 parent e5b432d commit d8e6f0d

5 files changed

Lines changed: 71 additions & 131 deletions

File tree

src/app/pages/settings/settings.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ <h2>Terminology</h2>
165165
</p>
166166
<div class="terminology-grid">
167167
<div class="terminology-row">
168-
<mat-form-field appearance="fill">
168+
<mat-form-field appearance="fill" floatLabel="always">
169169
<mat-label>Team (singular)</mat-label>
170170
<input
171171
matInput
172-
placeholder="e.g. App"
172+
[placeholder]="getTeamSingularPlaceholder()"
173173
name="customTeamLabel"
174174
[(ngModel)]="customTeamLabel"
175175
(ngModelChange)="onTeamLabelChange()" />
@@ -185,11 +185,11 @@ <h2>Terminology</h2>
185185
</mat-form-field>
186186
</div>
187187
<div class="terminology-row">
188-
<mat-form-field appearance="fill">
188+
<mat-form-field appearance="fill" floatLabel="always">
189189
<mat-label>Group (singular)</mat-label>
190190
<input
191191
matInput
192-
placeholder="e.g. Portfolio"
192+
[placeholder]="getGroupSingularPlaceholder()"
193193
name="customGroupLabel"
194194
[(ngModel)]="customGroupLabel"
195195
(ngModelChange)="onGroupLabelChange()" />

src/app/pages/settings/settings.component.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ describe('SettingsComponent', () => {
4949
'getGroupLabelPlural',
5050
'setTeamLabel',
5151
'setGroupLabel',
52+
'getMetaTeamLabel',
53+
'getMetaGroupLabel',
5254
'initFromMeta',
5355
]);
5456
settingsService.getTeamLabel.and.returnValue('Team');
5557
settingsService.getTeamLabelPlural.and.returnValue('Teams');
5658
settingsService.getGroupLabel.and.returnValue('Group');
5759
settingsService.getGroupLabelPlural.and.returnValue('Groups');
60+
settingsService.getMetaTeamLabel.and.returnValue({ singular: 'Team', plural: 'Teams' });
61+
settingsService.getMetaGroupLabel.and.returnValue({ singular: 'Group', plural: 'Groups' });
5862
modalComponent = jasmine.createSpyObj('ModalMessageComponent', ['openDialog']);
5963

6064
await TestBed.configureTestingModule({

src/app/pages/settings/settings.component.ts

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export class SettingsComponent implements OnInit {
6161
];
6262
selectedDateFormat: string = this.BROWSER_LOCALE;
6363

64-
customTeamLabel: string = 'Team';
64+
customTeamLabel: string = '';
6565
customTeamLabelPlural: string = '';
66-
customGroupLabel: string = 'Group';
66+
customGroupLabel: string = '';
6767
customGroupLabelPlural: string = '';
6868

6969
// GitHub release check state
@@ -90,6 +90,7 @@ export class SettingsComponent implements OnInit {
9090
.then((dataStore: DataStore) => {
9191
this.setYamlData(dataStore);
9292
this.updateProgressDefinitionsForm();
93+
this.initLabels(); // Re-read labels now that meta.yaml is loaded
9394
})
9495
.catch(err => {
9596
this.modal.openDialog(new DialogInfo(err.message, 'An error occurred'));
@@ -150,19 +151,7 @@ export class SettingsComponent implements OnInit {
150151

151152
initialize(): void {
152153
this.selectedDateFormat = this.settings.getDateFormat() || this.BROWSER_LOCALE;
153-
this.customTeamLabel = this.settings.getTeamLabel();
154-
this.customTeamLabelPlural = this.settings.getTeamLabelPlural();
155-
this.customGroupLabel = this.settings.getGroupLabel();
156-
this.customGroupLabelPlural = this.settings.getGroupLabelPlural();
157-
158-
// If the plural is just the auto-generated default (singular + 's'),
159-
// leave the field empty so the dynamic placeholder shows instead.
160-
if (this.customTeamLabelPlural === this.customTeamLabel + 's') {
161-
this.customTeamLabelPlural = '';
162-
}
163-
if (this.customGroupLabelPlural === this.customGroupLabel + 's') {
164-
this.customGroupLabelPlural = '';
165-
}
154+
this.initLabels();
166155

167156
// Init dates
168157
let date: Date = new Date();
@@ -176,6 +165,29 @@ export class SettingsComponent implements OnInit {
176165
}
177166
}
178167

168+
/**
169+
* Read current labels from the service into the component fields.
170+
* Called both on init and after meta.yaml loads.
171+
*/
172+
initLabels(): void {
173+
const teamLabel = this.settings.getTeamLabel();
174+
const teamPlural = this.settings.getTeamLabelPlural();
175+
const groupLabel = this.settings.getGroupLabel();
176+
const groupPlural = this.settings.getGroupLabelPlural();
177+
178+
// Show the value in the field only if it differs from the meta.yaml default.
179+
// Otherwise, leave the field empty and let the placeholder show the default.
180+
const metaTeam = this.settings.getMetaTeamLabel();
181+
const metaGroup = this.settings.getMetaGroupLabel();
182+
183+
this.customTeamLabel = teamLabel === metaTeam.singular ? '' : teamLabel;
184+
this.customGroupLabel = groupLabel === metaGroup.singular ? '' : groupLabel;
185+
186+
// For plural: show empty if it matches the auto-generated default (singular + 's')
187+
this.customTeamLabelPlural = teamPlural === teamLabel + 's' ? '' : teamPlural;
188+
this.customGroupLabelPlural = groupPlural === groupLabel + 's' ? '' : groupPlural;
189+
}
190+
179191
setYamlData(dataStore: DataStore): void {
180192
this.dataStoreMaxLevel = dataStore.getMaxLevel();
181193
this.selectedMaxLevel = this.settings.getMaxLevel() || this.dataStoreMaxLevel;
@@ -198,38 +210,49 @@ export class SettingsComponent implements OnInit {
198210
}
199211

200212
onTeamLabelChange(): void {
201-
this.settings.setTeamLabel(this.customTeamLabel, this.customTeamLabelPlural);
202-
// Update plural placeholder when singular changes
203-
if (!this.customTeamLabelPlural || this.customTeamLabelPlural === this.customTeamLabel + 's') {
213+
// If cleared, revert to meta.yaml default
214+
const effective = this.customTeamLabel || this.settings.getMetaTeamLabel().singular;
215+
this.settings.setTeamLabel(effective, this.customTeamLabelPlural);
216+
// Clear plural so placeholder updates
217+
if (!this.customTeamLabelPlural || this.customTeamLabelPlural === effective + 's') {
204218
this.customTeamLabelPlural = '';
205219
}
206220
}
207221

208222
onTeamLabelPluralChange(): void {
209-
this.settings.setTeamLabel(this.customTeamLabel, this.customTeamLabelPlural);
223+
const effective = this.customTeamLabel || this.settings.getMetaTeamLabel().singular;
224+
this.settings.setTeamLabel(effective, this.customTeamLabelPlural);
210225
}
211226

212227
onGroupLabelChange(): void {
213-
this.settings.setGroupLabel(this.customGroupLabel, this.customGroupLabelPlural);
214-
// Update plural placeholder when singular changes
215-
if (
216-
!this.customGroupLabelPlural ||
217-
this.customGroupLabelPlural === this.customGroupLabel + 's'
218-
) {
228+
// If cleared, revert to meta.yaml default
229+
const effective = this.customGroupLabel || this.settings.getMetaGroupLabel().singular;
230+
this.settings.setGroupLabel(effective, this.customGroupLabelPlural);
231+
// Clear plural so placeholder updates
232+
if (!this.customGroupLabelPlural || this.customGroupLabelPlural === effective + 's') {
219233
this.customGroupLabelPlural = '';
220234
}
221235
}
222236

223237
onGroupLabelPluralChange(): void {
224-
this.settings.setGroupLabel(this.customGroupLabel, this.customGroupLabelPlural);
238+
const effective = this.customGroupLabel || this.settings.getMetaGroupLabel().singular;
239+
this.settings.setGroupLabel(effective, this.customGroupLabelPlural);
240+
}
241+
242+
getTeamSingularPlaceholder(): string {
243+
return this.settings.getMetaTeamLabel().singular || 'Team';
244+
}
245+
246+
getGroupSingularPlaceholder(): string {
247+
return this.settings.getMetaGroupLabel().singular || 'Group';
225248
}
226249

227250
getTeamPluralPlaceholder(): string {
228-
return (this.customTeamLabel || 'Team') + 's';
251+
return (this.customTeamLabel || this.settings.getMetaTeamLabel().singular || 'Team') + 's';
229252
}
230253

231254
getGroupPluralPlaceholder(): string {
232-
return (this.customGroupLabel || 'Group') + 's';
255+
return (this.customGroupLabel || this.settings.getMetaGroupLabel().singular || 'Group') + 's';
233256
}
234257

235258
onMaxLevelChange(value: number | null): void {

src/app/service/settings/settings.service.spec.ts

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,6 @@ describe('SettingsService', () => {
6161
});
6262
});
6363

64-
describe('migrateOldKeys', () => {
65-
it('should migrate legacy team label key', () => {
66-
localStorage.clear();
67-
localStorage.setItem('settings.teamLabel', JSON.stringify('Client'));
68-
// Create a new service instance to trigger migration
69-
const freshService = new SettingsService();
70-
expect(localStorage.getItem('settings.teamLabel')).toBeNull();
71-
expect(freshService.getTeamLabel()).toBe('Client');
72-
});
73-
74-
it('should migrate legacy group label key', () => {
75-
localStorage.clear();
76-
localStorage.setItem('settings.groupLabel', JSON.stringify('Portfolio'));
77-
const freshService = new SettingsService();
78-
expect(localStorage.getItem('settings.groupLabel')).toBeNull();
79-
expect(freshService.getGroupLabel()).toBe('Portfolio');
80-
});
81-
82-
it('should not overwrite existing consolidated key', () => {
83-
localStorage.clear();
84-
localStorage.setItem('settings.labels', JSON.stringify({ team: 'Existing', group: '' }));
85-
localStorage.setItem('settings.teamLabel', JSON.stringify('ShouldBeIgnored'));
86-
const freshService = new SettingsService();
87-
expect(freshService.getTeamLabel()).toBe('Existing');
88-
});
89-
});
90-
9164
describe('initFromMeta', () => {
9265
it('should set meta defaults for team and group', () => {
9366
service.initFromMeta({
@@ -162,22 +135,7 @@ describe('SettingsService', () => {
162135
});
163136
});
164137

165-
describe('General Settings Operations', () => {
166-
it('should handle empty string settings', () => {
167-
service.saveSettings('test.key', '');
168-
expect(localStorage.getItem('test.key')).toBeNull();
169-
});
170-
171-
it('should handle empty array settings', () => {
172-
service.saveSettings('test.key', []);
173-
expect(localStorage.getItem('test.key')).toBeNull();
174-
});
175-
176-
it('should handle empty object settings', () => {
177-
service.saveSettings('test.key', {});
178-
expect(localStorage.getItem('test.key')).toBeNull();
179-
});
180-
138+
describe('Settings helpers', () => {
181139
it('should properly store and retrieve number settings', () => {
182140
localStorage.setItem('test.key', '42');
183141
expect(service.getSettingsNumber('test.key')).toBe(42);
@@ -186,15 +144,5 @@ describe('SettingsService', () => {
186144
it('should return null for non-existent number settings', () => {
187145
expect(service.getSettingsNumber('nonexistent.key')).toBeNull();
188146
});
189-
190-
it('should handle complex object settings', () => {
191-
const complexObj = {
192-
key1: 'value1',
193-
key2: 42,
194-
nested: { prop: true },
195-
};
196-
service.saveSettings('test.complex', complexObj);
197-
expect(service.getSettings('test.complex')).toEqual(complexObj);
198-
});
199147
});
200148
});

src/app/service/settings/settings.service.ts

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export class SettingsService {
1919
private readonly KEY_MAX_LEVEL = 'settings.maxlevel';
2020
private readonly KEY_LABELS = 'settings.labels';
2121

22-
// Legacy keys for migration
23-
private readonly LEGACY_KEY_TEAM_LABEL = 'settings.teamLabel';
24-
private readonly LEGACY_KEY_GROUP_LABEL = 'settings.groupLabel';
25-
2622
private dateformat: string | null = null;
2723
private maxLevel: number | null = null;
2824
private _labels: Labels | null = null;
@@ -32,9 +28,7 @@ export class SettingsService {
3228
private _metaGroup: LabelParts = { singular: 'Group', plural: 'Groups' };
3329
private _metaInitialized: boolean = false;
3430

35-
constructor() {
36-
this.migrateOldKeys();
37-
}
31+
constructor() {}
3832

3933
// --- Meta initialization ---
4034

@@ -53,6 +47,16 @@ export class SettingsService {
5347
this._labels = null;
5448
}
5549

50+
// --- Meta defaults (for placeholder display) ---
51+
52+
getMetaTeamLabel(): LabelParts {
53+
return this._metaTeam;
54+
}
55+
56+
getMetaGroupLabel(): LabelParts {
57+
return this._metaGroup;
58+
}
59+
5660
// --- Label parsing ---
5761

5862
/**
@@ -85,45 +89,6 @@ export class SettingsService {
8589
return `${singular}|${plural}`;
8690
}
8791

88-
// --- Migration ---
89-
90-
/**
91-
* Migrate old separate localStorage keys into the consolidated settings.labels key.
92-
*/
93-
migrateOldKeys(): void {
94-
const oldTeam = localStorage.getItem(this.LEGACY_KEY_TEAM_LABEL);
95-
const oldGroup = localStorage.getItem(this.LEGACY_KEY_GROUP_LABEL);
96-
97-
if (oldTeam !== null || oldGroup !== null) {
98-
// Only migrate if we don't already have the consolidated key
99-
const existing = localStorage.getItem(this.KEY_LABELS);
100-
if (existing === null) {
101-
const labels: Labels = { team: '', group: '' };
102-
if (oldTeam !== null) {
103-
try {
104-
labels.team = JSON.parse(oldTeam);
105-
} catch {
106-
labels.team = oldTeam;
107-
}
108-
}
109-
if (oldGroup !== null) {
110-
try {
111-
labels.group = JSON.parse(oldGroup);
112-
} catch {
113-
labels.group = oldGroup;
114-
}
115-
}
116-
// Only save if there's actually custom data
117-
if (labels.team || labels.group) {
118-
localStorage.setItem(this.KEY_LABELS, JSON.stringify(labels));
119-
}
120-
}
121-
// Remove legacy keys
122-
localStorage.removeItem(this.LEGACY_KEY_TEAM_LABEL);
123-
localStorage.removeItem(this.LEGACY_KEY_GROUP_LABEL);
124-
}
125-
}
126-
12792
// --- Labels (consolidated) ---
12893

12994
private loadLabels(): Labels {

0 commit comments

Comments
 (0)