Skip to content

Commit

Permalink
Added generic modal windows for both stats and settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyhill21 committed Mar 4, 2020
1 parent 60e6ad0 commit 3ce5749
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 10 deletions.
5 changes: 4 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"src/assets"
],
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": []
Expand Down Expand Up @@ -93,6 +94,7 @@
"src/assets"
],
"styles": [
"./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"src/styles.scss"
],
"scripts": []
Expand Down Expand Up @@ -124,6 +126,7 @@
}
}
}
}},
}
},
"defaultProject": "TaskFocus"
}
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"private": true,
"dependencies": {
"@angular/animations": "~8.2.2",
"@angular/cdk": "~8.2.3",
"@angular/common": "~8.2.2",
"@angular/compiler": "~8.2.2",
"@angular/core": "~8.2.2",
"@angular/forms": "~8.2.2",
"@angular/material": "^8.2.3",
"@angular/platform-browser": "~8.2.2",
"@angular/platform-browser-dynamic": "~8.2.2",
"@angular/router": "~8.2.2",
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<h1 class="app-title">TaskFocus</h1>
</div>
<div class="nav-buttons">
<a href="" class="nav-button"> Settings </a>
<a href="" class="nav-button"> Statistics </a>
<a href="" class="nav-button"> Login </a>
<a [routerLink]="" class="nav-button" (click)="openSettingsModal()"> Settings </a>
<a [routerLink]="" class="nav-button" (click)="openStatisticsModal()"> Statistics </a>
<a [routerLink]="" class="nav-button"> Login </a>
</div>
</div>

Expand Down
27 changes: 24 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { StatsModalComponent } from './stats-modal/stats-modal.component';
import { SettingsModalComponent } from './settings-modal/settings-modal.component';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-root',
Expand All @@ -23,11 +26,29 @@ export class AppComponent {
timeLeft: number = this.focusLength * 60;
interval;

public constructor(private titleService: Title ) { }
public constructor(private titleService: Title, public matDialog: MatDialog) { }

public setTitle(newTitle: string) {
openStatisticsModal() {
var dialogConfig = this.initDialogConfig(350, 600);
this.matDialog.open(StatsModalComponent, dialogConfig);
}
openSettingsModal() {
var dialogConfig = this.initDialogConfig(350, 600);
this.matDialog.open(SettingsModalComponent, dialogConfig);
}

this.titleService.setTitle( newTitle );
initDialogConfig(height: Number, width: Number): MatDialogConfig {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true; // The user can't close the dialog by clicking outside its body
dialogConfig.id = "modal-component";
dialogConfig.height = height.toString() + "px";
dialogConfig.width = width.toString() + "px";
return dialogConfig;
}


public setTitle(newTitle: string) {
this.titleService.setTitle( newTitle );
}
focusSelected() {
this.focus = true;
Expand Down
18 changes: 15 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { SettingsModalComponent } from './settings-modal/settings-modal.component';
import { StatsModalComponent } from './stats-modal/stats-modal.component';

@NgModule({
declarations: [
AppComponent
AppComponent,
SettingsModalComponent,
StatsModalComponent
],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
BrowserAnimationsModule,
MatButtonModule,
MatDialogModule
],
providers: [],
bootstrap: [AppComponent]
bootstrap: [AppComponent],
entryComponents: [StatsModalComponent, SettingsModalComponent]
})
export class AppModule { }
12 changes: 12 additions & 0 deletions src/app/settings-modal/settings-modal.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="modal-content-wrapper">
<header id="modal-header">
<h1 id="modal-title">HEADER TEXT!</h1>
</header>
<section id="modal-body">
<p>BODY SECTION TEXT</p>
</section>
<footer id="modal-footer">
<button mat-raised-button id="modal-action-button" (click)="actionFunction()">BUTTON 1</button>
<button mat-raised-button id="modal-cancel-button" (click)="closeModal()">BUTTON 2</button>
</footer>
</div>
47 changes: 47 additions & 0 deletions src/app/settings-modal/settings-modal.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
html,
body {
height: 100%;
}

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
display: grid;
justify-items: center;
align-items: center;
background-color: #3a3a3a;
}

/* Overwrite the styles of the mat-dialog-container element globally, but only for those
that have an id of `modal-component` */
/* https://stackoverflow.com/a/48689004/9263761 */
mat-dialog-container#modal-component {
border: 3px solid #262626;
border-radius: 11px;
background-color: #1a1a1a;
}

#modal-content-wrapper {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: repeat(1fr, 3);
}

#modal-title {
font-size: 22px;
}

#modal-footer {
justify-self: right;
align-self: center;
}

#modal-action-button {
margin-right: 30px;
background-color: #3b3b3b;
}

#modal-cancel-button {
background-color: #4e4e4e;
}
25 changes: 25 additions & 0 deletions src/app/settings-modal/settings-modal.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { SettingsModalComponent } from './settings-modal.component';

describe('SettingsModalComponent', () => {
let component: SettingsModalComponent;
let fixture: ComponentFixture<SettingsModalComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SettingsModalComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(SettingsModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
30 changes: 30 additions & 0 deletions src/app/settings-modal/settings-modal.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, OnInit } from '@angular/core';

import { MatDialogRef } from '@angular/material/dialog';

@Component({
selector: 'app-settings-modal',
templateUrl: './settings-modal.component.html',
styleUrls: ['./settings-modal.component.scss']
})

export class SettingsModalComponent implements OnInit {

constructor(public dialogRef: MatDialogRef<SettingsModalComponent>) { }

ngOnInit() {
}
// When the user clicks the action button a.k.a. the logout button in the\
// modal, show an alert and followed by the closing of the modal
actionFunction() {
alert("You have logged out.");
this.closeModal();
}

// If the user clicks the cancel button a.k.a. the go back button, then\
// just close the modal
closeModal() {
this.dialogRef.close();
}

}
12 changes: 12 additions & 0 deletions src/app/stats-modal/stats-modal.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="modal-content-wrapper">
<header id="modal-header">
<h1 id="modal-title">HEADER TEXT!</h1>
</header>
<section id="modal-body">
<p>BODY SECTION TEXT</p>
</section>
<footer id="modal-footer">
<button mat-raised-button id="modal-action-button" (click)="actionFunction()">BUTTON 1</button>
<button mat-raised-button id="modal-cancel-button" (click)="closeModal()">BUTTON 2</button>
</footer>
</div>
47 changes: 47 additions & 0 deletions src/app/stats-modal/stats-modal.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
html,
body {
height: 100%;
}

body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
display: grid;
justify-items: center;
align-items: center;
background-color: #3a3a3a;
}

/* Overwrite the styles of the mat-dialog-container element globally, but only for those
that have an id of `modal-component` */
/* https://stackoverflow.com/a/48689004/9263761 */
mat-dialog-container#modal-component {
border: 3px solid #262626;
border-radius: 11px;
background-color: #1a1a1a;
}

#modal-content-wrapper {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: repeat(1fr, 3);
}

#modal-title {
font-size: 22px;
}

#modal-footer {
justify-self: right;
align-self: center;
}

#modal-action-button {
margin-right: 30px;
background-color: #3b3b3b;
}

#modal-cancel-button {
background-color: #4e4e4e;
}
25 changes: 25 additions & 0 deletions src/app/stats-modal/stats-modal.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { StatsModalComponent } from './stats-modal.component';

describe('StatsModalComponent', () => {
let component: StatsModalComponent;
let fixture: ComponentFixture<StatsModalComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StatsModalComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(StatsModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions src/app/stats-modal/stats-modal.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';

@Component({
selector: 'app-stats-modal',
templateUrl: './stats-modal.component.html',
styleUrls: ['./stats-modal.component.scss']
})
export class StatsModalComponent implements OnInit {

constructor(public dialogRef: MatDialogRef<StatsModalComponent>) { }

ngOnInit() {
}

// When the user clicks the action button a.k.a. the logout button in the\
// modal, show an alert and followed by the closing of the modal
actionFunction() {
alert("You have logged out.");
this.closeModal();
}

// If the user clicks the cancel button a.k.a. the go back button, then\
// just close the modal
closeModal() {
this.dialogRef.close();
}
}
Loading

0 comments on commit 3ce5749

Please sign in to comment.