ichec-angular-core 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ import { ActivatedRoute, UrlSerializer, createUrlTreeFromSnapshot, RouterModule,
11
11
  import { MatDialogRef, MAT_DIALOG_DATA, MatDialogTitle, MatDialogContent, MatDialogActions, MatDialogClose, MatDialog } from '@angular/material/dialog';
12
12
  import * as i2 from '@angular/material/button';
13
13
  import { MatButtonModule } from '@angular/material/button';
14
+ import { MatSnackBar } from '@angular/material/snack-bar';
14
15
  import * as i1 from '@angular/material/table';
15
16
  import { MatTable, MatTableModule } from '@angular/material/table';
16
17
  import * as i2$1 from '@angular/material/form-field';
@@ -967,6 +968,7 @@ class EditView {
967
968
  _userService = inject(UserService);
968
969
  form;
969
970
  itemService;
971
+ snackBar = inject(MatSnackBar);
970
972
  uploadedFiles = [];
971
973
  constructor(itemService, form) {
972
974
  this.itemService = itemService;
@@ -1026,14 +1028,28 @@ class EditView {
1026
1028
  }
1027
1029
  postItem() {
1028
1030
  this.submitting.set(true);
1029
- this.itemService.postItem(this.createItem()).subscribe(item => this.saveFiles(item));
1031
+ this.itemService.postItem(this.createItem()).subscribe({
1032
+ next: (item) => this.saveFiles(item),
1033
+ error: (e) => this.onPostError(e)
1034
+ });
1035
+ }
1036
+ onPostError(e) {
1037
+ console.log(e);
1030
1038
  }
1031
1039
  putItem(item) {
1032
1040
  this.submitting.set(true);
1033
- this.itemService.putItem(this.updateItem(item)).subscribe(item => this.saveFiles(item));
1041
+ this.itemService.putItem(this.updateItem(item)).subscribe({
1042
+ next: (item) => this.saveFiles(item),
1043
+ error: (e) => this.onPutError(e)
1044
+ });
1045
+ }
1046
+ onPutError(e) {
1047
+ console.log(e);
1034
1048
  }
1035
1049
  saveFiles(item) {
1050
+ this.item.set(item);
1036
1051
  const next_file = this.getNextFileForUpload();
1052
+ console.log(next_file, this.form);
1037
1053
  if (next_file) {
1038
1054
  this.saveFile(item, next_file);
1039
1055
  }
@@ -1042,14 +1058,33 @@ class EditView {
1042
1058
  }
1043
1059
  }
1044
1060
  saveFile(item, record) {
1045
- this.uploadedFiles.push(record.name);
1046
1061
  if (record.file) {
1047
- this.itemService.putFile(item.id, record.name, record.file).subscribe(item => this.saveFiles(item));
1062
+ this.itemService.putFile(item.id, record.name, record.file).subscribe({
1063
+ next: (item) => { this.uploadedFiles.push(record.name); this.saveFiles(item); },
1064
+ error: (e) => this.onPutFileError(e)
1065
+ });
1048
1066
  }
1049
1067
  else {
1068
+ this.uploadedFiles.push(record.name);
1050
1069
  this.saveFiles(item);
1051
1070
  }
1052
1071
  }
1072
+ onPutFileError(e) {
1073
+ const item = this.item();
1074
+ if (item) {
1075
+ // Since the item is already created on the backend
1076
+ // switch to 'edit mode' for a file resubmit attempt
1077
+ this.form.setValue(item);
1078
+ this.createMode.set(false);
1079
+ }
1080
+ console.log(e);
1081
+ this.onPutFileErrorSnackbar(e);
1082
+ }
1083
+ onPutFileErrorSnackbar(_e) {
1084
+ this.snackBar.open("File upload failed - please try submitting again", "Dismiss", { verticalPosition: "bottom",
1085
+ duration: 5000
1086
+ });
1087
+ }
1053
1088
  getNextFileForUpload() {
1054
1089
  for (const key of this.fileKeys) {
1055
1090
  if (!this.uploadedFiles.includes(key)) {
@@ -1087,6 +1122,12 @@ class EditView {
1087
1122
  this.submitting.set(false);
1088
1123
  this.uploadedFiles = [];
1089
1124
  this.item.set(item);
1125
+ this.postItemUpdated();
1126
+ }
1127
+ postItemUpdated() {
1128
+ this.snackBar.open(this.itemService.typename + " updated ok", "Dismiss", { verticalPosition: "top",
1129
+ duration: 5000
1130
+ });
1090
1131
  this.goBack();
1091
1132
  }
1092
1133
  onOptions(options) {