Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
1. Add support for record_type
2. Add ID, first name, last name to error message to help user in troubleshooting
3. Bump to SDK 0.2.2 and use new alerts

Resolves #13 and #15
  • Loading branch information
jweisman committed Nov 17, 2020
1 parent b2ad504 commit f50bd31
Show file tree
Hide file tree
Showing 8 changed files with 718 additions and 648 deletions.
2 changes: 1 addition & 1 deletion cloudapp/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppService } from './app.service';

@Component({
selector: 'app-root',
template: '<router-outlet></router-outlet>'
template: '<cloudapp-alert></cloudapp-alert><router-outlet></router-outlet>'
})
export class AppComponent {

Expand Down
13 changes: 2 additions & 11 deletions cloudapp/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { MaterialModule, getTranslateModule, LazyTranslateLoader } from '@exlibris/exl-cloudapp-angular-lib';
import { MaterialModule, getTranslateModule, LazyTranslateLoader, AlertModule } from '@exlibris/exl-cloudapp-angular-lib';
import { ReactiveFormsModule } from '@angular/forms';
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
import { NgxDropzoneModule } from 'ngx-dropzone';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ToastrModule } from 'ngx-toastr';
import { TranslateICUParser } from 'ngx-translate-parser-plural-select';
import { TranslateModule, TranslateLoader, TranslateParser } from '@ngx-translate/core';

Expand All @@ -16,13 +14,6 @@ import { MainComponent, MainDialog } from './main/main.component';
import { SettingsComponent } from './settings/settings.component';
import { ProfileComponent } from './settings/profile/profile.component'

export function getToastrModule() {
return ToastrModule.forRoot({
positionClass: 'toast-top-right',
timeOut: 2000
});
}

export function getTranslateModuleWithICU() {
return TranslateModule.forRoot({
loader: {
Expand Down Expand Up @@ -51,7 +42,7 @@ export function getToastrModule() {
HttpClientModule,
ReactiveFormsModule,
getTranslateModule(),
getToastrModule(),
AlertModule,
BrowserAnimationsModule,
NgxDropzoneModule,
getTranslateModuleWithICU(),
Expand Down
19 changes: 15 additions & 4 deletions cloudapp/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export class MainComponent implements OnInit {
let users: any[] = result.data.map(row => this.mapUser(row)), results = [];
/* Generation of primary ID is not thread safe; only parallelize if primary ID is supplied */
const parallel = users.every(user=>user.primary_id) ? MAX_PARALLEL_CALLS : 1;
const dialogRef = this.dialog.open(MainDialog, { data: { count: users.length, type: this.selectedProfile.profileType }});
const dialogRef = this.dialog.open(MainDialog, {
data: { count: users.length, type: this.selectedProfile.profileType },
autoFocus: false
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.running = true;
Expand Down Expand Up @@ -114,7 +117,7 @@ export class MainComponent implements OnInit {
url: '/users',
method: HttpMethod.POST,
requestBody: user
}).pipe(catchError(e=>of(e)));
}).pipe(catchError(e=>of(this.handleError(e, user))));
case 'UPDATE':
return this.restService.call(`/users/${user.primary_id}`).pipe(
catchError(e=>{
Expand All @@ -130,7 +133,7 @@ export class MainComponent implements OnInit {
url: '/users',
method: HttpMethod.POST,
requestBody: user
}).pipe(catchError(e=>of(e)));
});
} else {
delete original['user_role']; // Don't update roles
return this.restService.call({
Expand All @@ -140,7 +143,7 @@ export class MainComponent implements OnInit {
})
}
}),
catchError(e=>of(e))
catchError(e=>of(this.handleError(e, user)))
)
case 'DELETE':
return this.restService.call({
Expand All @@ -154,6 +157,14 @@ export class MainComponent implements OnInit {

}

private handleError(e: RestErrorResponse, user: any) {
const props = ['primary_id', 'last_name', 'first_name'].map(p=>user[p]);
if (user) {
e.message = e.message + ` (${props.join(', ')})`
}
return e;
}

private mapUser = (user) => {
const arrayIndicator = new RegExp(/\[\d*\]/);
/* Map CSV to user fields */
Expand Down
1 change: 1 addition & 0 deletions cloudapp/src/app/settings/profile/profile.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h3 translate>Profile.FieldMapping</h3>
<mat-option value="pref_middle_name">Prefrerred Middle Name</mat-option>
<mat-option value="pref_last_name">Preferred Last Name</mat-option>
<mat-option value="external_id">External System Code</mat-option>
<mat-option value="record_type.value">Record Type</mat-option>
</mat-select>
</mat-form-field>
</mat-cell>
Expand Down
9 changes: 4 additions & 5 deletions cloudapp/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormArray, FormGroup, AbstractControl, FormControl } from '@angular/forms';
import { Utils } from '../utilities';
import { CloudAppSettingsService } from '@exlibris/exl-cloudapp-angular-lib';
import { CloudAppSettingsService, AlertService } from '@exlibris/exl-cloudapp-angular-lib';
import { TranslateService } from '@ngx-translate/core';
import { ToastrService } from 'ngx-toastr';

@Component({
selector: 'app-settings',
Expand All @@ -20,7 +19,7 @@ export class SettingsComponent implements OnInit {
private fb: FormBuilder,
private settingsService: CloudAppSettingsService,
private translate: TranslateService,
private toastr: ToastrService
private alert: AlertService
) { }

ngOnInit() {
Expand Down Expand Up @@ -65,12 +64,12 @@ export class SettingsComponent implements OnInit {
if (!this.form.valid) return;
this.saving = true;
this.settingsService.set(this.form.value).subscribe( response => {
this.toastr.success(this.translate.instant('Settings.Saved'));
this.alert.success(this.translate.instant('Settings.Saved'));
this.form.markAsPristine();
this.submitted = false;
this.saving = false;
},
err => this.toastr.error(err.message));
err => this.alert.error(err.message));
}

reset() {
Expand Down
2 changes: 1 addition & 1 deletion cloudapp/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"Title": "Settings",
"Profiles": "Profiles",
"Saving": "Saving...",
"Saved": "Saved",
"Saved": "Settings successfully saved.",
"Back": "Back",
"ProfileName": "Profile name",
"ConfirmDeleteProfile": "Are you sure you want to delete this profile?",
Expand Down
Loading

0 comments on commit f50bd31

Please sign in to comment.