Skip to content

Commit

Permalink
Merge pull request #151 from severinbeauvais/master
Browse files Browse the repository at this point in the history
PRC-304, PRC-242, PRC-280: see commit details
  • Loading branch information
severinbeauvais authored Apr 9, 2018
2 parents 67f69e3 + d9ba021 commit d601c35
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 261 deletions.
16 changes: 8 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
// Ref: https://github.com/Microsoft/vscode-chrome-debug
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200/#",
"webRoot": "${workspaceRoot}"
},
// {
// "name": "Launch Chrome",
// "type": "chrome",
// "request": "launch",
// "url": "http://localhost:4200/admin/#",
// "webRoot": "${workspaceRoot}"
// },
{
"name": "Attach Chrome",
"type": "chrome",
"request": "attach",
"url": "http://localhost:4200",
"url": "http://localhost:4200/admin",
"webRoot": "${workspaceRoot}",
"port": 9222
// },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ <h3>Disposition</h3>

<!-- APPLICATION BUTTONS -->
<div class="section-form-btns mt-3 mb-3">
<button class="btn btn-success" type="button" (click)="saveApplication()" title="Save application">
<button class="btn btn-success" type="button" *ngIf="application._id === '0'" (click)="createApplication()" title="Create application">
<i class="material-icons">save</i>
<span>Create</span>
</button>
<button class="btn btn-success" type="button" *ngIf="application._id !== '0'" (click)="saveApplication()" title="Save application">
<i class="material-icons">save</i>
<span>Save</span>
</button>
Expand Down Expand Up @@ -350,7 +354,7 @@ <h4 class="mb-3">Interest ID: {{shape.properties.INTRID_SID}}</h4>
</main>

<aside class="col-lg-4">
<app-application-aside></app-application-aside>
<app-application-aside [application]="application"></app-application-aside>
</aside>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
// check for unsaved changes before closing (or refreshing) current tab/window
@HostListener('window:beforeunload', ['$event'])
handleBeforeUnload(event) {
// display browser alert if needed
if (!this.allowDeactivate && this.applicationForm.dirty) {
event.returnValue = true;
}
Expand All @@ -79,8 +80,8 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
message: 'Click OK to discard your changes or Cancel to return to the application.'
}, {
backdropColor: 'rgba(0, 0, 0, 0.5)'
}
);
})
.takeUntil(this.ngUnsubscribe);
}

ngOnInit() {
Expand All @@ -95,7 +96,9 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
.subscribe(
(data: { application: Application }) => {
if (data.application) {
this.application = data.application;
// make a (deep) copy of the in-memory application so we don't change it
// this allows us to abort editing
this.application = _.cloneDeep(data.application);

if (!this.application.publishDate) {
this.application.publishDate = new Date();
Expand Down Expand Up @@ -225,7 +228,50 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
);
}

saveApplication() {
// create new application
public createApplication() {
if (this.applicationForm.invalid) {
this.dialogService.addDialog(ConfirmComponent,
{
title: 'Cannot Create Application',
message: 'Please check for required fields or errors.',
okOnly: true
}, {
backdropColor: 'rgba(0, 0, 0, 0.5)'
})
.takeUntil(this.ngUnsubscribe);
} else if (!this.isDispositionValid()) {
this.dialogService.addDialog(ConfirmComponent,
{
title: 'Cannot Create Application',
message: 'Please check that disposition data (basic information) has been successfully loaded.',
okOnly: true
}, {
backdropColor: 'rgba(0, 0, 0, 0.5)'
})
.takeUntil(this.ngUnsubscribe);
} else {
// adjust for current tz
this.application.publishDate = moment(this.application.publishDate).format();

this.applicationService.add(this.application)
.takeUntil(this.ngUnsubscribe)
.subscribe(
application => {
this.showMessage(false, 'Application created!');
// reload cached data
this.reloadData(application._id);
},
error => {
console.log('error =', error);
this.showMessage(true, 'Error creating application');
}
);
}
}

// save current application
public saveApplication() {
if (this.applicationForm.invalid) {
this.dialogService.addDialog(ConfirmComponent,
{
Expand All @@ -247,11 +293,22 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
})
.takeUntil(this.ngUnsubscribe);
} else {
if (this.application._id === '0') {
this.internalAddApplication();
} else {
this.internalSaveApplication();
}
// adjust for current tz
this.application.publishDate = moment(this.application.publishDate).format();

this.applicationService.save(this.application)
.takeUntil(this.ngUnsubscribe)
.subscribe(
application => {
this.showMessage(false, 'Application saved!');
// reload cached data
this.reloadData(application._id);
},
error => {
console.log('error =', error);
this.showMessage(true, 'Error saving application');
}
);
}
}

Expand All @@ -260,54 +317,34 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
&& this.application.features[0].properties.DISPOSITION_TRANSACTION_SID === this.application.tantalisID);
}

private internalAddApplication() {
// adjust for current tz
this.application.publishDate = moment(this.application.publishDate).format();

// create new application
// then reload the page
this.applicationService.addApplication(this.application)
.takeUntil(this.ngUnsubscribe)
.subscribe(
application => {
this.allowDeactivate = true;
this.router.navigate(['/a', application._id, 'edit']);
},
error => {
console.log('error =', error);
this.showMessage(true, 'Error adding application');
}
);
}

private internalSaveApplication() {
// adjust for current tz
this.application.publishDate = moment(this.application.publishDate).format();

// save current application
this.applicationService.save(this.application)
.takeUntil(this.ngUnsubscribe)
.subscribe(
() => {
this.showMessage(false, 'Application saved!');
// reload cached app data
this.applicationService.getById(this.application._id, true)
.takeUntil(this.ngUnsubscribe)
.subscribe(() => this.applicationForm.form.markAsPristine());
},
error => {
console.log('error =', error);
this.showMessage(true, 'Error saving application');
}
);
public resetApplication() {
if (this.applicationForm.pristine) {
this.reloadData(this.application._id);
} else {
this.dialogService.addDialog(ConfirmComponent,
{
title: 'Confirm Reset',
message: 'Click OK to discard your changes or Cancel to return to the application.'
}, {
backdropColor: 'rgba(0, 0, 0, 0.5)'
})
.takeUntil(this.ngUnsubscribe)
.subscribe(isConfirmed => {
if (isConfirmed) {
this.reloadData(this.application._id);
}
});
}
}

resetApplication() {
// reload cached app data
this.applicationService.getById(this.application._id, true)
private reloadData(id: string) {
// force-reload app data
this.applicationService.getById(id, true)
.takeUntil(this.ngUnsubscribe)
.subscribe(application => {
this.application = application;
// make a (deep) copy of the in-memory application so we don't change it
// this allows us to abort editing
this.application = _.cloneDeep(application);
this.applicationForm.form.markAsPristine();
});
}
Expand Down Expand Up @@ -539,6 +576,6 @@ export class ApplicationAddEditComponent implements OnInit, OnDestroy {
this.error = isError;
this.showMsg = true;
this.status = msg;
setTimeout(() => this.showMsg = false, 3000);
setTimeout(() => this.showMsg = false, 2000);
}
}
Loading

0 comments on commit d601c35

Please sign in to comment.