-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from ljw980105/drinks-admin-menu
add-drinks-component
- Loading branch information
Showing
14 changed files
with
1,599 additions
and
3,003 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/app/admin-panel/edit-drinks/edit-drinks.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<h3 class="mohave admin-header">DRINKS</h3> | ||
|
||
<div class="admin-section flex"> | ||
<div class="left-half"> | ||
<table *ngIf="dataReady" class="helvetica"> | ||
<tr> | ||
<th>Name</th> | ||
<th>Ingredients</th> | ||
</tr> | ||
<tr *ngFor="let drink of drinks"> | ||
<td>{{drink.name}}</td> | ||
<td>{{drink.description}}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
<div class="right-half"> | ||
<h3 class="helvetica">JSON Spec</h3> | ||
<div> | ||
<pre class="minimal-top-spacing"> | ||
<code [highlight]="jsonSpec"></code> | ||
</pre> | ||
</div> | ||
|
||
<div> | ||
<h3 class="helvetica">Submit JSON</h3> | ||
<label> | ||
<textarea class="admin-textarea" [(ngModel)]="textAreaContents"></textarea> | ||
</label> | ||
<button (click)="submitViaJSON()">Submit</button> | ||
</div> | ||
</div> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
src/app/admin-panel/edit-drinks/edit-drinks.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
table { | ||
margin: 0 0 1% 1%; | ||
width: 98%; | ||
border-collapse: collapse; | ||
} | ||
|
||
td, th { | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
$tableGray: rgb(240, 240, 240); | ||
|
||
th { | ||
background-color: $tableGray; | ||
} | ||
|
||
tr:nth-child(odd) { | ||
background-color: $tableGray; | ||
} | ||
|
||
textarea { | ||
width: 400px; | ||
height: 200px; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/app/admin-panel/edit-drinks/edit-drinks.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { EditDrinksComponent } from './edit-drinks.component'; | ||
|
||
describe('EditDrinksComponent', () => { | ||
let component: EditDrinksComponent; | ||
let fixture: ComponentFixture<EditDrinksComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ EditDrinksComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(EditDrinksComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {MemoryManagerComponent} from '../../shared/memory-manager/memory-manager.component'; | ||
import {ApiService} from '../../services/api.service'; | ||
import {AdminHelperService} from '../admin-helper.service'; | ||
import {takeUntil} from 'rxjs/operators'; | ||
import {NameAndDescription} from '../../models/pure-models/NameAndDescription'; | ||
|
||
@Component({ | ||
selector: 'app-edit-drinks', | ||
templateUrl: './edit-drinks.component.html', | ||
styleUrls: ['./edit-drinks.component.scss'] | ||
}) | ||
export class EditDrinksComponent extends MemoryManagerComponent implements OnInit { | ||
|
||
jsonSpec = ` | ||
{ | ||
"drinks": [ | ||
{ | ||
"name": "...", | ||
"description": "..." | ||
}, | ||
... | ||
] | ||
} | ||
`; | ||
textAreaContents = ''; | ||
drinks: NameAndDescription[]; | ||
dataReady = false; | ||
|
||
constructor(public apiService: ApiService, private helperService: AdminHelperService) { | ||
super(); | ||
} | ||
|
||
|
||
|
||
ngOnInit(): void { | ||
this.getDrinks(); | ||
} | ||
|
||
getDrinks() { | ||
this.apiService.getDrinks() | ||
.pipe(takeUntil(this.unsubscribe$)) | ||
.subscribe((drinks) => { | ||
this.drinks = drinks.drinks; | ||
this.dataReady = true; | ||
}); | ||
} | ||
|
||
submitViaJSON() { | ||
this.helperService.showActivityIndicatorWithObservable( | ||
this.apiService.addDrinks(this.textAreaContents), () => this.getDrinks() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {NameAndDescription} from './NameAndDescription'; | ||
|
||
export class Drinks { | ||
constructor(public drinks: NameAndDescription[]) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters