Adds discard on dataset editor (1st commit)
This commit is contained in:
parent
bcdaf144d2
commit
e7db9ee664
|
@ -55,7 +55,7 @@
|
|||
<div class="heading">1.5 {{'DATASET-EDITOR.FIELDS.PROFILE' | translate}}*</div>
|
||||
<div class="profile-form">
|
||||
<mat-form-field>
|
||||
<mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" [formControl]="formGroup.get('profile')">
|
||||
<mat-select placeholder="{{'DATASET-WIZARD.FIRST-STEP.PROFILE'| translate}}" [required]="true" [compareWith]="compareWith" formControlName="profile">
|
||||
<mat-option *ngFor="let profile of availableProfiles" [value]="profile">
|
||||
{{profile.label}}
|
||||
</mat-option>
|
||||
|
|
|
@ -76,8 +76,8 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="col-auto form">
|
||||
<app-dataset-editor-component [hidden]="this.step !== 0" [formGroup]="formGroup" [dmpId]="formGroup.get('dmp').value.id" [availableProfiles]="formGroup.get('dmp').value.profiles" (formChanged)="formChanged()"></app-dataset-editor-component>
|
||||
<app-dataset-description-form [hidden]="this.step === 0" *ngIf="formGroup && datasetWizardModel && datasetWizardModel.datasetProfileDefinition" [form]="this.formGroup.get('datasetProfileDefinition')" [visibilityRules]="datasetWizardModel.datasetProfileDefinition.rules" [datasetProfileId]="formGroup.get('profile').value" [linkToScroll]="linkToScroll"></app-dataset-description-form>
|
||||
<app-dataset-editor-component [hidden]="this.step !== 0" [formGroup]="formGroup" [dmpId]="formGroup.get('dmp').value.id" [availableProfiles]="formGroup.get('dmp').value.profiles"></app-dataset-editor-component>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -41,12 +41,7 @@ import { isNullOrUndefined } from 'util';
|
|||
import { AuthService } from '@app/core/services/auth/auth.service';
|
||||
import { environment } from 'environments/environment';
|
||||
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
||||
|
||||
|
||||
enum SaveType {
|
||||
close = 0,
|
||||
addNew = 1
|
||||
}
|
||||
import { SaveType } from '@app/core/common/enum/save-type';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dataset-wizard-component',
|
||||
|
@ -59,6 +54,9 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
viewOnly = false;
|
||||
editMode = false;
|
||||
publicMode = false;
|
||||
hasChanges = false;
|
||||
isDiscarded = false;
|
||||
formGroupRawValue: any;
|
||||
|
||||
DatasetStatus = DatasetStatus;
|
||||
dmpAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
|
||||
|
@ -156,6 +154,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
]
|
||||
}]);
|
||||
this.formGroup = this.datasetWizardModel.buildForm();
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
||||
if (this.datasetWizardModel.status === DatasetStatus.Finalized || lockStatus) {
|
||||
this.formGroup.disable();
|
||||
|
@ -198,6 +197,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
setTimeout(() => {
|
||||
this.datasetWizardModel.dmp = data;
|
||||
this.formGroup = this.datasetWizardModel.buildForm();
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
||||
this.formGroup.get('dmp').disable();
|
||||
|
||||
|
@ -241,6 +241,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
setTimeout(() => {
|
||||
this.datasetWizardModel.dmp = data;
|
||||
this.formGroup.get('dmp').setValue(this.datasetWizardModel.dmp);
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
|
||||
this.loadDatasetProfiles();
|
||||
this.breadCrumbs = observableOf([
|
||||
|
@ -294,6 +295,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
if (data) {
|
||||
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
||||
this.formGroup = this.datasetWizardModel.buildForm();
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
this.formGroup.disable();
|
||||
this.viewOnly = true;
|
||||
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
||||
|
@ -310,6 +312,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(data => {
|
||||
this.datasetWizardModel = new DatasetWizardEditorModel().fromModel(data);
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
|
||||
this.needsUpdate();
|
||||
this.breadCrumbs = observableOf([
|
||||
{
|
||||
|
@ -342,6 +346,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
} else {
|
||||
this.datasetWizardModel = new DatasetWizardEditorModel();
|
||||
this.formGroup = this.datasetWizardModel.buildForm();
|
||||
this.formGroupRawValue = JSON.parse(JSON.stringify(this.formGroup.getRawValue()));
|
||||
|
||||
this.editMode = this.datasetWizardModel.status === DatasetStatus.Draft;
|
||||
if (this.datasetWizardModel.status === DatasetStatus.Finalized) {
|
||||
this.formGroup.disable();
|
||||
|
@ -359,6 +365,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
}
|
||||
|
||||
!this.isNew ? this.maxStep = 1 : this.maxStep = 0;
|
||||
|
||||
// this.route.params
|
||||
// .pipe(takeUntil(this._destroyed))
|
||||
// .subscribe((params: Params) => {
|
||||
|
@ -376,7 +383,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
this.formGroup.get('profile').valueChanges
|
||||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(x => {
|
||||
this.datasetProfileValueChanged(x.id);
|
||||
console.log(x)
|
||||
if (x) { this.datasetProfileValueChanged(x.id); }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -424,6 +432,12 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
}
|
||||
}
|
||||
|
||||
public formChanged() {
|
||||
if (!this.isDiscarded) {
|
||||
this.hasChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
public cancel(): void {
|
||||
if (!isNullOrUndefined(this.lock)) {
|
||||
this.lockService.unlockTarget(this.datasetWizardModel.id).pipe(takeUntil(this._destroyed)).subscribe(
|
||||
|
@ -814,11 +828,23 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
|
|||
}
|
||||
|
||||
isDirty() {
|
||||
|
||||
return this.formGroup.dirty && this.hasChanges; // do we need this.formGroup.dirty
|
||||
}
|
||||
|
||||
discardChanges() {
|
||||
|
||||
this.isDiscarded = true;
|
||||
this.hasChanges = false;
|
||||
if (this.isNew) {
|
||||
console.log(this.formGroup);
|
||||
Object.keys(this.formGroup['controls']).forEach((key: string) => {
|
||||
if (key !== 'dmp') {
|
||||
this.formGroup.get(key).reset();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.formGroup.patchValue(JSON.parse(JSON.stringify(this.formGroupRawValue)));
|
||||
}
|
||||
this.isDiscarded = false;
|
||||
}
|
||||
|
||||
addDataset(dmpId: string) {
|
||||
|
|
Loading…
Reference in New Issue