Skip to content

Commit 895e6ce

Browse files
Bugfix/designer default values (#436)
* retain default values on save * set initial designModule name to module's name
1 parent 8a151a2 commit 895e6ce

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

src/app/designs/components/design-modules/design-modules.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h3>Modules</h3>
2222
*ngIf="showModuleList$ | async"
2323
[modules]="modules$ | async"
2424
[isEditing]="true"
25-
(getModule)="getModuleFn($event.id)"
25+
(getModule)="getModuleFn($event.id, $event.name)"
2626
></cas-module-list>
2727

2828
<div fxLayout="row wrap" fxLayoutGap="1em grid" *ngIf="!showModuleList">

src/app/designs/components/design-modules/design-modules.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ export class DesignModulesComponent implements OnInit {
6060
return item.id;
6161
}
6262

63-
getModuleFn(moduleId: string) {
63+
getModuleFn(moduleId: string, moduleName: string) {
6464
this.designModulesService
6565
.create({
6666
designId: this.designId,
6767
moduleId: moduleId,
68-
name: 'New Module',
68+
name: moduleName.replace(/ /g, '_'),
6969
values: [],
7070
})
7171
.subscribe(() => {

src/app/editor/component/module-list/module-list.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export class ModuleListComponent implements OnInit {
3838

3939
@Output()
4040
insertModule: EventEmitter<CreateSnippetCommand> = new EventEmitter<CreateSnippetCommand>();
41-
@Output() getModule: EventEmitter<{ id: string }> = new EventEmitter();
41+
@Output() getModule: EventEmitter<{ id: string; name: string }> =
42+
new EventEmitter();
4243
private _modules: Module[];
4344
_selectedModule: Module;
4445
code: string;
@@ -81,7 +82,10 @@ export class ModuleListComponent implements OnInit {
8182
}
8283

8384
selectModuleFn(module) {
84-
this.getModule.emit({ id: module.id });
85+
this.getModule.emit({
86+
id: module.id,
87+
name: module.name,
88+
});
8589
}
8690
private updateDataSource() {
8791
this.dataSource.data = this._modules;

src/app/editor/component/module-variables/module-variables.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export class ModuleVariablesComponent implements OnInit, OnChanges {
130130
moduleField.value = variable.defaultValue;
131131
}
132132

133+
moduleField.defaultValue = variable.defaultValue;
133134
this.moduleFields.push(moduleField);
134135
});
135136
}
@@ -139,13 +140,13 @@ export class ModuleVariablesComponent implements OnInit, OnChanges {
139140
const value = this.values.find((x) => x.name == moduleField.name);
140141
const formControl = this.form?.get(['values', moduleField.name]);
141142

142-
moduleField.value = value ? value.value : null;
143+
moduleField.value = value ? value.value : moduleField.defaultValue;
143144

144145
if (formControl != null) {
145146
// if the update was from us or if we didn't change this formControl,
146147
// update to the new value
147148
if (this.isSaving || !formControl.dirty) {
148-
formControl.setValue(value ? value.value : null);
149+
formControl.setValue(value ? value.value : moduleField.defaultValue);
149150
} else {
150151
// if the update is different than what we changed it to, mark it as changed
151152
// if the update is the same as what we changed it to, mark the control as pristine

src/app/editor/component/module-variables/module-variables.models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class ModuleField {
2323
type = 'string';
2424
previousValue = this.value;
2525
changed = false;
26+
defaultValue: string;
2627

2728
isMultiLine() {
2829
return !(

0 commit comments

Comments
 (0)