Skip to content

Commit

Permalink
handle errors better.
Browse files Browse the repository at this point in the history
add dashboard location validation.
  • Loading branch information
AnalogJ committed Aug 25, 2023
1 parent 9a4dcf9 commit 3498632
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
20 changes: 19 additions & 1 deletion frontend/src/app/pages/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,34 @@ <h4 class="modal-title" id="modal-basic-title">Profile update</h4>
id="remoteDashboardLocation"
class="form-control"
placeholder="https://gist.github.com/..."
pattern="https://gist.github.com/.*"
name="remoteDashboardLocation"
type="url"
[(ngModel)]="dashboardLocation"
#dashboardLocationField="ngModel"
/>
</div>
</div>

<div *ngIf="dashboardLocationField.invalid && (dashboardLocationField.dirty || dashboardLocationField.touched)"
class="alert alert-danger">

<div *ngIf="dashboardLocationField.errors?.['required']">
Dashboard Location is required.
</div>
<div *ngIf="dashboardLocationField.errors?.['pattern']">
Dashboard Location must be a valid github gist url.
</div>
</div>

<div *ngIf="dashboardLocationError" class="alert alert-danger">
{{dashboardLocationError}}
</div>

</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" [disabled]="addDashboardLoading" (click)="addDashboardLocation()">Add</button>
<button type="button" class="btn btn-outline-indigo" [disabled]="addDashboardLoading" (click)="addDashboardLocation()">Add</button>
</div>
</ng-template>

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class DashboardComponent implements OnInit {
//dashboardLocation is used to store the location of the dashboard that we're trying to add
addDashboardLoading: boolean = false
dashboardLocation: string = ''
dashboardLocationError: string = ''

@ViewChild(GridstackComponent) gridComp?: GridstackComponent;

Expand Down Expand Up @@ -140,6 +141,7 @@ export class DashboardComponent implements OnInit {

public addDashboardLocation(){
this.addDashboardLoading = true
this.dashboardLocationError = ''
this.fastenApi.addDashboardLocation(this.dashboardLocation).subscribe((result) => {
console.log("Added Remote Dashboard", result)
this.addDashboardLoading = false
Expand All @@ -151,7 +153,9 @@ export class DashboardComponent implements OnInit {
}, (error) => {
console.log("Error Adding Remote Dashboard", error)
this.addDashboardLoading = false
},
this.dashboardLocationError = error

},
() => {
console.log("Completed Adding Remote Dashboard")
this.addDashboardLoading = false
Expand Down

0 comments on commit 3498632

Please sign in to comment.