Skip to content
Snippets Groups Projects
Commit 7efd40c1 authored by Scott Berg's avatar Scott Berg
Browse files

Add prompt modal. Minor style updates

parent f1b77cce
No related branches found
No related tags found
No related merge requests found
Pipeline #33069 passed
...@@ -58,6 +58,7 @@ import { ...@@ -58,6 +58,7 @@ import {
ModifyPlanDialogComponent, ModifyPlanDialogComponent,
DialogMode, DialogMode,
} from './dialogs/modify-plan-dialog/modify-plan-dialog.component'; } from './dialogs/modify-plan-dialog/modify-plan-dialog.component';
import { PromptDialogComponent } from '@app/shared/dialogs/prompt-dialog/prompt-dialog.component';
import { import {
ToggleAcademicYear, ToggleAcademicYear,
CloseCourseSearch, CloseCourseSearch,
...@@ -157,15 +158,23 @@ export class DegreePlannerComponent implements OnInit { ...@@ -157,15 +158,23 @@ export class DegreePlannerComponent implements OnInit {
} }
public onRenamePlanClick(currentPlan: DegreePlan) { public onRenamePlanClick(currentPlan: DegreePlan) {
const data: DialogMode = { mode: 'rename', oldName: currentPlan.name }; // const data: DialogMode = { mode: 'rename', oldName: currentPlan.name };
this.dialog this.dialog
.open(ModifyPlanDialogComponent, { data }) .open(PromptDialogComponent, {
data: {
initalValue: currentPlan.name,
title: 'Rename Degree Plan',
confirmText: 'Save',
inputName: 'Plan name',
},
})
.afterClosed() .afterClosed()
.subscribe((result: { name: string } | undefined) => { .subscribe((result: { confirmed: boolean; value: string }) => {
if (result !== undefined && typeof result.name === 'string') { const { confirmed, value } = result;
const newName = result.name;
if (confirmed) {
const { roadmapId } = currentPlan; const { roadmapId } = currentPlan;
const action = new ChangePlanName({ roadmapId, newName }); const action = new ChangePlanName({ roadmapId, newName: value });
this.store.dispatch(action); this.store.dispatch(action);
} }
}); });
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RemoveCourseConfirmDialogComponent } from './remove-course-confirm-dialog.component'; import { ConfirmDialogComponent } from './confirm-dialog.component';
describe('RemoveCourseConfirmDialogComponent', () => { describe('ConfirmDialogComponent', () => {
let component: RemoveCourseConfirmDialogComponent; let component: ConfirmDialogComponent;
let fixture: ComponentFixture<RemoveCourseConfirmDialogComponent>; let fixture: ComponentFixture<ConfirmDialogComponent>;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [RemoveCourseConfirmDialogComponent], declarations: [ConfirmDialogComponent],
}).compileComponents(); }).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(RemoveCourseConfirmDialogComponent); fixture = TestBed.createComponent(ConfirmDialogComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
}); });
......
...@@ -4,7 +4,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; ...@@ -4,7 +4,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
@Component({ @Component({
selector: 'cse-confirm-dialog', selector: 'cse-confirm-dialog',
templateUrl: './confirm-dialog.component.html', templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.scss'], styleUrls: ['../dialogs.scss'],
}) })
export class ConfirmDialogComponent { export class ConfirmDialogComponent {
title: string; title: string;
...@@ -17,8 +17,6 @@ export class ConfirmDialogComponent { ...@@ -17,8 +17,6 @@ export class ConfirmDialogComponent {
private dialogRef: MatDialogRef<ConfirmDialogComponent>, private dialogRef: MatDialogRef<ConfirmDialogComponent>,
@Inject(MAT_DIALOG_DATA) data: any, @Inject(MAT_DIALOG_DATA) data: any,
) { ) {
// this.course = data.course;
// this.type = data.type;
const { const {
title = 'Are you sure?', title = 'Are you sure?',
text = 'Are you sure you want to do this?', text = 'Are you sure you want to do this?',
......
.dialog-text {
color: #7e7e7e;
font-size: 16px;
margin-top: 1.2em;
}
<mat-toolbar class="dialog-toolbar">
<h1 class="dialog-toolbar-title">{{title}}</h1>
<button mat-button mat-dialog-close class="close-btn" aria-label="Close note dialog"><i class="material-icons">clear</i></button>
</mat-toolbar>
<mat-dialog-content id="confirmation-dialog" class="mat-typography dialog-with-toolbar">
<mat-dialog-content>
<p class="dialog-text" *ngFor="let line of text">{{line}}</p>
<form [formGroup]='inputForm' (ngSubmit)="confirm()" fxLayout="column" fxLayoutAlign="space-around none" style="padding: 12px 22px;">
<mat-form-field>
<input matInput [placeholder]="inputName" formControlName="value">
</mat-form-field>
</form>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button (click)="cancel()" aria-label="Cancel">{{cancelText}}</button>
<button mat-button [color]="confirmColor" mat-raised-button (click)="confirm()" aria-label="Confirm">{{confirmText}}</button>
</mat-dialog-actions>
</mat-dialog-content>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PromptDialogComponent } from './prompt-dialog.component';
describe('PromptDialogComponent', () => {
let component: PromptDialogComponent;
let fixture: ComponentFixture<PromptDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PromptDialogComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PromptDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
// Form imports
import {
FormBuilder,
FormGroup,
FormControl,
Validators,
} from '@angular/forms';
@Component({
selector: 'cse-prompt-dialog',
templateUrl: './prompt-dialog.component.html',
styleUrls: ['../dialogs.scss'],
})
export class PromptDialogComponent implements OnInit {
title: string;
text: string[];
inputName: string;
placeholder?: string;
tooltip?: string;
cancelText: string;
confirmText: string;
confirmColor: string;
inputForm: FormGroup;
initalValue: string;
constructor(
private dialogRef: MatDialogRef<PromptDialogComponent>,
private fb: FormBuilder,
@Inject(MAT_DIALOG_DATA) data: any,
) {
const {
title = 'User Input Required',
text = [],
inputName = 'Data',
initalValue = '',
placeholder,
tooltip,
cancelText = 'Cancel',
confirmText = 'Confirm',
confirmColor = 'primary',
} = data;
this.title = title;
this.text = text;
this.inputName = inputName;
this.placeholder = placeholder;
this.tooltip = tooltip;
this.cancelText = cancelText;
this.confirmText = confirmText;
this.confirmColor = confirmColor;
this.initalValue = initalValue;
if (typeof text === 'string') {
this.text = [text];
}
}
ngOnInit() {
// Deafults for input form
this.inputForm = this.fb.group({
value: this.initalValue,
});
}
confirm() {
const { value } = this.inputForm.value;
this.dialogRef.close({ confirmed: true, value });
}
cancel() {
const { value } = this.inputForm.value;
this.dialogRef.close({ confirmed: false, value });
}
}
...@@ -27,6 +27,7 @@ import { MatFormFieldModule } from '@angular/material/form-field'; ...@@ -27,6 +27,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { CourseDetailsDialogComponent } from '../degree-planner/dialogs/course-details-dialog/course-details-dialog.component'; import { CourseDetailsDialogComponent } from '../degree-planner/dialogs/course-details-dialog/course-details-dialog.component';
import { ConfirmDialogComponent } from './dialogs/confirm-dialog/confirm-dialog.component'; import { ConfirmDialogComponent } from './dialogs/confirm-dialog/confirm-dialog.component';
import { PromptDialogComponent } from './dialogs/prompt-dialog/prompt-dialog.component';
const modules = [ const modules = [
CommonModule, CommonModule,
...@@ -59,12 +60,13 @@ const pipes = [ ...@@ -59,12 +60,13 @@ const pipes = [
@NgModule({ @NgModule({
imports: [modules], imports: [modules],
exports: [modules, pipes, CourseDetailsComponent], exports: [modules, pipes, CourseDetailsComponent],
entryComponents: [ConfirmDialogComponent], entryComponents: [ConfirmDialogComponent, PromptDialogComponent],
declarations: [ declarations: [
pipes, pipes,
CourseDetailsComponent, CourseDetailsComponent,
CourseDetailsDialogComponent, CourseDetailsDialogComponent,
ConfirmDialogComponent, ConfirmDialogComponent,
PromptDialogComponent,
], ],
}) })
export class SharedModule {} export class SharedModule {}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment